16#ifndef OPM_SIMULATORS_LINALG_GPUISTL_DETAIL_GPU_POINTER_ATTRIBUTES_HPP
17#define OPM_SIMULATORS_LINALG_GPUISTL_DETAIL_GPU_POINTER_ATTRIBUTES_HPP
21#include <opm/common/ErrorMacros.hpp>
24#include <cuda_runtime.h>
28#include <source_location>
53 cudaPointerAttributes attributes {};
56 return attributes.type == cudaMemoryTypeDevice;
68template <
class T,
class D>
112 if (ptr ==
nullptr) {
116 cudaPointerAttributes attributes {};
121 const auto pointerTypeUnregistered =
static_cast<cudaMemoryType
>(0);
122 return attributes.type == cudaMemoryTypeHost || attributes.type == pointerTypeUnregistered;
134template <
class T,
class D>
163 [[maybe_unused]] std::string_view name,
164 [[maybe_unused]]
const std::source_location location
165 = std::source_location::current())
169 OPM_THROW(std::invalid_argument,
170 std::format(
"{} is not a CPU pointer\n"
176 location.file_name(),
179 location.function_name()));
192 [[maybe_unused]] std::string_view name,
193 [[maybe_unused]]
const std::source_location location
194 = std::source_location::current())
198 OPM_THROW(std::invalid_argument,
199 std::format(
"{} is not a device/GPU pointer\n"
205 location.file_name(),
208 location.function_name()));
218#define OPM_GPUISTL_DETAIL_ASSERT_HOST_POINTER(x) ::Opm::gpuistl::detail::assertHostPointer((x), #x)
223#define OPM_GPUISTL_DETAIL_ASSERT_DEVICE_POINTER(x) \
224 ::Opm::gpuistl::detail::assertDevicePointer((x), #x)
#define OPM_GPU_SAFE_CALL(expression)
OPM_GPU_SAFE_CALL checks the return type of the GPU expression (function call) and throws an exceptio...
Definition: gpu_safe_call.hpp:164
Definition: autotuner.hpp:30
bool isGPUPointer(const T *ptr)
Checks whether the given pointer is associated with GPU device memory.
Definition: gpu_pointer_attributes.hpp:48
void assertDevicePointer(const void *ptr, std::string_view name, const std::source_location location=std::source_location::current())
Debug-only check that ptr is device/GPU memory.
Definition: gpu_pointer_attributes.hpp:191
void assertHostPointer(const void *ptr, std::string_view name, const std::source_location location=std::source_location::current())
Debug-only check that ptr is host/CPU memory.
Definition: gpu_pointer_attributes.hpp:162
bool isCPUPointer(const T *ptr)
Checks whether the given pointer is associated with CPU host memory.
Definition: gpu_pointer_attributes.hpp:110