Merge pull request #4883 from jychang48/jychang48-edits

Removed OpenCL dependencies for rocsparse backend & error exception handling
This commit is contained in:
Markus Blatt 2023-10-06 20:50:22 +02:00 committed by GitHub
commit 3f436501d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 44 deletions

View File

@ -92,12 +92,12 @@ struct EdgeWeightsMethod {
using type = UndefinedProperty; using type = UndefinedProperty;
}; };
#if HAVE_OPENCL #if HAVE_OPENCL || HAVE_ROCSPARSE
template<class TypeTag, class MyTypeTag> template<class TypeTag, class MyTypeTag>
struct NumJacobiBlocks { struct NumJacobiBlocks {
using type = UndefinedProperty; using type = UndefinedProperty;
}; };
#endif // HAVE_OPENCL #endif // HAVE_OPENCL || HAVE_ROCSPARSE
template<class TypeTag, class MyTypeTag> template<class TypeTag, class MyTypeTag>
struct OwnerCellsFirst { struct OwnerCellsFirst {
@ -153,12 +153,12 @@ struct EdgeWeightsMethod<TypeTag, TTag::EclBaseVanguard> {
static constexpr int value = 1; static constexpr int value = 1;
}; };
#if HAVE_OPENCL #if HAVE_OPENCL || HAVE_ROCSPARSE
template<class TypeTag> template<class TypeTag>
struct NumJacobiBlocks<TypeTag, TTag::EclBaseVanguard> { struct NumJacobiBlocks<TypeTag, TTag::EclBaseVanguard> {
static constexpr int value = 0; static constexpr int value = 0;
}; };
#endif // HAVE_OPENCL #endif // HAVE_OPENCL || HAVE_ROCSPARSE
template<class TypeTag> template<class TypeTag>
struct OwnerCellsFirst<TypeTag, TTag::EclBaseVanguard> { struct OwnerCellsFirst<TypeTag, TTag::EclBaseVanguard> {
@ -248,7 +248,7 @@ public:
EWOMS_REGISTER_PARAM(TypeTag, int, EdgeWeightsMethod, EWOMS_REGISTER_PARAM(TypeTag, int, EdgeWeightsMethod,
"Choose edge-weighing strategy: 0=uniform, 1=trans, 2=log(trans)."); "Choose edge-weighing strategy: 0=uniform, 1=trans, 2=log(trans).");
#if HAVE_OPENCL #if HAVE_OPENCL || HAVE_ROCSPARSE
EWOMS_REGISTER_PARAM(TypeTag, int, NumJacobiBlocks, EWOMS_REGISTER_PARAM(TypeTag, int, NumJacobiBlocks,
"Number of blocks to be created for the Block-Jacobi preconditioner."); "Number of blocks to be created for the Block-Jacobi preconditioner.");
#endif #endif
@ -288,7 +288,7 @@ public:
fileName_ = EWOMS_GET_PARAM(TypeTag, std::string, EclDeckFileName); fileName_ = EWOMS_GET_PARAM(TypeTag, std::string, EclDeckFileName);
edgeWeightsMethod_ = Dune::EdgeWeightMethod(EWOMS_GET_PARAM(TypeTag, int, EdgeWeightsMethod)); edgeWeightsMethod_ = Dune::EdgeWeightMethod(EWOMS_GET_PARAM(TypeTag, int, EdgeWeightsMethod));
#if HAVE_OPENCL #if HAVE_OPENCL || HAVE_ROCSPARSE
numJacobiBlocks_ = EWOMS_GET_PARAM(TypeTag, int, NumJacobiBlocks); numJacobiBlocks_ = EWOMS_GET_PARAM(TypeTag, int, NumJacobiBlocks);
#endif #endif

View File

@ -202,7 +202,7 @@ public:
*/ */
int numJacobiBlocks() const int numJacobiBlocks() const
{ {
#if HAVE_OPENCL #if HAVE_OPENCL || HAVE_ROCSPARSE
return numJacobiBlocks_; return numJacobiBlocks_;
#else #else
return 0; return 0;
@ -283,9 +283,9 @@ protected:
std::string fileName_; std::string fileName_;
Dune::EdgeWeightMethod edgeWeightsMethod_; Dune::EdgeWeightMethod edgeWeightsMethod_;
#if HAVE_OPENCL #if HAVE_OPENCL || HAVE_ROCSPARSE
int numJacobiBlocks_{0}; int numJacobiBlocks_{0};
#endif // HAVE_OPENCL #endif // HAVE_OPENCL || HAVE_ROCSPARSE
bool ownersFirst_; bool ownersFirst_;
#if HAVE_MPI #if HAVE_MPI

View File

@ -48,29 +48,41 @@
#undef HIP_HAVE_CUDA_DEFINED #undef HIP_HAVE_CUDA_DEFINED
#endif #endif
#define HIP_CHECK(stat) \ #define HIP_CHECK(STAT) \
{ \ do { \
if(stat != hipSuccess) \ const hipError_t stat = (STAT); \
{ \ if(stat != hipSuccess) \
OPM_THROW(std::logic_error, "HIP error"); \ { \
} \ std::ostringstream oss; \
} oss << "rocsparseSolverBackend::hip "; \
oss << "error: " << hipGetErrorString(stat); \
OPM_THROW(std::logic_error, oss.str()); \
} \
} while(0)
#define ROCSPARSE_CHECK(stat) \ #define ROCSPARSE_CHECK(STAT) \
{ \ do { \
if(stat != rocsparse_status_success) \ const rocsparse_status stat = (STAT); \
{ \ if(stat != rocsparse_status_success) \
OPM_THROW(std::logic_error, "rocsparse error"); \ { \
} \ std::ostringstream oss; \
} oss << "rocsparseSolverBackend::rocsparse "; \
oss << "error: " << stat; \
OPM_THROW(std::logic_error, oss.str()); \
} \
} while(0)
#define ROCBLAS_CHECK(stat) \ #define ROCBLAS_CHECK(STAT) \
{ \ do { \
if(stat != rocblas_status_success) \ const rocblas_status stat = (STAT); \
{ \ if(stat != rocblas_status_success) \
OPM_THROW(std::logic_error, "rocblas error"); \ { \
} \ std::ostringstream oss; \
} oss << "rocsparseSolverBackend::rocblas "; \
oss << "error: " << stat; \
OPM_THROW(std::logic_error, oss.str()); \
} \
} while(0)
#include <cstddef> #include <cstddef>
@ -153,7 +165,6 @@ void rocsparseSolverBackend<block_size>::gpu_pbicgstab([[maybe_unused]] WellCont
d_Avals, d_Arows, d_Acols, block_size, d_Avals, d_Arows, d_Acols, block_size,
d_x, &zero, d_r)); d_x, &zero, d_r));
#endif #endif
ROCBLAS_CHECK(rocblas_dscal(blas_handle, N, &mone, d_r, 1)); ROCBLAS_CHECK(rocblas_dscal(blas_handle, N, &mone, d_r, 1));
ROCBLAS_CHECK(rocblas_daxpy(blas_handle, N, &one, d_b, 1, d_r, 1)); ROCBLAS_CHECK(rocblas_daxpy(blas_handle, N, &one, d_b, 1, d_r, 1));
ROCBLAS_CHECK(rocblas_dcopy(blas_handle, N, d_r, 1, d_rw, 1)); ROCBLAS_CHECK(rocblas_dcopy(blas_handle, N, d_r, 1, d_rw, 1));
@ -526,18 +537,7 @@ void rocsparseSolverBackend<block_size>::solve_system(WellContributions &wellCon
Timer t; Timer t;
// actually solve // actually solve
try { gpu_pbicgstab(wellContribs, res);
gpu_pbicgstab(wellContribs, res);
} catch (const cl::Error& error) {
std::ostringstream oss;
oss << "rocsparseSolverBackend::solve_system error: " << error.what() << "(" << error.err() << ")\n";
oss << getErrorString(error.err());
// rethrow exception
OPM_THROW(std::logic_error, oss.str());
} catch (const std::logic_error& error) {
// rethrow exception by OPM_THROW in the try{}, without this, a segfault occurs
throw error;
}
if (verbosity >= 3) { if (verbosity >= 3) {
HIP_CHECK(hipStreamSynchronize(stream)); HIP_CHECK(hipStreamSynchronize(stream));

View File

@ -22,7 +22,6 @@
#include <memory> #include <memory>
#include <opm/simulators/linalg/bda/opencl/opencl.hpp>
#include <opm/simulators/linalg/bda/BdaResult.hpp> #include <opm/simulators/linalg/bda/BdaResult.hpp>
#include <opm/simulators/linalg/bda/BdaSolver.hpp> #include <opm/simulators/linalg/bda/BdaSolver.hpp>
#include <opm/simulators/linalg/bda/WellContributions.hpp> #include <opm/simulators/linalg/bda/WellContributions.hpp>