16 #ifndef OPM_SIMULATORS_LINALG_GPUISTL_GPU_SMART_POINTER_HPP 17 #define OPM_SIMULATORS_LINALG_GPUISTL_GPU_SMART_POINTER_HPP 19 #include <cuda_runtime.h> 23 #include <opm/common/utility/gpuDecorators.hpp> 24 #include <opm/simulators/linalg/gpuistl/detail/gpu_safe_call.hpp> 25 #include <opm/simulators/linalg/gpuistl/detail/is_gpu_pointer.hpp> 51 OPM_GPU_SAFE_CALL(cudaMalloc(&ptr,
sizeof(T)));
52 auto deleter = [](T* ptrToDelete) { OPM_GPU_WARN_IF_ERROR(cudaFree(ptrToDelete)); };
53 return std::shared_ptr<T>(ptr, deleter);
71 auto ptr = make_gpu_shared_ptr<T>();
72 OPM_GPU_SAFE_CALL(cudaMemcpy(ptr.get(), &value,
sizeof(T), cudaMemcpyHostToDevice));
92 OPM_GPU_SAFE_CALL(cudaMalloc(&ptr,
sizeof(T)));
94 auto deleter = [](T* ptrToDelete) { OPM_GPU_WARN_IF_ERROR(cudaFree(ptrToDelete)); };
95 return std::unique_ptr<T, decltype(deleter)>(ptr, deleter);
109 template <
typename T>
113 auto ptr = make_gpu_unique_ptr<T>();
114 OPM_GPU_SAFE_CALL(cudaMemcpy(ptr.get(), &value,
sizeof(T), cudaMemcpyHostToDevice));
135 OPM_GPU_SAFE_CALL(cudaMemcpy(&result, value,
sizeof(T), cudaMemcpyDeviceToHost));
165 template <
class T,
class Deleter>
187 OPM_GPU_SAFE_CALL(cudaMemcpy(ptr, &value,
sizeof(T), cudaMemcpyHostToDevice));
200 copyToGPU(
const T& value,
const std::shared_ptr<T>& ptr)
214 template <
class T,
class Deleter>
216 copyToGPU(
const T& value,
const std::unique_ptr<T, Deleter>& ptr)
240 template <
class Deleter>
241 PointerView(
const std::unique_ptr<T, Deleter>& ptr)
251 OPM_HOST_DEVICE T*
get()
const 256 OPM_HOST_DEVICE
const T& operator*()
const 261 OPM_HOST_DEVICE T& operator*()
266 OPM_HOST_DEVICE T* operator->()
const 291 template <
class Deleter>
292 PointerView(
const std::unique_ptr<void, Deleter>& ptr)
302 OPM_HOST_DEVICE
void*
get()
const 307 OPM_HOST_DEVICE
void* operator->()
const 318 make_view(
const std::shared_ptr<T>& ptr)
323 template <
class T,
class Deleter>
325 make_view(
const std::unique_ptr<T, Deleter>& ptr)
327 return PointerView<T>(ptr);
337 using element_type = T;
341 OPM_HOST_DEVICE T* operator->() {
345 OPM_HOST_DEVICE T*
get() {
349 OPM_HOST_DEVICE
const T* operator->()
const {
353 OPM_HOST_DEVICE
const T*
get()
const {
357 OPM_HOST_DEVICE T& operator*() {
361 OPM_HOST_DEVICE
const T& operator*()
const {
A view towards a smart pointer to GPU-allocated memory.
Definition: gpu_smart_pointer.hpp:230
auto make_gpu_unique_ptr()
Creates a unique pointer managing GPU-allocated memory of the specified element type.
Definition: gpu_smart_pointer.hpp:89
T copyFromGPU(const T *value)
Copies a value from GPU-allocated memory to the host.
Definition: gpu_smart_pointer.hpp:129
A small, fixed‑dimension MiniVector class backed by std::array that can be used in both host and CUD...
Definition: AmgxInterface.hpp:37
A value stored with a pointer interface.
Definition: gpu_smart_pointer.hpp:335
bool isGPUPointer(const T *ptr)
Checks whether the given pointer is associated with GPU device memory.
Definition: is_gpu_pointer.hpp:40
std::shared_ptr< T > make_gpu_shared_ptr()
Creates a shared pointer managing GPU-allocated memory of the specified element type.
Definition: gpu_smart_pointer.hpp:48
void copyToGPU(const T &value, T *ptr)
Copies a value from the host to GPU-allocated memory.
Definition: gpu_smart_pointer.hpp:182