41 #include "Kokkos_Core.hpp"
42 #ifdef HAVE_TPETRACORE_CUDA
43 # include "cuda_runtime_api.h"
44 #endif // HAVE_TPETRACORE_CUDA
50 enum class EMemoryType {
58 EMemoryType getCudaMemoryType (
const void* ptr)
60 #ifdef HAVE_TPETRACORE_CUDA
61 cudaPointerAttributes attr;
62 const cudaError_t err = cudaPointerGetAttributes (&attr, ptr);
63 (void) cudaGetLastError ();
65 if (err == cudaErrorInvalidValue) {
71 return EMemoryType::HOST;
73 else if (err != cudaSuccess) {
74 return EMemoryType::ERROR;
81 if (attr.memoryType == cudaMemoryTypeDevice) {
83 return EMemoryType::CUDA_UVM;
86 return EMemoryType::CUDA;
92 else if (attr.memoryType == cudaMemoryTypeHost) {
93 if (attr.devicePointer ==
nullptr) {
94 return EMemoryType::HOST;
97 return EMemoryType::CUDA_HOST_PINNED;
101 return EMemoryType::ERROR;
106 const enum cudaMemoryType theType = attr.type;
107 if (theType == cudaMemoryTypeManaged) {
108 return EMemoryType::CUDA_UVM;
110 else if (theType == cudaMemoryTypeDevice) {
111 return EMemoryType::CUDA;
113 else if (theType == cudaMemoryTypeHost) {
114 return EMemoryType::CUDA_HOST_PINNED;
117 return EMemoryType::HOST;
121 #else // NOT HAVE_TPETRACORE_CUDA
122 return EMemoryType::HOST;
123 #endif // HAVE_TPETRACORE_CUDA
126 #ifdef HAVE_TPETRACORE_CUDA
128 CheckPointerAccessibility<Kokkos::Cuda>::
129 accessible (
const void* ptr,
130 const Kokkos::Cuda& )
132 const EMemoryType type = getCudaMemoryType (ptr);
133 return type != EMemoryType::HOST && type != EMemoryType::ERROR;
135 #endif // HAVE_TPETRACORE_CUDA
137 bool isHostAccessible (
const void* ptr)
139 #ifdef HAVE_TPETRACORE_CUDA
140 return getCudaMemoryType (ptr) != EMemoryType::CUDA;
143 #endif // HAVE_TPETRACORE_CUDA
150 using Impl::EMemoryType;
152 const EMemoryType type = Impl::getCudaMemoryType (ptr);
153 if (type == EMemoryType::CUDA_UVM) {
154 return "CudaUVMSpace";
156 else if (type == EMemoryType::CUDA) {
159 else if (type == EMemoryType::CUDA_HOST_PINNED) {
160 return "CudaHostPinnedSpace";
162 else if (type == EMemoryType::HOST) {
std::string memorySpaceName(const void *ptr)
Return the Kokkos memory space name (without "Kokkos::") corresponding to the given nonnull pointer...
Declaration of functions for checking whether a given pointer is accessible from a given Kokkos execu...