Skip to content

Commit

Permalink
[HIPIFY][ROCm#674][rocSPARSE][feature] rocSPARSE support - Step 107 -…
Browse files Browse the repository at this point in the history
… `cusparseSpVV_bufferSize` -> `rocsparse_spvv`

+ [IMP] `rocsparse_spvv` 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 Feb 12, 2024
1 parent 6d420fe commit 9d71e03
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 9 deletions.
1 change: 1 addition & 0 deletions bin/hipify-perl
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,7 @@ sub rocSubstitutions {
subst("cusparseSpMatSetValues", "rocsparse_spmat_set_values", "library");
subst("cusparseSpSM_analysis", "rocsparse_spsm", "library");
subst("cusparseSpSM_solve", "rocsparse_spsm", "library");
subst("cusparseSpVV_bufferSize", "rocsparse_spvv", "library");
subst("cusparseSpVecGet", "rocsparse_spvec_get", "library");
subst("cusparseSpVecGetIndexBase", "rocsparse_spvec_get_index_base", "library");
subst("cusparseSpVecGetValues", "rocsparse_spvec_get_values", "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 @@ -905,7 +905,7 @@
|`cusparseSpSV_solve`|11.3| |12.0| |`hipsparseSpSV_solve`|4.5.0| |6.0.0| | | | | | | | |
|`cusparseSpSV_updateMatrix`|12.1| | | | | | | | | | | | | | | |
|`cusparseSpVV`|10.2| |12.0| |`hipsparseSpVV`|4.1.0| |6.0.0| | | | | | | | |
|`cusparseSpVV_bufferSize`|10.2| |12.0| |`hipsparseSpVV_bufferSize`|4.1.0| |6.0.0| | | | | | | | |
|`cusparseSpVV_bufferSize`|10.2| |12.0| |`hipsparseSpVV_bufferSize`|4.1.0| |6.0.0| | |`rocsparse_spvv`|4.1.0| |6.0.0| | |
|`cusparseSpVecGet`|10.2| | | |`hipsparseSpVecGet`|4.1.0| | | | |`rocsparse_spvec_get`|4.1.0| | | | |
|`cusparseSpVecGetIndexBase`|10.2| |12.0| |`hipsparseSpVecGetIndexBase`|4.1.0| |6.0.0| | |`rocsparse_spvec_get_index_base`|4.1.0| |6.0.0| | |
|`cusparseSpVecGetValues`|10.2| | | |`hipsparseSpVecGetValues`|4.1.0| | | | |`rocsparse_spvec_get_values`|4.1.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 @@ -905,7 +905,7 @@
|`cusparseSpSV_solve`|11.3| |12.0| | | | | | | |
|`cusparseSpSV_updateMatrix`|12.1| | | | | | | | | |
|`cusparseSpVV`|10.2| |12.0| | | | | | | |
|`cusparseSpVV_bufferSize`|10.2| |12.0| | | | | | | |
|`cusparseSpVV_bufferSize`|10.2| |12.0| |`rocsparse_spvv`|4.1.0| |6.0.0| | |
|`cusparseSpVecGet`|10.2| | | |`rocsparse_spvec_get`|4.1.0| | | | |
|`cusparseSpVecGetIndexBase`|10.2| |12.0| |`rocsparse_spvec_get_index_base`|4.1.0| |6.0.0| | |
|`cusparseSpVecGetValues`|10.2| | | |`rocsparse_spvec_get_values`|4.1.0| | | | |
Expand Down
4 changes: 3 additions & 1 deletion src/CUDA2HIP_SPARSE_API_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ const std::map<llvm::StringRef, hipCounter> CUDA_SPARSE_FUNCTION_MAP {
// Sparse Vector * Vector Operations
// NOTE: rocsparse_spvv has one additional argument: size_t* buffer_size, thus cusparseSpVV is still ROC_UNSUPPORTED
{"cusparseSpVV", {"hipsparseSpVV", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}},
{"cusparseSpVV_bufferSize", {"hipsparseSpVV_bufferSize", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}},
{"cusparseSpVV_bufferSize", {"hipsparseSpVV_bufferSize", "rocsparse_spvv", CONV_LIB_FUNC, API_SPARSE, 15}},

{"cusparseAxpby", {"hipsparseAxpby", "rocsparse_axpby", CONV_LIB_FUNC, API_SPARSE, 15}},
{"cusparseGather", {"hipsparseGather", "rocsparse_gather", CONV_LIB_FUNC, API_SPARSE, 15}},
Expand Down Expand Up @@ -2431,6 +2431,7 @@ const std::map<llvm::StringRef, hipAPIversions> HIP_SPARSE_FUNCTION_VER_MAP {
{"rocsparse_dense_to_sparse", {HIP_4010, HIP_0, HIP_0 }},
{"rocsparse_spmm", {HIP_4020, HIP_0, HIP_0 }},
{"rocsparse_spsm", {HIP_4050, HIP_0, HIP_0 }},
{"rocsparse_spvv", {HIP_4010, HIP_0, HIP_0 }},
};

const std::map<llvm::StringRef, cudaAPIChangedVersions> CUDA_SPARSE_FUNCTION_CHANGED_VER_MAP {
Expand Down Expand Up @@ -2537,6 +2538,7 @@ const std::map<llvm::StringRef, hipAPIChangedVersions> HIP_SPARSE_FUNCTION_CHANG
{"rocsparse_dense_to_sparse", {HIP_6000}},
{"rocsparse_spmm", {HIP_6000}},
{"rocsparse_spsm", {HIP_6000}},
{"rocsparse_spvv", {HIP_6000}},
};

const std::map<unsigned int, llvm::StringRef> CUDA_SPARSE_API_SECTION_MAP {
Expand Down
15 changes: 14 additions & 1 deletion src/HipifyAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ const std::string sCusparseSpSM_solve = "cusparseSpSM_solve";
const std::string sCusparseXcsrgeam2Nnz = "cusparseXcsrgeam2Nnz";
const std::string sCudaMallocHost = "cudaMallocHost";
const std::string sCusparseSpMM = "cusparseSpMM";
const std::string sCusparseSpVV_bufferSize = "cusparseSpVV_bufferSize";

// CUDA_OVERLOADED
const std::string sCudaEventCreate = "cudaEventCreate";
Expand Down Expand Up @@ -2060,6 +2061,17 @@ std::map<std::string, std::vector<ArgCastStruct>> FuncArgCasts {
}
}
},
{sCusparseSpVV_bufferSize,
{
{
{
{7, {e_add_const_argument, cw_None, "nullptr"}},
},
true,
false
}
}
},
};

void HipifyAction::RewriteString(StringRef s, clang::SourceLocation start) {
Expand Down Expand Up @@ -2923,7 +2935,8 @@ std::unique_ptr<clang::ASTConsumer> HipifyAction::CreateASTConsumer(clang::Compi
sCusparseSpSM_solve,
sCusparseXcsrgeam2Nnz,
sCudaMallocHost,
sCusparseSpMM
sCusparseSpMM,
sCusparseSpVV_bufferSize
)
)
)
Expand Down
5 changes: 1 addition & 4 deletions tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ int main() {
status_t = cusparseDestroyCsrgemm2Info(csrgemm2_info);
#endif

#if (CUDA_VERSION >= 10020 && CUDA_VERSION < 11000 && !defined(_WIN32)) || CUDA_VERSION >= 11000
#if (CUDA_VERSION >= 10010 && CUSPARSE_VERSION >= 10200 && CUDA_VERSION < 11000 && !defined(_WIN32)) || CUDA_VERSION >= 11000
// CHECK: hipsparseSpVecDescr_t spVecDescr_t;
cusparseSpVecDescr_t spVecDescr_t;

Expand Down Expand Up @@ -2061,7 +2061,6 @@ int main() {
// CHECK: status_t = hipsparseDestroyDnVec(dnVecDescr_t);
status_t = cusparseDestroyDnVec(dnVecDescr_t);

// TODO: Mark as C-Changed in 12.0.0
// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpVV_bufferSize(cusparseHandle_t handle, cusparseOperation_t opX, const cusparseSpVecDescr_t vecX, const cusparseDnVecDescr_t vecY, const void* result, cudaDataType computeType, size_t* bufferSize);
// HIP: HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY, void* result, hipDataType computeType, size_t* bufferSize);
// CHECK: status_t = hipsparseSpVV_bufferSize(handle_t, opX, spVecDescr_t, vecY, result, dataType, &bufferSize);
Expand Down Expand Up @@ -2737,13 +2736,11 @@ int main() {
cusparseSpGEMMAlg_t SPGEMM_CSR_ALG_NONDETERMINITIC = CUSPARSE_SPGEMM_CSR_ALG_NONDETERMINITIC;

#if CUDA_VERSION < 12000
// TODO: Mark as C-Changed in 12.0.0
// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpGEMMreuse_workEstimation(cusparseHandle_t handle, cusparseOperation_t opA, cusparseOperation_t opB, cusparseSpMatDescr_t matA, cusparseSpMatDescr_t matB, cusparseSpMatDescr_t matC, cusparseSpGEMMAlg_t alg, cusparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1);
// HIP: HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1);
// CHECK: status_t = hipsparseSpGEMMreuse_workEstimation(handle_t, opA, opB, spmatA, spmatB, spmatC, spGEMMAlg_t, spGEMMDescr, &bufferSize, tempBuffer);
status_t = cusparseSpGEMMreuse_workEstimation(handle_t, opA, opB, spmatA, spmatB, spmatC, spGEMMAlg_t, spGEMMDescr, &bufferSize, tempBuffer);

// TODO: Mark as C-Changed in 12.0.0
// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpGEMMreuse_nnz(cusparseHandle_t handle, cusparseOperation_t opA, cusparseOperation_t opB, cusparseSpMatDescr_t matA, cusparseSpMatDescr_t matB, cusparseSpMatDescr_t matC, cusparseSpGEMMAlg_t alg, cusparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2, size_t* bufferSize3, void* externalBuffer3, size_t* bufferSize4, void* externalBuffer4);
// HIP: HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_nnz(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2, size_t* bufferSize3, void* externalBuffer3, size_t* bufferSize4, void* externalBuffer4);
// CHECK: status_t = hipsparseSpGEMMreuse_nnz(handle_t, opA, opB, spmatA, spmatB, spmatC, spGEMMAlg_t, spGEMMDescr, &bufferSize2, tempBuffer2, &bufferSize3, tempBuffer3, &bufferSize4, tempBuffer4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int main() {
void *alpha = nullptr;
void *beta = nullptr;
void *tempBuffer = nullptr;
void* result = nullptr;

// CHECK: rocsparse_operation opA, opB, opX;
cusparseOperation_t opA, opB, opX;
Expand All @@ -58,7 +59,7 @@ int main() {
cudaDataType dataType;
#endif

#if CUDA_VERSION >= 10010
#if CUDA_VERSION >= 10010 && CUSPARSE_VERSION >= 10200
// TODO: cusparseCsr2CscAlg_t has no analogue in rocSPARSE. The deletion of declaration and usage is needed to be implemented
cusparseCsr2CscAlg_t Csr2CscAlg_t;

Expand All @@ -72,6 +73,16 @@ int main() {
// CHECK: rocsparse_spmm_alg spMMAlg_t;
cusparseSpMMAlg_t spMMAlg_t;

// CHECK: _rocsparse_spvec_descr *spVecDescr = nullptr;
// CHECK-NEXT: rocsparse_spvec_descr spVecDescr_t;
cusparseSpVecDescr *spVecDescr = nullptr;
cusparseSpVecDescr_t spVecDescr_t;

// CHECK: _rocsparse_dnvec_descr *dnVecDescr = nullptr;
// CHECK-NEXT: rocsparse_dnvec_descr dnVecDescr_t, vecX, vecY;
cusparseDnVecDescr *dnVecDescr = nullptr;
cusparseDnVecDescr_t dnVecDescr_t, vecX, vecY;

#if CUDA_VERSION < 12000
// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpMM_bufferSize(cusparseHandle_t handle, cusparseOperation_t opA, cusparseOperation_t opB, const void* alpha, const cusparseSpMatDescr_t matA, const cusparseDnMatDescr_t matB, const void* beta, cusparseDnMatDescr_t matC, cudaDataType computeType, cusparseSpMMAlg_t alg, size_t* bufferSize);
// 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);
Expand All @@ -82,6 +93,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, nullptr, tempBuffer);
status_t = cusparseSpMM(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, tempBuffer);

// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpVV_bufferSize(cusparseHandle_t handle, cusparseOperation_t opX, const cusparseSpVecDescr_t vecX, const cusparseDnVecDescr_t vecY, const void* result, cudaDataType computeType, size_t* bufferSize);
// ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_spvv(rocsparse_handle handle, rocsparse_operation trans, const rocsparse_spvec_descr x, const rocsparse_dnvec_descr y, void* result, rocsparse_datatype compute_type, size_t* buffer_size, void* temp_buffer);
// CHECK: status_t = rocsparse_spvv(handle_t, opX, spVecDescr_t, vecY, result, dataType, &bufferSize, nullptr);
status_t = cusparseSpVV_bufferSize(handle_t, opX, spVecDescr_t, vecY, result, dataType, &bufferSize);
#endif
#endif
#endif
Expand Down
12 changes: 12 additions & 0 deletions tests/unit_tests/synthetic/libraries/cusparse2rocsparse_12000.cu
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ int main() {
void *tempBuffer = nullptr;
void *alpha = nullptr;
void *beta = nullptr;
void* result = nullptr;

// TODO: should be rocsparse_double_complex
// TODO: add to TypeOverloads cuDoubleComplex -> rocsparse_double_complex under a new option --sparse
Expand Down Expand Up @@ -128,6 +129,12 @@ int main() {
cusparseConstDnMatDescr_t constDnMatDescr = nullptr;
cusparseConstDnMatDescr_t constDnMatDescrB = nullptr;

// CHECK: rocsparse_const_spvec_descr constSpVecDescr = nullptr;
cusparseConstSpVecDescr_t constSpVecDescr = nullptr;

// CHECK: rocsparse_const_dnvec_descr constDnVecDescr = nullptr;
cusparseConstDnVecDescr_t constDnVecDescr = 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 Down Expand Up @@ -167,6 +174,11 @@ int main() {
// 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);

// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpVV_bufferSize(cusparseHandle_t handle, cusparseOperation_t opX, cusparseConstSpVecDescr_t vecX, cusparseConstDnVecDescr_t vecY, const void* result, cudaDataType computeType, size_t* bufferSize);
// ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_spvv(rocsparse_handle handle, rocsparse_operation trans, rocsparse_const_spvec_descr x, rocsparse_const_dnvec_descr y, void* result, rocsparse_datatype compute_type, size_t* buffer_size, void* temp_buffer);
// CHECK: status_t = rocsparse_spvv(handle_t, opX, constSpVecDescr, constDnVecDescr, result, dataType, &bufferSize, nullptr);
status_t = cusparseSpVV_bufferSize(handle_t, opX, constSpVecDescr, constDnVecDescr, result, dataType, &bufferSize);
#endif

return 0;
Expand Down

0 comments on commit 9d71e03

Please sign in to comment.