kernel_enums.hpp
Go to the documentation of this file.
1/*
2 Copyright 2024 Equinor ASA
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_GPUISTL_KERNEL_ENUMS_HPP
21#define OPM_GPUISTL_KERNEL_ENUMS_HPP
22
23#include <cuda_runtime.h>
24
25/*
26 This file organizes a growing amount of different mixed precision options for the preconditioners.
27*/
28
29namespace Opm::gpuistl {
30 // Mixed precision schemes used for storing the matrix in GPU memory
32 DOUBLE_DIAG_DOUBLE_OFFDIAG = 0, // full precision should be default
35 };
36
37 namespace detail {
38 bool isValidMatrixStorageMPScheme(int scheme);
39 }
40
43 OPM_THROW(std::invalid_argument,
44 fmt::format("Invalid matrix storage mixed precision scheme chosen: {}.\n"
45 "Valid Schemes:\n"
46 "\t0: DOUBLE_DIAG_DOUBLE_OFFDIAG\n"
47 "\t1: FLOAT_DIAG_FLOAT_OFFDIAG\n"
48 "\t2: DOUBLE_DIAG_FLOAT_OFFDIAG",
49 scheme));
50 }
51 return static_cast<MatrixStorageMPScheme>(scheme);
52 }
53
54 namespace detail {
55
56 __host__ __device__ constexpr bool storeDiagonalAsFloat(MatrixStorageMPScheme scheme) {
57 switch (scheme) {
59 return false;
61 return true;
63 return false;
64 default:
65 return false;
66 }
67 }
68
69 __host__ __device__ constexpr bool storeOffDiagonalAsFloat(MatrixStorageMPScheme scheme) {
70 switch (scheme) {
72 return false;
74 return true;
76 return true;
77 default:
78 return false;
79 }
80 }
81
82 // returns true if we use anything else that the the default double precision for everything
83 __host__ __device__ constexpr bool usingMixedPrecision(MatrixStorageMPScheme scheme) {
84 switch (scheme) {
86 return false;
88 return true;
90 return true;
91 default:
92 return false;
93 }
94 }
95
96 inline bool isValidMatrixStorageMPScheme(int scheme) {
97 switch (static_cast<MatrixStorageMPScheme>(scheme)) {
101 return true;
102 default:
103 return false;
104 }
105 }
106 }
107}
108
109#endif // OPM_GPUISTL_KERNEL_ENUMS_HPP
__host__ __device__ constexpr bool storeDiagonalAsFloat(MatrixStorageMPScheme scheme)
Definition: kernel_enums.hpp:56
bool isValidMatrixStorageMPScheme(int scheme)
Definition: kernel_enums.hpp:96
__host__ __device__ constexpr bool usingMixedPrecision(MatrixStorageMPScheme scheme)
Definition: kernel_enums.hpp:83
__host__ __device__ constexpr bool storeOffDiagonalAsFloat(MatrixStorageMPScheme scheme)
Definition: kernel_enums.hpp:69
Definition: autotuner.hpp:30
MatrixStorageMPScheme
Definition: kernel_enums.hpp:31
MatrixStorageMPScheme makeMatrixStorageMPScheme(int scheme)
Definition: kernel_enums.hpp:41