Rename namespace bda to Opm::Accelerator

This commit is contained in:
Tong Dong Qiu 2021-10-25 11:08:06 +02:00
parent b945502a82
commit 920eeee426
32 changed files with 165 additions and 84 deletions

View File

@ -30,7 +30,9 @@
#include <opm/simulators/linalg/bda/Reorder.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -322,4 +324,5 @@ INSTANTIATE_BDA_FUNCTIONS(6);
#undef INSTANTIATE_BDA_FUNCTIONS
} // end namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -30,7 +30,9 @@
#include <opm/simulators/linalg/bda/ChowPatelIlu.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
/// This class implementa a Blocked ILU0 preconditioner
@ -117,7 +119,8 @@ namespace bda
};
} // end namespace bda
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -47,10 +47,10 @@ typedef Dune::InverseOperatorResult InverseOperatorResult;
namespace Opm
{
using bda::BdaResult;
using bda::BdaSolver;
using bda::SolverStatus;
using bda::ILUReorder;
using Opm::Accelerator::BdaResult;
using Opm::Accelerator::BdaSolver;
using Opm::Accelerator::SolverStatus;
using Opm::Accelerator::ILUReorder;
template <class BridgeMatrix, class BridgeVector, int block_size>
BdaBridge<BridgeMatrix, BridgeVector, block_size>::BdaBridge(std::string accelerator_mode_,
@ -65,7 +65,7 @@ BdaBridge<BridgeMatrix, BridgeVector, block_size>::BdaBridge(std::string acceler
if (accelerator_mode.compare("cusparse") == 0) {
#if HAVE_CUDA
use_gpu = true;
backend.reset(new bda::cusparseSolverBackend<block_size>(linear_solver_verbosity, maxit, tolerance, deviceID));
backend.reset(new Opm::Accelerator::cusparseSolverBackend<block_size>(linear_solver_verbosity, maxit, tolerance, deviceID));
#else
OPM_THROW(std::logic_error, "Error cusparseSolver was chosen, but CUDA was not found by CMake");
#endif
@ -74,17 +74,17 @@ BdaBridge<BridgeMatrix, BridgeVector, block_size>::BdaBridge(std::string acceler
use_gpu = true;
ILUReorder ilu_reorder;
if (opencl_ilu_reorder == "") {
ilu_reorder = bda::ILUReorder::GRAPH_COLORING; // default when not selected by user
ilu_reorder = Opm::Accelerator::ILUReorder::GRAPH_COLORING; // default when not selected by user
} else if (opencl_ilu_reorder == "level_scheduling") {
ilu_reorder = bda::ILUReorder::LEVEL_SCHEDULING;
ilu_reorder = Opm::Accelerator::ILUReorder::LEVEL_SCHEDULING;
} else if (opencl_ilu_reorder == "graph_coloring") {
ilu_reorder = bda::ILUReorder::GRAPH_COLORING;
ilu_reorder = Opm::Accelerator::ILUReorder::GRAPH_COLORING;
} else if (opencl_ilu_reorder == "none") {
ilu_reorder = bda::ILUReorder::NONE;
ilu_reorder = Opm::Accelerator::ILUReorder::NONE;
} else {
OPM_THROW(std::logic_error, "Error invalid argument for --opencl-ilu-reorder, usage: '--opencl-ilu-reorder=[level_scheduling|graph_coloring]'");
}
backend.reset(new bda::openclSolverBackend<block_size>(linear_solver_verbosity, maxit, tolerance, platformID, deviceID, ilu_reorder));
backend.reset(new Opm::Accelerator::openclSolverBackend<block_size>(linear_solver_verbosity, maxit, tolerance, platformID, deviceID, ilu_reorder));
#else
OPM_THROW(std::logic_error, "Error openclSolver was chosen, but OpenCL was not found by CMake");
#endif
@ -93,22 +93,22 @@ BdaBridge<BridgeMatrix, BridgeVector, block_size>::BdaBridge(std::string acceler
use_fpga = true;
ILUReorder ilu_reorder;
if (opencl_ilu_reorder == "") {
ilu_reorder = bda::ILUReorder::LEVEL_SCHEDULING; // default when not selected by user
ilu_reorder = Opm::Accelerator::ILUReorder::LEVEL_SCHEDULING; // default when not selected by user
} else if (opencl_ilu_reorder == "level_scheduling") {
ilu_reorder = bda::ILUReorder::LEVEL_SCHEDULING;
ilu_reorder = Opm::Accelerator::ILUReorder::LEVEL_SCHEDULING;
} else if (opencl_ilu_reorder == "graph_coloring") {
ilu_reorder = bda::ILUReorder::GRAPH_COLORING;
ilu_reorder = Opm::Accelerator::ILUReorder::GRAPH_COLORING;
} else {
OPM_THROW(std::logic_error, "Error invalid argument for --opencl-ilu-reorder, usage: '--opencl-ilu-reorder=[level_scheduling|graph_coloring]'");
}
backend.reset(new bda::FpgaSolverBackend<block_size>(fpga_bitstream, linear_solver_verbosity, maxit, tolerance, ilu_reorder));
backend.reset(new Opm::Accelerator::FpgaSolverBackend<block_size>(fpga_bitstream, linear_solver_verbosity, maxit, tolerance, ilu_reorder));
#else
OPM_THROW(std::logic_error, "Error fpgaSolver was chosen, but FPGA was not enabled by CMake");
#endif
} else if (accelerator_mode.compare("amgcl") == 0) {
#if HAVE_AMGCL
use_gpu = true; // should be replaced by a 'use_bridge' boolean
backend.reset(new bda::amgclSolverBackend<block_size>(linear_solver_verbosity, maxit, tolerance, platformID, deviceID));
backend.reset(new Opm::Accelerator::amgclSolverBackend<block_size>(linear_solver_verbosity, maxit, tolerance, platformID, deviceID));
#else
OPM_THROW(std::logic_error, "Error amgclSolver was chosen, but amgcl was not found by CMake");
#endif
@ -269,7 +269,7 @@ template <class BridgeMatrix, class BridgeVector, int block_size>
void BdaBridge<BridgeMatrix, BridgeVector, block_size>::initWellContributions([[maybe_unused]] WellContributions& wellContribs) {
if(accelerator_mode.compare("opencl") == 0){
#if HAVE_OPENCL
const auto openclBackend = static_cast<const bda::openclSolverBackend<block_size>*>(backend.get());
const auto openclBackend = static_cast<const Opm::Accelerator::openclSolverBackend<block_size>*>(backend.get());
wellContribs.setOpenCLEnv(openclBackend->context.get(), openclBackend->queue.get());
#else
OPM_THROW(std::logic_error, "Error openclSolver was chosen, but OpenCL was not found by CMake");

View File

@ -38,7 +38,7 @@ namespace Opm
{
typedef Dune::InverseOperatorResult InverseOperatorResult;
using bda::ILUReorder;
using Opm::Accelerator::ILUReorder;
/// BdaBridge acts as interface between opm-simulators with the BdaSolvers
template <class BridgeMatrix, class BridgeVector, int block_size>
@ -49,7 +49,7 @@ private:
bool use_gpu = false;
bool use_fpga = false;
std::string accelerator_mode;
std::unique_ptr<bda::BdaSolver<block_size> > backend;
std::unique_ptr<Opm::Accelerator::BdaSolver<block_size> > backend;
public:
/// Construct a BdaBridge

View File

@ -20,7 +20,9 @@
#ifndef BDARESULT_HEADER_INCLUDED
#define BDARESULT_HEADER_INCLUDED
namespace bda
namespace Opm
{
namespace Accelerator
{
/// This class is based on InverseOperatorResult struct from dune/istl/solver.hh
@ -39,6 +41,7 @@ public:
}; // end class BdaResult
}
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -24,7 +24,9 @@
#include <opm/simulators/linalg/bda/BdaResult.hpp>
#include <opm/simulators/linalg/bda/WellContributions.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::WellContributions;
@ -91,6 +93,7 @@ namespace bda
}; // end class BdaSolver
} // end namespace bda
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -28,7 +28,9 @@
#include <opm/simulators/linalg/bda/BlockedMatrix.hpp>
#include <opm/simulators/linalg/bda/FPGAUtils.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -504,5 +506,5 @@ INSTANTIATE_BDA_FPGA_FUNCTIONS(4);
#undef INSTANTIATE_BDA_FPGA_FUNCTIONS
#endif // HAVE_FPGA
} // end namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -26,7 +26,9 @@
#include <opm/simulators/linalg/bda/FPGAMatrix.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
/// This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
@ -164,6 +166,7 @@ void blockVectMult(double *mat, double *vect, double scale, double *resVect, boo
void blockedDiagtoRDF(double *blockedDiagVals, int rowSize, int numColors, std::vector<int>& rowsPerColor, double *RDFDiag);
#endif
} // end namespace bda
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -28,7 +28,9 @@
#if CHOW_PATEL
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -1004,7 +1006,8 @@ INSTANTIATE_BDA_FUNCTIONS(6);
#undef INSTANTIATE_BDA_FUNCTIONS
} // end namespace bda
} // namespace Accelerator
} // namespace Opm
#endif // CHOW_PATEL

View File

@ -40,7 +40,9 @@
#if CHOW_PATEL
namespace bda
namespace Opm
{
namespace Accelerator
{
@ -117,7 +119,8 @@ public:
};
} // end namespace bda
} // namespace Accelerator
} // namespace Opm
#endif // CHOW_PATEL

View File

@ -29,7 +29,9 @@
#include <opm/simulators/linalg/bda/Reorder.hpp>
#include <opm/simulators/linalg/bda/FPGAUtils.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -412,4 +414,5 @@ INSTANTIATE_BDA_FUNCTIONS(6);
#undef INSTANTIATE_BDA_FUNCTIONS
} //namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -25,7 +25,9 @@
#include <opm/simulators/linalg/bda/ILUReorder.hpp>
#include <opm/simulators/linalg/bda/BlockedMatrix.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
/*
@ -112,6 +114,7 @@ public:
};
} //namespace bda
} // namespace Accelerator
} // namespace Opm
#endif // FPGA_BILU0_HEADER_INCLUDED

View File

@ -23,7 +23,9 @@
#include <opm/simulators/linalg/bda/FPGAMatrix.hpp>
#include <opm/simulators/linalg/bda/FPGAUtils.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
/*Sort a row of matrix elements from a CSR-format.*/
@ -246,4 +248,5 @@ int Matrix::toRDF(int numColors, std::vector<int>& nodesPerColor,
return 0;
}
} // end namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -22,7 +22,9 @@
#include <vector>
namespace bda
namespace Opm
{
namespace Accelerator
{
/// This struct resembles a csr matrix, only doubles are supported
@ -79,6 +81,7 @@ public:
void sortRow(int *colIndices, double *data, int left, int right);
} // end namespace bda
} // namespace Accelerator
} // namespace Opm
#endif // FPGA_MATRIX_HEADER_INCLUDED

View File

@ -39,7 +39,9 @@
//#define FPGA_STATISTICS_FILE_ENABLED
#undef FPGA_STATISTICS_FILE_ENABLED
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -731,4 +733,5 @@ INSTANTIATE_BDA_FUNCTIONS(6);
#undef INSTANTIATE_BDA_FUNCTIONS
} //namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -27,7 +27,9 @@
#include <linearalgebra/ilu0bicgstab/xilinx/src/sda_app/common/opencl_lib.hpp>
#include <linearalgebra/ilu0bicgstab/xilinx/src/sda_app/common/fpga_functions_bicgstab.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
/// This class implements an ilu0-bicgstab solver on FPGA
@ -259,7 +261,8 @@ public:
}; // end class fpgaSolverBackend
} //namespace bda
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -20,7 +20,9 @@
#include <sys/time.h>
#include <fstream>
namespace bda
namespace Opm
{
namespace Accelerator
{
double second(void)
@ -60,4 +62,5 @@ bool fileExists(const char *filename)
}
}
} //namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -20,7 +20,9 @@
#ifndef FPGA_UTILS_HEADER_INCLUDED
#define FPGA_UTILS_HEADER_INCLUDED
namespace bda
namespace Opm
{
namespace Accelerator
{
union double2int
@ -34,6 +36,7 @@ bool even(int n);
int roundUpTo(int i, int n);
bool fileExists(const char *filename);
} // end namespace bda
} // namespace Accelerator
} // namespace Opm
#endif // FPGA_UTILS_HEADER_INCLUDED

View File

@ -20,7 +20,9 @@
#ifndef ILUREORDER_HEADER_INCLUDED
#define ILUREORDER_HEADER_INCLUDED
namespace bda
namespace Opm
{
namespace Accelerator
{
// Level Scheduling respects the dependencies in the original matrix, and behaves like Dune and cusparse
// Graph Coloring is more aggresive and is likely to increase the number of linearizations and linear iterations to converge significantly, but can still be faster on GPU because it results in more parallelism
@ -31,6 +33,7 @@ namespace bda
NONE
};
}
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -45,7 +45,9 @@ namespace {
}
namespace bda
namespace Opm
{
namespace Accelerator
{
@ -381,4 +383,5 @@ INSTANTIATE_BDA_FUNCTIONS(6);
#undef INSTANTIATE_BDA_FUNCTIONS
} //namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -24,7 +24,9 @@
#include <opm/simulators/linalg/bda/BlockedMatrix.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
#define MAX_COLORS 256
@ -121,6 +123,7 @@ void findGraphColoring(const int *CSRColIndices, const int *CSRRowPointers, cons
/// \param[in] Nb number of blockrows in the matrix
void csrPatternToCsc(int *CSRColIndices, int *CSRRowPointers, int *CSCRowIndices, int *CSCColPointers, int Nb);
}
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -29,7 +29,7 @@
namespace Opm
{
using bda::OpenclKernels;
using Opm::Accelerator::OpenclKernels;
WellContributions::WellContributions(std::string accelerator_mode, bool useWellConn){
if(accelerator_mode.compare("cusparse") == 0){
@ -85,8 +85,8 @@ void WellContributions::setOpenCLEnv(cl::Context *context_, cl::CommandQueue *qu
this->queue = queue_;
}
void WellContributions::setKernel(bda::stdwell_apply_kernel_type *kernel_,
bda::stdwell_apply_no_reorder_kernel_type *kernel_no_reorder_){
void WellContributions::setKernel(Opm::Accelerator::stdwell_apply_kernel_type *kernel_,
Opm::Accelerator::stdwell_apply_no_reorder_kernel_type *kernel_no_reorder_){
this->kernel = kernel_;
this->kernel_no_reorder = kernel_no_reorder_;
}

View File

@ -94,8 +94,8 @@ private:
#if HAVE_OPENCL
cl::Context *context;
cl::CommandQueue *queue;
bda::stdwell_apply_kernel_type *kernel;
bda::stdwell_apply_no_reorder_kernel_type *kernel_no_reorder;
Opm::Accelerator::stdwell_apply_kernel_type *kernel;
Opm::Accelerator::stdwell_apply_no_reorder_kernel_type *kernel_no_reorder;
std::vector<cl::Event> events;
std::unique_ptr<cl::Buffer> d_Cnnzs_ocl, d_Dnnzs_ocl, d_Bnnzs_ocl;
@ -147,8 +147,8 @@ public:
#endif
#if HAVE_OPENCL
void setKernel(bda::stdwell_apply_kernel_type *kernel_,
bda::stdwell_apply_no_reorder_kernel_type *kernel_no_reorder_);
void setKernel(Opm::Accelerator::stdwell_apply_kernel_type *kernel_,
Opm::Accelerator::stdwell_apply_no_reorder_kernel_type *kernel_no_reorder_);
void setOpenCLEnv(cl::Context *context_, cl::CommandQueue *queue_);
/// Since the rows of the matrix are reordered, the columnindices of the matrixdata is incorrect

View File

@ -35,7 +35,9 @@
#include <amgcl/backend/vexcl_static_matrix.hpp>
#endif
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -381,4 +383,5 @@ INSTANTIATE_BDA_FUNCTIONS(6);
#undef INSTANTIATE_BDA_FUNCTIONS
} // namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -28,7 +28,9 @@
/// This file is only compiled when both amgcl and CUDA are found by CMake
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -87,5 +89,6 @@ INSTANTIATE_BDA_FUNCTIONS(6);
#undef INSTANTIATE_BDA_FUNCTIONS
} // namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -38,7 +38,9 @@
#include <amgcl/preconditioner/runtime.hpp>
#include <amgcl/value_type/static_matrix.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
/// This class does not implement a solver, but converts the BCSR format to normal CSR and uses amgcl for solving
@ -149,7 +151,8 @@ public:
}; // end class amgclSolverBackend
} // namespace bda
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -37,7 +37,9 @@
// otherwise, the nonzeroes of the matrix are assumed to be in a contiguous array, and a single GPU memcpy is enough
#define COPY_ROW_BY_ROW 0
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -511,6 +513,5 @@ INSTANTIATE_BDA_FUNCTIONS(6);
#undef INSTANTIATE_BDA_FUNCTIONS
} // namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -28,7 +28,9 @@
#include <opm/simulators/linalg/bda/BdaSolver.hpp>
#include <opm/simulators/linalg/bda/WellContributions.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
/// This class implements a cusparse-based ilu0-bicgstab solver on GPU
@ -142,7 +144,8 @@ public:
}; // end class cusparseSolverBackend
} // namespace bda
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -27,7 +27,9 @@
#include <opm/simulators/linalg/bda/openclKernels.hpp>
#include <opm/simulators/linalg/bda/ChowPatelIlu.hpp> // defines CHOW_PATEL
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -968,5 +970,6 @@ void OpenclKernels::apply_stdwells_no_reorder(cl::Buffer& d_Cnnzs_ocl, cl::Buffe
)";
}
} // end namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -25,7 +25,9 @@
#include <opm/simulators/linalg/bda/opencl.hpp>
namespace bda
namespace Opm
{
namespace Accelerator
{
using spmv_kernel_type = cl::KernelFunctor<cl::Buffer&, cl::Buffer&, cl::Buffer&, const unsigned int,
@ -145,6 +147,7 @@ public:
int dim, int dim_wells, cl::Buffer &d_val_pointers_ocl, int num_std_wells);
};
} // end namespace bda
} // namespace Accelerator
} // namespace Opm
#endif

View File

@ -35,7 +35,9 @@
// otherwise, the nonzeroes of the matrix are assumed to be in a contiguous array, and a single GPU memcpy is enough
#define COPY_ROW_BY_ROW 0
namespace bda
namespace Opm
{
namespace Accelerator
{
using Opm::OpmLog;
@ -633,4 +635,5 @@ INSTANTIATE_BDA_FUNCTIONS(6);
#undef INSTANTIATE_BDA_FUNCTIONS
} // namespace bda
} // namespace Accelerator
} // namespace Opm

View File

@ -30,7 +30,9 @@
#include <tuple>
namespace bda
namespace Opm
{
namespace Accelerator
{
/// This class implements a opencl-based ilu0-bicgstab solver on GPU
@ -204,7 +206,8 @@ public:
}; // end class openclSolverBackend
} // namespace bda
} // namespace Accelerator
} // namespace Opm
#endif