22 #ifndef OPM_ISTLSOLVER_WITH_GPUBRIDGE_HEADER_INCLUDED 23 #define OPM_ISTLSOLVER_WITH_GPUBRIDGE_HEADER_INCLUDED 25 #include <opm/simulators/linalg/ISTLSolver.hpp> 37 template<
class Matrix,
class Vector,
int block_size>
class GpuBridge;
38 template<
class Scalar>
class WellContributions;
41 template<
class Matrix,
class Vector>
44 using Scalar =
typename Vector::field_type;
45 using WellContribFunc = std::function<void(WellContributions<Scalar>&)>;
49 const int linear_solver_verbosity,
51 const Scalar tolerance,
54 const bool opencl_ilu_parallel,
55 const std::string& linsolver);
60 void prepare(
const Grid& grid,
62 const std::vector<Well>& wellsForConn,
63 const std::unordered_map<std::string, std::set<int>>& possibleFutureConnections,
64 const std::vector<int>& cellPartition,
65 const std::size_t nonzeroes,
66 const bool useWellConn);
68 bool apply(Vector& rhs,
69 const bool useWellConn,
70 WellContribFunc getContribs,
74 Dune::InverseOperatorResult& result);
78 int numJacobiBlocks_ = 0;
84 void blockJacobiAdjacency(
const Grid& grid,
85 const std::vector<int>& cell_part,
86 std::size_t nonzeroes);
88 void copyMatToBlockJac(
const Matrix& mat, Matrix& blockJac);
90 std::unique_ptr<Bridge> bridge_;
91 std::string accelerator_mode_;
92 std::unique_ptr<Matrix> blockJacobiForGPUILU0_;
93 std::vector<std::set<int>> wellConnectionsGraph_;
102 template <
class TypeTag>
114 using Matrix =
typename SparseMatrixAdapter::IstlMatrix;
117 using AbstractSolverType = Dune::InverseOperator<Vector, Vector>;
118 using AbstractOperatorType = Dune::AssembledLinearOperator<Matrix, Vector, Vector>;
125 using CommunicationType = Dune::OwnerOverlapCopyCommunication<int,int>;
127 using CommunicationType = Dune::Communication<int>;
131 using AssembledLinearOperatorType = Dune::AssembledLinearOperator< Matrix, Vector, Vector >;
153 OPM_TIMEBLOCK(initializeGpu);
155 std::string accelerator_mode = Parameters::Get<Parameters::AcceleratorMode>();
157 if ((this->simulator_.vanguard().grid().comm().size() > 1) && (accelerator_mode !=
"none")) {
158 const bool on_io_rank = (this->simulator_.gridView().comm().rank() == 0);
160 OpmLog::warning(
"Cannot use AcceleratorMode feature with MPI, setting AcceleratorMode to 'none'.");
162 accelerator_mode =
"none";
165 if (accelerator_mode ==
"none") {
170 const int platformID = Parameters::Get<Parameters::OpenclPlatformId>();
171 const int deviceID = Parameters::Get<Parameters::GpuDeviceId>();
172 const int maxit = Parameters::Get<Parameters::LinearSolverMaxIter>();
173 const double tolerance = Parameters::Get<Parameters::LinearSolverReduction>();
174 const bool opencl_ilu_parallel = Parameters::Get<Parameters::OpenclIluParallel>();
175 const int linear_solver_verbosity = this->parameters_[0].linear_solver_verbosity_;
176 std::string linsolver = Parameters::Get<Parameters::LinearSolver>();
177 gpuBridge_ = std::make_unique<detail::GpuSolverInfo<Matrix,Vector>>(accelerator_mode,
178 linear_solver_verbosity,
187 using ISTLSolver<TypeTag>::prepare;
188 void prepare(
const Matrix& M, Vector& b)
override 190 OPM_TIMEBLOCK(prepare);
191 [[maybe_unused]]
const bool firstcall = (this->matrix_ ==
nullptr);
196 ParentType::initPrepare(M,b);
198 ParentType::prepare(M,b);
201 #if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA 203 if (firstcall && gpuBridge_) {
208 gpuBridge_->numJacobiBlocks_ = Parameters::Get<Parameters::NumJacobiBlocks>();
209 gpuBridge_->prepare(this->simulator_.vanguard().grid(),
210 this->simulator_.vanguard().cartesianIndexMapper(),
211 this->simulator_.vanguard().schedule().getWellsatEnd(),
212 this->simulator_.vanguard().schedule().getPossibleFutureConnections(),
213 this->simulator_.vanguard().cellPartition(),
214 this->getMatrix().nonzeroes(), this->useWellConn_);
220 void setResidual(Vector& )
override 225 void getResidual(Vector& b)
const override 230 void setMatrix(
const SparseMatrixAdapter& )
override 235 bool solve(Vector& x)
override 238 return ParentType::solve(x);
241 OPM_TIMEBLOCK(istlSolverGpuBridgeSolve);
242 this->solveCount_ += 1;
244 const int verbosity = this->prm_[this->activeSolverNum_].template get<int>(
"verbosity", 0);
245 const bool write_matrix = verbosity > 10;
247 Helper::writeSystem(this->simulator_,
254 Dune::InverseOperatorResult result;
256 std::function<void(WellContributions<Scalar>&)> getContribs =
257 [
this](WellContributions<Scalar>& w)
259 this->simulator_.problem().wellModel().getWellContributions(w);
261 if (!gpuBridge_->apply(*(this->rhs_), this->useWellConn_, getContribs,
262 this->simulator_.gridView().comm().rank(),
263 const_cast<Matrix&
>(this->getMatrix()),
266 if(gpuBridge_->gpuActive()){
268 ParentType::prepareFlexibleSolver();
270 assert(this->flexibleSolver_[this->activeSolverNum_].solver_);
271 this->flexibleSolver_[this->activeSolverNum_].solver_->apply(x, *(this->rhs_), result);
275 return this->checkConvergence(result);
279 std::unique_ptr<detail::GpuSolverInfo<Matrix, Vector>> gpuBridge_;
284 #endif // OPM_ISTLSOLVER_WITH_GPUBRIDGE_HEADER_INCLUDED Simplifies multi-threaded capabilities.
Definition: threadmanager.hpp:35
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
ISTLSolverGpuBridge(const Simulator &simulator, const FlowLinearSolverParameters ¶meters)
Construct a system solver.
Definition: ISTLSolverGpuBridge.hpp:137
This class solves the fully implicit black-oil system by solving the reduced system (after eliminatin...
Definition: FlowLinearSolverParameters.hpp:40
ISTLSolverGpuBridge(const Simulator &simulator)
Construct a system solver.
Definition: ISTLSolverGpuBridge.hpp:145
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: ISTLSolverGpuBridge.hpp:42
Interface class adding the update() method to the preconditioner interface.
Definition: PreconditionerWithUpdate.hpp:33
This class carries all parameters for the NewtonIterationBlackoilInterleaved class.
Definition: FlowLinearSolverParameters.hpp:97
GpuBridge acts as interface between opm-simulators with the GpuSolvers.
Definition: GpuBridge.hpp:36
This class solves the fully implicit black-oil system by solving the reduced system (after eliminatin...
Definition: FlowLinearSolverParameters.hpp:37
Definition: WellOperators.hpp:69
Definition: CollectDataOnIORank.hpp:50
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:83