From b9e4bd3a9594b6f66a8c8d18994aa1c741f5cc56 Mon Sep 17 00:00:00 2001 From: "T.D. (Tongdong) Qiu" Date: Tue, 23 Jun 2020 18:19:33 +0200 Subject: [PATCH] Updated HAVE_XX guards. Replaced string == compare with .compare() --- opm/simulators/linalg/ISTLSolverEbos.hpp | 12 ++++++------ opm/simulators/linalg/bda/BdaBridge.cpp | 13 ++++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/opm/simulators/linalg/ISTLSolverEbos.hpp b/opm/simulators/linalg/ISTLSolverEbos.hpp index 830706627..9a0a0ef79 100644 --- a/opm/simulators/linalg/ISTLSolverEbos.hpp +++ b/opm/simulators/linalg/ISTLSolverEbos.hpp @@ -49,7 +49,7 @@ #include -#if HAVE_CUDA +#if HAVE_CUDA + HAVE_OPENCL #include #endif @@ -278,7 +278,7 @@ protected: enum { pressureVarIndex = Indices::pressureSwitchIdx }; static const int numEq = Indices::numEq; -#if HAVE_CUDA +#if HAVE_CUDA + HAVE_OPENCL std::unique_ptr bdaBridge; #endif @@ -316,9 +316,9 @@ protected: prm_ = setupPropertyTree(parameters_); } const auto& gridForConn = simulator_.vanguard().grid(); -#if HAVE_CUDA +#if HAVE_CUDA + HAVE_OPENCL std::string gpu_mode = EWOMS_GET_PARAM(TypeTag, std::string, GpuMode); - if (gridForConn.comm().size() > 1 && "none" != gpu_mode) { + if (gridForConn.comm().size() > 1 && gpu_mode.compare("none") != 0) { OpmLog::warning("Warning cannot use GPU with MPI, GPU is disabled"); gpu_mode = "none"; } @@ -328,7 +328,7 @@ protected: bdaBridge.reset(new BdaBridge(gpu_mode, linear_solver_verbosity, maxit, tolerance)); #else const bool gpu_mode = EWOMS_GET_PARAM(TypeTag, bool, GpuMode); - if ("none" != gpu_mode) { + if (gpu_mode.compare("none") != 0) { OPM_THROW(std::logic_error,"Error cannot use GPU solver since CUDA was not found during compilation"); } #endif @@ -622,7 +622,7 @@ protected: #endif { // tries to solve linear system -#if HAVE_CUDA +#if HAVE_CUDA + HAVE_OPENCL bool use_gpu = bdaBridge->getUseGpu(); if (use_gpu) { WellContributions wellContribs; diff --git a/opm/simulators/linalg/bda/BdaBridge.cpp b/opm/simulators/linalg/bda/BdaBridge.cpp index 2d2a03a5d..c5107c6d7 100644 --- a/opm/simulators/linalg/bda/BdaBridge.cpp +++ b/opm/simulators/linalg/bda/BdaBridge.cpp @@ -41,17 +41,24 @@ namespace Opm BdaBridge::BdaBridge(std::string gpu_mode_, int linear_solver_verbosity, int maxit, double tolerance) : gpu_mode(gpu_mode_) { - if (gpu_mode == "cusparse") { + std::cout << "mode: " << gpu_mode_ << std::endl; + if (gpu_mode.compare("cusparse") == 0) { +#if HAVE_CUDA use_gpu = true; backend.reset(new bda::cusparseSolverBackend(linear_solver_verbosity, maxit, tolerance)); - } else if (gpu_mode == "opencl") { +#else + OPM_THROW(std::logic_error, "Error cusparseSolver was chosen, but CUDA was not found by CMake"); +#endif + } else if (gpu_mode.compare("opencl") == 0) { #if HAVE_OPENCL use_gpu = true; backend.reset(new bda::openclSolverBackend(linear_solver_verbosity, maxit, tolerance)); #else OPM_THROW(std::logic_error, "Error openclSolver was chosen, but OpenCL was not found by CMake"); #endif - } else if (gpu_mode != "none") { + } else if (gpu_mode.compare("none") == 0) { + use_gpu = false; + } else { OPM_THROW(std::logic_error, "Error unknown value for parameter 'GpuMode', should be passed like '--gpu-mode=[none|cusparse|opencl]"); } }