Skip to content

Commit

Permalink
[HIPIFY][ROCm#674][rocSPARSE][feature] rocSPARSE support - Step 97 - …
Browse files Browse the repository at this point in the history
…function `rocsparse_csr2csc_buffer_size`

+ Updated `SPARSE` synthetic tests, the regenerated hipify-perl, and `SPARSE` `CUDA2HIP` documentation
  • Loading branch information
emankov committed Jan 12, 2024
1 parent 2868b8c commit 770fe50
Show file tree
Hide file tree
Showing 7 changed files with 97 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 @@ -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");
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 @@ -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| | | | | | | | | | | | |
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 @@ -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| | | | | | |
Expand Down
6 changes: 3 additions & 3 deletions src/CUDA2HIP_SPARSE_API_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ const std::map<llvm::StringRef, hipCounter> 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}},
Expand Down Expand Up @@ -592,7 +591,7 @@ const std::map<llvm::StringRef, hipCounter> 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}},
Expand Down Expand Up @@ -793,7 +792,7 @@ const std::map<llvm::StringRef, hipCounter> 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}},
Expand Down Expand Up @@ -2423,6 +2422,7 @@ const std::map<llvm::StringRef, hipAPIversions> 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<llvm::StringRef, cudaAPIChangedVersions> CUDA_SPARSE_FUNCTION_CHANGED_VER_MAP {
Expand Down
19 changes: 18 additions & 1 deletion src/HipifyAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1615,6 +1616,21 @@ std::map<std::string, ArgCastStruct> 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) {
Expand Down Expand Up @@ -2458,7 +2474,8 @@ std::unique_ptr<clang::ASTConsumer> HipifyAction::CreateASTConsumer(clang::Compi
sCusparseZbsrilu02_bufferSize,
sCusparseCbsrilu02_bufferSize,
sCusparseDbsrilu02_bufferSize,
sCusparseSbsrilu02_bufferSize
sCusparseSbsrilu02_bufferSize,
sCusparseCsr2cscEx2_bufferSize
)
)
)
Expand Down
7 changes: 7 additions & 0 deletions tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions tests/unit_tests/synthetic/libraries/cusparse2rocsparse_10010.cu
Original file line number Diff line number Diff line change
@@ -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 <hip/hip_runtime.h>
#include <cuda_runtime.h>
// CHECK: #include "hip/hip_complex.h"
#include "cuComplex.h"
#include <stdio.h>
// 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;
}

0 comments on commit 770fe50

Please sign in to comment.