Skip to content

Commit

Permalink
Teuchos: Purge calls to deprecated Kokkos::View methods
Browse files Browse the repository at this point in the history
@trilinos/teuchos See #2705 for context.
  • Loading branch information
Mark Hoemmen authored and mhoemmen committed May 10, 2018
1 parent 074b921 commit 81695d0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 40 deletions.
28 changes: 14 additions & 14 deletions packages/teuchos/kokkoscomm/src/Kokkos_TeuchosCommAdapters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ send (const ViewType& sendBuffer,
const int tag,
const Comm<Ordinal>& comm)
{
send(sendBuffer.ptr_on_device(), count, destRank, tag, comm);
send(sendBuffer.data(), count, destRank, tag, comm);
}

//! Variant of ssend() that takes a tag (and restores the correct order of arguments).
Expand All @@ -80,7 +80,7 @@ ssend (const ViewType& sendBuffer,
const int tag,
const Comm<Ordinal>& comm)
{
ssend(sendBuffer.ptr_on_device(), count, destRank, tag, comm);
ssend(sendBuffer.data(), count, destRank, tag, comm);
}

//! Variant of readySend() that accepts a message tag.
Expand All @@ -92,7 +92,7 @@ readySend (const ViewType& sendBuffer,
const int tag,
const Comm<Ordinal>& comm)
{
readySend(sendBuffer.ptr_on_device(), count, destRank, tag, comm);
readySend(sendBuffer.data(), count, destRank, tag, comm);
}

//! Variant of isend() that takes a tag (and restores the correct order of arguments).
Expand Down Expand Up @@ -147,10 +147,10 @@ reduceAll (const SendViewType& sendBuf,
"The send View's rank is " << SendViewType::rank << " and the receive "
"View's rank is " << RecvViewType::rank << ".");
TEUCHOS_TEST_FOR_EXCEPTION(
sendBuf.dimension_0 () != recvBuf.dimension_0 (), std::invalid_argument,
"Send and receive buffer lengths do not match. sendBuf.dimension_0() = "
<< sendBuf.dimension_0 () << " != recvBuf.dimension_0() = "
<< recvBuf.dimension_0 () << ".");
sendBuf.extent (0) != recvBuf.extent (0), std::invalid_argument,
"Send and receive buffer lengths do not match. sendBuf.extent(0) = "
<< sendBuf.extent (0) << " != recvBuf.extent(0) = "
<< recvBuf.extent (0) << ".");

// mfh 04 Nov 2014: Don't let Teuchos::SerialComm do a deep copy;
// that always happens on the host, since SerialComm doesn't know
Expand All @@ -159,10 +159,10 @@ reduceAll (const SendViewType& sendBuf,
Kokkos::deep_copy (recvBuf, sendBuf);
}
else {
const Ordinal count = static_cast<Ordinal> (sendBuf.dimension_0 ());
const Ordinal count = static_cast<Ordinal> (sendBuf.extent (0));
reduceAll (comm, reductionType, count,
sendBuf.ptr_on_device (),
recvBuf.ptr_on_device ());
sendBuf.data (),
recvBuf.data ());
}
}

Expand Down Expand Up @@ -203,8 +203,8 @@ reduceAll(const Comm<Ordinal>& comm,
}
else {
reduceAll (comm, serializer, reductType, count,
sendBuffer.ptr_on_device (),
recvBuffer.ptr_on_device ());
sendBuffer.data (),
recvBuffer.data ());
}
}

Expand All @@ -216,7 +216,7 @@ broadcast(const Comm<Ordinal>& comm,
const Ordinal count,
const ViewType& buffer)
{
broadcast( comm, rootRank, count, buffer.ptr_on_device() );
broadcast( comm, rootRank, count, buffer.data() );
}

template<typename Ordinal,
Expand All @@ -229,7 +229,7 @@ broadcast(const Comm<Ordinal>& comm,
const Ordinal count,
const ViewType& buffer)
{
broadcast( comm, serializer, rootRank, count, buffer.ptr_on_device() );
broadcast( comm, serializer, rootRank, count, buffer.data() );
}

} // namespace Teuchos
Expand Down
8 changes: 4 additions & 4 deletions packages/teuchos/kokkoscompat/src/KokkosCompat_View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ namespace Kokkos {
Teuchos::ArrayView<typename ViewType::value_type>
getArrayView(const ViewType& a) {
return Teuchos::ArrayView<typename ViewType::value_type>(
a.ptr_on_device(), a.size());
a.data(), a.size());
}
template <typename ViewType>
Teuchos::ArrayView<const typename ViewType::value_type>
getConstArrayView(const ViewType& a) {
return Teuchos::ArrayView<const typename ViewType::value_type>(
a.ptr_on_device(), a.size());
a.data(), a.size());
}

// Convert Teuchos::ArrayView to Kokkos::View through deep_copy
Expand Down Expand Up @@ -184,7 +184,7 @@ namespace Kokkos {
// allocated (e.g.,) using new or malloc, but it's not a problem
// here, because the custom deallocator does not free anything.
// Nevertheless, it's better not to trouble the tracking system.
return Teuchos::arcp(view.ptr_on_device(), 0, view.capacity(),
return Teuchos::arcp(view.data(), 0, view.capacity(),
deallocator(view), false);
}

Expand All @@ -195,7 +195,7 @@ namespace Kokkos {
const ViewType& view,
typename Teuchos::ArrayRCP<typename ViewType::value_type>::size_type offset,
typename Teuchos::ArrayRCP<typename ViewType::value_type>::size_type size) {
return Teuchos::arcp(view.ptr_on_device()+offset, 0, size,
return Teuchos::arcp(view.data()+offset, 0, size,
deallocator(view), false);
}

Expand Down
40 changes: 18 additions & 22 deletions packages/teuchos/kokkoscompat/test/linkTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, NoInteraction ) {

typedef Kokkos::View<double*, TestDevice> ka_view_type;
ka_view_type y ("y", numElts);
Kokkos::parallel_for (y.dimension_0 (), FillFunctor<TestDevice> (y));
Kokkos::parallel_for (y.extent (0), FillFunctor<TestDevice> (y));
TestDevice::finalize();
}

Expand All @@ -136,14 +136,10 @@ TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, ArrayViewOfView ) {

const size_type numElts = 10;
ka_view_type y ("y", numElts);
Kokkos::parallel_for (y.dimension_0 (), FillFunctor<TestDevice> (y));
Kokkos::parallel_for (y.extent (0), FillFunctor<TestDevice> (y));

// It's possible to get the View's raw pointer because we know its
// layout. Not every kind of View necessarily implements the
// ptr_on_device() method, but certainly Views in HostSpace memory with
// left or right (Fortran or C) layout implement this method.
double* const y_raw = y.ptr_on_device ();
const size_type y_size = static_cast<size_type> (y.dimension_0 ());
double* const y_raw = y.data ();
const size_type y_size = static_cast<size_type> (y.extent (0));

Teuchos::ArrayView<double> y_view (y_raw, y_size);
TEST_EQUALITY_CONST( y_view.size(), y_size );
Expand Down Expand Up @@ -180,7 +176,7 @@ TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, ViewOfArrayView ) {
// subview with the desired dimensions.
ka_view_type x_view (x.getRawPtr (), x.size ());

TEST_EQUALITY( x.size(), static_cast<size_type>(x_view.dimension_0()) );
TEST_EQUALITY( x.size(), static_cast<size_type>(x_view.extent(0)) );
for (size_type k = 0; k < x.size (); ++k) {
TEST_EQUALITY( x_view[k], x[k] );
}
Expand All @@ -189,7 +185,7 @@ TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, ViewOfArrayView ) {
// x.getRawPtr() returns double*.
ka_const_view_type x_view_const ( (const double*) x.getRawPtr (), x.size ());

TEST_EQUALITY( x.size(), static_cast<size_type>(x_view_const.dimension_0()) );
TEST_EQUALITY( x.size(), static_cast<size_type>(x_view_const.extent(0)) );
for (size_type k = 0; k < x.size (); ++k) {
TEST_EQUALITY( x_view_const[k], x[k] );
}
Expand All @@ -214,8 +210,8 @@ TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, ArrayRCP1D_of_2DView ) {

ka_view_type X ("X", stride, numCols);
ka_view_type X_view = Kokkos::subview (X, std::make_pair (ZERO, numRows), std::make_pair (ZERO, numCols));
TEST_EQUALITY(X_view.dimension_0(), numRows);
TEST_EQUALITY(X_view.dimension_1(), numCols);
TEST_EQUALITY(X_view.extent(0), numRows);
TEST_EQUALITY(X_view.extent(1), numCols);

// Test that the strides of X_view are correct, for int. Kokkos
// Array templates the stride() method on the integer type of the
Expand Down Expand Up @@ -244,9 +240,9 @@ TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, ArrayRCP1D_of_2DView ) {
// View's raw pointer, but still defers to the View for memory
// management.

Teuchos::ArrayRCP<double> Y_values (X.ptr_on_device (), 0, stride*numCols, Deallocator<double, ka_view_type> (X), true);
TEST_EQUALITY(Y_values.getRawPtr(), X.ptr_on_device());
TEST_EQUALITY(Y_values.getRawPtr(), X_view.ptr_on_device());
Teuchos::ArrayRCP<double> Y_values (X.data (), 0, stride*numCols, Deallocator<double, ka_view_type> (X), true);
TEST_EQUALITY(Y_values.getRawPtr(), X.data());
TEST_EQUALITY(Y_values.getRawPtr(), X_view.data());
TEST_EQUALITY(Y_values.size(), stride*numCols);

TestDevice::finalize();
Expand Down Expand Up @@ -277,8 +273,8 @@ TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, ArrayRCP2D_of_2DView ) {
ka_view_type X ("X", stride, numCols);
ka_view_type X_view = Kokkos::subview (X, std::make_pair (ZERO, numRows), std::make_pair (ZERO, numCols));
TEST_EQUALITY( & X(0,0) , & X_view(0,0) );
TEST_EQUALITY(X_view.dimension_0(), numRows);
TEST_EQUALITY(X_view.dimension_1(), numCols);
TEST_EQUALITY(X_view.extent(0), numRows);
TEST_EQUALITY(X_view.extent(1), numCols);

// Test that the strides of X_view are correct, for size_t.
{
Expand All @@ -294,12 +290,12 @@ TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, ArrayRCP2D_of_2DView ) {

// Make a 2-D "view" (array of arrays) of X_view. This is how we
// will implement Tpetra::MultiVector methods like get2dView.
Teuchos::ArrayRCP<Teuchos::ArrayRCP<double> > Y_2D (X_view.dimension_1 ());
for (size_t j = 0; j < static_cast<size_t> (X_view.dimension_1 ()); ++j) {
Teuchos::ArrayRCP<Teuchos::ArrayRCP<double> > Y_2D (X_view.extent (1));
for (size_t j = 0; j < static_cast<size_t> (X_view.extent (1)); ++j) {
ka_view_type X_j = Kokkos::subview (X_view, std::make_pair (ZERO, numRows), std::make_pair (j, j+1));
TEST_EQUALITY( & X_view(0,j) , & X_j(0,0) );
TEST_EQUALITY(static_cast<size_t>(X_j.dimension_0()), numRows);
TEST_EQUALITY_CONST(X_j.dimension_1(), 1);
TEST_EQUALITY(static_cast<size_t>(X_j.extent(0)), numRows);
TEST_EQUALITY_CONST(X_j.extent(1), 1);

// Test that the strides of X_j are correct.
{
Expand All @@ -320,7 +316,7 @@ TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, ArrayRCP2D_of_2DView ) {
// X_j, and doesn't actually deallocate memory. That way, the
// ArrayRCP can use the View's raw pointer, but still defers to
// the View for memory management.
Teuchos::ArrayRCP<double> Y_j (X_j.ptr_on_device (), 0, numRows, Deallocator<double, ka_view_type> (X_j), true);
Teuchos::ArrayRCP<double> Y_j (X_j.data (), 0, numRows, Deallocator<double, ka_view_type> (X_j), true);
Y_2D[j] = Y_j;
}
TestDevice::finalize();
Expand Down

0 comments on commit 81695d0

Please sign in to comment.