Initialize HIP/rocsparse in constructor

This commit is contained in:
Tong Dong Qiu
2023-03-02 13:37:58 +01:00
parent 35ea8d7e30
commit ed8f37ec82
2 changed files with 20 additions and 16 deletions

View File

@@ -72,11 +72,29 @@ using Dune::Timer;
template <unsigned int block_size>
rocsparseSolverBackend<block_size>::rocsparseSolverBackend(int verbosity_, int maxit_, double tolerance_, unsigned int platformID_, unsigned int deviceID_) : BdaSolver<block_size>(verbosity_, maxit_, tolerance_, platformID_, deviceID_) {
hipDevice_t device;
if(hipDeviceGet(&device, deviceID) != hipSuccess)
{
OPM_THROW(std::logic_error, "HIP Error: could not get device");
}
ROCSPARSE_CHECK(rocsparse_create_handle(&handle));
ROCBLAS_CHECK(rocblas_create_handle(&blas_handle));
ROCSPARSE_CHECK(rocsparse_get_version(handle, &ver));
ROCSPARSE_CHECK(rocsparse_get_git_rev(handle, rev));
std::ostringstream out;
out << "rocSPARSE version: " << ver / 100000 << "." << ver / 100 % 1000 << "."
<< ver % 100 << "-" << rev << "\n";
OpmLog::info(out.str());
HIP_CHECK(hipStreamCreate(&stream));
ROCSPARSE_CHECK(rocsparse_set_stream(handle, stream));
ROCBLAS_CHECK(rocblas_set_stream(blas_handle, stream));
}
template <unsigned int block_size>
rocsparseSolverBackend<block_size>::~rocsparseSolverBackend() {
HIP_CHECK(hipStreamSynchronize(stream));
@@ -290,20 +308,6 @@ void rocsparseSolverBackend<block_size>::initialize(std::shared_ptr<BlockedMatri
HIP_CHECK(hipMalloc((void**)&d_t, sizeof(double) * N));
HIP_CHECK(hipMalloc((void**)&d_v, sizeof(double) * N));
ROCSPARSE_CHECK(rocsparse_create_handle(&handle));
ROCBLAS_CHECK(rocblas_create_handle(&blas_handle));
ROCSPARSE_CHECK(rocsparse_get_version(handle, &ver));
ROCSPARSE_CHECK(rocsparse_get_git_rev(handle, rev));
out << "rocSPARSE version: " << ver / 100000 << "." << ver / 100 % 1000 << "."
<< ver % 100 << "-" << rev << "\n";
OpmLog::info(out.str());
HIP_CHECK(hipStreamCreate(&stream));
ROCSPARSE_CHECK(rocsparse_set_stream(handle, stream));
ROCBLAS_CHECK(rocblas_set_stream(blas_handle, stream));
HIP_CHECK(hipMalloc((void**)&d_Arows, sizeof(rocsparse_int) * (Nb + 1)));
HIP_CHECK(hipMalloc((void**)&d_Acols, sizeof(rocsparse_int) * nnzb));
HIP_CHECK(hipMalloc((void**)&d_Avals, sizeof(double) * nnz));

View File

@@ -114,7 +114,7 @@ createBridge(const boost::property_tree::ptree& prm, std::unique_ptr<Opm::BdaBri
linsolver);
} catch (const std::logic_error& error) {
BOOST_WARN_MESSAGE(true, error.what());
if (strstr(error.what(), "HIP error: hipInit() failed") != nullptr)
if (strstr(error.what(), "HIP Error: could not get device") != nullptr)
throw HIPInitException(error.what());
else
throw error;