opm-simulators
is_gpu_operator.hpp
1 /*
2  Copyright 2025 Equinor ASA
3 
4  This file is part of the Open Porous Media project (OPM).
5  OPM is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9  OPM is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13  You should have received a copy of the GNU General Public License
14  along with OPM. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
17 #ifndef OPM_IS_GPU_OPERATOR_HEADER
18 #define OPM_IS_GPU_OPERATOR_HEADER
19 
20 #include <type_traits>
21 
22 #if HAVE_CUDA // Avoid including GpuVector.hpp if CUDA
23  // is not enabled to avoid linking errors.
24 #include <opm/simulators/linalg/gpuistl/GpuVector.hpp>
25 #endif
26 namespace Opm {
27 
36 template <typename T>
38 {
39 #if HAVE_CUDA
40  // TODO: This can be done more thoroughly by checking if range and matrix also is a gpu operator, but this
41  // works for now.
42  static constexpr bool value
43  = std::is_same_v<typename T::domain_type, Opm::gpuistl::GpuVector<typename T::field_type>>;
44 #else
45  // If CUDA is not enabled, we assume that the operator is not a GPU operator.
46  static constexpr bool value = false;
47 #endif
48 };
49 
50 template <typename T>
51 static constexpr bool is_gpu_operator_v = is_gpu_operator<T>::value;
52 
53 
62  template <typename T>
64  {
65  #if HAVE_CUDA
66 
67  static constexpr bool value
68  = std::is_same_v<T, Opm::gpuistl::GpuSparseMatrix<typename T::field_type>>
69  || std::is_same_v<T, Opm::gpuistl::GpuSparseMatrixWrapper<typename T::field_type>>
70  || std::is_same_v<T, Opm::gpuistl::GpuSparseMatrixWrapper<typename T::field_type, true>>
71  || std::is_same_v<T, Opm::gpuistl::GpuSparseMatrixGeneric<typename T::field_type>>;
72  #else
73  // If CUDA is not enabled, we assume that the matrix is not a GPU matrix.
74  static constexpr bool value = false;
75  #endif
76  };
77 
78  template <typename T>
79  static constexpr bool is_gpu_matrix_v = is_gpu_matrix<T>::value;
80 
81 } // namespace Opm
82 
83 #endif // OPM_IS_GPU_OPERATOR_HEADER
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Check if a given operator is a GPU matrix.
Definition: is_gpu_operator.hpp:63
Check if a given operator is a GPU operator.
Definition: is_gpu_operator.hpp:37