Skip to content

Commit

Permalink
Merge pull request ROCm#1345 from emankov/HIPIFY
Browse files Browse the repository at this point in the history
[HIPIFY][ROCm#674][rocSPARSE][feature] rocSPARSE support - Step 105 - `cusparseSpSM_solve` -> `rocsparse_spsm`
  • Loading branch information
emankov authored Feb 8, 2024
2 parents c9bddc2 + 3dc964e commit 54f9d5c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions bin/hipify-perl
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,7 @@ sub rocSubstitutions {
subst("cusparseSpMatSetStridedBatch", "rocsparse_spmat_set_strided_batch", "library");
subst("cusparseSpMatSetValues", "rocsparse_spmat_set_values", "library");
subst("cusparseSpSM_analysis", "rocsparse_spsm", "library");
subst("cusparseSpSM_solve", "rocsparse_spsm", "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 @@ -897,7 +897,7 @@
|`cusparseSpSM_bufferSize`|11.3| |12.0| |`hipsparseSpSM_bufferSize`|4.5.0| |6.0.0| | | | | | | | |
|`cusparseSpSM_createDescr`|11.3| | | |`hipsparseSpSM_createDescr`|4.5.0| | | | | | | | | | |
|`cusparseSpSM_destroyDescr`|11.3| | | |`hipsparseSpSM_destroyDescr`|4.5.0| | | | | | | | | | |
|`cusparseSpSM_solve`|11.3| |12.0| |`hipsparseSpSM_solve`|4.5.0| |6.0.0| | | | | | | | |
|`cusparseSpSM_solve`|11.3| |12.0| |`hipsparseSpSM_solve`|4.5.0| |6.0.0| | |`rocsparse_spsm`|4.5.0| |6.0.0| | |
|`cusparseSpSV_analysis`|11.3| |12.0| |`hipsparseSpSV_analysis`|4.5.0| |6.0.0| | | | | | | | |
|`cusparseSpSV_bufferSize`|11.3| |12.0| |`hipsparseSpSV_bufferSize`|4.5.0| |6.0.0| | | | | | | | |
|`cusparseSpSV_createDescr`|11.3| | | |`hipsparseSpSV_createDescr`|4.5.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 @@ -897,7 +897,7 @@
|`cusparseSpSM_bufferSize`|11.3| |12.0| | | | | | | |
|`cusparseSpSM_createDescr`|11.3| | | | | | | | | |
|`cusparseSpSM_destroyDescr`|11.3| | | | | | | | | |
|`cusparseSpSM_solve`|11.3| |12.0| | | | | | | |
|`cusparseSpSM_solve`|11.3| |12.0| |`rocsparse_spsm`|4.5.0| |6.0.0| | |
|`cusparseSpSV_analysis`|11.3| |12.0| | | | | | | |
|`cusparseSpSV_bufferSize`|11.3| |12.0| | | | | | | |
|`cusparseSpSV_createDescr`|11.3| | | | | | | | | |
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 @@ -840,7 +840,7 @@ const std::map<llvm::StringRef, hipCounter> CUDA_SPARSE_FUNCTION_MAP {
// NTOE: Additional calculations are needed after calling rocsparse_spsm
{"cusparseSpSM_bufferSize", {"hipsparseSpSM_bufferSize", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}},
{"cusparseSpSM_analysis", {"hipsparseSpSM_analysis", "rocsparse_spsm", CONV_LIB_FUNC, API_SPARSE, 15}},
{"cusparseSpSM_solve", {"hipsparseSpSM_solve", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}},
{"cusparseSpSM_solve", {"hipsparseSpSM_solve", "rocsparse_spsm", CONV_LIB_FUNC, API_SPARSE, 15}},

// Sparse Matrix Multiplication (SpGEMM) Structure Reuse
{"cusparseSpGEMMreuse_workEstimation", {"hipsparseSpGEMMreuse_workEstimation", "", CONV_LIB_FUNC, API_SPARSE, 15, ROC_UNSUPPORTED}},
Expand Down
13 changes: 13 additions & 0 deletions src/HipifyAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const std::string sCusparseDenseToSparse_bufferSize = "cusparseDenseToSparse_buf
const std::string sCusparseDenseToSparse_analysis = "cusparseDenseToSparse_analysis";
const std::string sCusparseSpMM_bufferSize = "cusparseSpMM_bufferSize";
const std::string sCusparseSpSM_analysis = "cusparseSpSM_analysis";
const std::string sCusparseSpSM_solve = "cusparseSpSM_solve";
const std::string sCusparseXcsrgeam2Nnz = "cusparseXcsrgeam2Nnz";

// CUDA_OVERLOADED
Expand Down Expand Up @@ -1694,6 +1695,17 @@ std::map<std::string, ArgCastStruct> FuncArgCasts {
false
}
},
{sCusparseSpSM_solve,
{
{
{9, {e_replace_argument_with_const, cw_None, "rocsparse_spsm_stage_compute"}},
{10, {e_add_const_argument, cw_None, "nullptr"}},
{11, {e_add_const_argument, cw_None, "nullptr"}},
},
true,
false
}
},
{sCusparseXcsrgeam2Nnz,
{
{
Expand Down Expand Up @@ -2561,6 +2573,7 @@ std::unique_ptr<clang::ASTConsumer> HipifyAction::CreateASTConsumer(clang::Compi
sCusparseDenseToSparse_analysis,
sCusparseSpMM_bufferSize,
sCusparseSpSM_analysis,
sCusparseSpSM_solve,
sCusparseXcsrgeam2Nnz
)
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/synthetic/libraries/cusparse2hipsparse.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,7 @@ int main() {
// CHECK: status_t = hipsparseSpSM_analysis(handle_t, opA, opB, alpha, spmatA, dnmatB, dnmatC, dataType, spSMAlg_t, spSMDescr, tempBuffer);
status_t = cusparseSpSM_analysis(handle_t, opA, opB, alpha, spmatA, dnmatB, dnmatC, dataType, spSMAlg_t, spSMDescr, tempBuffer);

// TODO: Mark as C-Changed in 12.0.0
// TODO: hipsparseSpSM_solve has an additional argument void* externalBuffer - might be added as nullptr
// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpSM_solve(cusparseHandle_t handle, cusparseOperation_t opA, cusparseOperation_t opB, const void* alpha, cusparseSpMatDescr_t matA, cusparseDnMatDescr_t matB, cusparseDnMatDescr_t matC, cudaDataType computeType, cusparseSpSMAlg_t alg, cusparseSpSMDescr_t spsmDescr);
// HIP: HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSM_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer);
// CHECK: status_t = hipsparseSpSM_solve(handle_t, opA, opB, alpha, spmatA, dnmatB, dnmatC, dataType, spSMAlg_t, spSMDescr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ int main() {
// ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_spsm(rocsparse_handle handle, rocsparse_operation trans_A, rocsparse_operation trans_B, const void* alpha, const rocsparse_spmat_descr matA, const rocsparse_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, spmatA, dnmatB, dnmatC, dataType, spSMAlg_t, rocsparse_spsm_stage_compute, nullptr, tempBuffer);
status_t = cusparseSpSM_analysis(handle_t, opA, opB, alpha, spmatA, dnmatB, dnmatC, dataType, spSMAlg_t, spSMDescr, tempBuffer);

// CUDA: cusparseStatus_t CUSPARSEAPI cusparseSpSM_solve(cusparseHandle_t handle, cusparseOperation_t opA, cusparseOperation_t opB, const void* alpha, cusparseSpMatDescr_t matA, cusparseDnMatDescr_t matB, cusparseDnMatDescr_t matC, cudaDataType computeType, cusparseSpSMAlg_t alg, cusparseSpSMDescr_t spsmDescr);
// ROC: ROCSPARSE_EXPORT rocsparse_status rocsparse_spsm(rocsparse_handle handle, rocsparse_operation trans_A, rocsparse_operation trans_B, const void* alpha, const rocsparse_spmat_descr matA, const rocsparse_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, spmatA, dnmatB, dnmatC, dataType, spSMAlg_t, rocsparse_spsm_stage_compute, nullptr, nullptr);
status_t = cusparseSpSM_solve(handle_t, opA, opB, alpha, spmatA, dnmatB, dnmatC, dataType, spSMAlg_t, spSMDescr);
#endif
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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, tempBuffer);
status_t = cusparseSpSM_analysis(handle_t, opA, opB, alpha, constSpMatDescr, constDnMatDescrB, dnmatC, dataType, spSMAlg_t, spSMDescr, tempBuffer);

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

return 0;
Expand Down

0 comments on commit 54f9d5c

Please sign in to comment.