From 3dc368b0b46dfe66d8e7144f1e90ba150bcced5e Mon Sep 17 00:00:00 2001 From: "T.D. (Tongdong) Qiu" Date: Wed, 24 Jun 2020 16:46:04 +0200 Subject: [PATCH] Added block_size templates to the BdaBridge. Removed unused gpu_mode variable --- opm/simulators/linalg/ISTLSolverEbos.hpp | 5 ++-- opm/simulators/linalg/bda/BdaBridge.cpp | 38 ++++++++++++++---------- opm/simulators/linalg/bda/BdaBridge.hpp | 7 ++--- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/opm/simulators/linalg/ISTLSolverEbos.hpp b/opm/simulators/linalg/ISTLSolverEbos.hpp index cd11da8e7..d838cda3e 100644 --- a/opm/simulators/linalg/ISTLSolverEbos.hpp +++ b/opm/simulators/linalg/ISTLSolverEbos.hpp @@ -279,7 +279,8 @@ protected: static const int numEq = Indices::numEq; #if HAVE_CUDA + HAVE_OPENCL - std::unique_ptr bdaBridge; + static const unsigned int block_size = Matrix::block_type::rows; + std::unique_ptr> bdaBridge; #endif #if HAVE_MPI @@ -325,7 +326,7 @@ protected: const int maxit = EWOMS_GET_PARAM(TypeTag, int, LinearSolverMaxIter); const double tolerance = EWOMS_GET_PARAM(TypeTag, double, LinearSolverReduction); const int linear_solver_verbosity = parameters_.linear_solver_verbosity_; - bdaBridge.reset(new BdaBridge(gpu_mode, linear_solver_verbosity, maxit, tolerance)); + bdaBridge.reset(new BdaBridge(gpu_mode, linear_solver_verbosity, maxit, tolerance)); #else const std::string gpu_mode = EWOMS_GET_PARAM(TypeTag, std::string, GpuMode); if (gpu_mode.compare("none") != 0) { diff --git a/opm/simulators/linalg/bda/BdaBridge.cpp b/opm/simulators/linalg/bda/BdaBridge.cpp index c5107c6d7..134b07322 100644 --- a/opm/simulators/linalg/bda/BdaBridge.cpp +++ b/opm/simulators/linalg/bda/BdaBridge.cpp @@ -38,10 +38,9 @@ namespace Opm using bda::BdaResult; using bda::BdaSolver; -BdaBridge::BdaBridge(std::string gpu_mode_, int linear_solver_verbosity, int maxit, double tolerance) - : gpu_mode(gpu_mode_) +template +BdaBridge::BdaBridge(std::string gpu_mode, int linear_solver_verbosity, int maxit, double tolerance) { - std::cout << "mode: " << gpu_mode_ << std::endl; if (gpu_mode.compare("cusparse") == 0) { #if HAVE_CUDA use_gpu = true; @@ -132,8 +131,8 @@ void getSparsityPattern(BridgeMatrix& mat, std::vector &h_rows, std::vector } // end getSparsityPattern() -template -void BdaBridge::solve_system(BridgeMatrix *mat OPM_UNUSED, BridgeVector &b OPM_UNUSED, WellContributions& wellContribs OPM_UNUSED, InverseOperatorResult &res OPM_UNUSED) +template +void BdaBridge::solve_system(BridgeMatrix *mat OPM_UNUSED, BridgeVector &b OPM_UNUSED, WellContributions& wellContribs OPM_UNUSED, InverseOperatorResult &res OPM_UNUSED) { if (use_gpu) { @@ -207,21 +206,30 @@ void BdaBridge::solve_system(BridgeMatrix *mat OPM_UNUSED, BridgeVector &b OPM_U } -template -void BdaBridge::get_result(BridgeVector &x OPM_UNUSED) { +template +void BdaBridge::get_result(BridgeVector &x OPM_UNUSED) { if (use_gpu) { backend->get_result(static_cast(&(x[0][0]))); } } -#define INSTANTIATE_BDA_FUNCTIONS(n) \ -template void BdaBridge::solve_system \ -(Dune::BCRSMatrix, std::allocator > >*, \ - Dune::BlockVector, std::allocator > >&, \ - WellContributions&, InverseOperatorResult&); \ - \ -template void BdaBridge::get_result \ -(Dune::BlockVector, std::allocator > >&); \ +#define INSTANTIATE_BDA_FUNCTIONS(n) \ +template BdaBridge, std::allocator > >, \ +Dune::BlockVector, std::allocator > >, \ +n>::BdaBridge \ +(std::string gpu_mode_, int linear_solver_verbosity, int maxit, double tolerance); \ + \ +template void BdaBridge, std::allocator > >, \ +Dune::BlockVector, std::allocator > >, \ +n>::solve_system \ +(Dune::BCRSMatrix, std::allocator > >*, \ + Dune::BlockVector, std::allocator > >&, \ + WellContributions&, InverseOperatorResult&); \ + \ +template void BdaBridge, std::allocator > >, \ +Dune::BlockVector, std::allocator > >, \ +n>::get_result \ +(Dune::BlockVector, std::allocator > >&); \ INSTANTIATE_BDA_FUNCTIONS(1); INSTANTIATE_BDA_FUNCTIONS(2); diff --git a/opm/simulators/linalg/bda/BdaBridge.hpp b/opm/simulators/linalg/bda/BdaBridge.hpp index d301a2c95..cd5145746 100644 --- a/opm/simulators/linalg/bda/BdaBridge.hpp +++ b/opm/simulators/linalg/bda/BdaBridge.hpp @@ -42,13 +42,12 @@ namespace Opm typedef Dune::InverseOperatorResult InverseOperatorResult; -/// BdaBridge acts as interface between opm-simulators with the cusparseSolver -/// if CUDA was not found during CMake, function bodies of this class are empty +/// BdaBridge acts as interface between opm-simulators with the BdaSolvers +template class BdaBridge { private: std::unique_ptr backend; - std::string gpu_mode; bool use_gpu = false; public: @@ -66,12 +65,10 @@ public: /// \param[in] b vector b, should be of type Dune::BlockVector /// \param[in] wellContribs contains all WellContributions, to apply them separately, instead of adding them to matrix A /// \param[inout] result summary of solver result - template void solve_system(BridgeMatrix *mat, BridgeVector &b, WellContributions& wellContribs, InverseOperatorResult &result); /// Get the resulting x vector /// \param[inout] x vector x, should be of type Dune::BlockVector - template void get_result(BridgeVector &x); /// Return whether the BdaBridge will use the GPU or not