Loading...
Searching...
No Matches
is_gpu_pointer.hpp
/*
Copyright 2025 Equinor ASA
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_SIMULATORS_LINALG_GPUISTL_DETAIL_IS_GPU_POINTER_HPP
#define OPM_SIMULATORS_LINALG_GPUISTL_DETAIL_IS_GPU_POINTER_HPP
#include <cuda.h>
#include <cuda_runtime.h>
#include <memory>
#include <opm/simulators/linalg/gpuistl/detail/gpu_safe_call.hpp>
namespace Opm::gpuistl::detail
{
template <class T>
inline bool
isGPUPointer(const T* ptr)
{
if (ptr == nullptr) {
return false;
}
cudaPointerAttributes attributes;
OPM_GPU_SAFE_CALL(cudaPointerGetAttributes(&attributes, ptr));
return attributes.type == cudaMemoryTypeDevice;
}
template <class T, class D>
inline bool
isGPUPointer(const std::unique_ptr<T, D>& ptr)
{
return isGPUPointer(ptr.get());
}
template <class T>
inline bool
isGPUPointer(const std::shared_ptr<T>& ptr)
{
return isGPUPointer(ptr.get());
}
} // namespace Opm::gpuistl::detail
#endif
Opm::gpuistl::detail
Contains wrappers to make the CuBLAS library behave as a modern C++ library with function overlading.
Definition autotuner.hpp:30
Opm::gpuistl::detail::isGPUPointer
bool isGPUPointer(const T *ptr)
Checks whether the given pointer is associated with GPU device memory.
Definition is_gpu_pointer.hpp:40