tpfalinearizergpukernels.hh
Go to the documentation of this file.
1/*
2 Copyright 2026 Equinor ASA
3 This file is part of the Open Porous Media project (OPM).
4 OPM is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 OPM is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with OPM. If not, see <http://www.gnu.org/licenses/>.
14*/
15
16#ifndef TPFA_LINEARIZER_GPUKERNELS_HH
17#define TPFA_LINEARIZER_GPUKERNELS_HH
18
19/*
20 This file contains the GPU kernels that handles the GPU parallelization of the linearization.
21 This is effectively just the GPU alternative to what is a for-loop on the CPU
22*/
23
24namespace Opm
25{
26
27#if HAVE_CUDA && OPM_IS_COMPILING_WITH_GPU_COMPILER
28template <class TpfaLinearizerType,
29 class ModelClass,
30 class LocalResidualT,
31 class DiagPtrType,
32 class ScalarType,
33 class DomainType,
34 class NeighborSparseTable,
35 class ResidualType,
36 class ProblemT>
37__global__ __launch_bounds__(256) void kernel_linearize(const unsigned int numCells,
38 const DomainType domain,
39 const NeighborSparseTable neighborInfo,
40 DiagPtrType diagMatAddress,
41 ResidualType residual,
42 ModelClass model,
43 ScalarType dt,
44 ProblemT problem)
45{
46 const unsigned int ii = blockIdx.x * blockDim.x + threadIdx.x;
47
48 if (ii < numCells) {
49 // velocityInfo is unused on GPU (guarded by if constexpr (!useGPU)),
50 // but the parameter is T& so we need an lvalue to bind to.
51 std::nullptr_t dummyVelocityInfo = nullptr;
52 TpfaLinearizerType::template linearize_cell<true, LocalResidualT>(ii,
53 domain,
54 neighborInfo,
55 diagMatAddress,
56 residual,
57 model,
58 dummyVelocityInfo,
59 dt,
60 problem);
61 }
62}
63
64template <class TpfaLinearizerType,
65 class IntensiveQuantities,
66 class ModelT,
67 class LocalResidualT,
68 class DiagPtrType,
69 class ResidualT,
70 class BoundaryInfo,
71 class ProblemT>
72__global__ void
73linearize_bc_threadsafe(DiagPtrType diagMatAddress,
74 ResidualT residual,
75 const BoundaryInfo boundaryInfo,
76 ModelT model,
77 ProblemT gpuProblem)
78{
79 const unsigned int ii = blockIdx.x * blockDim.x + threadIdx.x;
80 if (ii < boundaryInfo.size()) {
81 TpfaLinearizerType::template linearize_bc_threadsafe_single_cell<IntensiveQuantities,
82 LocalResidualT>(
83 diagMatAddress, residual, boundaryInfo[ii], model, gpuProblem);
84 }
85}
86
87#endif
88
89} // namespace Opm
90
91#endif // TPFA_LINEARIZER_GPUKERNELS_HH
Definition: blackoilbioeffectsmodules.hh:45