Loading...
Searching...
No Matches
GpuSolver.hpp
/*
Copyright 2019 Equinor ASA
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_GPUSOLVER_BACKEND_HEADER_INCLUDED
#define OPM_GPUSOLVER_BACKEND_HEADER_INCLUDED
#include <opm/simulators/linalg/gpubridge/GpuResult.hpp>
#include <opm/simulators/linalg/gpubridge/BlockedMatrix.hpp>
#include <memory>
namespace Opm {
template<class Scalar> class WellContributions;
namespace Accelerator {
enum class SolverStatus {
GPU_SOLVER_SUCCESS,
GPU_SOLVER_ANALYSIS_FAILED,
GPU_SOLVER_CREATE_PRECONDITIONER_FAILED,
GPU_SOLVER_UNKNOWN_ERROR
};
template<class Scalar, unsigned int block_size>
class GpuSolver
{
protected:
// verbosity
// 0: print nothing during solves, only when initializing
// 1: print number of iterations and final norm
// 2: also print norm each iteration
// 3: also print timings of different backend functions
int verbosity = 0;
int maxit = 200;
Scalar tolerance = 1e-2;
int N; // number of rows
int Nb; // number of blocked rows (Nb*block_size == N)
int nnz; // number of nonzeroes (scalars)
int nnzb; // number of nonzero blocks (nnzb*block_size*block_size == nnz)
unsigned int platformID = 0; // ID of OpenCL platform to be used, only used by openclSolver now
unsigned int deviceID = 0; // ID of the device to be used
bool initialized = false;
public:
GpuSolver(int linear_solver_verbosity, int max_it, Scalar tolerance_)
: verbosity(linear_solver_verbosity)
, maxit(max_it)
, tolerance(tolerance_)
{}
GpuSolver(int linear_solver_verbosity, int max_it,
Scalar tolerance_, unsigned int deviceID_)
: verbosity(linear_solver_verbosity)
, maxit(max_it)
, tolerance(tolerance_)
, deviceID(deviceID_) {};
GpuSolver(int linear_solver_verbosity, int max_it,
double tolerance_, unsigned int platformID_,
unsigned int deviceID_)
: verbosity(linear_solver_verbosity)
, maxit(max_it)
, tolerance(tolerance_)
, platformID(platformID_)
, deviceID(deviceID_)
{}
virtual ~GpuSolver() = default;
virtual SolverStatus solve_system(std::shared_ptr<BlockedMatrix<Scalar>> matrix,
Scalar* b,
std::shared_ptr<BlockedMatrix<Scalar>> jacMatrix,
WellContributions<Scalar>& wellContribs,
GpuResult& res) = 0;
virtual void get_result(Scalar* x) = 0;
}; // end class GpuSolver
} // namespace Accelerator
} // namespace Opm
#endif
Opm::Accelerator::BlockedMatrix
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition BlockedMatrix.hpp:29
Opm::Accelerator::GpuResult
This class is based on InverseOperatorResult struct from dune/istl/solver.hh It is needed to prevent ...
Definition GpuResult.hpp:31
Opm::Accelerator::GpuSolver::~GpuSolver
virtual ~GpuSolver()=default
Define virtual destructor, so that the derivedclass destructor will be called.
Opm::Accelerator::GpuSolver::solve_system
virtual SolverStatus solve_system(std::shared_ptr< BlockedMatrix< Scalar > > matrix, Scalar *b, std::shared_ptr< BlockedMatrix< Scalar > > jacMatrix, WellContributions< Scalar > &wellContribs, GpuResult &res)=0
Define as pure virtual functions, so derivedclass must implement them.
Opm::Accelerator::GpuSolver::GpuSolver
GpuSolver(int linear_solver_verbosity, int max_it, Scalar tolerance_)
Construct a GpuSolver.
Definition GpuSolver.hpp:73
Opm::WellContributions
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition WellContributions.hpp:51
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43