My Project
Loading...
Searching...
No Matches
is_gpu_pointer.hpp
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>
22#include <opm/simulators/linalg/gpuistl/detail/gpu_safe_call.hpp>
23
25{
26
38template <class T>
39inline bool
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
Contains wrappers to make the CuBLAS library behave as a modern C++ library with function overlading.
Definition autotuner.hpp:29
bool isGPUPointer(const T *ptr)
Checks whether the given pointer is associated with GPU device memory.
Definition is_gpu_pointer.hpp:40
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242