My Project
Loading...
Searching...
No Matches
kernel_enums.hpp
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
31 enum class MatrixStorageMPScheme {
32 DOUBLE_DIAG_DOUBLE_OFFDIAG = 0, // full precision should be default
33 FLOAT_DIAG_FLOAT_OFFDIAG = 1,
34 DOUBLE_DIAG_FLOAT_OFFDIAG = 2
35 };
36
37 namespace detail {
38 bool isValidMatrixStorageMPScheme(int scheme);
39 }
40
41 inline MatrixStorageMPScheme makeMatrixStorageMPScheme(int scheme) {
42 if (!detail::isValidMatrixStorageMPScheme(scheme)) {
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) {
58 case MatrixStorageMPScheme::DOUBLE_DIAG_DOUBLE_OFFDIAG:
59 return false;
60 case MatrixStorageMPScheme::FLOAT_DIAG_FLOAT_OFFDIAG:
61 return true;
62 case MatrixStorageMPScheme::DOUBLE_DIAG_FLOAT_OFFDIAG:
63 return false;
64 default:
65 return false;
66 }
67 }
68
69 __host__ __device__ constexpr bool storeOffDiagonalAsFloat(MatrixStorageMPScheme scheme) {
70 switch (scheme) {
71 case MatrixStorageMPScheme::DOUBLE_DIAG_DOUBLE_OFFDIAG:
72 return false;
73 case MatrixStorageMPScheme::FLOAT_DIAG_FLOAT_OFFDIAG:
74 return true;
75 case MatrixStorageMPScheme::DOUBLE_DIAG_FLOAT_OFFDIAG:
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) {
85 case MatrixStorageMPScheme::DOUBLE_DIAG_DOUBLE_OFFDIAG:
86 return false;
87 case MatrixStorageMPScheme::FLOAT_DIAG_FLOAT_OFFDIAG:
88 return true;
89 case MatrixStorageMPScheme::DOUBLE_DIAG_FLOAT_OFFDIAG:
90 return true;
91 default:
92 return false;
93 }
94 }
95
96 inline bool isValidMatrixStorageMPScheme(int scheme) {
97 switch (static_cast<MatrixStorageMPScheme>(scheme)) {
98 case MatrixStorageMPScheme::DOUBLE_DIAG_DOUBLE_OFFDIAG:
99 case MatrixStorageMPScheme::FLOAT_DIAG_FLOAT_OFFDIAG:
100 case MatrixStorageMPScheme::DOUBLE_DIAG_FLOAT_OFFDIAG:
101 return true;
102 default:
103 return false;
104 }
105 }
106 }
107}
108
109#endif // OPM_GPUISTL_KERNEL_ENUMS_HPP
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242