is_gpu_pointer.hpp
Go to the documentation of this file.
1/*
2 Copyright 2025 Equinor ASA
3 This file is part of the Open Porous Media project (OPM).
4 OPM is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 OPM is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with OPM. If not, see <http://www.gnu.org/licenses/>.
14*/
15
16#ifndef OPM_SIMULATORS_LINALG_GPUISTL_DETAIL_IS_GPU_POINTER_HPP
17#define OPM_SIMULATORS_LINALG_GPUISTL_DETAIL_IS_GPU_POINTER_HPP
18
19#include <cuda.h>
20#include <cuda_runtime.h>
21#include <memory>
23
25{
26
38template <class T>
39inline bool
40isGPUPointer(const T* ptr)
41{
42 if (ptr == nullptr) {
43 return false;
44 }
45 cudaPointerAttributes attributes;
46 OPM_GPU_SAFE_CALL(cudaPointerGetAttributes(&attributes, ptr));
47 return attributes.type == cudaMemoryTypeDevice;
48}
49
50
59template <class T, class D>
60inline bool
61isGPUPointer(const std::unique_ptr<T, D>& ptr)
62{
63 return isGPUPointer(ptr.get());
64}
65
73template <class T>
74inline bool
75isGPUPointer(const std::shared_ptr<T>& ptr)
76{
77 return isGPUPointer(ptr.get());
78}
79} // namespace Opm::gpuistl::detail
80#endif
#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:150
Definition: autotuner.hpp:30
bool isGPUPointer(const T *ptr)
Checks whether the given pointer is associated with GPU device memory.
Definition: is_gpu_pointer.hpp:40