mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Allow amgcl without CUDA
This commit is contained in:
@@ -90,10 +90,14 @@ void amgclSolverBackend<block_size>::initialize(int N_, int nnz_, int dim, doubl
|
|||||||
prm.erase("backend_type_cuda"); // delete custom parameter, otherwise amgcl prints a warning
|
prm.erase("backend_type_cuda"); // delete custom parameter, otherwise amgcl prints a warning
|
||||||
|
|
||||||
if (backend_type_cuda) {
|
if (backend_type_cuda) {
|
||||||
|
#if HAVE_CUDA
|
||||||
cudaDeviceProp prop;
|
cudaDeviceProp prop;
|
||||||
cudaGetDeviceProperties(&prop, deviceID);
|
cudaGetDeviceProperties(&prop, deviceID);
|
||||||
out << prop.name << std::endl;
|
out << prop.name << std::endl;
|
||||||
cusparseCreate(&CUDA_bprm.cusparse_handle);
|
cusparseCreate(&CUDA_bprm.cusparse_handle);
|
||||||
|
#else
|
||||||
|
OPM_THROW(std::logic_error, "Error amgcl is trying to use CUDA, but CUDA was not found by CMake");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
OpmLog::info(out.str());
|
OpmLog::info(out.str());
|
||||||
|
|
||||||
@@ -165,6 +169,7 @@ void amgclSolverBackend<block_size>::solve_system(double *b, WellContributions &
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (backend_type_cuda) { // use CUDA
|
if (backend_type_cuda) { // use CUDA
|
||||||
|
#if HAVE_CUDA
|
||||||
// create matrix object
|
// create matrix object
|
||||||
auto A = std::tie(N, A_rows, A_cols, A_vals);
|
auto A = std::tie(N, A_rows, A_cols, A_vals);
|
||||||
|
|
||||||
@@ -186,6 +191,7 @@ void amgclSolverBackend<block_size>::solve_system(double *b, WellContributions &
|
|||||||
std::tie(iters, error) = solve(B, X);
|
std::tie(iters, error) = solve(B, X);
|
||||||
|
|
||||||
thrust::copy(X.begin(), X.end(), x.begin());
|
thrust::copy(X.begin(), X.end(), x.begin());
|
||||||
|
#endif
|
||||||
} else { // use builtin backend (CPU)
|
} else { // use builtin backend (CPU)
|
||||||
// create matrix object
|
// create matrix object
|
||||||
auto Atmp = std::tie(N, A_rows, A_cols, A_vals);
|
auto Atmp = std::tie(N, A_rows, A_cols, A_vals);
|
||||||
|
|||||||
@@ -64,12 +64,15 @@ class amgclSolverBackend : public BdaSolver<block_size>
|
|||||||
using Base::tolerance;
|
using Base::tolerance;
|
||||||
using Base::initialized;
|
using Base::initialized;
|
||||||
|
|
||||||
|
#if HAVE_CUDA
|
||||||
typedef amgcl::backend::cuda<double> CUDA_Backend;
|
typedef amgcl::backend::cuda<double> CUDA_Backend;
|
||||||
|
typedef amgcl::make_solver<amgcl::runtime::preconditioner<CUDA_Backend>, amgcl::runtime::solver::wrapper<CUDA_Backend> > CUDA_Solver;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef amgcl::static_matrix<double, block_size, block_size> dmat_type; // matrix value type in double precision
|
typedef amgcl::static_matrix<double, block_size, block_size> dmat_type; // matrix value type in double precision
|
||||||
typedef amgcl::static_matrix<double, block_size, 1> dvec_type; // the corresponding vector value type
|
typedef amgcl::static_matrix<double, block_size, 1> dvec_type; // the corresponding vector value type
|
||||||
typedef amgcl::backend::builtin<dmat_type> CPU_Backend;
|
typedef amgcl::backend::builtin<dmat_type> CPU_Backend;
|
||||||
|
|
||||||
typedef amgcl::make_solver<amgcl::runtime::preconditioner<CUDA_Backend>, amgcl::runtime::solver::wrapper<CUDA_Backend> > CUDA_Solver;
|
|
||||||
typedef amgcl::make_solver<amgcl::runtime::preconditioner<CPU_Backend>, amgcl::runtime::solver::wrapper<CPU_Backend> > CPU_Solver;
|
typedef amgcl::make_solver<amgcl::runtime::preconditioner<CPU_Backend>, amgcl::runtime::solver::wrapper<CPU_Backend> > CPU_Solver;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -82,7 +85,9 @@ private:
|
|||||||
// if more backend are supported (vexcl), turn into enum
|
// if more backend are supported (vexcl), turn into enum
|
||||||
|
|
||||||
boost::property_tree::ptree prm; // amgcl parameters
|
boost::property_tree::ptree prm; // amgcl parameters
|
||||||
|
#if HAVE_CUDA
|
||||||
typename CUDA_Backend::params CUDA_bprm; // amgcl backend parameters, only used for cusparseHandle
|
typename CUDA_Backend::params CUDA_bprm; // amgcl backend parameters, only used for cusparseHandle
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Initialize GPU and allocate memory
|
/// Initialize GPU and allocate memory
|
||||||
/// \param[in] N number of nonzeroes, divide by dim*dim to get number of blocks
|
/// \param[in] N number of nonzeroes, divide by dim*dim to get number of blocks
|
||||||
|
|||||||
Reference in New Issue
Block a user