Skip to content

Commit

Permalink
[HIPIFY][ROCm#674][rocSPARSE][feature] rocSPARSE support - Step 101 -…
Browse files Browse the repository at this point in the history
… `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
  • Loading branch information
emankov committed Jan 18, 2024
1 parent 2762e19 commit f3d220f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions bin/hipify-perl
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion docs/tables/CUSPARSE_API_supported_by_HIP_and_ROC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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| | |
Expand Down
2 changes: 1 addition & 1 deletion docs/tables/CUSPARSE_API_supported_by_ROC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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| | |
Expand Down
4 changes: 2 additions & 2 deletions src/CUDA2HIP_SPARSE_API_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ const std::map<llvm::StringRef, hipCounter> 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
Expand Down Expand Up @@ -1225,7 +1225,7 @@ const std::map<llvm::StringRef, cudaAPIversions> 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
Expand Down
13 changes: 12 additions & 1 deletion src/HipifyAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1661,6 +1662,15 @@ std::map<std::string, ArgCastStruct> FuncArgCasts {
false
}
},
{sCusparseDenseToSparse_analysis,
{
{
{4, {e_add_const_argument, cw_None, "nullptr"}}
},
true,
false
}
},
};

void HipifyAction::RewriteString(StringRef s, clang::SourceLocation start) {
Expand Down Expand Up @@ -2508,7 +2518,8 @@ std::unique_ptr<clang::ASTConsumer> HipifyAction::CreateASTConsumer(clang::Compi
sCusparseCsr2cscEx2_bufferSize,
sCusparseSparseToDense,
sCusparseSparseToDense_bufferSize,
sCusparseDenseToSparse_bufferSize
sCusparseDenseToSparse_bufferSize,
sCusparseDenseToSparse_analysis
)
)
)
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f3d220f

Please sign in to comment.