16 #ifndef TPFA_LINEARIZER_STRUCTS_HH 17 #define TPFA_LINEARIZER_STRUCTS_HH 27 #include <opm/common/Exceptions.hpp> 28 #include <opm/grid/utility/SparseTable.hpp> 29 #include <opm/input/eclipse/Schedule/BCProp.hpp> 31 #include <opm/common/utility/gpuistl_if_available.hpp> 32 #include <opm/common/utility/pointerArithmetic.hpp> 36 template <
class Storage = std::vector<
int>>
42 #if HAVE_CUDA && OPM_IS_COMPILING_WITH_GPU_COMPILER 45 if (CPUDomain.cells.size() == 0) {
46 OPM_THROW(std::runtime_error,
"Cannot copy empty full domain to GPU.");
48 return FullDomain<gpuistl::GpuBuffer<int>>{
49 gpuistl::GpuBuffer<int>(CPUDomain.cells)
53 inline FullDomain<gpuistl::GpuView<int>> make_view(FullDomain<gpuistl::GpuBuffer<int>>& buffer)
55 if (buffer.cells.size() == 0) {
56 OPM_THROW(std::runtime_error,
"Cannot make view of empty full domain buffer.");
58 return FullDomain<gpuistl::GpuView<int>>{
59 gpuistl::make_view(buffer.cells)
64 template <
class Res
idualNBInfoType,
class BlockType>
67 unsigned int neighbor;
68 ResidualNBInfoType res_nbinfo;
69 BlockType* matBlockAddress;
71 template <
class PtrType>
75 , matBlockAddress(static_cast<BlockType*>(ptr))
83 , matBlockAddress(
nullptr)
88 template <
class VectorBlock,
class ScalarFlu
idState>
92 unsigned pvtRegionIdx;
93 unsigned boundaryFaceIndex;
96 ScalarFluidState exFluidState;
99 template <
class BoundaryConditionData>
103 unsigned int bfIndex;
107 #if HAVE_CUDA && OPM_IS_COMPILING_WITH_GPU_COMPILER 110 template <
class MiniMatrixType,
113 class MatrixBlockType,
114 class ResidualNBInfoType>
116 cpuNeighborInfoTable,
117 GpuMatrixType& gpuJacobian,
118 CpuMatrixType& cpuJacobian)
122 using Scalar =
typename GpuMatrixType::field_type;
123 std::vector<StructWithMinimatrix> minimatrices(cpuNeighborInfoTable.dataSize());
124 Scalar* gpuBufStart = gpuJacobian.getNonZeroValues().data();
125 Scalar* cpuBufStart = &(cpuJacobian[0][0][0][0]);
129 using CpuBlockType =
typename CpuMatrixType::block_type::BaseType;
131 const size_t gpuBufferSize
132 = gpuJacobian.nonzeroes() * gpuJacobian.blockSize() * gpuJacobian.blockSize();
133 const size_t cpuBufferSize
134 = cpuJacobian.nonzeroes() * CpuBlockType::rows * CpuBlockType::cols;
135 assert(gpuBufferSize == cpuBufferSize);
137 const auto& dataStorage = cpuNeighborInfoTable.dataStorage();
138 const size_t dataSize = cpuNeighborInfoTable.dataSize();
140 #pragma omp parallel for 142 for (
size_t idx = 0; idx < dataSize; ++idx) {
143 const auto& e = dataStorage[idx];
144 Scalar* cpuPtr = &((*e.matBlockAddress)[0][0]);
147 Scalar* gpuPtr = ComputePtrBasedOnOffsetInOtherBuffer(
148 gpuBufStart, gpuBufferSize, cpuBufStart, cpuBufferSize, cpuPtr);
150 minimatrices[idx] = StructWithMinimatrix(
151 e.neighbor, e.res_nbinfo, reinterpret_cast<MiniMatrixType*>(gpuPtr));
154 return SparseTable<StructWithMinimatrix, gpuistl::GpuBuffer>(
155 gpuistl::GpuBuffer<StructWithMinimatrix>(minimatrices),
156 gpuistl::GpuBuffer<int>(cpuNeighborInfoTable.rowStarts())
161 template <
class GpuVecBlock,
163 class BoundaryInfoTypeGPU,
164 class BoundaryInfoTypeCPU,
165 typename GpuFluidSystemPtr>
166 auto copy_to_gpu(
const std::vector<BoundaryInfoTypeCPU>& cpu_boundary_info,
167 const GpuFluidSystemPtr& dynamicGpuFluidSystemPtr)
169 std::vector<BoundaryInfoTypeGPU> gpu_boundary_info;
170 for (
const auto& info : cpu_boundary_info) {
171 gpu_boundary_info.push_back(BoundaryInfoTypeGPU {
175 BoundaryConditionData<GpuVecBlock, GpuFluidState> {
177 GpuVecBlock(info.bcdata.massRate),
178 info.bcdata.pvtRegionIdx,
179 info.bcdata.boundaryFaceIndex,
180 info.bcdata.faceArea,
181 info.bcdata.faceZCoord,
182 info.bcdata.exFluidState.withOtherFluidSystem(dynamicGpuFluidSystemPtr)}});
185 return gpuistl::GpuBuffer<BoundaryInfoTypeGPU>(gpu_boundary_info);
190 template <
class CPURes
idualType,
class GpuMiniVector>
191 auto copy_to_gpu_residual(CPUResidualType& residual)
193 std::vector<GpuMiniVector> vectorOfMiniVectors;
194 for (
const auto& minivec : residual) {
195 vectorOfMiniVectors.emplace_back(minivec);
198 return gpuistl::GpuBuffer<GpuMiniVector>(vectorOfMiniVectors);
206 #endif // TPFA_LINEARIZER_STRUCTS_HH Definition: BlackoilWellModel.hpp:90
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: tpfalinearizerstructs.hh:89
Definition: tpfalinearizerstructs.hh:65
Definition: tpfalinearizerstructs.hh:37
Definition: tpfalinearizerstructs.hh:100