mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Move opencl variables to Preconditioner
This commit is contained in:
parent
94ea2dcd30
commit
374f8276dc
@ -48,14 +48,6 @@ BILU0<block_size>::BILU0(ILUReorder opencl_ilu_reorder_, int verbosity_) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <unsigned int block_size>
|
|
||||||
void BILU0<block_size>::init(int Nb, int nnzb, std::shared_ptr<cl::Context>& context_, std::shared_ptr<cl::CommandQueue>& queue_)
|
|
||||||
{
|
|
||||||
context = context_.get();
|
|
||||||
queue = queue_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <unsigned int block_size>
|
template <unsigned int block_size>
|
||||||
bool BILU0<block_size>::analyze_matrix(BlockedMatrix *mat)
|
bool BILU0<block_size>::analyze_matrix(BlockedMatrix *mat)
|
||||||
{
|
{
|
||||||
|
@ -48,6 +48,10 @@ class BILU0 : public Preconditioner<block_size>
|
|||||||
using Base::nnz;
|
using Base::nnz;
|
||||||
using Base::nnzb;
|
using Base::nnzb;
|
||||||
using Base::verbosity;
|
using Base::verbosity;
|
||||||
|
using Base::context;
|
||||||
|
using Base::queue;
|
||||||
|
using Base::events;
|
||||||
|
using Base::err;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<BlockedMatrix> LUmat = nullptr;
|
std::unique_ptr<BlockedMatrix> LUmat = nullptr;
|
||||||
@ -78,10 +82,6 @@ private:
|
|||||||
} GPU_storage;
|
} GPU_storage;
|
||||||
|
|
||||||
GPU_storage s;
|
GPU_storage s;
|
||||||
cl::Context *context;
|
|
||||||
cl::CommandQueue *queue;
|
|
||||||
std::vector<cl::Event> events;
|
|
||||||
cl_int err;
|
|
||||||
|
|
||||||
#if CHOW_PATEL
|
#if CHOW_PATEL
|
||||||
ChowPatelIlu<block_size> chowPatelIlu;
|
ChowPatelIlu<block_size> chowPatelIlu;
|
||||||
@ -91,8 +91,6 @@ public:
|
|||||||
|
|
||||||
BILU0(ILUReorder opencl_ilu_reorder, int verbosity);
|
BILU0(ILUReorder opencl_ilu_reorder, int verbosity);
|
||||||
|
|
||||||
void init(int Nb, int nnzb, std::shared_ptr<cl::Context>& context, std::shared_ptr<cl::CommandQueue>& queue) override;
|
|
||||||
|
|
||||||
// analysis, find reordering if specified
|
// analysis, find reordering if specified
|
||||||
bool analyze_matrix(BlockedMatrix *mat) override;
|
bool analyze_matrix(BlockedMatrix *mat) override;
|
||||||
|
|
||||||
|
@ -47,31 +47,28 @@ CPR<block_size>::CPR(int verbosity_, ILUReorder opencl_ilu_reorder_) :
|
|||||||
Preconditioner<block_size>(verbosity_), opencl_ilu_reorder(opencl_ilu_reorder_)
|
Preconditioner<block_size>(verbosity_), opencl_ilu_reorder(opencl_ilu_reorder_)
|
||||||
{
|
{
|
||||||
bilu0 = std::make_unique<BILU0<block_size> >(opencl_ilu_reorder, verbosity_);
|
bilu0 = std::make_unique<BILU0<block_size> >(opencl_ilu_reorder, verbosity_);
|
||||||
|
diagIndices.resize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <unsigned int block_size>
|
template <unsigned int block_size>
|
||||||
void CPR<block_size>::init(int Nb_, int nnzb_, std::shared_ptr<cl::Context>& context_, std::shared_ptr<cl::CommandQueue>& queue_) {
|
void CPR<block_size>::setOpencl(std::shared_ptr<cl::Context>& context_, std::shared_ptr<cl::CommandQueue>& queue_) {
|
||||||
this->Nb = Nb_;
|
|
||||||
this->nnzb = nnzb_;
|
|
||||||
this->N = Nb_ * block_size;
|
|
||||||
this->nnz = nnzb_ * block_size * block_size;
|
|
||||||
|
|
||||||
context = context_;
|
context = context_;
|
||||||
queue = queue_;
|
queue = queue_;
|
||||||
|
|
||||||
coarse_vals.resize(nnzb);
|
bilu0->setOpencl(context, queue);
|
||||||
coarse_x.resize(Nb);
|
|
||||||
coarse_y.resize(Nb);
|
|
||||||
weights.resize(N);
|
|
||||||
diagIndices.resize(1);
|
|
||||||
|
|
||||||
bilu0->init(Nb, nnzb, context, queue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <unsigned int block_size>
|
template <unsigned int block_size>
|
||||||
bool CPR<block_size>::analyze_matrix(BlockedMatrix *mat_) {
|
bool CPR<block_size>::analyze_matrix(BlockedMatrix *mat_) {
|
||||||
|
|
||||||
|
this->Nb = mat_->Nb;
|
||||||
|
this->nnzb = mat_->nnzbs;
|
||||||
|
this->N = Nb * block_size;
|
||||||
|
this->nnz = nnzb * block_size * block_size;
|
||||||
|
|
||||||
bool success = bilu0->analyze_matrix(mat_);
|
bool success = bilu0->analyze_matrix(mat_);
|
||||||
|
|
||||||
if (opencl_ilu_reorder == ILUReorder::NONE) {
|
if (opencl_ilu_reorder == ILUReorder::NONE) {
|
||||||
@ -191,6 +188,11 @@ template <unsigned int block_size>
|
|||||||
void CPR<block_size>::create_preconditioner_amg(BlockedMatrix *mat_) {
|
void CPR<block_size>::create_preconditioner_amg(BlockedMatrix *mat_) {
|
||||||
this->mat = mat_;
|
this->mat = mat_;
|
||||||
|
|
||||||
|
coarse_vals.resize(nnzb);
|
||||||
|
coarse_x.resize(Nb);
|
||||||
|
coarse_y.resize(Nb);
|
||||||
|
weights.resize(N);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
double rhs[] = {0, 0, 0};
|
double rhs[] = {0, 0, 0};
|
||||||
rhs[pressure_idx] = 1;
|
rhs[pressure_idx] = 1;
|
||||||
|
@ -57,6 +57,10 @@ class CPR : public Preconditioner<block_size>
|
|||||||
using Base::nnz;
|
using Base::nnz;
|
||||||
using Base::nnzb;
|
using Base::nnzb;
|
||||||
using Base::verbosity;
|
using Base::verbosity;
|
||||||
|
using Base::context;
|
||||||
|
using Base::queue;
|
||||||
|
using Base::events;
|
||||||
|
using Base::err;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int num_levels;
|
int num_levels;
|
||||||
@ -96,11 +100,6 @@ private:
|
|||||||
std::unique_ptr<openclSolverBackend<1> > coarse_solver; // coarse solver is scalar
|
std::unique_ptr<openclSolverBackend<1> > coarse_solver; // coarse solver is scalar
|
||||||
ILUReorder opencl_ilu_reorder; // reordering strategy for ILU0 in coarse solver
|
ILUReorder opencl_ilu_reorder; // reordering strategy for ILU0 in coarse solver
|
||||||
|
|
||||||
std::shared_ptr<cl::Context> context;
|
|
||||||
std::shared_ptr<cl::CommandQueue> queue;
|
|
||||||
std::vector<cl::Event> events;
|
|
||||||
cl_int err;
|
|
||||||
|
|
||||||
// Analyze the AMG hierarchy build by Dune
|
// Analyze the AMG hierarchy build by Dune
|
||||||
void analyzeHierarchy();
|
void analyzeHierarchy();
|
||||||
|
|
||||||
@ -125,10 +124,11 @@ public:
|
|||||||
|
|
||||||
CPR(int verbosity, ILUReorder opencl_ilu_reorder);
|
CPR(int verbosity, ILUReorder opencl_ilu_reorder);
|
||||||
|
|
||||||
void init(int Nb, int nnzb, std::shared_ptr<cl::Context>& context, std::shared_ptr<cl::CommandQueue>& queue) override;
|
|
||||||
|
|
||||||
bool analyze_matrix(BlockedMatrix *mat) override;
|
bool analyze_matrix(BlockedMatrix *mat) override;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
// applies blocked ilu0
|
// applies blocked ilu0
|
||||||
// also applies amg for pressure component
|
// also applies amg for pressure component
|
||||||
void apply(const cl::Buffer& y, cl::Buffer& x) override;
|
void apply(const cl::Buffer& y, cl::Buffer& x) override;
|
||||||
|
@ -31,6 +31,13 @@ namespace Opm
|
|||||||
namespace Accelerator
|
namespace Accelerator
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
template <unsigned int block_size>
|
||||||
|
void Preconditioner<block_size>::setOpencl(std::shared_ptr<cl::Context>& context_, std::shared_ptr<cl::CommandQueue>& queue_) {
|
||||||
|
context = context_;
|
||||||
|
queue = queue_;
|
||||||
|
}
|
||||||
|
|
||||||
template <unsigned int block_size>
|
template <unsigned int block_size>
|
||||||
std::unique_ptr<Preconditioner<block_size> > Preconditioner<block_size>::create(PreconditionerType type, int verbosity, ILUReorder opencl_ilu_reorder) {
|
std::unique_ptr<Preconditioner<block_size> > Preconditioner<block_size>::create(PreconditionerType type, int verbosity, ILUReorder opencl_ilu_reorder) {
|
||||||
if (type == PreconditionerType::BILU0) {
|
if (type == PreconditionerType::BILU0) {
|
||||||
@ -44,7 +51,8 @@ std::unique_ptr<Preconditioner<block_size> > Preconditioner<block_size>::create(
|
|||||||
|
|
||||||
|
|
||||||
#define INSTANTIATE_BDA_FUNCTIONS(n) \
|
#define INSTANTIATE_BDA_FUNCTIONS(n) \
|
||||||
template std::unique_ptr<Preconditioner<n> > Preconditioner<n>::create(PreconditionerType, int, ILUReorder);
|
template std::unique_ptr<Preconditioner<n> > Preconditioner<n>::create(PreconditionerType, int, ILUReorder); \
|
||||||
|
template void Preconditioner<n>::setOpencl(std::shared_ptr<cl::Context>&, std::shared_ptr<cl::CommandQueue>&);
|
||||||
|
|
||||||
INSTANTIATE_BDA_FUNCTIONS(1);
|
INSTANTIATE_BDA_FUNCTIONS(1);
|
||||||
INSTANTIATE_BDA_FUNCTIONS(2);
|
INSTANTIATE_BDA_FUNCTIONS(2);
|
||||||
|
@ -42,6 +42,11 @@ protected:
|
|||||||
int nnzb = 0; // number of blocks of the matrix
|
int nnzb = 0; // number of blocks of the matrix
|
||||||
int verbosity = 0;
|
int verbosity = 0;
|
||||||
|
|
||||||
|
std::shared_ptr<cl::Context> context;
|
||||||
|
std::shared_ptr<cl::CommandQueue> queue;
|
||||||
|
std::vector<cl::Event> events;
|
||||||
|
cl_int err;
|
||||||
|
|
||||||
Preconditioner(int verbosity_) :
|
Preconditioner(int verbosity_) :
|
||||||
verbosity(verbosity_)
|
verbosity(verbosity_)
|
||||||
{};
|
{};
|
||||||
@ -54,7 +59,8 @@ public:
|
|||||||
|
|
||||||
static std::unique_ptr<Preconditioner> create(PreconditionerType type, int verbosity, ILUReorder opencl_ilu_reorder);
|
static std::unique_ptr<Preconditioner> create(PreconditionerType type, int verbosity, ILUReorder opencl_ilu_reorder);
|
||||||
|
|
||||||
virtual void init(int Nb, int nnzb, std::shared_ptr<cl::Context>& context, std::shared_ptr<cl::CommandQueue>& queue);
|
// nested Preconditioners might need to override this
|
||||||
|
virtual void setOpencl(std::shared_ptr<cl::Context>& context, std::shared_ptr<cl::CommandQueue>& queue);
|
||||||
|
|
||||||
// apply preconditioner, x = prec(y)
|
// apply preconditioner, x = prec(y)
|
||||||
virtual void apply(const cl::Buffer& y, cl::Buffer& x) = 0;
|
virtual void apply(const cl::Buffer& y, cl::Buffer& x) = 0;
|
||||||
|
@ -388,7 +388,7 @@ void openclSolverBackend<block_size>::initialize(int N_, int nnz_, int dim, doub
|
|||||||
out.clear();
|
out.clear();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
prec->init(Nb, nnzb, context, queue);
|
prec->setOpencl(context, queue);
|
||||||
|
|
||||||
#if COPY_ROW_BY_ROW
|
#if COPY_ROW_BY_ROW
|
||||||
vals_contiguous.resize(nnz);
|
vals_contiguous.resize(nnz);
|
||||||
|
Loading…
Reference in New Issue
Block a user