Skip to content

Commit

Permalink
Changes to make Tpetra compile its test with HIP as the execution space
Browse files Browse the repository at this point in the history
WIth these changes MPI, off and hacking the Kokkos::Experiment::HIP::memory_space
typedef to be Kokkos::Experimental::HIPHostPinnedSpace we get these failures:

124/124 Test trilinos#124: TpetraCore_TsqrAdaptor ..........................................   Passed    0.55 sec
95% tests passed, 5 tests failed out of 124
Label Time Summary:
Tpetra    = 147.76 sec*proc (124 tests)
Total Test time (real) = 147.96 sec
The following tests FAILED:
         19 - TpetraCore_idot (Subprocess aborted)
         83 - TpetraCore_MatrixMatrix_UnitTests (NUMERICAL)
        121 - TpetraCore_RowMatrixTransposer_test (Subprocess aborted)
        122 - TpetraCore_RowMatrixTransposer_UnitTests (Failed)
        123 - TpetraCore_CrsMatrix_transpose_sortedRows (Failed)

This IS running on the AMD GPU ...
  • Loading branch information
crtrott committed Dec 17, 2020
1 parent 2eff47b commit 0f19bc9
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 6 deletions.
31 changes: 30 additions & 1 deletion packages/tpetra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,27 @@ ELSE () # NOT Tpetra_INST_CUDA
ENDIF ()
ENDIF () # Tpetra_INST_CUDA

# Kokkos::HIP (Kokkos::Compat::KokkosHIPWrapperNode)
GLOBAL_SET(HAVE_TPETRA_INST_HIP_DEFAULT off)
TRIBITS_ADD_OPTION_AND_DEFINE(
Tpetra_INST_HIP
HAVE_TPETRA_INST_HIP
"Instantiate and/or test Tpetra classes over Node = Kokkos::Compat::KokkosHIPWrapperNode. If ETI is OFF, enable tests for that Node type. This option is ${HAVE_TPETRA_INST_HIP_DEFAULT} by default."
${HAVE_TPETRA_INST_HIP_DEFAULT}
)
GLOBAL_SET(HAVE_TPETRA_HIP ${Tpetra_INST_HIP})
IF (Tpetra_INST_HIP)
IF (NOT Kokkos_ENABLE_HIP)
MESSAGE(FATAL_ERROR "Tpetra: The Kokkos::HIP execution space is disabled, but you enabled the corresponding Tpetra Node type by setting Tpetra_INST_HIP=ON. If you want to enable instantiation and use of Kokkos::HIP in Tpetra, you must enable the Kokkos::HIP execution space by setting Kokkos_ENABLE_HIP=ON.")
ENDIF ()
ELSE () # NOT Tpetra_INST_HIP
IF (HAVE_TPETRA_DEFAULTNODE_HIPWRAPPERNODE)
MESSAGE(FATAL_ERROR "Tpetra: Node = Kokkos::Compat::KokkosHIPWrapperNode is disabled (since Tpetra_INST_HIP=OFF), but you set it as the default Node type. Try setting the CMake options Kokkos_ENABLE_HIP:BOOL=ON and Tpetra_INST_HIP:BOOL=ON. If you are building with a HIP-capable compiler and Kokkos can detect that, then you are unlikely to see this message, since both Kokkos and Tpetra enable HIP support by default in that case.")
ENDIF()
IF (Kokkos_ENABLE_HIP)
MESSAGE(STATUS "NOTE: Kokkos::HIP is ON (the CMake option Kokkos_ENABLE_HIP is ON), but the corresponding Tpetra Node type is disabled. If you want to enable instantiation and use of Kokkos::HIP in Tpetra, please also set the CMake option Tpetra_INST_HIP:BOOL=ON. If you use the Kokkos::HIP version of Tpetra without doing this, you will get link errors!")
ENDIF ()
ENDIF () # Tpetra_INST_HIP
#
# Check that users did not attempt to enable both the OpenMP and
# Pthreads back-ends.
Expand Down Expand Up @@ -539,17 +560,25 @@ IF(Tpetra_INST_CUDA)
LIST(APPEND ${PACKAGE_NAME}_ETI_DEVICES "Kokkos::Device<Kokkos::Cuda, Kokkos::CudaUVMSpace>")
LIST(APPEND ${PACKAGE_NAME}_ETI_NODES "Kokkos::Compat::KokkosCudaWrapperNode")
ENDIF()
IF(Tpetra_INST_HIP)
# TpetraCore currently requires UVM, so it doesn't make sense to
# instantiate over Kokkos::HIPSpace as well as
# Kokkos::HIPHostPinnedSpace.
LIST(APPEND ${PACKAGE_NAME}_ETI_DEVICES "Kokkos::Device<Kokkos::Experimental::HIP, Kokkos::Experimental::HIPHostPinnedSpace>")
LIST(APPEND ${PACKAGE_NAME}_ETI_NODES "Kokkos::Compat::KokkosHIPWrapperNode")
ENDIF()

# Tell users what Nodes are enabled.
MESSAGE(STATUS "Tpetra execution space availability (ON means available): ")
MESSAGE(STATUS " - Serial: ${HAVE_TPETRA_SERIAL}")
MESSAGE(STATUS " - Threads: ${HAVE_TPETRA_PTHREAD}")
MESSAGE(STATUS " - OpenMP: ${HAVE_TPETRA_OPENMP}")
MESSAGE(STATUS " - Cuda: ${HAVE_TPETRA_CUDA}")
MESSAGE(STATUS " - HIP: ${HAVE_TPETRA_HIP}")

# Fix Github Issue #190 by making sure that users enabled at least one
# Node type.
IF(NOT Tpetra_INST_SERIAL AND NOT Tpetra_INST_PTHREAD AND NOT Tpetra_INST_OPENMP AND NOT Tpetra_INST_CUDA)
IF(NOT Tpetra_INST_SERIAL AND NOT Tpetra_INST_PTHREAD AND NOT Tpetra_INST_OPENMP AND NOT Tpetra_INST_CUDA AND NOT Tpetra_INST_HIP)
MESSAGE(FATAL_ERROR "It appears that you have disabled all of Tpetra's Node types. This is a bad idea; please don't do this. This may have happened either if all Kokkos execution spaces got disabled, or if you explicitly disabled some Tpetra Node types. To fix this, look in your CMake configuration to see if you set any of the following variables to OFF explicitly: Kokkos_ENABLE_CUDA, Kokkos_ENABLE_OPENMP, Kokkos_ENABLE_SERIAL, Kokkos_ENABLE_PTHREAD, Tpetra_INST_SERIAL, Tpetra_INST_PTHREAD, Tpetra_INST_OPENMP, or Tpetra_INST_CUDA.")
ENDIF()

Expand Down
19 changes: 17 additions & 2 deletions packages/tpetra/classic/NodeAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ ENDIF()
# performance of users' own threads -- OpenMP doesn't have
# that problem).

IF (Tpetra_DefaultNode STREQUAL "Kokkos::Compat::KokkosCudaWrapperNode")
IF (Tpetra_DefaultNode STREQUAL "Kokkos::Compat::KokkosHIPWrapperNode")
IF (NOT Kokkos_ENABLE_HIP)
MESSAGE (FATAL_ERROR "Kokkos_ENABLE_HIP is OFF, but you set Tpetra's default Node type to Kokkos::Compat::KokkosHIPWrapperNode.")
ENDIF ()
IF (NOT Tpetra_INST_HIP)
MESSAGE (FATAL_ERROR "Tpetra_INST_HIP is OFF, but you set Tpetra's default Node type to Kokkos::Compat::KokkosHIPWrapperNode.")
ENDIF ()
SET (HAVE_TPETRA_DEFAULTNODE_HIPWRAPPERNODE ON CACHE BOOL "")
ELSEIF (Tpetra_DefaultNode STREQUAL "Kokkos::Compat::KokkosCudaWrapperNode")
IF (NOT Kokkos_ENABLE_CUDA)
MESSAGE (FATAL_ERROR "Kokkos_ENABLE_CUDA is OFF, but you set Tpetra's default Node type to Kokkos::Compat::KokkosCudaWrapperNode.")
ENDIF ()
Expand Down Expand Up @@ -107,7 +115,14 @@ ELSEIF (Tpetra_DefaultNode STREQUAL "")
#
# The user didn't set Tpetra_DefaultNode, so we need to pick it.
#
IF (Tpetra_INST_CUDA)
IF (Tpetra_INST_HIP)
IF(NOT Kokkos_ENABLE_HIP)
MESSAGE(FATAL_ERROR "Tpetra_INST_HIP is ON, but Kokkos_ENABLE_HIP is OFF.")
ENDIF()
MESSAGE(STATUS "Setting default Node to Kokkos::Compat::KokkosHIPWrapperNode.")
SET(Tpetra_DefaultNode "Kokkos::Compat::KokkosHIPWrapperNode")
SET(HAVE_TPETRA_DEFAULTNODE_HIPWRAPPERNODE ON CACHE BOOL "")
ELSEIF (Tpetra_INST_CUDA)
IF(NOT Kokkos_ENABLE_CUDA)
MESSAGE(FATAL_ERROR "Tpetra_INST_CUDA is ON, but Kokkos_ENABLE_CUDA is OFF.")
ENDIF()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ namespace Kokkos {
}
#endif // KOKKOS_ENABLE_CUDA

#ifdef KOKKOS_ENABLE_HIP
template<>
std::string KokkosDeviceWrapperNode<Kokkos::Experimental::HIP>::name() {
return std::string("HIP/Wrapper");
}
#endif // KOKKOS_ENABLE_HIP

} // namespace Compat
} // namespace Kokkos

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class KokkosDeviceWrapperNode {
static std::string name ();
};

#ifdef KOKKOS_ENABLE_HIP
typedef KokkosDeviceWrapperNode<Kokkos::Experimental::HIP> KokkosHIPWrapperNode;
#endif

#ifdef KOKKOS_ENABLE_CUDA
typedef KokkosDeviceWrapperNode<Kokkos::Cuda> KokkosCudaWrapperNode;
#endif
Expand Down
4 changes: 3 additions & 1 deletion packages/tpetra/classic/NodeAPI/Kokkos_DefaultNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ namespace KokkosClassic {
/// \endcode
class DefaultNode {
public:
#if defined(HAVE_TPETRA_DEFAULTNODE_CUDAWRAPPERNODE)
#if defined(HAVE_TPETRA_DEFAULTNODE_HIPWRAPPERNODE)
typedef ::Kokkos::Compat::KokkosHIPWrapperNode DefaultNodeType;
#elif defined(HAVE_TPETRA_DEFAULTNODE_CUDAWRAPPERNODE)
typedef ::Kokkos::Compat::KokkosCudaWrapperNode DefaultNodeType;
#elif defined(HAVE_TPETRA_DEFAULTNODE_OPENMPWRAPPERNODE)
typedef ::Kokkos::Compat::KokkosOpenMPWrapperNode DefaultNodeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
// For backwards compatibility ONLY.
#define KOKKOSCLASSIC_DEFAULTNODE TPETRA_DEFAULTNODE

// Defined if and only if Tpetra's default execution space is Kokkos::HIP.
#cmakedefine HAVE_TPETRA_DEFAULTNODE_HIPWRAPPERNODE
// For backwards compatibility ONLY.
#ifdef HAVE_TPETRA_DEFAULTNODE_HIPWRAPPERNODE
# define HAVE_KOKKOSCLASSIC_DEFAULTNODE_HIPWRAPPERNODE 1
#endif // HAVE_TPETRA_DEFAULTNODE_HIPWRAPPERNODE

// Defined if and only if Tpetra's default execution space is Kokkos::Cuda.
#cmakedefine HAVE_TPETRA_DEFAULTNODE_CUDAWRAPPERNODE
// For backwards compatibility ONLY.
Expand Down
2 changes: 2 additions & 0 deletions packages/tpetra/core/cmake/TpetraCore_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
#cmakedefine HAVE_TPETRA_INST_PTHREAD
#cmakedefine HAVE_TPETRA_INST_OPENMP
#cmakedefine HAVE_TPETRA_INST_CUDA
#cmakedefine HAVE_TPETRA_INST_HIP

#cmakedefine HAVE_TPETRA_INT_INT
#cmakedefine HAVE_TPETRA_INT_LONG
Expand All @@ -163,6 +164,7 @@
#cmakedefine HAVE_TPETRA_PTHREAD
#cmakedefine HAVE_TPETRA_OPENMP
#cmakedefine HAVE_TPETRA_CUDA
#cmakedefine HAVE_TPETRA_HIP

#cmakedefine HAVE_TPETRA_THREADED_MKL

Expand Down
6 changes: 6 additions & 0 deletions packages/tpetra/core/src/Tpetra_BlockCrsMatrix_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,13 @@ class BlockCrsMatrix :
static constexpr bool value =
std::is_same<typename Device::execution_space, Kokkos::Cuda>::value;
#else
// Gonna badly fake this here for other execspaces
#if defined(KOKKOS_ENABLE_HIP)
static constexpr bool value =
std::is_same<typename Device::execution_space, Kokkos::Experimental::HIP>::value;
#else
static constexpr bool value = false;
#endif
#endif // defined(KOKKOS_ENABLE_CUDA)
};

Expand Down
4 changes: 3 additions & 1 deletion packages/tpetra/core/src/Tpetra_Details_DefaultTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ namespace DefaultTypes {

/// \typedef execution_space
/// \brief Default Tpetra execution space.
#if defined(HAVE_TPETRA_DEFAULTNODE_CUDAWRAPPERNODE)
#if defined(HAVE_TPETRA_DEFAULTNODE_HIPWRAPPERNODE)
using execution_space = ::Kokkos::Experimental::HIP;
#elif defined(HAVE_TPETRA_DEFAULTNODE_CUDAWRAPPERNODE)
using execution_space = ::Kokkos::Cuda;
#elif defined(HAVE_TPETRA_DEFAULTNODE_OPENMPWRAPPERNODE)
using execution_space = ::Kokkos::OpenMP;
Expand Down
79 changes: 79 additions & 0 deletions packages/tpetra/core/src/Tpetra_Details_StaticView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ void finalize_cuda_host_pinned_memory ()
}
#endif // KOKKOS_ENABLE_CUDA

#ifdef KOKKOS_ENABLE_HIP

void* hip_memory_ = nullptr;
size_t hip_memory_size_ = 0;

void finalize_hip_memory ()
{
if (hip_memory_ != nullptr) {
Kokkos::kokkos_free<Kokkos::Experimental::HIPSpace> (hip_memory_);
hip_memory_ = nullptr;
hip_memory_size_ = 0;
}
}

void* hip_host_pinned_memory_ = nullptr;
size_t hip_host_pinned_memory_size_ = 0;

void finalize_hip_host_pinned_memory ()
{
if (hip_host_pinned_memory_ != nullptr) {
Kokkos::kokkos_free<Kokkos::Experimental::HIPHostPinnedSpace> (hip_host_pinned_memory_);
hip_host_pinned_memory_ = nullptr;
hip_host_pinned_memory_size_ = 0;
}
}
#endif // KOKKOS_ENABLE_HIP

void* host_memory_ = nullptr;
size_t host_memory_size_ = 0;

Expand Down Expand Up @@ -186,6 +213,58 @@ resize (Kokkos::CudaHostPinnedSpace /* space */,

#endif // KOKKOS_ENABLE_CUDA

#ifdef KOKKOS_ENABLE_HIP

void*
StaticKokkosAllocation<Kokkos::Experimental::HIPSpace>::
resize (Kokkos::Experimental::HIPSpace /* space */,
const size_t size)
{
using memory_space = Kokkos::Experimental::HIPSpace;
static bool created_finalize_hook = false;

if (size > hip_memory_size_) {
if (hip_memory_ != nullptr) {
Kokkos::kokkos_free<memory_space> (hip_memory_);
}
const size_t req_size = size > minimum_initial_size ? size : minimum_initial_size;
hip_memory_ = Kokkos::kokkos_malloc<memory_space> (req_size);
hip_memory_size_ = size;
}
if (! created_finalize_hook) {
Kokkos::push_finalize_hook (finalize_hip_memory);
created_finalize_hook = true;
}

return hip_memory_;
}

void*
StaticKokkosAllocation<Kokkos::Experimental::HIPHostPinnedSpace>::
resize (Kokkos::Experimental::HIPHostPinnedSpace /* space */,
const size_t size)
{
using memory_space = Kokkos::Experimental::HIPHostPinnedSpace;
static bool created_finalize_hook = false;

const size_t req_size = size > minimum_initial_size ? size : minimum_initial_size;
if (req_size > hip_host_pinned_memory_size_) {
if (hip_host_pinned_memory_ != nullptr) {
Kokkos::kokkos_free<memory_space> (hip_host_pinned_memory_);
}
hip_host_pinned_memory_ = Kokkos::kokkos_malloc<memory_space> (req_size);
hip_host_pinned_memory_size_ = req_size;
}
if (! created_finalize_hook) {
Kokkos::push_finalize_hook (finalize_hip_host_pinned_memory);
created_finalize_hook = true;
}

return hip_host_pinned_memory_;
}

#endif // KOKKOS_ENABLE_HIP

void*
StaticKokkosAllocation<Kokkos::HostSpace>::
resize (Kokkos::HostSpace /* space */,
Expand Down
28 changes: 28 additions & 0 deletions packages/tpetra/core/src/Tpetra_Details_StaticView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,34 @@ class StaticKokkosAllocation<Kokkos::CudaHostPinnedSpace> {
};
#endif // KOKKOS_ENABLE_CUDA

#ifdef KOKKOS_ENABLE_HIP
template<>
class StaticKokkosAllocation<Kokkos::Experimental::HIPSpace> {
public:
StaticKokkosAllocation () = delete;
~StaticKokkosAllocation () = delete;
StaticKokkosAllocation (const StaticKokkosAllocation&) = delete;
StaticKokkosAllocation& operator= (const StaticKokkosAllocation&) = delete;
StaticKokkosAllocation (StaticKokkosAllocation&&) = delete;
StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) = delete;

static void* resize (Kokkos::Experimental::HIPSpace space, const size_t size);
};

template<>
class StaticKokkosAllocation<Kokkos::Experimental::HIPHostPinnedSpace> {
public:
StaticKokkosAllocation () = delete;
~StaticKokkosAllocation () = delete;
StaticKokkosAllocation (const StaticKokkosAllocation&) = delete;
StaticKokkosAllocation& operator= (const StaticKokkosAllocation&) = delete;
StaticKokkosAllocation (StaticKokkosAllocation&&) = delete;
StaticKokkosAllocation& operator= (StaticKokkosAllocation&&) = delete;

static void* resize (Kokkos::Experimental::HIPHostPinnedSpace space, const size_t size);
};
#endif // KOKKOS_ENABLE_HIP

template<>
class StaticKokkosAllocation<Kokkos::HostSpace> {
public:
Expand Down
5 changes: 4 additions & 1 deletion packages/tpetra/core/test/Block/BlockCrsMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,12 @@ namespace {
blockMat.modify_host ();
{
if (! std::is_same<typename Node::device_type::memory_space, Kokkos::HostSpace>::value) {
// This is messed up with HIP using HIPHostPinnedSpace as its memory space
#ifndef KOKKOS_ENABLE_HIP
TEST_ASSERT( blockMat.template need_sync<typename Node::device_type::memory_space> () );
TEST_ASSERT( blockMat.need_sync_device () );
TEST_ASSERT( ! blockMat.template need_sync<Kokkos::HostSpace> () );
#endif
TEST_ASSERT( blockMat.need_sync_device () );
TEST_ASSERT( ! blockMat.need_sync_host () );
}
auto val = blockMat.template getValues<Kokkos::HostSpace> ();
Expand Down
3 changes: 3 additions & 0 deletions packages/tpetra/core/test/MultiVector/WithLocalAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,14 @@ namespace { // (anonymous)
"Result of getNonowningLocalObject for a Vector must be "
"a rank-1 Kokkos::View");
#endif // KOKKOS_ENABLE_CUDA
// Using HipHostPinnedSpace for HIP makes this assertion not hold so we disabel the assert
#ifndef KOKKOS_ENABLE_HIP
static_assert
(std::is_same<
decltype (X_lcl_1d_wo)::device_type::execution_space,
vec_type::dual_view_type::t_dev::execution_space>::value,
"Wrong execution space");
#endif
Kokkos::parallel_for (
"Device kernel for write-only Tpetra::Vector",
range_type (0, LO (numLocal)),
Expand Down

0 comments on commit 0f19bc9

Please sign in to comment.