From f3d220fc60e16f5b844d6e7cabdd048949da0794 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Thu, 18 Jan 2024 13:06:03 +0000 Subject: [PATCH] [HIPIFY][#674][rocSPARSE][feature] rocSPARSE support - Step 101 - `cusparseDenseToSparse_analysis` -> `rocsparse_dense_to_sparse` + [IMP] `rocsparse_dense_to_sparse` 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 + .../tables/CUSPARSE_API_supported_by_HIP_and_ROC.md | 2 +- docs/tables/CUSPARSE_API_supported_by_ROC.md | 2 +- src/CUDA2HIP_SPARSE_API_functions.cpp | 4 ++-- src/HipifyAction.cpp | 13 ++++++++++++- .../synthetic/libraries/cusparse2hipsparse.cu | 1 - .../synthetic/libraries/cusparse2rocsparse_12000.cu | 10 ++++++++++ .../libraries/cusparse2rocsparse_before_12000.cu | 5 +++++ 8 files changed, 32 insertions(+), 6 deletions(-) diff --git a/bin/hipify-perl b/bin/hipify-perl index b5fe1bed..a980cfe7 100755 --- a/bin/hipify-perl +++ b/bin/hipify-perl @@ -2438,6 +2438,7 @@ sub rocSubstitutions { subst("cusparseDdense2csc", "rocsparse_ddense2csc", "library"); subst("cusparseDdense2csr", "rocsparse_ddense2csr", "library"); subst("cusparseDdoti", "rocsparse_ddoti", "library"); + subst("cusparseDenseToSparse_analysis", "rocsparse_dense_to_sparse", "library"); subst("cusparseDenseToSparse_bufferSize", "rocsparse_dense_to_sparse", "library"); subst("cusparseDestroy", "rocsparse_destroy_handle", "library"); subst("cusparseDestroyBsric02Info", "rocsparse_destroy_mat_info", "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 866d2a70..be06afc1 100644 --- a/docs/tables/CUSPARSE_API_supported_by_HIP_and_ROC.md +++ b/docs/tables/CUSPARSE_API_supported_by_HIP_and_ROC.md @@ -842,7 +842,7 @@ |`cusparseCsrGet`|10.2| | | |`hipsparseCsrGet`|4.1.0| | | | |`rocsparse_csr_get`|4.1.0| | | | | |`cusparseCsrSetPointers`|11.0| | | |`hipsparseCsrSetPointers`|4.1.0| | | | |`rocsparse_csr_set_pointers`|4.1.0| | | | | |`cusparseCsrSetStridedBatch`|11.0| | | |`hipsparseCsrSetStridedBatch`|5.2.0| | | | |`rocsparse_csr_set_strided_batch`|5.2.0| | | | | -|`cusparseDenseToSparse_analysis`|11.1| |12.0| |`hipsparseDenseToSparse_analysis`|4.2.0| |6.0.0| | | | | | | | | +|`cusparseDenseToSparse_analysis`|11.1| |12.0| |`hipsparseDenseToSparse_analysis`|4.2.0| |6.0.0| | |`rocsparse_dense_to_sparse`|4.1.0| |6.0.0| | | |`cusparseDenseToSparse_bufferSize`|11.1| |12.0| |`hipsparseDenseToSparse_bufferSize`|4.2.0| |6.0.0| | |`rocsparse_dense_to_sparse`|4.1.0| |6.0.0| | | |`cusparseDenseToSparse_convert`|11.1| |12.0| |`hipsparseDenseToSparse_convert`|4.2.0| |6.0.0| | | | | | | | | |`cusparseDestroyDnMat`|10.1| |12.0| |`hipsparseDestroyDnMat`|4.2.0| |6.0.0| | |`rocsparse_destroy_dnmat_descr`|4.1.0| |6.0.0| | | diff --git a/docs/tables/CUSPARSE_API_supported_by_ROC.md b/docs/tables/CUSPARSE_API_supported_by_ROC.md index 5fd30135..cec83050 100644 --- a/docs/tables/CUSPARSE_API_supported_by_ROC.md +++ b/docs/tables/CUSPARSE_API_supported_by_ROC.md @@ -842,7 +842,7 @@ |`cusparseCsrGet`|10.2| | | |`rocsparse_csr_get`|4.1.0| | | | | |`cusparseCsrSetPointers`|11.0| | | |`rocsparse_csr_set_pointers`|4.1.0| | | | | |`cusparseCsrSetStridedBatch`|11.0| | | |`rocsparse_csr_set_strided_batch`|5.2.0| | | | | -|`cusparseDenseToSparse_analysis`|11.1| |12.0| | | | | | | | +|`cusparseDenseToSparse_analysis`|11.1| |12.0| |`rocsparse_dense_to_sparse`|4.1.0| |6.0.0| | | |`cusparseDenseToSparse_bufferSize`|11.1| |12.0| |`rocsparse_dense_to_sparse`|4.1.0| |6.0.0| | | |`cusparseDenseToSparse_convert`|11.1| |12.0| | | | | | | | |`cusparseDestroyDnMat`|10.1| |12.0| |`rocsparse_destroy_dnmat_descr`|4.1.0| |6.0.0| | | diff --git a/src/CUDA2HIP_SPARSE_API_functions.cpp b/src/CUDA2HIP_SPARSE_API_functions.cpp index ba0395de..c16f0479 100644 --- a/src/CUDA2HIP_SPARSE_API_functions.cpp +++ b/src/CUDA2HIP_SPARSE_API_functions.cpp @@ -866,7 +866,7 @@ const std::map CUDA_SPARSE_FUNCTION_MAP { {"cusparseSparseToDense", {"hipsparseSparseToDense", "rocsparse_sparse_to_dense", CONV_LIB_FUNC, API_SPARSE, 15}}, {"cusparseSparseToDense_bufferSize", {"hipsparseSparseToDense_bufferSize", "rocsparse_sparse_to_dense", CONV_LIB_FUNC, API_SPARSE, 15}}, {"cusparseDenseToSparse_bufferSize", {"hipsparseDenseToSparse_bufferSize", "rocsparse_dense_to_sparse", CONV_LIB_FUNC, API_SPARSE, 15}}, - {"cusparseDenseToSparse_analysis", {"hipsparseDenseToSparse_analysis", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}}, + {"cusparseDenseToSparse_analysis", {"hipsparseDenseToSparse_analysis", "rocsparse_dense_to_sparse", CONV_LIB_FUNC, API_SPARSE, 15}}, {"cusparseDenseToSparse_convert", {"hipsparseDenseToSparse_convert", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}}, // Sampled Dense-dense Matrix Multiplication @@ -1225,7 +1225,7 @@ const std::map CUDA_SPARSE_FUNCTION_VER_MAP { {"cusparseSparseToDense_bufferSize", {CUDA_111, CUDA_0, CUDA_0 }}, // A: CUSPARSE_VERSION 11300 C: CUSPARSE_VERSION 12000 {"cusparseSparseToDense", {CUDA_111, CUDA_0, CUDA_0 }}, // A: CUSPARSE_VERSION 11300 C: CUSPARSE_VERSION 12000 {"cusparseDenseToSparse_bufferSize", {CUDA_111, CUDA_0, CUDA_0 }}, // A: CUSPARSE_VERSION 11300 C: CUSPARSE_VERSION 12000 - {"cusparseDenseToSparse_analysis", {CUDA_111, CUDA_0, CUDA_0 }}, + {"cusparseDenseToSparse_analysis", {CUDA_111, CUDA_0, CUDA_0 }}, // A: CUSPARSE_VERSION 11300 C: CUSPARSE_VERSION 12000 {"cusparseDenseToSparse_convert", {CUDA_111, CUDA_0, CUDA_0 }}, {"cusparseCreateCsrsv2Info", {CUDA_0, CUDA_113, CUDA_120}}, // D: CUSPARSE_VERSION 11500 R: CUSPARSE_VERSION 12000 {"cusparseDestroyCsrsv2Info", {CUDA_0, CUDA_113, CUDA_120}}, // D: CUSPARSE_VERSION 11500 R: CUSPARSE_VERSION 12000 diff --git a/src/HipifyAction.cpp b/src/HipifyAction.cpp index f6dd0214..628a9aa5 100644 --- a/src/HipifyAction.cpp +++ b/src/HipifyAction.cpp @@ -207,6 +207,7 @@ const std::string sCusparseCsr2cscEx2_bufferSize = "cusparseCsr2cscEx2_bufferSiz const std::string sCusparseSparseToDense = "cusparseSparseToDense"; const std::string sCusparseSparseToDense_bufferSize = "cusparseSparseToDense_bufferSize"; const std::string sCusparseDenseToSparse_bufferSize = "cusparseDenseToSparse_bufferSize"; +const std::string sCusparseDenseToSparse_analysis = "cusparseDenseToSparse_analysis"; // CUDA_OVERLOADED const std::string sCudaEventCreate = "cudaEventCreate"; @@ -1661,6 +1662,15 @@ std::map FuncArgCasts { false } }, + {sCusparseDenseToSparse_analysis, + { + { + {4, {e_add_const_argument, cw_None, "nullptr"}} + }, + true, + false + } + }, }; void HipifyAction::RewriteString(StringRef s, clang::SourceLocation start) { @@ -2508,7 +2518,8 @@ std::unique_ptr HipifyAction::CreateASTConsumer(clang::Compi sCusparseCsr2cscEx2_bufferSize, sCusparseSparseToDense, sCusparseSparseToDense_bufferSize, - sCusparseDenseToSparse_bufferSize + sCusparseDenseToSparse_bufferSize, + sCusparseDenseToSparse_analysis ) ) ) diff --git a/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu b/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu index c35196e4..0f784bdb 100644 --- a/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu +++ b/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu @@ -2590,7 +2590,6 @@ int main() { // CHECK: status_t = hipsparseDenseToSparse_bufferSize(handle_t, dnmatA, spmatB, denseToSparseAlg_t, &bufferSize); status_t = cusparseDenseToSparse_bufferSize(handle_t, dnmatA, spmatB, denseToSparseAlg_t, &bufferSize); - // TODO: Mark as C-Changed in 12.0.0 // CUDA: cusparseStatus_t CUSPARSEAPI cusparseDenseToSparse_analysis(cusparseHandle_t handle, cusparseDnMatDescr_t matA, cusparseSpMatDescr_t matB, cusparseDenseToSparseAlg_t alg, void* buffer); // HIP: HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDenseToSparse_analysis(hipsparseHandle_t handle, hipsparseDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer); // CHECK: status_t = hipsparseDenseToSparse_analysis(handle_t, dnmatA, spmatB, denseToSparseAlg_t, tempBuffer); diff --git a/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu index 5406e510..de1783a8 100644 --- a/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu +++ b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu @@ -102,6 +102,11 @@ int main() { cusparseConstSpMatDescr_t constSpMatDescr = nullptr; cusparseConstSpMatDescr_t constSpMatDescrB = nullptr; + // CHECK: rocsparse_const_dnmat_descr constDnMatDescr = nullptr; + // CHECK-NEXT: rocsparse_const_dnmat_descr constDnMatDescrB = nullptr; + cusparseConstDnMatDescr_t constDnMatDescr = nullptr; + cusparseConstDnMatDescr_t constDnMatDescrB = nullptr; + // CUDA: cusparseStatus_t CUSPARSEAPI cusparseSparseToDense(cusparseHandle_t handle, cusparseConstSpMatDescr_t matA, cusparseDnMatDescr_t matB, cusparseSparseToDenseAlg_t alg, void* externalBuffer); // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_sparse_to_dense(rocsparse_handle handle, rocsparse_const_spmat_descr mat_A, rocsparse_dnmat_descr mat_B, rocsparse_sparse_to_dense_alg alg, size_t* buffer_size, void* temp_buffer); // CHECK: status_t = rocsparse_sparse_to_dense(handle_t, constSpMatDescr, dnmatB, sparseToDenseAlg_t, nullptr, tempBuffer); @@ -116,6 +121,11 @@ int main() { // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_dense_to_sparse(rocsparse_handle handle, rocsparse_const_dnmat_descr mat_A, rocsparse_spmat_descr mat_B, rocsparse_dense_to_sparse_alg alg, size_t* buffer_size, void* temp_buffer); // CHECK: status_t = rocsparse_dense_to_sparse(handle_t, dnmatB, spMatDescr_t, denseToSparseAlg_t, &bufferSize, nullptr); status_t = cusparseDenseToSparse_bufferSize(handle_t, dnmatB, spMatDescr_t, denseToSparseAlg_t, &bufferSize); + + // CUDA: cusparseStatus_t CUSPARSEAPI cusparseDenseToSparse_analysis(cusparseHandle_t handle, cusparseConstDnMatDescr_t matA, cusparseSpMatDescr_t matB, cusparseDenseToSparseAlg_t alg, void* externalBuffer); + // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_dense_to_sparse(rocsparse_handle handle, rocsparse_const_dnmat_descr mat_A, rocsparse_spmat_descr mat_B, rocsparse_dense_to_sparse_alg alg, size_t* buffer_size, void* temp_buffer); + // CHECK: status_t = rocsparse_dense_to_sparse(handle_t, constDnMatDescr, spmatB, denseToSparseAlg_t, nullptr, tempBuffer); + status_t = cusparseDenseToSparse_analysis(handle_t, constDnMatDescr, spmatB, denseToSparseAlg_t, tempBuffer); #endif return 0; diff --git a/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_before_12000.cu b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_before_12000.cu index cfc23ead..857a1706 100644 --- a/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_before_12000.cu +++ b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_before_12000.cu @@ -110,6 +110,11 @@ int main() { // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_dense_to_sparse(rocsparse_handle handle, const rocsparse_dnmat_descr mat_A, rocsparse_spmat_descr mat_B, rocsparse_dense_to_sparse_alg alg, size_t* buffer_size, void* temp_buffer); // CHECK: status_t = rocsparse_dense_to_sparse(handle_t, dnmatA, spmatB, denseToSparseAlg_t, &bufferSize, nullptr); status_t = cusparseDenseToSparse_bufferSize(handle_t, dnmatA, spmatB, denseToSparseAlg_t, &bufferSize); + + // CUDA: cusparseStatus_t CUSPARSEAPI cusparseDenseToSparse_analysis(cusparseHandle_t handle, cusparseDnMatDescr_t matA, cusparseSpMatDescr_t matB, cusparseDenseToSparseAlg_t alg, void* buffer); + // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_dense_to_sparse(rocsparse_handle handle, const rocsparse_dnmat_descr mat_A, rocsparse_spmat_descr mat_B, rocsparse_dense_to_sparse_alg alg, size_t* buffer_size, void* temp_buffer); + // CHECK: status_t = rocsparse_dense_to_sparse(handle_t, dnmatA, spmatB, denseToSparseAlg_t, nullptr, tempBuffer); + status_t = cusparseDenseToSparse_analysis(handle_t, dnmatA, spmatB, denseToSparseAlg_t, tempBuffer); #endif #endif