Loading...
Searching...
No Matches
openclBISAI.hpp
/*
Copyright 2022 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_OPENCLBISAI_HPP
#define OPM_OPENCLBISAI_HPP
#include <mutex>
#include <opm/simulators/linalg/gpubridge/opencl/opencl.hpp>
#include <opm/simulators/linalg/gpubridge/opencl/openclBILU0.hpp>
#include <opm/simulators/linalg/gpubridge/opencl/openclPreconditioner.hpp>
namespace Opm::Accelerator {
template<class Scalar> class BlockedMatrix;
template<class Scalar, unsigned int block_size>
class openclBISAI : public openclPreconditioner<Scalar,block_size>
{
using Base = openclPreconditioner<Scalar,block_size>;
using Base::N;
using Base::Nb;
using Base::nnz;
using Base::nnzb;
using Base::verbosity;
using Base::context;
using Base::queue;
using Base::events;
using Base::err;
private:
std::once_flag initialize;
std::vector<int> colPointers;
std::vector<int> rowIndices;
std::vector<int> diagIndex;
std::vector<int> csrToCscOffsetMap;
std::vector<Scalar> invLvals;
std::vector<Scalar> invUvals;
cl::Buffer d_colPointers;
cl::Buffer d_rowIndices;
cl::Buffer d_csrToCscOffsetMap;
cl::Buffer d_diagIndex;
cl::Buffer d_LUvals;
cl::Buffer d_invDiagVals;
cl::Buffer d_invLvals;
cl::Buffer d_invUvals;
cl::Buffer d_invL_x;
bool opencl_ilu_parallel;
std::unique_ptr<openclBILU0<Scalar,block_size>> bilu0;
struct subsystemStructure {
std::vector<int> subsystemPointers;
std::vector<int> nzIndices;
std::vector<int> knownRhsIndices;
std::vector<int> unknownRhsIndices;
};
struct subsystemStructureGPU {
cl::Buffer subsystemPointers;
cl::Buffer nzIndices;
cl::Buffer knownRhsIndices;
cl::Buffer unknownRhsIndices;
} ;
subsystemStructure lower, upper;
subsystemStructureGPU d_lower, d_upper;
void buildLowerSubsystemsStructures();
void buildUpperSubsystemsStructures();
public:
openclBISAI(bool opencl_ilu_parallel, int verbosity);
// set own Opencl variables, but also that of the bilu0 preconditioner
void setOpencl(std::shared_ptr<cl::Context>& context,
std::shared_ptr<cl::CommandQueue>& queue) override;
// analysis, extract parallelism
bool analyze_matrix(BlockedMatrix<Scalar>* mat) override;
bool analyze_matrix(BlockedMatrix<Scalar>* mat,
BlockedMatrix<Scalar>* jacMat) override;
// ilu_decomposition
bool create_preconditioner(BlockedMatrix<Scalar>* mat) override;
bool create_preconditioner(BlockedMatrix<Scalar>* mat,
BlockedMatrix<Scalar>* jacMat) override;
// apply preconditioner, x = prec(y)
void apply(const cl::Buffer& y,
cl::Buffer& x,
WellContributions<Scalar>& wellContribs) override;
};
std::vector<int> buildCsrToCscOffsetMap(std::vector<int> colPointers, std::vector<int> rowIndices);
} // namespace Opm::Accelerator
#endif
Opm::Accelerator::BlockedMatrix
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition BlockedMatrix.hpp:29
Opm::WellContributions
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition WellContributions.hpp:51