Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tpetra: first step toward #9289 -- DO NOT MERGE YET #10233

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tpetra/core/ext/TpetraExt_MatrixMatrix_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ struct AddKernels
typedef typename map_type::local_map_type local_map_type;
typedef typename Kokkos::View<GlobalOrdinal*, device_type> global_col_inds_array;
typedef Kokkos::RangePolicy<execution_space> range_type;
typedef KokkosKernels::Experimental::KokkosKernelsHandle<size_t, LocalOrdinal, impl_scalar_type,
typedef KokkosKernels::Experimental::KokkosKernelsHandle<Details::DefaultTypes::offset_type, LocalOrdinal, impl_scalar_type,
execution_space, memory_space, memory_space> KKH;

/// \brief Given two matrices in CRS format, return their sum
Expand Down
2 changes: 1 addition & 1 deletion packages/tpetra/core/ext/TpetraExt_MatrixMatrix_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3285,7 +3285,7 @@ convertToGlobalAndAdd(
using Teuchos::TimeMonitor;
//Need to use a different KokkosKernelsHandle type than other versions,
//since the ordinals are now GO
using KKH_GO = KokkosKernels::Experimental::KokkosKernelsHandle<size_t, GO, impl_scalar_type,
using KKH_GO = KokkosKernels::Experimental::KokkosKernelsHandle<Details::DefaultTypes::offset_type, GO, impl_scalar_type,
typename NO::execution_space, typename NO::memory_space, typename NO::memory_space>;

const values_array Avals = A.values;
Expand Down
6 changes: 4 additions & 2 deletions packages/tpetra/core/src/Tpetra_CrsGraphTransposer_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ namespace Tpetra {
auto lclGraph = graph->getLocalGraphDevice();
auto lclGraphT = graphT->getLocalGraphDevice();

using KKH_LO = KokkosKernels::Experimental::KokkosKernelsHandle<size_t, LocalOrdinal, impl_scalar_type,
using KKH_LO = KokkosKernels::Experimental::KokkosKernelsHandle<Details::DefaultTypes::offset_type,
LocalOrdinal, impl_scalar_type,
typename Node::execution_space, typename Node::memory_space, typename Node::memory_space>;
using KKH_GO = KokkosKernels::Experimental::KokkosKernelsHandle<size_t, GlobalOrdinal, impl_scalar_type,
using KKH_GO = KokkosKernels::Experimental::KokkosKernelsHandle<Details::DefaultTypes::offset_type,
GlobalOrdinal, impl_scalar_type,
typename Node::execution_space, typename Node::memory_space, typename Node::memory_space>;

auto rowptrs = lclGraph.row_map;
Expand Down
9 changes: 5 additions & 4 deletions packages/tpetra/core/src/Tpetra_CrsGraph_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ namespace Tpetra {
//! The type of the part of the sparse graph on each MPI process.
using local_graph_device_type =
Kokkos::StaticCrsGraph<local_ordinal_type, Kokkos::LayoutLeft,
device_type, void, size_t>;
device_type, void,
Details::DefaultTypes::offset_type>;
#ifdef TPETRA_ENABLE_DEPRECATED_CODE
using local_graph_type = local_graph_device_type;
#endif
Expand Down Expand Up @@ -550,7 +551,7 @@ namespace Tpetra {
/// default values.
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const Teuchos::ArrayRCP<size_t>& rowPointers,
const Teuchos::ArrayRCP<Details::DefaultTypes::offset_type>& rowPointers,
const Teuchos::ArrayRCP<local_ordinal_type>& columnIndices,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);

Expand Down Expand Up @@ -1508,7 +1509,7 @@ namespace Tpetra {
/// \warning This method is intended for expert developer use
/// only, and should never be called by user code.
void
setAllIndices (const Teuchos::ArrayRCP<size_t> & rowPointers,
setAllIndices (const Teuchos::ArrayRCP<Details::DefaultTypes::offset_type> & rowPointers,
const Teuchos::ArrayRCP<local_ordinal_type> & columnIndices);

/// \brief Get a host view of the packed row offsets.
Expand Down Expand Up @@ -2505,7 +2506,7 @@ namespace Tpetra {
/// inexplicable test failures only on CUDA. Thus, I left it as a
/// HostMirror, which means (given Trilinos' current UVM
/// requirement) that it will be a UVM allocation.
typedef typename Kokkos::View<size_t*, Kokkos::LayoutLeft, device_type>::HostMirror num_row_entries_type;
typedef typename Kokkos::View<Details::DefaultTypes::offset_type*, Kokkos::LayoutLeft, device_type>::HostMirror num_row_entries_type;

// typedef Kokkos::View<
// size_t*,
Expand Down
10 changes: 5 additions & 5 deletions packages/tpetra/core/src/Tpetra_CrsGraph_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ namespace Tpetra {
CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
CrsGraph (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const Teuchos::ArrayRCP<size_t>& rowPointers,
const Teuchos::ArrayRCP<Details::DefaultTypes::offset_type>& rowPointers,
const Teuchos::ArrayRCP<LocalOrdinal> & columnIndices,
const Teuchos::RCP<Teuchos::ParameterList>& params) :
dist_object_type (rowMap)
Expand Down Expand Up @@ -3220,14 +3220,14 @@ namespace Tpetra {
template <class LocalOrdinal, class GlobalOrdinal, class Node>
void
CrsGraph<LocalOrdinal, GlobalOrdinal, Node>::
setAllIndices (const Teuchos::ArrayRCP<size_t>& rowPointers,
setAllIndices (const Teuchos::ArrayRCP<Details::DefaultTypes::offset_type>& rowPointers,
const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices)
{
using Kokkos::View;
typedef typename local_graph_device_type::row_map_type row_map_type;
typedef typename row_map_type::array_layout layout_type;
typedef typename row_map_type::non_const_value_type row_offset_type;
typedef View<size_t*, layout_type , Kokkos::HostSpace,
typedef View<Details::DefaultTypes::offset_type*, layout_type , Kokkos::HostSpace,
Kokkos::MemoryUnmanaged> input_view_type;
typedef typename row_map_type::non_const_type nc_row_map_type;

Expand Down Expand Up @@ -3262,7 +3262,7 @@ namespace Tpetra {
// FIXME (mfh 24 Mar 2015) If CUDA UVM, running in the host's
// execution space would avoid the double copy.
//
View<size_t*, layout_type, device_type> ptr_st ("Tpetra::CrsGraph::ptr", size);
View<Details::DefaultTypes::offset_type*, layout_type, device_type> ptr_st ("Tpetra::CrsGraph::ptr", size);
Kokkos::deep_copy (ptr_st, ptr_in);
// Copy on device (casting from size_t to row_offset_type,
// with bounds checking if necessary) to ptr_rot. This
Expand Down Expand Up @@ -7659,7 +7659,7 @@ namespace Tpetra {
size_t N = BaseRowMap->getLocalNumElements();

// Allocations
ArrayRCP<size_t> CSR_rowptr(N+1);
ArrayRCP<Details::DefaultTypes::offset_type> CSR_rowptr(N+1);
ArrayRCP<GO> CSR_colind_GID;
ArrayRCP<LO> CSR_colind_LID;
CSR_colind_GID.resize(mynnz);
Expand Down
4 changes: 2 additions & 2 deletions packages/tpetra/core/src/Tpetra_CrsMatrix_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ namespace Tpetra {
/// default values.
CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const Teuchos::ArrayRCP<size_t>& rowPointers,
const Teuchos::ArrayRCP<Details::DefaultTypes::offset_type>& rowPointers,
const Teuchos::ArrayRCP<LocalOrdinal>& columnIndices,
const Teuchos::ArrayRCP<Scalar>& values,
const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
Expand Down Expand Up @@ -1919,7 +1919,7 @@ namespace Tpetra {
/// shallow copy. Any method that changes the matrix's values
/// may then change this.
void
setAllValues (const Teuchos::ArrayRCP<size_t>& ptr,
setAllValues (const Teuchos::ArrayRCP<Details::DefaultTypes::offset_type>& ptr,
const Teuchos::ArrayRCP<LocalOrdinal>& ind,
const Teuchos::ArrayRCP<Scalar>& val);

Expand Down
14 changes: 8 additions & 6 deletions packages/tpetra/core/src/Tpetra_CrsMatrix_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ namespace Tpetra {
CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
CrsMatrix (const Teuchos::RCP<const map_type>& rowMap,
const Teuchos::RCP<const map_type>& colMap,
const Teuchos::ArrayRCP<size_t>& ptr,
const Teuchos::ArrayRCP<Details::DefaultTypes::offset_type>& ptr,
const Teuchos::ArrayRCP<LocalOrdinal>& ind,
const Teuchos::ArrayRCP<Scalar>& val,
const Teuchos::RCP<Teuchos::ParameterList>& params) :
Expand Down Expand Up @@ -4001,7 +4001,7 @@ CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
void
CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
setAllValues (const Teuchos::ArrayRCP<size_t>& ptr,
setAllValues (const Teuchos::ArrayRCP<Details::DefaultTypes::offset_type>& ptr,
const Teuchos::ArrayRCP<LocalOrdinal>& ind,
const Teuchos::ArrayRCP<Scalar>& val)
{
Expand All @@ -4019,7 +4019,7 @@ CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
// copy. We need to make a deep copy anyway so that Kokkos can
// own the memory. Regardless, ptrIn gets the copy.
typename row_map_type::non_const_type ptrNative ("ptr", ptr.size ());
Kokkos::View<const size_t*,
Kokkos::View<const Details::DefaultTypes::offset_type*,
typename row_map_type::array_layout,
Kokkos::HostSpace,
Kokkos::MemoryUnmanaged> ptrSizeT (ptr.getRawPtr (), ptr.size ());
Expand Down Expand Up @@ -5566,10 +5566,12 @@ CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
if(nrows != 0)
maxRowImbalance = getLocalMaxNumRowEntries() - (getLocalNumEntries() / nrows);

if(size_t(maxRowImbalance) >= Tpetra::Details::Behavior::rowImbalanceThreshold())
if(size_t(maxRowImbalance) >= Tpetra::Details::Behavior::rowImbalanceThreshold()) {
matrix_lcl->applyImbalancedRows (X_lcl, Y_lcl, mode, alpha, beta);
else
}
else {
matrix_lcl->apply (X_lcl, Y_lcl, mode, alpha, beta);
}
}

template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
Expand Down Expand Up @@ -8947,7 +8949,7 @@ CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
size_t N = BaseRowMap->getLocalNumElements ();

// Allocations
ArrayRCP<size_t> CSR_rowptr(N+1);
ArrayRCP<Details::DefaultTypes::offset_type> CSR_rowptr(N+1);
ArrayRCP<GO> CSR_colind_GID;
ArrayRCP<LO> CSR_colind_LID;
ArrayRCP<Scalar> CSR_vals;
Expand Down
6 changes: 6 additions & 0 deletions packages/tpetra/core/src/Tpetra_Details_DefaultTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ namespace DefaultTypes {
#error "Tpetra: No global ordinal types in the set {int, long long, long, unsigned long, unsigned} have been enabled."
#endif

//! Default offset type
using offset_type = size_t; // For #9289, change this line to local_ordinal_type
// On 2/22/22, Tpetra would compile and pass tests
// with offset_type = local_ordinal_type
// (albeit with lots of unsigned vs signed compiler warnings)

/// \typedef execution_space
/// \brief Default Tpetra execution space and Node type.
#if defined(HAVE_TPETRA_DEFAULTNODE_SYCLWRAPPERNODE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class GetGraphDiagOffsets {
typedef ::Kokkos::StaticCrsGraph<LO,
::Kokkos::LayoutLeft,
device_type,
void, size_t> local_graph_device_type;
void,
Details::DefaultTypes::offset_type>
local_graph_device_type;
typedef ::Tpetra::Details::LocalMap<LO, GO, device_type> local_map_type;
typedef ::Kokkos::View<const typename local_graph_device_type::size_type*,
::Kokkos::LayoutLeft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace Impl {
template<class LO,
class GO,
class DeviceType,
class OffsetType = size_t>
class OffsetType = Details::DefaultTypes::offset_type>
class GetGraphOffRankOffsets {
public:
typedef typename DeviceType::device_type device_type;
Expand All @@ -86,7 +86,9 @@ class GetGraphOffRankOffsets {
typedef ::Kokkos::StaticCrsGraph<LO,
::Kokkos::LayoutLeft,
device_type,
void, size_t> local_graph_type;
void,
Details::DefaultTypes::offset_type>
local_graph_type;
typedef ::Tpetra::Details::LocalMap<LO, GO, device_type> local_map_type;
typedef ::Kokkos::View<const typename local_graph_type::size_type*,
::Kokkos::LayoutLeft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ KokkosSparse::CrsMatrix<
LO,
typename NT::device_type,
void,
size_t>
Details::DefaultTypes::offset_type>
localDeepCopyLocallyIndexedRowMatrix
(const RowMatrix<SC, LO, GO, NT>& A,
const char label[]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ KokkosSparse::CrsMatrix<
LO,
typename NT::device_type,
void,
size_t>
Details::DefaultTypes::offset_type>
localDeepCopyLocallyIndexedRowMatrix
(const RowMatrix<SC, LO, GO, NT>& A,
const char label[])
Expand Down Expand Up @@ -98,7 +98,8 @@ localDeepCopyLocallyIndexedRowMatrix
using Kokkos::WithoutInitializing;
using IST = typename Kokkos::ArithTraits<SC>::val_type;
using local_matrix_device_type = KokkosSparse::CrsMatrix<
IST, LO, typename NT::device_type, void, size_t>;
IST, LO, typename NT::device_type, void,
Details::DefaultTypes::offset_type>;
using local_graph_device_type =
typename local_matrix_device_type::staticcrsgraph_type;
using inds_type = typename local_graph_device_type::entries_type;
Expand Down Expand Up @@ -170,7 +171,7 @@ localDeepCopyLocallyIndexedRowMatrix
namespace Details { \
template KokkosSparse::CrsMatrix< \
Kokkos::ArithTraits<SC>::val_type, \
LO, NT::device_type, void, size_t> \
LO, NT::device_type, void, Details::DefaultTypes::offset_type> \
localDeepCopyLocallyIndexedRowMatrix<SC, LO, GO, NT> \
(const RowMatrix<SC, LO, GO, NT>& A, \
const char label[]); \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ struct LocalRowOffsetsResult {
private:
using local_graph_device_type =
typename KokkosSparse::CrsMatrix<
double, int, typename NT::device_type, void, size_t>::
double, int, typename NT::device_type, void,
Details::DefaultTypes::offset_type>::
staticcrsgraph_type;
public:
using offsets_type =
Expand Down
18 changes: 9 additions & 9 deletions packages/tpetra/core/src/Tpetra_Details_residual.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void localResidual(const CrsMatrix<SC,LO,GO,NO> & A,
const MultiVector<SC,LO,GO,NO> & X_colmap,
const MultiVector<SC,LO,GO,NO> & B,
MultiVector<SC,LO,GO,NO> & R,
const Kokkos::View<const size_t*, typename NO::device_type>& offsets,
const typename CrsMatrix<SC,LO,GO,NO>::row_ptrs_device_view_type & offsets,
const MultiVector<SC,LO,GO,NO> * X_domainmap=nullptr) {
using Tpetra::Details::ProfilingRegion;
using Teuchos::NO_TRANS;
Expand All @@ -287,7 +287,7 @@ void localResidual(const CrsMatrix<SC,LO,GO,NO> & A,
using local_matrix_device_type = typename CrsMatrix<SC,LO,GO,NO>::local_matrix_device_type;
using local_view_device_type = typename MultiVector<SC,LO,GO,NO>::dual_view_type::t_dev::non_const_type;
using const_local_view_device_type = typename MultiVector<SC,LO,GO,NO>::dual_view_type::t_dev::const_type;
using offset_type = Kokkos::View<const size_t*, typename NO::device_type>;
using offset_type = Kokkos::View<const Details::DefaultTypes::offset_type*, typename NO::device_type>;

local_matrix_device_type A_lcl = A.getLocalMatrixDevice ();
const_local_view_device_type X_colmap_lcl = X_colmap.getLocalViewDevice(Access::ReadOnly);
Expand Down Expand Up @@ -434,7 +434,7 @@ void localResidualWithCommCompOverlap(const CrsMatrix<SC,LO,GO,NO> & A,
MultiVector<SC,LO,GO,NO> & X_colmap,
const MultiVector<SC,LO,GO,NO> & B,
MultiVector<SC,LO,GO,NO> & R,
const Kokkos::View<const size_t*, typename NO::device_type>& offsets,
const typename CrsMatrix<SC,LO,GO,NO>::row_ptrs_device_view_type & offsets,
const MultiVector<SC,LO,GO,NO> & X_domainmap) {
using Tpetra::Details::ProfilingRegion;
using Teuchos::NO_TRANS;
Expand All @@ -446,7 +446,7 @@ void localResidualWithCommCompOverlap(const CrsMatrix<SC,LO,GO,NO> & A,
using local_matrix_device_type = typename CrsMatrix<SC,LO,GO,NO>::local_matrix_device_type;
using local_view_device_type = typename MultiVector<SC,LO,GO,NO>::dual_view_type::t_dev::non_const_type;
using const_local_view_device_type = typename MultiVector<SC,LO,GO,NO>::dual_view_type::t_dev::const_type;
using offset_type = Kokkos::View<const size_t*, typename NO::device_type>;
using offset_type = Kokkos::View<const Details::DefaultTypes::offset_type*, typename NO::device_type>;

local_matrix_device_type A_lcl = A.getLocalMatrixDevice ();
const_local_view_device_type X_colmap_lcl = X_colmap.getLocalViewDevice(Access::ReadOnly);
Expand Down Expand Up @@ -725,9 +725,9 @@ void residual(const Operator<SC,LO,GO,NO> & Aop,
if ( ! importer.is_null ())
X_colMap->endImport (X_in, *importer, INSERT, restrictedMode);
if (restrictedMode && !importer.is_null ())
localResidual (A, *X_colMap, *B_rowMap, *R_rowMap, offsets, &X_in);
localResidual<SC,LO,GO,NO> (A, *X_colMap, *B_rowMap, *R_rowMap, offsets, &X_in);
else
localResidual (A, *X_colMap, *B_rowMap, *R_rowMap, offsets);
localResidual<SC,LO,GO,NO> (A, *X_colMap, *B_rowMap, *R_rowMap, offsets);

{
ProfilingRegion regionExport ("Tpetra::CrsMatrix::residual: R Export");
Expand All @@ -740,15 +740,15 @@ void residual(const Operator<SC,LO,GO,NO> & Aop,

if (restrictedMode)
if (overlapCommunicationAndComputation) {
localResidualWithCommCompOverlap (A, *X_colMap, *B_rowMap, *R_rowMap, offsets, X_in);
localResidualWithCommCompOverlap<SC,LO,GO,NO> (A, *X_colMap, *B_rowMap, *R_rowMap, offsets, X_in);
} else {
X_colMap->endImport (X_in, *importer, INSERT, restrictedMode);
localResidual (A, *X_colMap, *B_rowMap, *R_rowMap, offsets, &X_in);
localResidual<SC,LO,GO,NO> (A, *X_colMap, *B_rowMap, *R_rowMap, offsets, &X_in);
}
else {
if ( ! importer.is_null ())
X_colMap->endImport (X_in, *importer, INSERT, restrictedMode);
localResidual (A, *X_colMap, *B_rowMap, *R_rowMap, offsets);
localResidual<SC,LO,GO,NO> (A, *X_colMap, *B_rowMap, *R_rowMap, offsets);
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ unpackAndCombineIntoCrsArrays(
size_t TargetNumRows,
size_t TargetNumNonzeros,
const int MyTargetPID,
const Teuchos::ArrayView<size_t>& CRS_rowptr,
const Teuchos::ArrayView<Details::DefaultTypes::offset_type>& CRS_rowptr,
const Teuchos::ArrayView<GO>& CRS_colind,
const Teuchos::ArrayView<const int>& SourcePids,
Teuchos::Array<int>& TargetPids);
Expand Down
Loading