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
|
||||
|
||||
if (backend_type_cuda) {
|
||||
#if HAVE_CUDA
|
||||
cudaDeviceProp prop;
|
||||
cudaGetDeviceProperties(&prop, deviceID);
|
||||
out << prop.name << std::endl;
|
||||
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());
|
||||
|
||||
@@ -165,6 +169,7 @@ void amgclSolverBackend<block_size>::solve_system(double *b, WellContributions &
|
||||
|
||||
try {
|
||||
if (backend_type_cuda) { // use CUDA
|
||||
#if HAVE_CUDA
|
||||
// create matrix object
|
||||
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);
|
||||
|
||||
thrust::copy(X.begin(), X.end(), x.begin());
|
||||
#endif
|
||||
} else { // use builtin backend (CPU)
|
||||
// create matrix object
|
||||
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::initialized;
|
||||
|
||||
#if HAVE_CUDA
|
||||
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, 1> dvec_type; // the corresponding vector value type
|
||||
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;
|
||||
|
||||
private:
|
||||
@@ -82,7 +85,9 @@ private:
|
||||
// if more backend are supported (vexcl), turn into enum
|
||||
|
||||
boost::property_tree::ptree prm; // amgcl parameters
|
||||
#if HAVE_CUDA
|
||||
typename CUDA_Backend::params CUDA_bprm; // amgcl backend parameters, only used for cusparseHandle
|
||||
#endif
|
||||
|
||||
/// Initialize GPU and allocate memory
|
||||
/// \param[in] N number of nonzeroes, divide by dim*dim to get number of blocks
|
||||
|
||||
Reference in New Issue
Block a user