From 1ece9a04ccea2a100313db28cffe485426bd2203 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Sun, 11 Feb 2024 21:50:02 +0000 Subject: [PATCH] [HIPIFY][#674][rocSPARSE][feature] rocSPARSE support - Step 106 - `cusparseSpMM` -> `rocsparse_spmm` + [IMP] `rocsparse_spmm` has been changed in 6.0.0, so reflected that in HIPIFY, docs, and tests + Updated `SPARSE` synthetic tests, the regenerated hipify-perl, and `SPARSE` `CUDA2HIP` documentation --- bin/hipify-perl | 1 + .../CUSPARSE_API_supported_by_HIP_and_ROC.md | 2 +- docs/tables/CUSPARSE_API_supported_by_ROC.md | 2 +- src/CUDA2HIP_SPARSE_API_functions.cpp | 2 +- src/HipifyAction.cpp | 15 ++++++++++++++- .../synthetic/libraries/cusparse2hipsparse.cu | 1 - .../libraries/cusparse2rocsparse_10010_12000.cu | 6 ++++++ .../libraries/cusparse2rocsparse_12000.cu | 5 +++++ 8 files changed, 29 insertions(+), 5 deletions(-) diff --git a/bin/hipify-perl b/bin/hipify-perl index 6397256d..6d67c042 100755 --- a/bin/hipify-perl +++ b/bin/hipify-perl @@ -2272,6 +2272,7 @@ sub rocSubstitutions { subst("cusparseShybmv", "rocsparse_shybmv", "library"); subst("cusparseSnnz", "rocsparse_snnz", "library"); subst("cusparseSnnz_compress", "rocsparse_snnz_compress", "library"); + subst("cusparseSpMM", "rocsparse_spmm", "library"); subst("cusparseSpMM_bufferSize", "rocsparse_spmm", "library"); subst("cusparseSpMV", "rocsparse_spmv", "library"); subst("cusparseSpMatGetAttribute", "rocsparse_spmat_get_attribute", "library"); diff --git a/docs/tables/CUSPARSE_API_supported_by_HIP_and_ROC.md b/docs/tables/CUSPARSE_API_supported_by_HIP_and_ROC.md index 45890e96..84733159 100644 --- a/docs/tables/CUSPARSE_API_supported_by_HIP_and_ROC.md +++ b/docs/tables/CUSPARSE_API_supported_by_HIP_and_ROC.md @@ -874,7 +874,7 @@ |`cusparseSpGEMMreuse_copy`|11.3| |12.0| |`hipsparseSpGEMMreuse_copy`|5.1.0| |6.0.0| | | | | | | | | |`cusparseSpGEMMreuse_nnz`|11.3| |12.0| |`hipsparseSpGEMMreuse_nnz`|5.1.0| |6.0.0| | | | | | | | | |`cusparseSpGEMMreuse_workEstimation`|11.3| |12.0| |`hipsparseSpGEMMreuse_workEstimation`|5.1.0| |6.0.0| | | | | | | | | -|`cusparseSpMM`|10.1| |12.0| |`hipsparseSpMM`|4.2.0| |6.0.0| | | | | | | | | +|`cusparseSpMM`|10.1| |12.0| |`hipsparseSpMM`|4.2.0| |6.0.0| | |`rocsparse_spmm`|4.2.0| |6.0.0| | | |`cusparseSpMMOp`|11.5| | | | | | | | | | | | | | | | |`cusparseSpMMOp_createPlan`|11.5| | | | | | | | | | | | | | | | |`cusparseSpMMOp_destroyPlan`|11.5| | | | | | | | | | | | | | | | diff --git a/docs/tables/CUSPARSE_API_supported_by_ROC.md b/docs/tables/CUSPARSE_API_supported_by_ROC.md index 26b4bbdd..d1eb76aa 100644 --- a/docs/tables/CUSPARSE_API_supported_by_ROC.md +++ b/docs/tables/CUSPARSE_API_supported_by_ROC.md @@ -874,7 +874,7 @@ |`cusparseSpGEMMreuse_copy`|11.3| |12.0| | | | | | | | |`cusparseSpGEMMreuse_nnz`|11.3| |12.0| | | | | | | | |`cusparseSpGEMMreuse_workEstimation`|11.3| |12.0| | | | | | | | -|`cusparseSpMM`|10.1| |12.0| | | | | | | | +|`cusparseSpMM`|10.1| |12.0| |`rocsparse_spmm`|4.2.0| |6.0.0| | | |`cusparseSpMMOp`|11.5| | | | | | | | | | |`cusparseSpMMOp_createPlan`|11.5| | | | | | | | | | |`cusparseSpMMOp_destroyPlan`|11.5| | | | | | | | | | diff --git a/src/CUDA2HIP_SPARSE_API_functions.cpp b/src/CUDA2HIP_SPARSE_API_functions.cpp index ef401e16..3ed14cbf 100644 --- a/src/CUDA2HIP_SPARSE_API_functions.cpp +++ b/src/CUDA2HIP_SPARSE_API_functions.cpp @@ -826,7 +826,7 @@ const std::map CUDA_SPARSE_FUNCTION_MAP { // Sparse Matrix * Matrix Multiplication // TODO: hipification cusparseSpMM into rocsparse_spmm needs additional variable declared and allocated - {"cusparseSpMM", {"hipsparseSpMM", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}}, + {"cusparseSpMM", {"hipsparseSpMM", "rocsparse_spmm", CONV_LIB_FUNC, API_SPARSE, 15}}, {"cusparseSpMM_bufferSize", {"hipsparseSpMM_bufferSize", "rocsparse_spmm", CONV_LIB_FUNC, API_SPARSE, 15}}, // TODO: hipification cusparseSpMM_preprocess into rocsparse_spmm needs additional variable declared and allocated {"cusparseSpMM_preprocess", {"hipsparseSpMM_preprocess", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}}, diff --git a/src/HipifyAction.cpp b/src/HipifyAction.cpp index a24c728d..d9cad926 100644 --- a/src/HipifyAction.cpp +++ b/src/HipifyAction.cpp @@ -213,6 +213,7 @@ const std::string sCusparseSpSM_analysis = "cusparseSpSM_analysis"; const std::string sCusparseSpSM_solve = "cusparseSpSM_solve"; const std::string sCusparseXcsrgeam2Nnz = "cusparseXcsrgeam2Nnz"; const std::string sCudaMallocHost = "cudaMallocHost"; +const std::string sCusparseSpMM = "cusparseSpMM"; // CUDA_OVERLOADED const std::string sCudaEventCreate = "cudaEventCreate"; @@ -2048,6 +2049,17 @@ std::map> FuncArgCasts { } } }, + {sCusparseSpMM, + { + { + { + {10, {e_add_const_argument, cw_None, "rocsparse_spmm_stage_compute, nullptr"}}, + }, + true, + false + } + } + }, }; void HipifyAction::RewriteString(StringRef s, clang::SourceLocation start) { @@ -2910,7 +2922,8 @@ std::unique_ptr HipifyAction::CreateASTConsumer(clang::Compi sCusparseSpSM_analysis, sCusparseSpSM_solve, sCusparseXcsrgeam2Nnz, - sCudaMallocHost + sCudaMallocHost, + sCusparseSpMM ) ) ) diff --git a/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu b/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu index fefca166..52c1b145 100644 --- a/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu +++ b/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu @@ -1979,7 +1979,6 @@ int main() { // CHECK: status_t = hipsparseSpMM_bufferSize(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, &bufferSize); status_t = cusparseSpMM_bufferSize(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, &bufferSize); - // TODO: Mark as C-Changed in 12.0.0 // CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpMM(cusparseHandle_t handle, cusparseOperation_t transA, cusparseOperation_t transB, const void* alpha, const cusparseSpMatDescr_t matA, const cusparseDnMatDescr_t matB, const void* beta, cusparseDnMatDescr_t matC, cudaDataType computeType, cusparseSpMMAlg_t alg, void* externalBuffer); // HIP: HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer); // CHECK: status_t = hipsparseSpMM(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, tempBuffer); diff --git a/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_10010_12000.cu b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_10010_12000.cu index e91120b5..0f53e13f 100644 --- a/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_10010_12000.cu +++ b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_10010_12000.cu @@ -47,6 +47,7 @@ int main() { void *pcscVal = nullptr; void *alpha = nullptr; void *beta = nullptr; + void *tempBuffer = nullptr; // CHECK: rocsparse_operation opA, opB, opX; cusparseOperation_t opA, opB, opX; @@ -76,6 +77,11 @@ int main() { // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_spmm(rocsparse_handle handle, rocsparse_operation trans_A, rocsparse_operation trans_B, const void* alpha, const rocsparse_spmat_descr mat_A, const rocsparse_dnmat_descr mat_B, const void* beta, const rocsparse_dnmat_descr mat_C, rocsparse_datatype compute_type, rocsparse_spmm_alg alg, rocsparse_spmm_stage stage, size_t* buffer_size, void* temp_buffer); // CHECK: status_t = rocsparse_spmm(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, rocsparse_spmm_stage_compute, &bufferSize, nullptr); status_t = cusparseSpMM_bufferSize(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, &bufferSize); + + // CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpMM(cusparseHandle_t handle, cusparseOperation_t transA, cusparseOperation_t transB, const void* alpha, const cusparseSpMatDescr_t matA, const cusparseDnMatDescr_t matB, const void* beta, cusparseDnMatDescr_t matC, cudaDataType computeType, cusparseSpMMAlg_t alg, void* externalBuffer); + // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_spmm(rocsparse_handle handle, rocsparse_operation trans_A, rocsparse_operation trans_B, const void* alpha, const rocsparse_spmat_descr mat_A, const rocsparse_dnmat_descr mat_B, const void* beta, const rocsparse_dnmat_descr mat_C, rocsparse_datatype compute_type, rocsparse_spmm_alg alg, rocsparse_spmm_stage stage, size_t* buffer_size, void* temp_buffer); + // CHECK: status_t = rocsparse_spmm(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, rocsparse_spmm_stage_compute, nullptr, tempBuffer); + status_t = cusparseSpMM(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, tempBuffer); #endif #endif #endif diff --git a/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu index 33cff8d8..4f7dad15 100644 --- a/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu +++ b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu @@ -162,6 +162,11 @@ int main() { // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_spsm(rocsparse_handle handle, rocsparse_operation trans_A, rocsparse_operation trans_B, const void* alpha, rocsparse_const_spmat_descr matA, rocsparse_const_dnmat_descr matB, const rocsparse_dnmat_descr matC, rocsparse_datatype compute_type, rocsparse_spsm_alg alg, rocsparse_spsm_stage stage, size_t* buffer_size, void* temp_buffer); // CHECK: status_t = rocsparse_spsm(handle_t, opA, opB, alpha, constSpMatDescr, constDnMatDescrB, dnmatC, dataType, spSMAlg_t, rocsparse_spsm_stage_compute, nullptr, nullptr); status_t = cusparseSpSM_solve(handle_t, opA, opB, alpha, constSpMatDescr, constDnMatDescrB, dnmatC, dataType, spSMAlg_t, spSMDescr); + + // CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpMM(cusparseHandle_t handle, cusparseOperation_t opA, cusparseOperation_t opB, const void* alpha, cusparseConstSpMatDescr_t matA, cusparseConstDnMatDescr_t matB, const void* beta, cusparseDnMatDescr_t matC, cudaDataType computeType, cusparseSpMMAlg_t alg, void* externalBuffer); + // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_spmm(rocsparse_handle handle, rocsparse_operation trans_A, rocsparse_operation trans_B, const void* alpha, rocsparse_const_spmat_descr mat_A, rocsparse_const_dnmat_descr mat_B, const void* beta, const rocsparse_dnmat_descr mat_C, rocsparse_datatype compute_type, rocsparse_spmm_alg alg, rocsparse_spmm_stage stage, size_t* buffer_size, void* temp_buffer); + // CHECK: status_t = rocsparse_spmm(handle_t, opA, opB, alpha, constSpMatDescr, constDnMatDescr, beta, dnmatC, dataType, spMMAlg_t, rocsparse_spmm_stage_compute, nullptr, tempBuffer); + status_t = cusparseSpMM(handle_t, opA, opB, alpha, constSpMatDescr, constDnMatDescr, beta, dnmatC, dataType, spMMAlg_t, tempBuffer); #endif return 0;