diff --git a/bin/hipify-perl b/bin/hipify-perl index 5a826cdd..da2969a7 100755 --- a/bin/hipify-perl +++ b/bin/hipify-perl @@ -2381,6 +2381,7 @@ sub rocSubstitutions { subst("cusparseCreateSpVec", "rocsparse_create_spvec_descr", "library"); subst("cusparseCscSetPointers", "rocsparse_csc_set_pointers", "library"); subst("cusparseCsctr", "rocsparse_csctr", "library"); + subst("cusparseCsr2cscEx2_bufferSize", "rocsparse_csr2csc_buffer_size", "library"); subst("cusparseCsrGet", "rocsparse_csr_get", "library"); subst("cusparseCsrSetPointers", "rocsparse_csr_set_pointers", "library"); subst("cusparseCsrSetStridedBatch", "rocsparse_csr_set_strided_batch", "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 dedb4007..231cca71 100644 --- a/docs/tables/CUSPARSE_API_supported_by_HIP_and_ROC.md +++ b/docs/tables/CUSPARSE_API_supported_by_HIP_and_ROC.md @@ -655,7 +655,7 @@ |`cusparseCreateIdentityPermutation`| |12.2| | |`hipsparseCreateIdentityPermutation`|1.9.2| | | | |`rocsparse_create_identity_permutation`|1.9.0| | | | | |`cusparseCsr2cscEx`|8.0|10.2| |11.0| | | | | | | | | | | | | |`cusparseCsr2cscEx2`|10.1| | | |`hipsparseCsr2cscEx2`|5.4.0| | | | | | | | | | | -|`cusparseCsr2cscEx2_bufferSize`|10.1| | | |`hipsparseCsr2cscEx2_bufferSize`|5.4.0| | | | | | | | | | | +|`cusparseCsr2cscEx2_bufferSize`|10.1| | | |`hipsparseCsr2cscEx2_bufferSize`|5.4.0| | | | |`rocsparse_csr2csc_buffer_size`|1.9.0| | | | | |`cusparseDbsr2csr`| | | | |`hipsparseDbsr2csr`|3.5.0| | | | |`rocsparse_dbsr2csr`|3.10.0| | | | | |`cusparseDcsc2dense`| |11.1| |12.0|`hipsparseDcsc2dense`|3.5.0| | | | |`rocsparse_dcsc2dense`|3.5.0| | | | | |`cusparseDcsc2hyb`| |10.2| |11.0| | | | | | | | | | | | | diff --git a/docs/tables/CUSPARSE_API_supported_by_ROC.md b/docs/tables/CUSPARSE_API_supported_by_ROC.md index 11195fe9..b2ee9621 100644 --- a/docs/tables/CUSPARSE_API_supported_by_ROC.md +++ b/docs/tables/CUSPARSE_API_supported_by_ROC.md @@ -655,7 +655,7 @@ |`cusparseCreateIdentityPermutation`| |12.2| | |`rocsparse_create_identity_permutation`|1.9.0| | | | | |`cusparseCsr2cscEx`|8.0|10.2| |11.0| | | | | | | |`cusparseCsr2cscEx2`|10.1| | | | | | | | | | -|`cusparseCsr2cscEx2_bufferSize`|10.1| | | | | | | | | | +|`cusparseCsr2cscEx2_bufferSize`|10.1| | | |`rocsparse_csr2csc_buffer_size`|1.9.0| | | | | |`cusparseDbsr2csr`| | | | |`rocsparse_dbsr2csr`|3.10.0| | | | | |`cusparseDcsc2dense`| |11.1| |12.0|`rocsparse_dcsc2dense`|3.5.0| | | | | |`cusparseDcsc2hyb`| |10.2| |11.0| | | | | | | diff --git a/src/CUDA2HIP_SPARSE_API_functions.cpp b/src/CUDA2HIP_SPARSE_API_functions.cpp index e4d33843..144886bc 100644 --- a/src/CUDA2HIP_SPARSE_API_functions.cpp +++ b/src/CUDA2HIP_SPARSE_API_functions.cpp @@ -412,7 +412,6 @@ const std::map CUDA_SPARSE_FUNCTION_MAP { {"cusparseCbsrilu02_numericBoost", {"hipsparseCbsrilu02_numericBoost", "rocsparse_dcbsrilu0_numeric_boost", CONV_LIB_FUNC, API_SPARSE, 12, CUDA_DEPRECATED}}, {"cusparseZbsrilu02_numericBoost", {"hipsparseZbsrilu02_numericBoost", "rocsparse_zbsrilu0_numeric_boost", CONV_LIB_FUNC, API_SPARSE, 12, CUDA_DEPRECATED}}, - // NOTE: rocsparse_(s|d|c|z)bsrilu0_buffer_size have an additional parameter void* temp_buffer {"cusparseSbsrilu02_bufferSize", {"hipsparseSbsrilu02_bufferSize", "rocsparse_sbsrilu0_buffer_size", CONV_LIB_FUNC, API_SPARSE, 12, CUDA_DEPRECATED}}, {"cusparseSbsrilu02_bufferSizeExt", {"hipsparseSbsrilu02_bufferSizeExt", "", CONV_LIB_FUNC, API_SPARSE, 12, UNSUPPORTED | CUDA_DEPRECATED}}, {"cusparseDbsrilu02_bufferSize", {"hipsparseDbsrilu02_bufferSize", "rocsparse_dbsrilu0_buffer_size", CONV_LIB_FUNC, API_SPARSE, 12, CUDA_DEPRECATED}}, @@ -592,7 +591,7 @@ const std::map CUDA_SPARSE_FUNCTION_MAP { {"cusparseCsr2cscEx", {"hipsparseCsr2cscEx", "", CONV_LIB_FUNC, API_SPARSE, 14, UNSUPPORTED | CUDA_DEPRECATED | CUDA_REMOVED}}, {"cusparseCsr2cscEx2", {"hipsparseCsr2cscEx2", "", CONV_LIB_FUNC, API_SPARSE, 14, ROC_UNSUPPORTED}}, - {"cusparseCsr2cscEx2_bufferSize", {"hipsparseCsr2cscEx2_bufferSize", "", CONV_LIB_FUNC, API_SPARSE, 14, ROC_UNSUPPORTED}}, + {"cusparseCsr2cscEx2_bufferSize", {"hipsparseCsr2cscEx2_bufferSize", "rocsparse_csr2csc_buffer_size", CONV_LIB_FUNC, API_SPARSE, 14}}, {"cusparseScsr2dense", {"hipsparseScsr2dense", "rocsparse_scsr2dense", CONV_LIB_FUNC, API_SPARSE, 14, CUDA_DEPRECATED | CUDA_REMOVED}}, {"cusparseDcsr2dense", {"hipsparseDcsr2dense", "rocsparse_dcsr2dense", CONV_LIB_FUNC, API_SPARSE, 14, CUDA_DEPRECATED | CUDA_REMOVED}}, @@ -793,7 +792,7 @@ const std::map CUDA_SPARSE_FUNCTION_MAP { {"cusparseCreateConstDnMat", {"hipsparseCreateConstDnMat", "rocsparse_create_const_dnmat_descr", CONV_LIB_FUNC, API_SPARSE, 15}}, {"cusparseDestroyDnMat", {"hipsparseDestroyDnMat", "rocsparse_destroy_dnmat_descr", CONV_LIB_FUNC, API_SPARSE, 15}}, {"cusparseDnMatGet", {"hipsparseDnMatGet", "rocsparse_dnmat_get", CONV_LIB_FUNC, API_SPARSE, 15}}, - {"cusparseConstDnMatGet", {"hipsparseConstDnMatGet", "rocsparse_const_dnmat_get", CONV_LIB_FUNC, API_SPARSE, 15,}}, + {"cusparseConstDnMatGet", {"hipsparseConstDnMatGet", "rocsparse_const_dnmat_get", CONV_LIB_FUNC, API_SPARSE, 15}}, {"cusparseDnMatGetValues", {"hipsparseDnMatGetValues", "rocsparse_dnmat_get_values", CONV_LIB_FUNC, API_SPARSE, 15}}, {"cusparseConstDnMatGetValues", {"hipsparseConstDnMatGetValues", "rocsparse_const_dnmat_get_values", CONV_LIB_FUNC, API_SPARSE, 15}}, {"cusparseDnMatSetValues", {"hipsparseDnMatSetValues", "rocsparse_dnmat_set_values", CONV_LIB_FUNC, API_SPARSE, 15}}, @@ -2423,6 +2422,7 @@ const std::map HIP_SPARSE_FUNCTION_VER_MAP { {"rocsparse_dbsrilu0_buffer_size", {HIP_3080, HIP_0, HIP_0 }}, {"rocsparse_cbsrilu0_buffer_size", {HIP_3080, HIP_0, HIP_0 }}, {"rocsparse_zbsrilu0_buffer_size", {HIP_3080, HIP_0, HIP_0 }}, + {"rocsparse_csr2csc_buffer_size", {HIP_1090, HIP_0, HIP_0 }}, }; const std::map CUDA_SPARSE_FUNCTION_CHANGED_VER_MAP { diff --git a/src/HipifyAction.cpp b/src/HipifyAction.cpp index a7fab2c6..33dae471 100644 --- a/src/HipifyAction.cpp +++ b/src/HipifyAction.cpp @@ -203,6 +203,7 @@ const std::string sCusparseZbsrilu02_bufferSize = "cusparseZbsrilu02_bufferSize" const std::string sCusparseCbsrilu02_bufferSize = "cusparseCbsrilu02_bufferSize"; const std::string sCusparseDbsrilu02_bufferSize = "cusparseDbsrilu02_bufferSize"; const std::string sCusparseSbsrilu02_bufferSize = "cusparseSbsrilu02_bufferSize"; +const std::string sCusparseCsr2cscEx2_bufferSize = "cusparseCsr2cscEx2_bufferSize"; // CUDA_OVERLOADED const std::string sCudaEventCreate = "cudaEventCreate"; @@ -1615,6 +1616,21 @@ std::map FuncArgCasts { false } }, + {sCusparseCsr2cscEx2_bufferSize, + { + { + {4, {e_remove_argument, cw_None}}, + {7, {e_remove_argument, cw_None}}, + {8, {e_remove_argument, cw_None}}, + {9, {e_remove_argument, cw_None}}, + {10, {e_remove_argument, cw_None}}, + {12, {e_remove_argument, cw_None}}, + {13, {e_remove_argument, cw_None}} + }, + true, + false + } + }, }; void HipifyAction::RewriteString(StringRef s, clang::SourceLocation start) { @@ -2458,7 +2474,8 @@ std::unique_ptr HipifyAction::CreateASTConsumer(clang::Compi sCusparseZbsrilu02_bufferSize, sCusparseCbsrilu02_bufferSize, sCusparseDbsrilu02_bufferSize, - sCusparseSbsrilu02_bufferSize + sCusparseSbsrilu02_bufferSize, + sCusparseCsr2cscEx2_bufferSize ) ) ) diff --git a/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu b/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu index b418bc54..816ef6c8 100644 --- a/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu +++ b/tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu @@ -226,6 +226,8 @@ int main() { void *alpha = nullptr; void *beta = nullptr; void *pBuffer = nullptr; + void *pcsrVal = nullptr; + void *pcscVal = nullptr; int *P = nullptr; void *tempBuffer = nullptr; void *tempBuffer1 = nullptr; @@ -1857,6 +1859,11 @@ int main() { // CHECK-NEXT: hipsparseCsr2CscAlg_t CSR2CSC_ALG1 = HIPSPARSE_CSR2CSC_ALG1; cusparseCsr2CscAlg_t Csr2CscAlg_t; cusparseCsr2CscAlg_t CSR2CSC_ALG1 = CUSPARSE_CSR2CSC_ALG1; + + // CUDA: cusparseStatus_t CUSPARSEAPI cusparseCsr2cscEx2_bufferSize(cusparseHandle_t handle, int m, int n, int nnz, const void* csrVal, const int* csrRowPtr, const int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, cudaDataType valType, cusparseAction_t copyValues, cusparseIndexBase_t idxBase, cusparseCsr2CscAlg_t alg, size_t* bufferSize); + // HIP: HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCsr2cscEx2_bufferSize(hipsparseHandle_t handle, int m, int n, int nnz, const void* csrVal, const int* csrRowPtr, const int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, hipDataType valType, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, hipsparseCsr2CscAlg_t alg, size_t* bufferSize); + // CHECK: status_t = hipsparseCsr2cscEx2_bufferSize(handle_t, m, n, innz, pcsrVal, &csrRowPtrA, &csrColIndA, pcscVal, &cscColPtrA, &cscRowIndA, dataType, action_t, indexBase_t, Csr2CscAlg_t, &bufferSize); + status_t = cusparseCsr2cscEx2_bufferSize(handle_t, m, n, innz, pcsrVal, &csrRowPtrA, &csrColIndA, pcscVal, &cscColPtrA, &cscRowIndA, dataType, action_t, indexBase_t, Csr2CscAlg_t, &bufferSize); #endif #if (CUDA_VERSION >= 10010 && CUDA_VERSION < 11000 && !defined(_WIN32)) || CUDA_VERSION >= 11000 diff --git a/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_10010.cu b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_10010.cu new file mode 100644 index 00000000..15edb71a --- /dev/null +++ b/tests/unit_tests/synthetic/libraries/cusparse2rocsparse_10010.cu @@ -0,0 +1,66 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 4 --skip-excluded-preprocessor-conditional-blocks --experimental --roc --use-hip-data-types %clang_args -ferror-limit=500 + +// CHECK: #include +#include +// CHECK: #include "hip/hip_complex.h" +#include "cuComplex.h" +#include +// CHECK: #include "rocsparse.h" +#include "cusparse.h" +// CHECK-NOT: #include "rocsparse.h" + +int main() { + printf("18.1. cuSPARSE API to rocSPARSE API synthetic test\n"); + + // CHECK: _rocsparse_handle *handle = nullptr; + // CHECK-NEXT: rocsparse_handle handle_t; + cusparseContext *handle = nullptr; + cusparseHandle_t handle_t; + + // CHECK: rocsparse_status status_t; + cusparseStatus_t status_t; + + // CHECK: _rocsparse_mat_descr *matDescr = nullptr; + // CHECK-NEXT: rocsparse_mat_descr matDescr_t, matDescr_t_2, matDescr_A, matDescr_B, matDescr_C, matDescr_D; + cusparseMatDescr *matDescr = nullptr; + cusparseMatDescr_t matDescr_t, matDescr_t_2, matDescr_A, matDescr_B, matDescr_C, matDescr_D; + + // CHECK: rocsparse_action action_t; + cusparseAction_t action_t; + + // CHECK: rocsparse_index_base indexBase_t; + cusparseIndexBase_t indexBase_t; + + int m = 0; + int n = 0; + int innz = 0; + int csrRowPtrA = 0; + int csrRowPtrB = 0; + int csrRowPtrC = 0; + int cscRowIndA = 0; + int csrColIndA = 0; + int csrColIndB = 0; + int csrColIndC = 0; + int cscColPtrA = 0; + size_t bufferSize = 0; + void *pcsrVal = nullptr; + void *pcscVal = nullptr; + +#if CUDA_VERSION >= 8000 + // TODO: [#899] There should be rocsparse_datatype instead of hipDataType + cudaDataType_t dataType_t; + cudaDataType dataType; +#endif + +#if CUDA_VERSION >= 10010 + // TODO: cusparseCsr2CscAlg_t has no analogue in rocSPARSE. The deletion of declaration and usage is needed to be implemented + cusparseCsr2CscAlg_t Csr2CscAlg_t; + + // CUDA: cusparseStatus_t CUSPARSEAPI cusparseCsr2cscEx2_bufferSize(cusparseHandle_t handle, int m, int n, int nnz, const void* csrVal, const int* csrRowPtr, const int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, cudaDataType valType, cusparseAction_t copyValues, cusparseIndexBase_t idxBase, cusparseCsr2CscAlg_t alg, size_t* bufferSize); + // ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_csr2csc_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_int* csr_row_ptr, const rocsparse_int* csr_col_ind, rocsparse_action copy_values, size_t* buffer_size); + // CHECK: status_t = rocsparse_csr2csc_buffer_size(handle_t, m, n, innz, &csrRowPtrA, &csrColIndA, action_t, &bufferSize); + status_t = cusparseCsr2cscEx2_bufferSize(handle_t, m, n, innz, pcsrVal, &csrRowPtrA, &csrColIndA, pcscVal, &cscColPtrA, &cscRowIndA, dataType, action_t, indexBase_t, Csr2CscAlg_t, &bufferSize); +#endif + + return 0; +}