Skip to content

Commit

Permalink
Tpetra: Fix #2705 (don't use deprecated Kokkos::View methods)
Browse files Browse the repository at this point in the history
@trilinos/tpetra

Kokkos::View methods ptr_on_device() and dimension_N() (replace N with
0, 1, 2, ...) have been deprecated for a long time.  Kokkos has
replaced them with data() resp. extent(N).

This commit replaces all uses of the deprecated methods in Tpetra,
with their nondeprecated replacements.  This fixes #2705.
  • Loading branch information
Mark Hoemmen authored and mhoemmen committed May 9, 2018
1 parent f31e9a1 commit 1b5719c
Show file tree
Hide file tree
Showing 69 changed files with 1,285 additions and 1,285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ exampleRoutine (const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
// View, so we take a subview.
auto x_1d = Kokkos::subview (x_2d, Kokkos::ALL (), 0);

// x_data.dimension_0 () may be longer than the number of local
// x_data.extent (0) may be longer than the number of local
// rows in the Vector, so be sure to ask the Vector for its
// dimensions, rather than the ArrayRCP.
const size_t localLength = x.getLocalLength ();
Expand Down Expand Up @@ -210,7 +210,7 @@ exampleRoutine (const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
x.modify<Kokkos::HostSpace> ();

// Use local indices to access the entries of x_data.
// x_data.dimension_0 () may be longer than the number of local
// x_data.extent (0) may be longer than the number of local
// rows in the Vector, so be sure to ask the Vector for its
// dimensions.
const size_t localLength = x.getLocalLength ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ localApplyBlockNoTrans (Tpetra::Experimental::BlockCrsMatrix<Scalar, LO, GO, Nod
const LO meshCol = indHost[absBlkOff];

auto A_cur_1d = Kokkos::subview (val, absBlkOff * blockSize * blockSize);
little_blk_type A_cur (A_cur_1d.ptr_on_device (), blockSize, blockSize);
little_blk_type A_cur (A_cur_1d.data (), blockSize, blockSize);
auto X_cur = X.getLocalBlock (meshCol, j);

GEMV (alpha, A_cur, X_cur, Y_lcl); // Y_lcl += alpha*A_cur*X_cur
Expand Down Expand Up @@ -555,7 +555,7 @@ getTpetraBlockCrsMatrix (Teuchos::FancyOStream& out,
block_type curBlk ("curBlk", blkSize, blkSize);
// We only use this if filling with random values.
Kokkos::View<SC*, Kokkos::LayoutRight, host_device_type,
Kokkos::MemoryUnmanaged> curBlk_1d (curBlk.ptr_on_device (),
Kokkos::MemoryUnmanaged> curBlk_1d (curBlk.data (),
blkSize * blkSize);
if (! opts.runTest) {
// For benchmarks, we don't care so much about the values; we just
Expand All @@ -582,7 +582,7 @@ getTpetraBlockCrsMatrix (Teuchos::FancyOStream& out,
}
const LO lclColInd = lclColInds[k];
const LO err =
A->replaceLocalValues (lclRow, &lclColInd, curBlk.ptr_on_device (), 1);
A->replaceLocalValues (lclRow, &lclColInd, curBlk.data (), 1);
TEUCHOS_TEST_FOR_EXCEPTION(err != 1, std::logic_error, "Bug");
}
}
Expand Down
70 changes: 35 additions & 35 deletions packages/tpetra/core/ext/TpetraExt_MatrixMatrix_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ makeColMapAndConvertGids(GlobalOrdinal ncols,
typedef global_col_inds_array GView;
typedef col_inds_array LView;
//Functors (explained in the procedural code below)
auto nentries = gids.dimension_0();
auto nentries = gids.extent(0);
//each entry of entryUnion is 0 unless there is a local entry in that column (then it is 1)
ByteView entryUnion("entry union", ncols);
UnionEntries<ByteView, GView> ue(entryUnion, gids);
Expand All @@ -544,13 +544,13 @@ makeColMapAndConvertGids(GlobalOrdinal ncols,
::Tpetra::Details::computeOffsetsFromCounts<decltype(gtol), decltype(entryUnion)>(gtol, entryUnion);
//convert gids to local ids and put them in lids (implicitly sorted as long as input gids is sorted per row)
ConvertGlobalToLocal<LView, GView> cgtl(gtol, gids, lids);
Kokkos::parallel_for("Tpetra_MatrixMatrix_convertGlobalToLocal", range_type(0, gids.dimension_0()), cgtl);
Kokkos::parallel_for("Tpetra_MatrixMatrix_convertGlobalToLocal", range_type(0, gids.extent(0)), cgtl);
//build local set of GIDs for constructing column map - the last entry in gtol is the total number of local cols
execution_space::fence();
GView colmap("column map", gtol(ncols));
size_t localIter = 0;
execution_space::fence();
for(size_t i = 0; i < entryUnion.dimension_0(); i++)
for(size_t i = 0; i < entryUnion.extent(0); i++)
{
if(entryUnion(i) != 0)
{
Expand Down Expand Up @@ -758,7 +758,7 @@ add (const Scalar& alpha,
AddKern::convertToGlobalAndAdd(
Aprime->getLocalMatrix(), alpha, Bprime->getLocalMatrix(), beta, Acolmap, Bcolmap,
CRangeMap->getMinGlobalIndex(), Aprime->getGlobalNumCols(), vals, rowptrs, globalColinds);
colinds = col_inds_array("C colinds", globalColinds.dimension_0());
colinds = col_inds_array("C colinds", globalColinds.extent(0));
if (debug) {
std::ostringstream os;
os << "Proc " << A.getMap ()->getComm ()->getRank () << ": "
Expand Down Expand Up @@ -819,7 +819,7 @@ add (const Scalar& alpha,
#ifdef HAVE_TPETRA_MMM_TIMINGS
MM = rcp(new TimeMonitor(*TimeMonitor::getNewTimer(prefix_mmm + std::string("Tpetra::Crs constructor"))));
#endif
// C = rcp(new crs_matrix_type(CrowMap, CcolMap, rowptrs, colinds, vals, params));
// C = rcp(new crs_matrix_type(CrowMap, CcolMap, rowptrs, colinds, vals, params));
C.replaceColMap(CcolMap);
C.setAllValues(rowptrs,colinds,vals);
#ifdef HAVE_TPETRA_MMM_TIMINGS
Expand Down Expand Up @@ -1191,8 +1191,8 @@ addSorted(
typename AddDetails::AddKernels<SC, LO, GO, NO>::col_inds_array& Ccolinds)
{
using Teuchos::TimeMonitor;
TEUCHOS_TEST_FOR_EXCEPTION(Arowptrs.dimension_0() != Browptrs.dimension_0(), std::runtime_error, "Can't add matrices with different numbers of rows.");
auto nrows = Arowptrs.dimension_0() - 1;
TEUCHOS_TEST_FOR_EXCEPTION(Arowptrs.extent(0) != Browptrs.extent(0), std::runtime_error, "Can't add matrices with different numbers of rows.");
auto nrows = Arowptrs.extent(0) - 1;
Crowptrs = row_ptrs_array("C row ptrs", nrows + 1);
typedef KokkosKernels::Experimental::KokkosKernelsHandle<typename col_inds_array::size_type, LO, impl_scalar_type,
execution_space, memory_space, memory_space> KKH;
Expand Down Expand Up @@ -1236,8 +1236,8 @@ addUnsorted(
typename AddDetails::AddKernels<SC, LO, GO, NO>::col_inds_array& Ccolinds)
{
using Teuchos::TimeMonitor;
TEUCHOS_TEST_FOR_EXCEPTION(Arowptrs.dimension_0() != Browptrs.dimension_0(), std::runtime_error, "Can't add matrices with different numbers of rows.");
auto nrows = Arowptrs.dimension_0() - 1;
TEUCHOS_TEST_FOR_EXCEPTION(Arowptrs.extent(0) != Browptrs.extent(0), std::runtime_error, "Can't add matrices with different numbers of rows.");
auto nrows = Arowptrs.extent(0) - 1;
Crowptrs = row_ptrs_array("C row ptrs", nrows + 1);
typedef AddDetails::AddKernels<SC, LO, GO, NO> AddKern;
typedef KokkosKernels::Experimental::KokkosKernelsHandle<typename col_inds_array::size_type, LO, AddKern::impl_scalar_type,
Expand Down Expand Up @@ -1314,15 +1314,15 @@ convertToGlobalAndAdd(
const col_inds_array& Bcolinds = B.graph.entries;
auto Arowptrs = A.graph.row_map;
auto Browptrs = B.graph.row_map;
global_col_inds_array AcolindsConverted("A colinds (converted)", Acolinds.dimension_0());
global_col_inds_array BcolindsConverted("B colinds (converted)", Bcolinds.dimension_0());
global_col_inds_array AcolindsConverted("A colinds (converted)", Acolinds.extent(0));
global_col_inds_array BcolindsConverted("B colinds (converted)", Bcolinds.extent(0));
#ifdef HAVE_TPETRA_MMM_TIMINGS
auto MM = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("TpetraExt::MatrixMatrix::add() diff col map kernel: " + std::string("column map conversion"))));
#endif
ConvertColIndsFunctor<GO, col_inds_array, global_col_inds_array, local_map_type> convertA(minGlobalCol, Acolinds, AcolindsConverted, AcolMap);
Kokkos::parallel_for("Tpetra_MatrixMatrix_convertColIndsA", range_type(0, Acolinds.dimension_0()), convertA);
Kokkos::parallel_for("Tpetra_MatrixMatrix_convertColIndsA", range_type(0, Acolinds.extent(0)), convertA);
ConvertColIndsFunctor<GO, col_inds_array, global_col_inds_array, local_map_type> convertB(minGlobalCol, Bcolinds, BcolindsConverted, BcolMap);
Kokkos::parallel_for("Tpetra_MatrixMatrix_convertColIndsB", range_type(0, Bcolinds.dimension_0()), convertB);
Kokkos::parallel_for("Tpetra_MatrixMatrix_convertColIndsB", range_type(0, Bcolinds.extent(0)), convertB);
typedef KokkosKernels::Experimental::KokkosKernelsHandle<typename col_inds_array::size_type, GO, impl_scalar_type,
execution_space, memory_space, memory_space> KKH;
KKH handle;
Expand All @@ -1331,7 +1331,7 @@ convertToGlobalAndAdd(
#ifdef HAVE_TPETRA_MMM_TIMINGS
MM = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("TpetraExt::MatrixMatrix::add() diff col map kernel: unsorted symbolic")));
#endif
auto nrows = Arowptrs.dimension_0() - 1;
auto nrows = Arowptrs.extent(0) - 1;
Crowptrs = row_ptrs_array("C row ptrs", nrows + 1);
KokkosSparse::Experimental::spadd_symbolic
<KKH, typename row_ptrs_array::const_type, typename global_col_inds_array::const_type, typename row_ptrs_array::const_type, typename global_col_inds_array::const_type, row_ptrs_array, global_col_inds_array>
Expand Down Expand Up @@ -1868,7 +1868,7 @@ void mult_A_B_newmatrix(
});

}

// Replace the column map
//
// mfh 27 Sep 2016: We do this because C was originally created
Expand Down Expand Up @@ -1904,7 +1904,7 @@ void mult_A_B_newmatrix(
LO I_LID = Irowmap_local.getLocalElement(aidx);
targetMapToOrigRow(i) = LO_INVALID;
targetMapToImportRow(i) = I_LID;

}
});

Expand Down Expand Up @@ -2199,11 +2199,11 @@ void mult_A_B_reuse(
Kokkos::parallel_for(range_type(0,Bview.origMatrix->getColMap()->getNodeNumElements()),KOKKOS_LAMBDA(const LO i) {
Bcol2Ccol(i) = Ccolmap_local.getLocalElement(Bcolmap_local.getGlobalElement(i));
});

if (!Bview.importMatrix.is_null()) {
TEUCHOS_TEST_FOR_EXCEPTION(!Cimport->getSourceMap()->isSameAs(*Bview.origMatrix->getDomainMap()),
std::runtime_error, "Tpetra::MMM: Import setUnion messed with the DomainMap in an unfortunate way");

Kokkos::resize(Icol2Ccol,Bview.importMatrix->getColMap()->getNodeNumElements());
Kokkos::parallel_for(range_type(0,Bview.importMatrix->getColMap()->getNodeNumElements()),KOKKOS_LAMBDA(const LO i) {
Icol2Ccol(i) = Ccolmap_local.getLocalElement(Icolmap_local.getGlobalElement(i));
Expand All @@ -2224,7 +2224,7 @@ void mult_A_B_reuse(
LO I_LID = Irowmap_local.getLocalElement(aidx);
targetMapToOrigRow(i) = LO_INVALID;
targetMapToImportRow(i) = I_LID;

}
});

Expand Down Expand Up @@ -2371,7 +2371,7 @@ void KernelWrappers<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalOrdinalViewType>
}

#ifdef HAVE_TPETRA_MMM_TIMINGS
MM2= Teuchos::null;
MM2= Teuchos::null;
MM = rcp(new TimeMonitor (*TimeMonitor::getNewTimer(prefix_mmm + std::string("MMM Reuse ESFC"))));
#endif

Expand Down Expand Up @@ -2531,7 +2531,7 @@ void jacobi_A_B_newmatrix(
LO I_LID = Irowmap_local.getLocalElement(aidx);
targetMapToOrigRow(i) = LO_INVALID;
targetMapToImportRow(i) = I_LID;

}
});

Expand Down Expand Up @@ -2845,11 +2845,11 @@ void jacobi_A_B_reuse(
Kokkos::parallel_for(range_type(0,Bview.origMatrix->getColMap()->getNodeNumElements()),KOKKOS_LAMBDA(const LO i) {
Bcol2Ccol(i) = Ccolmap_local.getLocalElement(Bcolmap_local.getGlobalElement(i));
});

if (!Bview.importMatrix.is_null()) {
TEUCHOS_TEST_FOR_EXCEPTION(!Cimport->getSourceMap()->isSameAs(*Bview.origMatrix->getDomainMap()),
std::runtime_error, "Tpetra::Jacobi: Import setUnion messed with the DomainMap in an unfortunate way");

Kokkos::resize(Icol2Ccol,Bview.importMatrix->getColMap()->getNodeNumElements());
Kokkos::parallel_for(range_type(0,Bview.importMatrix->getColMap()->getNodeNumElements()),KOKKOS_LAMBDA(const LO i) {
Icol2Ccol(i) = Ccolmap_local.getLocalElement(Icolmap_local.getGlobalElement(i));
Expand All @@ -2870,7 +2870,7 @@ void jacobi_A_B_reuse(
LO I_LID = Irowmap_local.getLocalElement(aidx);
targetMapToOrigRow(i) = LO_INVALID;
targetMapToImportRow(i) = I_LID;

}
});

Expand Down Expand Up @@ -3036,7 +3036,7 @@ void KernelWrappers2<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalOrdinalViewType
}

#ifdef HAVE_TPETRA_MMM_TIMINGS
MM2= Teuchos::null;
MM2= Teuchos::null;
MM = rcp(new TimeMonitor (*TimeMonitor::getNewTimer(prefix_mmm + std::string("Jacobi Reuse ESFC"))));
#endif

Expand Down Expand Up @@ -3226,7 +3226,7 @@ merge_matrices(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview
const LocalOrdinalViewType & Acol2Brow,
const LocalOrdinalViewType & Acol2Irow,
const LocalOrdinalViewType & Bcol2Ccol,
const LocalOrdinalViewType & Icol2Ccol,
const LocalOrdinalViewType & Icol2Ccol,
const size_t mergedNodeNumCols) {

using Teuchos::RCP;
Expand All @@ -3251,13 +3251,13 @@ merge_matrices(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview
if(Ik!=0) Iks = *Ik;
size_t merge_numrows = Ak.numCols();
lno_view_t Mrowptr("Mrowptr", merge_numrows + 1);

const LocalOrdinal LO_INVALID =Teuchos::OrdinalTraits<LocalOrdinal>::invalid();

// Use a Kokkos::parallel_scan to build the rowptr
typedef typename Node::execution_space execution_space;
typedef Kokkos::RangePolicy<execution_space, size_t> range_type;
Kokkos::parallel_scan ("Tpetra_MatrixMatrix_merge_matrices_buildRowptr", range_type (0, merge_numrows),
Kokkos::parallel_scan ("Tpetra_MatrixMatrix_merge_matrices_buildRowptr", range_type (0, merge_numrows),
KOKKOS_LAMBDA(const size_t i, size_t& update, const bool final) {
if(final) Mrowptr(i) = update;
// Get the row count
Expand All @@ -3267,16 +3267,16 @@ merge_matrices(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview
else
ct = Iks.graph.row_map(Acol2Irow(i)+1) - Iks.graph.row_map(Acol2Irow(i));
update+=ct;

if(final && i+1==merge_numrows)
Mrowptr(i+1)=update;
});

// Allocate nnz
size_t merge_nnz = ::Tpetra::Details::getEntryOnHost(Mrowptr,merge_numrows);
lno_nnz_view_t Mcolind("Mcolind",merge_nnz);
scalar_view_t Mvalues("Mvals",merge_nnz);

// Use a Kokkos::parallel_for to fill the rowptr/colind arrays
typedef Kokkos::RangePolicy<execution_space, size_t> range_type;
Kokkos::parallel_for ("Tpetra_MatrixMatrix_merg_matrices_buildColindValues", range_type (0, merge_numrows),KOKKOS_LAMBDA(const size_t i) {
Expand All @@ -3297,14 +3297,14 @@ merge_matrices(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview
}
}
});

KCRS newmat("CrsMatrix",merge_numrows,mergedNodeNumCols,merge_nnz,Mvalues,Mrowptr,Mcolind);
return newmat;
}
else {
// We don't have a Bimport (the easy case)
return Bk;
}
}
}//end merge_matrices


Expand All @@ -3319,7 +3319,7 @@ merge_matrices(CrsMatrixStruct<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Aview
//
// Must be expanded from within the Tpetra namespace!
//
namespace Tpetra {
namespace Tpetra {

#define TPETRA_MATRIXMATRIX_INSTANT(SCALAR,LO,GO,NODE) \
template \
Expand Down
Loading

0 comments on commit 1b5719c

Please sign in to comment.