Skip to content

Commit

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

+ [IMP] `rocsparse_spmm` 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 11, 2024
1 parent 94fb7a4 commit 1ece9a0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions bin/hipify-perl
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,7 @@ sub rocSubstitutions {
subst("cusparseShybmv", "rocsparse_shybmv", "library");
subst("cusparseSnnz", "rocsparse_snnz", "library");
subst("cusparseSnnz_compress", "rocsparse_snnz_compress", "library");
subst("cusparseSpMM", "rocsparse_spmm", "library");
subst("cusparseSpMM_bufferSize", "rocsparse_spmm", "library");
subst("cusparseSpMV", "rocsparse_spmv", "library");
subst("cusparseSpMatGetAttribute", "rocsparse_spmat_get_attribute", "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 @@ -874,7 +874,7 @@
|`cusparseSpGEMMreuse_copy`|11.3| |12.0| |`hipsparseSpGEMMreuse_copy`|5.1.0| |6.0.0| | | | | | | | |
|`cusparseSpGEMMreuse_nnz`|11.3| |12.0| |`hipsparseSpGEMMreuse_nnz`|5.1.0| |6.0.0| | | | | | | | |
|`cusparseSpGEMMreuse_workEstimation`|11.3| |12.0| |`hipsparseSpGEMMreuse_workEstimation`|5.1.0| |6.0.0| | | | | | | | |
|`cusparseSpMM`|10.1| |12.0| |`hipsparseSpMM`|4.2.0| |6.0.0| | | | | | | | |
|`cusparseSpMM`|10.1| |12.0| |`hipsparseSpMM`|4.2.0| |6.0.0| | |`rocsparse_spmm`|4.2.0| |6.0.0| | |
|`cusparseSpMMOp`|11.5| | | | | | | | | | | | | | | |
|`cusparseSpMMOp_createPlan`|11.5| | | | | | | | | | | | | | | |
|`cusparseSpMMOp_destroyPlan`|11.5| | | | | | | | | | | | | | | |
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 @@ -874,7 +874,7 @@
|`cusparseSpGEMMreuse_copy`|11.3| |12.0| | | | | | | |
|`cusparseSpGEMMreuse_nnz`|11.3| |12.0| | | | | | | |
|`cusparseSpGEMMreuse_workEstimation`|11.3| |12.0| | | | | | | |
|`cusparseSpMM`|10.1| |12.0| | | | | | | |
|`cusparseSpMM`|10.1| |12.0| |`rocsparse_spmm`|4.2.0| |6.0.0| | |
|`cusparseSpMMOp`|11.5| | | | | | | | | |
|`cusparseSpMMOp_createPlan`|11.5| | | | | | | | | |
|`cusparseSpMMOp_destroyPlan`|11.5| | | | | | | | | |
Expand Down
2 changes: 1 addition & 1 deletion src/CUDA2HIP_SPARSE_API_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ const std::map<llvm::StringRef, hipCounter> CUDA_SPARSE_FUNCTION_MAP {

// Sparse Matrix * Matrix Multiplication
// TODO: hipification cusparseSpMM into rocsparse_spmm needs additional variable declared and allocated
{"cusparseSpMM", {"hipsparseSpMM", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}},
{"cusparseSpMM", {"hipsparseSpMM", "rocsparse_spmm", CONV_LIB_FUNC, API_SPARSE, 15}},
{"cusparseSpMM_bufferSize", {"hipsparseSpMM_bufferSize", "rocsparse_spmm", CONV_LIB_FUNC, API_SPARSE, 15}},
// TODO: hipification cusparseSpMM_preprocess into rocsparse_spmm needs additional variable declared and allocated
{"cusparseSpMM_preprocess", {"hipsparseSpMM_preprocess", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}},
Expand Down
15 changes: 14 additions & 1 deletion src/HipifyAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ const std::string sCusparseSpSM_analysis = "cusparseSpSM_analysis";
const std::string sCusparseSpSM_solve = "cusparseSpSM_solve";
const std::string sCusparseXcsrgeam2Nnz = "cusparseXcsrgeam2Nnz";
const std::string sCudaMallocHost = "cudaMallocHost";
const std::string sCusparseSpMM = "cusparseSpMM";

// CUDA_OVERLOADED
const std::string sCudaEventCreate = "cudaEventCreate";
Expand Down Expand Up @@ -2048,6 +2049,17 @@ std::map<std::string, std::vector<ArgCastStruct>> FuncArgCasts {
}
}
},
{sCusparseSpMM,
{
{
{
{10, {e_add_const_argument, cw_None, "rocsparse_spmm_stage_compute, nullptr"}},
},
true,
false
}
}
},
};

void HipifyAction::RewriteString(StringRef s, clang::SourceLocation start) {
Expand Down Expand Up @@ -2910,7 +2922,8 @@ std::unique_ptr<clang::ASTConsumer> HipifyAction::CreateASTConsumer(clang::Compi
sCusparseSpSM_analysis,
sCusparseSpSM_solve,
sCusparseXcsrgeam2Nnz,
sCudaMallocHost
sCudaMallocHost,
sCusparseSpMM
)
)
)
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 @@ -1979,7 +1979,6 @@ int main() {
// CHECK: status_t = hipsparseSpMM_bufferSize(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, &bufferSize);
status_t = cusparseSpMM_bufferSize(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, &bufferSize);

// TODO: Mark as C-Changed in 12.0.0
// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpMM(cusparseHandle_t handle, cusparseOperation_t transA, cusparseOperation_t transB, const void* alpha, const cusparseSpMatDescr_t matA, const cusparseDnMatDescr_t matB, const void* beta, cusparseDnMatDescr_t matC, cudaDataType computeType, cusparseSpMMAlg_t alg, void* externalBuffer);
// HIP: HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer);
// CHECK: status_t = hipsparseSpMM(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, tempBuffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ int main() {
void *pcscVal = nullptr;
void *alpha = nullptr;
void *beta = nullptr;
void *tempBuffer = nullptr;

// CHECK: rocsparse_operation opA, opB, opX;
cusparseOperation_t opA, opB, opX;
Expand Down Expand Up @@ -76,6 +77,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, &bufferSize, nullptr);
status_t = cusparseSpMM_bufferSize(handle_t, opA, opB, alpha, spmatA, dnmatB, beta, dnmatC, dataType, spMMAlg_t, &bufferSize);

// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpMM(cusparseHandle_t handle, cusparseOperation_t transA, cusparseOperation_t transB, const void* alpha, const cusparseSpMatDescr_t matA, const cusparseDnMatDescr_t matB, const void* beta, cusparseDnMatDescr_t matC, cudaDataType computeType, cusparseSpMMAlg_t alg, void* externalBuffer);
// 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);
#endif
#endif
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ int main() {
// ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_spsm(rocsparse_handle handle, rocsparse_operation trans_A, rocsparse_operation trans_B, const void* alpha, rocsparse_const_spmat_descr matA, rocsparse_const_dnmat_descr matB, const rocsparse_dnmat_descr matC, rocsparse_datatype compute_type, rocsparse_spsm_alg alg, rocsparse_spsm_stage stage, size_t* buffer_size, void* temp_buffer);
// CHECK: status_t = rocsparse_spsm(handle_t, opA, opB, alpha, constSpMatDescr, constDnMatDescrB, dnmatC, dataType, spSMAlg_t, rocsparse_spsm_stage_compute, nullptr, nullptr);
status_t = cusparseSpSM_solve(handle_t, opA, opB, alpha, constSpMatDescr, constDnMatDescrB, dnmatC, dataType, spSMAlg_t, spSMDescr);

// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpMM(cusparseHandle_t handle, cusparseOperation_t opA, cusparseOperation_t opB, const void* alpha, cusparseConstSpMatDescr_t matA, cusparseConstDnMatDescr_t matB, const void* beta, cusparseDnMatDescr_t matC, cudaDataType computeType, cusparseSpMMAlg_t alg, void* externalBuffer);
// 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);
#endif

return 0;
Expand Down

0 comments on commit 1ece9a0

Please sign in to comment.