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 #if USE_HIP
25 #include <opm/simulators/linalg/gpuistl_hip/GpuVector.hpp>
26 #else
27 #include <opm/simulators/linalg/gpuistl/GpuVector.hpp>
28 #endif
29 #endif
30 namespace Opm {
31 
40 template <typename T>
42 {
43 #if HAVE_CUDA
44  // TODO: This can be done more thoroughly by checking if range and matrix also is a gpu operator, but this
45  // works for now.
46  static constexpr bool value
47  = std::is_same_v<typename T::domain_type, Opm::gpuistl::GpuVector<typename T::field_type>>;
48 #else
49  // If CUDA is not enabled, we assume that the operator is not a GPU operator.
50  static constexpr bool value = false;
51 #endif
52 };
53 
54 template <typename T>
55 static constexpr bool is_gpu_operator_v = is_gpu_operator<T>::value;
56 
57 
66  template <typename T>
68  {
69  #if HAVE_CUDA
70 
71  static constexpr bool value
72  = std::is_same_v<T, Opm::gpuistl::GpuSparseMatrix<typename T::field_type>>
73  || std::is_same_v<T, Opm::gpuistl::GpuSparseMatrixWrapper<typename T::field_type>>
74  || std::is_same_v<T, Opm::gpuistl::GpuSparseMatrixWrapper<typename T::field_type, true>>
75  || std::is_same_v<T, Opm::gpuistl::GpuSparseMatrixGeneric<typename T::field_type>>;
76  #else
77  // If CUDA is not enabled, we assume that the matrix is not a GPU matrix.
78  static constexpr bool value = false;
79  #endif
80  };
81 
82  template <typename T>
83  static constexpr bool is_gpu_matrix_v = is_gpu_matrix<T>::value;
84 
85 } // namespace Opm
86 
87 #endif // OPM_IS_GPU_OPERATOR_HEADER
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Check if a given operator is a GPU matrix.
Definition: is_gpu_operator.hpp:67
Check if a given operator is a GPU operator.
Definition: is_gpu_operator.hpp:41