diff --git a/clients/common/arg_check.cpp b/clients/common/arg_check.cpp index ca47dac7..e1c37c1e 100644 --- a/clients/common/arg_check.cpp +++ b/clients/common/arg_check.cpp @@ -44,6 +44,22 @@ } \ } +void verify_hipsparse_status(hipsparseStatus_t status, + hipsparseStatus_t expected_status, + const char* message) +{ +#ifdef GOOGLE_TEST + ASSERT_EQ(status, expected_status); +#else + if(status != expected_status) + { + std::cerr << "rocSPARSE TEST ERROR: status(=" << status + << ") != expected_status(= " << expected_status << "), "; + std::cerr << message << std::endl; + } +#endif +} + void verify_hipsparse_status_invalid_pointer(hipsparseStatus_t status, const char* message) { #ifdef GOOGLE_TEST diff --git a/clients/common/hipsparse_template_specialization.cpp b/clients/common/hipsparse_template_specialization.cpp index 7eb1564c..f5bcc3ed 100644 --- a/clients/common/hipsparse_template_specialization.cpp +++ b/clients/common/hipsparse_template_specialization.cpp @@ -2862,6 +2862,237 @@ namespace hipsparse handle, dirA, m, n, descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr); } + template <> + hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* A, + int ld, + const int* nnzPerRow, + float* csrVal, + int* csrRowPtr, + int* csrColInd) + { + return hipsparseSdense2csr( + handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); + } + + template <> + hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* A, + int ld, + const int* nnzPerRow, + double* csrVal, + int* csrRowPtr, + int* csrColInd) + { + return hipsparseDdense2csr( + handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); + } + + template <> + hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* A, + int ld, + const int* nnzPerRow, + hipComplex* csrVal, + int* csrRowPtr, + int* csrColInd) + { + return hipsparseCdense2csr( + handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); + } + + template <> + hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* A, + int ld, + const int* nnzPerRow, + hipDoubleComplex* csrVal, + int* csrRowPtr, + int* csrColInd) + { + return hipsparseZdense2csr( + handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); + } + + template <> + hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* A, + int ld, + const int* nnz_per_columns, + float* cscVal, + int* cscRowInd, + int* cscColPtr) + { + return hipsparseSdense2csc( + handle, m, n, descr, A, ld, nnz_per_columns, cscVal, cscRowInd, cscColPtr); + } + template <> + hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* A, + int ld, + const int* nnz_per_columns, + double* cscVal, + int* cscRowInd, + int* cscColPtr) + { + return hipsparseDdense2csc( + handle, m, n, descr, A, ld, nnz_per_columns, cscVal, cscRowInd, cscColPtr); + } + template <> + hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* A, + int ld, + const int* nnz_per_columns, + hipComplex* cscVal, + int* cscRowInd, + int* cscColPtr) + { + return hipsparseCdense2csc( + handle, m, n, descr, A, ld, nnz_per_columns, cscVal, cscRowInd, cscColPtr); + } + template <> + hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* A, + int ld, + const int* nnz_per_columns, + hipDoubleComplex* cscVal, + int* cscRowInd, + int* cscColPtr) + { + return hipsparseZdense2csc( + handle, m, n, descr, A, ld, nnz_per_columns, cscVal, cscRowInd, cscColPtr); + } + + template <> + hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* csrVal, + const int* csrRowPtr, + const int* csrColInd, + float* A, + int ld) + { + return hipsparseScsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); + } + template <> + hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* csrVal, + const int* csrRowPtr, + const int* csrColInd, + double* A, + int ld) + { + return hipsparseDcsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); + } + template <> + hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* csrVal, + const int* csrRowPtr, + const int* csrColInd, + hipComplex* A, + int ld) + { + return hipsparseCcsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); + } + template <> + hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* csrVal, + const int* csrRowPtr, + const int* csrColInd, + hipDoubleComplex* A, + int ld) + { + return hipsparseZcsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); + } + + template <> + hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* cscVal, + const int* cscRowInd, + const int* cscColPtr, + float* A, + int ld) + { + return hipsparseScsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); + } + template <> + hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* cscVal, + const int* cscRowInd, + const int* cscColPtr, + double* A, + int ld) + { + return hipsparseDcsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); + } + template <> + hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* cscVal, + const int* cscRowInd, + const int* cscColPtr, + hipComplex* A, + int ld) + { + return hipsparseCcsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); + } + template <> + hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* cscVal, + const int* cscRowInd, + const int* cscColPtr, + hipDoubleComplex* A, + int ld) + { + return hipsparseZcsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); + } + template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, @@ -3071,19 +3302,19 @@ namespace hipsparse } template <> - hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const float* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - float* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) + hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const float* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + float* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { return hipsparseScsr2bsr(handle, dirA, @@ -3101,19 +3332,19 @@ namespace hipsparse } template <> - hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const double* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - double* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) + hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const double* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + double* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { return hipsparseDcsr2bsr(handle, dirA, @@ -3131,19 +3362,19 @@ namespace hipsparse } template <> - hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const hipComplex* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipComplex* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) + hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const hipComplex* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipComplex* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { return hipsparseCcsr2bsr(handle, dirA, @@ -3161,19 +3392,19 @@ namespace hipsparse } template <> - hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const hipDoubleComplex* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipDoubleComplex* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) + hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const hipDoubleComplex* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipDoubleComplex* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { return hipsparseZcsr2bsr(handle, dirA, @@ -3191,19 +3422,19 @@ namespace hipsparse } template <> - hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const float* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - float* csrValC, - int* csrRowPtrC, - int* csrColIndC) + hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const float* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + float* csrValC, + int* csrRowPtrC, + int* csrColIndC) { return hipsparseSbsr2csr(handle, dirA, @@ -3221,19 +3452,19 @@ namespace hipsparse } template <> - hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const double* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - double* csrValC, - int* csrRowPtrC, - int* csrColIndC) + hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const double* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + double* csrValC, + int* csrRowPtrC, + int* csrColIndC) { return hipsparseDbsr2csr(handle, dirA, @@ -3251,19 +3482,19 @@ namespace hipsparse } template <> - hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const hipComplex* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipComplex* csrValC, - int* csrRowPtrC, - int* csrColIndC) + hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const hipComplex* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipComplex* csrValC, + int* csrRowPtrC, + int* csrColIndC) { return hipsparseCbsr2csr(handle, dirA, @@ -3281,19 +3512,19 @@ namespace hipsparse } template <> - hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const hipDoubleComplex* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipDoubleComplex* csrValC, - int* csrRowPtrC, - int* csrColIndC) + hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const hipDoubleComplex* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipDoubleComplex* csrValC, + int* csrRowPtrC, + int* csrColIndC) { return hipsparseZbsr2csr(handle, dirA, diff --git a/clients/include/arg_check.hpp b/clients/include/arg_check.hpp index 6e866505..c99773c0 100644 --- a/clients/include/arg_check.hpp +++ b/clients/include/arg_check.hpp @@ -27,6 +27,10 @@ #include +void verify_hipsparse_status(hipsparseStatus_t status, + hipsparseStatus_t expected_status, + const char* message); + void verify_hipsparse_status_invalid_pointer(hipsparseStatus_t status, const char* message); void verify_hipsparse_status_invalid_size(hipsparseStatus_t status, const char* message); diff --git a/clients/include/hipsparse.hpp b/clients/include/hipsparse.hpp index 7547572d..1856ff8d 100644 --- a/clients/include/hipsparse.hpp +++ b/clients/include/hipsparse.hpp @@ -425,6 +425,52 @@ namespace hipsparse int* nnzPerRowColumn, int* nnzTotalDevHostPtr); + template + hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const T* A, + int ld, + const int* nnzPerRow, + T* csrVal, + int* csrRowPtr, + int* csrColInd); + + template + hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const T* A, + int ld, + const int* nnzPerColumn, + T* cscVal, + int* cscRowInd, + int* cscColPtr); + + template + hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const T* csrVal, + const int* csrRowPtr, + const int* csrColInd, + T* A, + int ld); + + template + hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const T* cscVal, + const int* cscRowInd, + const int* cscColPtr, + T* A, + int ld); + template hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, @@ -452,34 +498,34 @@ namespace hipsparse hipsparseHybPartition_t partition_type); template - hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const T* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - T* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC); - - template - hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const T* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - T* csrValC, - int* csrRowPtrC, - int* csrColIndC); + hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const T* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + T* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC); + + template + hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const T* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + T* csrValC, + int* csrRowPtrC, + int* csrColIndC); template hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, diff --git a/clients/include/testing_bsr2csr.hpp b/clients/include/testing_bsr2csr.hpp index fa8400a7..e7fd3e01 100644 --- a/clients/include/testing_bsr2csr.hpp +++ b/clients/include/testing_bsr2csr.hpp @@ -44,22 +44,22 @@ void testing_bsr2csr_bad_arg(void) // do not test for bad args return; #endif - int m = 100; - int n = 100; - int nnz = 100; - int safe_size = 100; - int block_dim = 2; - hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; - hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; - hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; - hipsparseStatus_t status; + int m = 100; + int n = 100; + int nnz = 100; + int safe_size = 100; + int block_dim = 2; + hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; + hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; + hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; + hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; - std::unique_ptr unique_ptr_csr_descr(new descr_struct); - hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; - std::unique_ptr unique_ptr_bsr_descr(new descr_struct); - hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; + std::unique_ptr unique_ptr_csr_descr(new descr_struct); + hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; + std::unique_ptr unique_ptr_bsr_descr(new descr_struct); + hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); @@ -92,199 +92,199 @@ void testing_bsr2csr_bad_arg(void) // Test invalid handle status = hipsparseXbsr2csr(nullptr, - dir, - m, - n, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind, - block_dim, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind); + dir, + m, + n, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind, + block_dim, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXbsr2csr(handle, - dir, - m, - n, - nullptr, - bsr_val, - bsr_row_ptr, - bsr_col_ind, - block_dim, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind); + dir, + m, + n, + nullptr, + bsr_val, + bsr_row_ptr, + bsr_col_ind, + block_dim, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); status = hipsparseXbsr2csr(handle, - dir, - m, - n, - bsr_descr, - (T*)nullptr, - bsr_row_ptr, - bsr_col_ind, - block_dim, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind); + dir, + m, + n, + bsr_descr, + (T*)nullptr, + bsr_row_ptr, + bsr_col_ind, + block_dim, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); status = hipsparseXbsr2csr(handle, - dir, - m, - n, - bsr_descr, - bsr_val, - nullptr, - bsr_col_ind, - block_dim, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind); + dir, + m, + n, + bsr_descr, + bsr_val, + nullptr, + bsr_col_ind, + block_dim, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXbsr2csr(handle, - dir, - m, - n, - bsr_descr, - bsr_val, - bsr_row_ptr, - nullptr, - block_dim, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind); + dir, + m, + n, + bsr_descr, + bsr_val, + bsr_row_ptr, + nullptr, + block_dim, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); status = hipsparseXbsr2csr(handle, - dir, - m, - n, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind, - block_dim, - nullptr, - csr_val, - csr_row_ptr, - csr_col_ind); + dir, + m, + n, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind, + block_dim, + nullptr, + csr_val, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); status = hipsparseXbsr2csr(handle, - dir, - m, - n, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind, - block_dim, - csr_descr, - (T*)nullptr, - csr_row_ptr, - csr_col_ind); + dir, + m, + n, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind, + block_dim, + csr_descr, + (T*)nullptr, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = hipsparseXbsr2csr(handle, - dir, - m, - n, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind, - block_dim, - csr_descr, - csr_val, - nullptr, - csr_col_ind); + dir, + m, + n, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind, + block_dim, + csr_descr, + csr_val, + nullptr, + csr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); - + status = hipsparseXbsr2csr(handle, - dir, - m, - n, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind, - block_dim, - csr_descr, - csr_val, - csr_row_ptr, - nullptr); - verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); + dir, + m, + n, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind, + block_dim, + csr_descr, + csr_val, + csr_row_ptr, + nullptr); + verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); // Test invalid sizes status = hipsparseXbsr2csr(handle, - dir, - -1, - n, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind, - block_dim, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind); + dir, + -1, + n, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind, + block_dim, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); status = hipsparseXbsr2csr(handle, - dir, - m, - -1, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind, - block_dim, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind); + dir, + m, + -1, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind, + block_dim, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); status = hipsparseXbsr2csr(handle, - dir, - m, - n, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind, - -1, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind); + dir, + m, + n, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind, + -1, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind); verify_hipsparse_status_invalid_size(status, "Error: block_dim is invalid"); } template hipsparseStatus_t testing_bsr2csr(Arguments argus) { - int m = argus.M; - int n = argus.N; - int block_dim = argus.block_dim; - hipsparseIndexBase_t csr_idx_base = argus.idx_base; - hipsparseIndexBase_t bsr_idx_base = argus.idx_base2; - hipsparseDirection_t dir = argus.dirA; - std::string binfile = ""; - std::string filename = ""; + int m = argus.M; + int n = argus.N; + int block_dim = argus.block_dim; + hipsparseIndexBase_t csr_idx_base = argus.idx_base; + hipsparseIndexBase_t bsr_idx_base = argus.idx_base2; + hipsparseDirection_t dir = argus.dirA; + std::string binfile = ""; + std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real @@ -311,10 +311,10 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; - std::unique_ptr unique_ptr_csr_descr(new descr_struct); - hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; - std::unique_ptr unique_ptr_bsr_descr(new descr_struct); - hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; + std::unique_ptr unique_ptr_csr_descr(new descr_struct); + hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; + std::unique_ptr unique_ptr_bsr_descr(new descr_struct); + hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); @@ -346,7 +346,8 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); - if(!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) + if(!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dcsr_row_ptr || !dcsr_col_ind + || !dcsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || " @@ -370,7 +371,8 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) if(mb < 0 || nb < 0 || block_dim < 0) { - verify_hipsparse_status_invalid_size(status, "Error: mb < 0 || nb < 0 || block_dim < 0"); + verify_hipsparse_status_invalid_size(status, + "Error: mb < 0 || nb < 0 || block_dim < 0"); } else { @@ -384,7 +386,7 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; - int nnz; + int nnz; srand(12345ULL); if(binfile != "") { @@ -477,11 +479,16 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) // Allocate memory on the device auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; - auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; - auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; - auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; - auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb * block_dim * block_dim), device_free}; - auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; + auto dbsr_col_ind_managed + = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; + auto dbsr_val_managed = hipsparse_unique_ptr{ + device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; + auto dcsr_row_ptr_managed + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; + auto dcsr_col_ind_managed = hipsparse_unique_ptr{ + device_malloc(sizeof(int) * nnzb * block_dim * block_dim), device_free}; + auto dcsr_val_managed = hipsparse_unique_ptr{ + device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); @@ -499,11 +506,14 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) } // Copy data from host to device - CHECK_HIP_ERROR( - hipMemcpy(dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); + CHECK_HIP_ERROR(hipMemcpy( + dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); - CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); + CHECK_HIP_ERROR(hipMemcpy(dbsr_val, + hbsr_val.data(), + sizeof(T) * nnzb * block_dim * block_dim, + hipMemcpyHostToDevice)); if(argus.unit_check) { @@ -522,12 +532,16 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) dcsr_col_ind)); // Copy output from device to host - CHECK_HIP_ERROR( - hipMemcpy(hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( - hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); - CHECK_HIP_ERROR( - hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); + hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); + CHECK_HIP_ERROR(hipMemcpy(hcsr_col_ind.data(), + dcsr_col_ind, + sizeof(int) * nnzb * block_dim * block_dim, + hipMemcpyDeviceToHost)); + CHECK_HIP_ERROR(hipMemcpy(hcsr_val.data(), + dcsr_val, + sizeof(T) * nnzb * block_dim * block_dim, + hipMemcpyDeviceToHost)); // Host computed bsr2csr conversion std::vector hcsr_row_ptr_gold(m + 1); @@ -550,8 +564,10 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); - unit_check_general(1, nnzb * block_dim * block_dim, 1, hcsr_col_ind_gold.data(), hcsr_col_ind.data()); - unit_check_general(1, nnzb * block_dim * block_dim, 1, hcsr_val_gold.data(), hcsr_val.data()); + unit_check_general( + 1, nnzb * block_dim * block_dim, 1, hcsr_col_ind_gold.data(), hcsr_col_ind.data()); + unit_check_general( + 1, nnzb * block_dim * block_dim, 1, hcsr_val_gold.data(), hcsr_val.data()); } return HIPSPARSE_STATUS_SUCCESS; diff --git a/clients/include/testing_csc2dense.hpp b/clients/include/testing_csc2dense.hpp new file mode 100644 index 00000000..00cf3551 --- /dev/null +++ b/clients/include/testing_csc2dense.hpp @@ -0,0 +1,43 @@ +/* ************************************************************************ + * Copyright (c) 2020 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ +#pragma once +#ifndef TESTING_CSC2DENSE_HPP +#define TESTING_CSC2DENSE_HPP + +#include "testing_csx2dense.hpp" + +template +void testing_csc2dense_bad_arg(void) +{ + static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; + testing_csx2dense_bad_arg(hipsparseXcsc2dense); +} + +template +hipsparseStatus_t testing_csc2dense(Arguments argus) +{ + static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; + return testing_csx2dense(argus, hipsparseXcsc2dense, hipsparseXdense2csc); +} + +#endif // TESTING_CSC2DENSE diff --git a/clients/include/testing_csr2bsr.hpp b/clients/include/testing_csr2bsr.hpp index ecde43af..97c16a48 100644 --- a/clients/include/testing_csr2bsr.hpp +++ b/clients/include/testing_csr2bsr.hpp @@ -44,22 +44,22 @@ void testing_csr2bsr_bad_arg(void) // do not test for bad args return; #endif - int m = 100; - int n = 100; - int nnz = 100; - int safe_size = 100; - int block_dim = 2; - hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; - hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; - hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; - hipsparseStatus_t status; + int m = 100; + int n = 100; + int nnz = 100; + int safe_size = 100; + int block_dim = 2; + hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; + hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; + hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; + hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; - std::unique_ptr unique_ptr_csr_descr(new descr_struct); - hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; - std::unique_ptr unique_ptr_bsr_descr(new descr_struct); - hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; + std::unique_ptr unique_ptr_csr_descr(new descr_struct); + hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; + std::unique_ptr unique_ptr_bsr_descr(new descr_struct); + hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); @@ -94,334 +94,334 @@ void testing_csr2bsr_bad_arg(void) // Test invalid handle status = hipsparseXcsr2bsrNnz(nullptr, - dir, - m, - n, - csr_descr, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_row_ptr, - &bsr_nnzb); + dir, + m, + n, + csr_descr, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_row_ptr, + &bsr_nnzb); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - nullptr, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_row_ptr, - &bsr_nnzb); + dir, + m, + n, + nullptr, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_row_ptr, + &bsr_nnzb); verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); status = hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - csr_descr, - nullptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_row_ptr, - &bsr_nnzb); + dir, + m, + n, + csr_descr, + nullptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_row_ptr, + &bsr_nnzb); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - csr_descr, - csr_row_ptr, - nullptr, - block_dim, - bsr_descr, - bsr_row_ptr, - &bsr_nnzb); + dir, + m, + n, + csr_descr, + csr_row_ptr, + nullptr, + block_dim, + bsr_descr, + bsr_row_ptr, + &bsr_nnzb); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); - + status = hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - csr_descr, - csr_row_ptr, - csr_col_ind, - block_dim, - nullptr, - bsr_row_ptr, - &bsr_nnzb); + dir, + m, + n, + csr_descr, + csr_row_ptr, + csr_col_ind, + block_dim, + nullptr, + bsr_row_ptr, + &bsr_nnzb); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); - + status = hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - csr_descr, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - nullptr, - &bsr_nnzb); + dir, + m, + n, + csr_descr, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + nullptr, + &bsr_nnzb); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - csr_descr, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_row_ptr, - nullptr); + dir, + m, + n, + csr_descr, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_row_ptr, + nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_nnzb is nullptr"); // Test invalid sizes status = hipsparseXcsr2bsrNnz(handle, - dir, - -1, - n, - csr_descr, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_row_ptr, - &bsr_nnzb); - verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); + dir, + -1, + n, + csr_descr, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_row_ptr, + &bsr_nnzb); + verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); status = hipsparseXcsr2bsrNnz(handle, - dir, - m, - -1, - csr_descr, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_row_ptr, - &bsr_nnzb); - verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); + dir, + m, + -1, + csr_descr, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_row_ptr, + &bsr_nnzb); + verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); status = hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - csr_descr, - csr_row_ptr, - csr_col_ind, - -1, - bsr_descr, - bsr_row_ptr, - &bsr_nnzb); - verify_hipsparse_status_invalid_size(status, "Error: block_dim is invalid"); + dir, + m, + n, + csr_descr, + csr_row_ptr, + csr_col_ind, + -1, + bsr_descr, + bsr_row_ptr, + &bsr_nnzb); + verify_hipsparse_status_invalid_size(status, "Error: block_dim is invalid"); // Testing hipsparseXcsr2bsr() // Test invalid handle status = hipsparseXcsr2bsr(nullptr, - dir, - m, - n, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind); + dir, + m, + n, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_handle(status); - + // Test invalid pointers status = hipsparseXcsr2bsr(handle, - dir, - m, - n, - nullptr, - csr_val, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind); + dir, + m, + n, + nullptr, + csr_val, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); - + status = hipsparseXcsr2bsr(handle, - dir, - m, - n, - csr_descr, - (T*)nullptr, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind); + dir, + m, + n, + csr_descr, + (T*)nullptr, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); - + status = hipsparseXcsr2bsr(handle, - dir, - m, - n, - csr_descr, - csr_val, - nullptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind); + dir, + m, + n, + csr_descr, + csr_val, + nullptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); - + status = hipsparseXcsr2bsr(handle, - dir, - m, - n, - csr_descr, - csr_val, - csr_row_ptr, - nullptr, - block_dim, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind); + dir, + m, + n, + csr_descr, + csr_val, + csr_row_ptr, + nullptr, + block_dim, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); - + status = hipsparseXcsr2bsr(handle, - dir, - m, - n, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind, - block_dim, - nullptr, - bsr_val, - bsr_row_ptr, - bsr_col_ind); + dir, + m, + n, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind, + block_dim, + nullptr, + bsr_val, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); - + status = hipsparseXcsr2bsr(handle, - dir, - m, - n, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - (T*)nullptr, - bsr_row_ptr, - bsr_col_ind); + dir, + m, + n, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + (T*)nullptr, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); - + status = hipsparseXcsr2bsr(handle, - dir, - m, - n, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_val, - nullptr, - bsr_col_ind); + dir, + m, + n, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_val, + nullptr, + bsr_col_ind); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); - + status = hipsparseXcsr2bsr(handle, - dir, - m, - n, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_val, - bsr_row_ptr, - nullptr); + dir, + m, + n, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_val, + bsr_row_ptr, + nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); // Test invalid sizes status = hipsparseXcsr2bsr(handle, - dir, - -1, - n, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind); + dir, + -1, + n, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); status = hipsparseXcsr2bsr(handle, - dir, - m, - -1, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind, - block_dim, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind); + dir, + m, + -1, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind, + block_dim, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); status = hipsparseXcsr2bsr(handle, - dir, - m, - n, - csr_descr, - csr_val, - csr_row_ptr, - csr_col_ind, - -1, - bsr_descr, - bsr_val, - bsr_row_ptr, - bsr_col_ind); + dir, + m, + n, + csr_descr, + csr_val, + csr_row_ptr, + csr_col_ind, + -1, + bsr_descr, + bsr_val, + bsr_row_ptr, + bsr_col_ind); verify_hipsparse_status_invalid_size(status, "Error: block_dim is invalid"); } template hipsparseStatus_t testing_csr2bsr(Arguments argus) { - int m = argus.M; - int n = argus.N; - int block_dim = argus.block_dim; - hipsparseIndexBase_t csr_idx_base = argus.idx_base; - hipsparseIndexBase_t bsr_idx_base = argus.idx_base2; - hipsparseDirection_t dir = argus.dirA; - std::string binfile = ""; - std::string filename = ""; + int m = argus.M; + int n = argus.N; + int block_dim = argus.block_dim; + hipsparseIndexBase_t csr_idx_base = argus.idx_base; + hipsparseIndexBase_t bsr_idx_base = argus.idx_base2; + hipsparseDirection_t dir = argus.dirA; + std::string binfile = ""; + std::string filename = ""; hipsparseStatus_t status; // When in testing mode, M == N == -99 indicates that we are testing with a real @@ -440,10 +440,10 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; - std::unique_ptr unique_ptr_csr_descr(new descr_struct); - hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; - std::unique_ptr unique_ptr_bsr_descr(new descr_struct); - hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; + std::unique_ptr unique_ptr_csr_descr(new descr_struct); + hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; + std::unique_ptr unique_ptr_bsr_descr(new descr_struct); + hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); @@ -475,7 +475,8 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); - if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbsr_row_ptr || !dbsr_col_ind || !dbsr_val) + if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbsr_row_ptr || !dbsr_col_ind + || !dbsr_val) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, "!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || " @@ -486,16 +487,16 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) int bsr_nnzb; status = hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - csr_descr, - dcsr_row_ptr, - dcsr_col_ind, - block_dim, - bsr_descr, - dbsr_row_ptr, - &bsr_nnzb); + dir, + m, + n, + csr_descr, + dcsr_row_ptr, + dcsr_col_ind, + block_dim, + bsr_descr, + dbsr_row_ptr, + &bsr_nnzb); if(m < 0 || n < 0 || block_dim < 0) { @@ -536,7 +537,7 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; - int nnz; + int nnz; srand(12345ULL); if(binfile != "") { @@ -550,8 +551,9 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) } else if(argus.laplacian) { - m = n = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base); - nnz = hcsr_row_ptr[m]; + m = n + = gen_2d_laplacian(argus.laplacian, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base); + nnz = hcsr_row_ptr[m]; } else { @@ -600,7 +602,8 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; - auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; + auto dbsr_row_ptr_managed + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); @@ -629,42 +632,45 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) int hbsr_nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - csr_descr, - dcsr_row_ptr, - dcsr_col_ind, - block_dim, - bsr_descr, - dbsr_row_ptr, - &hbsr_nnzb)); + dir, + m, + n, + csr_descr, + dcsr_row_ptr, + dcsr_col_ind, + block_dim, + bsr_descr, + dbsr_row_ptr, + &hbsr_nnzb)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dbsr_nnzb_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; - int* dbsr_nnzb = (int*)dbsr_nnzb_managed.get(); + int* dbsr_nnzb = (int*)dbsr_nnzb_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, - dir, - m, - n, - csr_descr, - dcsr_row_ptr, - dcsr_col_ind, - block_dim, - bsr_descr, - dbsr_row_ptr, - dbsr_nnzb)); + dir, + m, + n, + csr_descr, + dcsr_row_ptr, + dcsr_col_ind, + block_dim, + bsr_descr, + dbsr_row_ptr, + dbsr_nnzb)); int hbsr_nnzb_copied_from_device; - CHECK_HIP_ERROR(hipMemcpy(&hbsr_nnzb_copied_from_device, dbsr_nnzb, sizeof(int), hipMemcpyDeviceToHost)); + CHECK_HIP_ERROR(hipMemcpy( + &hbsr_nnzb_copied_from_device, dbsr_nnzb, sizeof(int), hipMemcpyDeviceToHost)); // Check that using host and device pointer mode gives the same result unit_check_general(1, 1, 1, &hbsr_nnzb_copied_from_device, &hbsr_nnzb); // Allocate memory on the device - auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hbsr_nnzb), device_free}; - auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hbsr_nnzb * block_dim * block_dim), device_free}; + auto dbsr_col_ind_managed + = hipsparse_unique_ptr{device_malloc(sizeof(int) * hbsr_nnzb), device_free}; + auto dbsr_val_managed = hipsparse_unique_ptr{ + device_malloc(sizeof(T) * hbsr_nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); @@ -695,12 +701,14 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) std::vector hbsr_col_ind(hbsr_nnzb); std::vector hbsr_val(hbsr_nnzb * block_dim * block_dim); - CHECK_HIP_ERROR( - hipMemcpy(hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost )); + CHECK_HIP_ERROR(hipMemcpy( + hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * hbsr_nnzb, hipMemcpyDeviceToHost)); - CHECK_HIP_ERROR( - hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * hbsr_nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); + CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), + dbsr_val, + sizeof(T) * hbsr_nnzb * block_dim * block_dim, + hipMemcpyDeviceToHost)); // Host csr2bsr conversion std::vector hbsr_row_ptr_gold(mb + 1); @@ -710,24 +718,25 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) // call host csr2bsr here int bsr_nnzb_gold; host_csr_to_bsr(dir, - m, - n, - block_dim, - bsr_nnzb_gold, - csr_idx_base, - hcsr_row_ptr, - hcsr_col_ind, - hcsr_val, - bsr_idx_base, - hbsr_row_ptr_gold, - hbsr_col_ind_gold, - hbsr_val_gold); + m, + n, + block_dim, + bsr_nnzb_gold, + csr_idx_base, + hcsr_row_ptr, + hcsr_col_ind, + hcsr_val, + bsr_idx_base, + hbsr_row_ptr_gold, + hbsr_col_ind_gold, + hbsr_val_gold); // Unit check unit_check_general(1, 1, 1, &bsr_nnzb_gold, &hbsr_nnzb); unit_check_general(1, mb + 1, 1, hbsr_row_ptr_gold.data(), hbsr_row_ptr.data()); unit_check_general(1, hbsr_nnzb, 1, hbsr_col_ind_gold.data(), hbsr_col_ind.data()); - unit_check_general(1, hbsr_nnzb * block_dim * block_dim, 1, hbsr_val_gold.data(), hbsr_val.data()); + unit_check_general( + 1, hbsr_nnzb * block_dim * block_dim, 1, hbsr_val_gold.data(), hbsr_val.data()); } return HIPSPARSE_STATUS_SUCCESS; diff --git a/clients/include/testing_csr2dense.hpp b/clients/include/testing_csr2dense.hpp new file mode 100644 index 00000000..467988ab --- /dev/null +++ b/clients/include/testing_csr2dense.hpp @@ -0,0 +1,43 @@ +/* ************************************************************************ + * Copyright (c) 2020 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ +#pragma once +#ifndef TESTING_CSR2DENSE_HPP +#define TESTING_CSR2DENSE_HPP + +#include "testing_csx2dense.hpp" + +template +void testing_csr2dense_bad_arg(void) +{ + static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; + testing_csx2dense_bad_arg(hipsparseXcsr2dense); +} + +template +hipsparseStatus_t testing_csr2dense(Arguments argus) +{ + static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; + return testing_csx2dense(argus, hipsparseXcsr2dense, hipsparseXdense2csr); +} + +#endif // TESTING_CSR2DENSE diff --git a/clients/include/testing_csx2dense.hpp b/clients/include/testing_csx2dense.hpp new file mode 100644 index 00000000..1143f89e --- /dev/null +++ b/clients/include/testing_csx2dense.hpp @@ -0,0 +1,359 @@ +/* ************************************************************************ + * Copyright (c) 2020 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ + +#pragma once +#ifndef TESTING_CSX2DENSE_HPP +#define TESTING_CSX2DENSE_HPP + +#include "hipsparse.hpp" +#include "hipsparse_test_unique_ptr.hpp" +#include "unit.hpp" +#include "utility.hpp" + +#include +#include +#include + +using namespace hipsparse; +using namespace hipsparse_test; + +#include +template +void testing_csx2dense_bad_arg(FUNC& csx2dense) +{ + +#ifdef __HIP_PLATFORM_NVCC__ + // do not test for bad args + return; +#endif + static constexpr size_t safe_size = 100; + static constexpr int M = 10; + static constexpr int N = 10; + static constexpr int LD = M; + static constexpr hipsparseDirection_t dirA = DIRA; + hipsparseStatus_t status; + + std::unique_ptr unique_ptr_handle(new handle_struct); + hipsparseHandle_t handle = unique_ptr_handle->handle; + + std::unique_ptr unique_ptr_descr(new descr_struct); + hipsparseMatDescr_t descr = unique_ptr_descr->descr; + + auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; + auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; + auto m_nnzPerRowColumn = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; + auto m_csx_row_col_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; + auto m_csx_row_col_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; + + T* d_dense_val = (T*)m_dense_val.get(); + T* d_csx_val = (T*)m_csx_val.get(); + int* d_nnzPerRowColumn = (int*)m_nnzPerRowColumn.get(); + int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); + int* d_csx_col_row_ind = (int*)m_csx_row_col_ind.get(); + + if(!d_dense_val || !d_nnzPerRowColumn || !d_csx_row_col_ptr || !d_csx_col_row_ind || !d_csx_val) + { + PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); + return; + } + + // + // Testing invalid handle. + // + status = csx2dense(nullptr, 0, 0, nullptr, (const T*)nullptr, nullptr, nullptr, (T*)nullptr, 0); + verify_hipsparse_status_invalid_handle(status); + + // + // Testing invalid pointers. + // + status = csx2dense( + handle, M, N, nullptr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, LD); + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + + status = csx2dense(handle, + M, + N, + descr, + (const T*)nullptr, + d_csx_row_col_ptr, + d_csx_col_row_ind, + d_dense_val, + LD); + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + + status = csx2dense(handle, M, N, descr, d_csx_val, nullptr, d_csx_col_row_ind, d_dense_val, LD); + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + + status = csx2dense(handle, M, N, descr, d_csx_val, d_csx_row_col_ptr, nullptr, d_dense_val, LD); + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + + status = csx2dense( + handle, M, N, descr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, (T*)nullptr, LD); + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + + // + // Testing invalid size on M + // + status = csx2dense( + handle, -1, N, descr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, LD); + verify_hipsparse_status_invalid_size(status, "Error: an invalid size must be detected."); + // + // Testing invalid size on N + // + status = csx2dense( + handle, M, -1, descr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, LD); + verify_hipsparse_status_invalid_size(status, "Error: an invalid size must be detected."); + // + // Testing invalid size on LD + // + status = csx2dense( + handle, M, -1, descr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind, d_dense_val, M - 1); + verify_hipsparse_status_invalid_size(status, "Error: an invalid size must be detected."); +} + +template +hipsparseStatus_t testing_csx2dense(const Arguments& argus, FUNC1& csx2dense, FUNC2& dense2csx) +{ + + int M = argus.M; + int N = argus.N; + int LD = argus.lda; + hipsparseDirection_t dirA = argus.dirA; + hipsparseIndexBase_t idx_base = argus.idx_base; + + hipsparseStatus_t status; + + std::unique_ptr unique_ptr_handle(new handle_struct); + hipsparseHandle_t handle = unique_ptr_handle->handle; + + std::unique_ptr unique_ptr_descr(new descr_struct); + hipsparseMatDescr_t descr = unique_ptr_descr->descr; + CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO)); + + if(M <= 0 || N <= 0 || LD < M) + { +#ifdef __HIP_PLATFORM_NVCC__ + // Do not test args in cusparse + return HIPSPARSE_STATUS_SUCCESS; +#endif + hipsparseStatus_t expected_status + = (((M == 0 && N >= 0) || (M >= 0 && N == 0)) && (LD >= M)) + ? HIPSPARSE_STATUS_SUCCESS + : HIPSPARSE_STATUS_INVALID_VALUE; + status + = csx2dense(handle, M, N, descr, (const T*)nullptr, nullptr, nullptr, (T*)nullptr, LD); + verify_hipsparse_status(status, + expected_status, + (expected_status == HIPSPARSE_STATUS_SUCCESS) + ? "Error: call with zero sizes must be succesfull." + : "Error: An invalid size must be detected."); + + return HIPSPARSE_STATUS_SUCCESS; + } + + int DIMDIR = (HIPSPARSE_DIRECTION_ROW == DIRA) ? M : N; + std::vector h_dense_val_ref(LD * N); + std::vector h_dense_val(LD * N); + std::vector h_nnzPerRowColumn(DIMDIR); + std::vector hd_nnzPerRowColumn(DIMDIR); + std::vector h_nnzTotalDevHostPtr(1); + std::vector hd_nnzTotalDevHostPtr(1); + + // + // Create the dense matrix. + // + int MN = (dirA == HIPSPARSE_DIRECTION_ROW) ? M : N; + auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * LD * N), device_free}; + auto nnzPerRowColumn_managed + = hipsparse_unique_ptr{device_malloc(sizeof(int) * MN), device_free}; + auto nnzTotalDevHostPtr_managed + = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; + + T* d_dense_val = (T*)m_dense_val.get(); + int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); + int* d_nnzTotalDevHostPtr = (int*)nnzTotalDevHostPtr_managed.get(); + if(!d_nnzPerRowColumn || !d_nnzTotalDevHostPtr || !d_dense_val) + { + verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, + "!h_nnzPerRowColumn || !d_nnzPerRowColumn || !d_dense_val"); + return HIPSPARSE_STATUS_ALLOC_FAILED; + } + + // + // Initialize the entire allocated memory. + // + for(int i = 0; i < LD; ++i) + { + for(int j = 0; j < N; ++j) + { + h_dense_val_ref[j * LD + i] = T(-1.0); + } + } + + // + // Initialize a random dense matrix. + // + srand(0); + gen_dense_random_sparsity_pattern(M, N, h_dense_val_ref.data(), LD, 0.2); + + // + // Transfer. + // + CHECK_HIP_ERROR( + hipMemcpy(d_dense_val, h_dense_val_ref.data(), sizeof(T) * LD * N, hipMemcpyHostToDevice)); + + int nnz; + CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); + CHECK_HIPSPARSE_ERROR( + hipsparseXnnz(handle, DIRA, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, &nnz)); + + // + // Transfer. + // + CHECK_HIP_ERROR(hipMemcpy( + h_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * DIMDIR, hipMemcpyDeviceToHost)); + + auto m_csx_row_col_ptr + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (DIMDIR + 1)), device_free}; + auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; + auto m_csx_col_row_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; + + int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); + int* d_csx_col_row_ind = (int*)m_csx_col_row_ind.get(); + T* d_csx_val = (T*)m_csx_val.get(); + + if(!d_csx_row_col_ptr || !d_csx_val || !d_csx_col_row_ind) + { + CHECK_HIP_ERROR(hipErrorOutOfMemory); + return HIPSPARSE_STATUS_ALLOC_FAILED; + } + + std::vector cpu_csx_row_col_ptr(DIMDIR + 1); + std::vector cpu_csx_val(nnz); + std::vector cpu_csx_col_row_ind(nnz); + if(!cpu_csx_row_col_ptr.data() || !cpu_csx_val.data() || !cpu_csx_col_row_ind.data()) + { + CHECK_HIP_ERROR(hipErrorOutOfMemory); + return HIPSPARSE_STATUS_ALLOC_FAILED; + } + + // + // Convert the dense matrix to a compressed sparse matrix. + // + if(DIRA == HIPSPARSE_DIRECTION_ROW) + { + CHECK_HIPSPARSE_ERROR(dense2csx(handle, + M, + N, + descr, + d_dense_val, + LD, + d_nnzPerRowColumn, + d_csx_val, + d_csx_row_col_ptr, + d_csx_col_row_ind)); + } + else + { + CHECK_HIPSPARSE_ERROR(dense2csx(handle, + M, + N, + descr, + d_dense_val, + LD, + d_nnzPerRowColumn, + d_csx_val, + d_csx_col_row_ind, + d_csx_row_col_ptr)); + } + + // + // Copy on host. + // + CHECK_HIP_ERROR(hipMemcpy( + cpu_csx_val.data(), d_csx_val, sizeof(T) * std::max(nnz, 1), hipMemcpyDeviceToHost)); + + CHECK_HIP_ERROR(hipMemcpy(cpu_csx_row_col_ptr.data(), + d_csx_row_col_ptr, + sizeof(int) * (DIMDIR + 1), + hipMemcpyDeviceToHost)); + + CHECK_HIP_ERROR(hipMemcpy(cpu_csx_col_row_ind.data(), + d_csx_col_row_ind, + sizeof(int) * std::max(nnz, 1), + hipMemcpyDeviceToHost)); + + if(argus.unit_check) + { + for(int i = 0; i < LD; ++i) + { + for(int j = 0; j < N; ++j) + { + h_dense_val[j * LD + i] = T(-2); + } + } + CHECK_HIP_ERROR( + hipMemcpy(d_dense_val, h_dense_val.data(), sizeof(T) * LD * N, hipMemcpyHostToDevice)); + host_csx2dense(M, + N, + hipsparseGetMatIndexBase(descr), + cpu_csx_val.data(), + cpu_csx_row_col_ptr.data(), + cpu_csx_col_row_ind.data(), + h_dense_val.data(), + LD); + + if(DIRA == HIPSPARSE_DIRECTION_ROW) + { + CHECK_HIPSPARSE_ERROR(csx2dense(handle, + M, + N, + descr, + d_csx_val, + d_csx_row_col_ptr, + d_csx_col_row_ind, + d_dense_val, + LD)); + } + else + { + CHECK_HIPSPARSE_ERROR(csx2dense(handle, + M, + N, + descr, + d_csx_val, + d_csx_col_row_ind, + d_csx_row_col_ptr, + d_dense_val, + LD)); + } + void* buffer = malloc(sizeof(T) * LD * N); + CHECK_HIP_ERROR(hipMemcpy(buffer, d_dense_val, sizeof(T) * LD * N, hipMemcpyDeviceToHost)); + unit_check_general(M, N, LD, h_dense_val.data(), (T*)buffer); + unit_check_general(M, N, LD, h_dense_val.data(), h_dense_val_ref.data()); + free(buffer); + buffer = nullptr; + } + return HIPSPARSE_STATUS_SUCCESS; +} +#endif // TESTING_CSX2DENSE_HPP diff --git a/clients/include/testing_dense2csc.hpp b/clients/include/testing_dense2csc.hpp new file mode 100644 index 00000000..03cae487 --- /dev/null +++ b/clients/include/testing_dense2csc.hpp @@ -0,0 +1,43 @@ +/* ************************************************************************ + * Copyright (c) 2020 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ +#pragma once +#ifndef TESTING_DENSE2CSC_HPP +#define TESTING_DENSE2CSC_HPP + +#include "testing_dense2csx.hpp" + +template +void testing_dense2csc_bad_arg(void) +{ + static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; + testing_dense2csx_bad_arg(hipsparseXdense2csc); +} + +template +hipsparseStatus_t testing_dense2csc(Arguments argus) +{ + static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; + return testing_dense2csx(argus, hipsparseXdense2csc); +} + +#endif // TESTING_DENSE2CSC diff --git a/clients/include/testing_dense2csr.hpp b/clients/include/testing_dense2csr.hpp new file mode 100644 index 00000000..8c21df29 --- /dev/null +++ b/clients/include/testing_dense2csr.hpp @@ -0,0 +1,43 @@ +/* ************************************************************************ + * Copyright (c) 2020 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ +#pragma once +#ifndef TESTING_DENSE2CSR_HPP +#define TESTING_DENSE2CSR_HPP + +#include "testing_dense2csx.hpp" + +template +void testing_dense2csr_bad_arg(void) +{ + static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; + testing_dense2csx_bad_arg(hipsparseXdense2csr); +} + +template +hipsparseStatus_t testing_dense2csr(Arguments argus) +{ + static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; + return testing_dense2csx(argus, hipsparseXdense2csr); +} + +#endif // TESTING_DENSE2CSR diff --git a/clients/include/testing_dense2csx.hpp b/clients/include/testing_dense2csx.hpp new file mode 100644 index 00000000..d693583e --- /dev/null +++ b/clients/include/testing_dense2csx.hpp @@ -0,0 +1,396 @@ +/* ************************************************************************ + * Copyright (c) 2020 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ + +#pragma once +#ifndef TESTING_DENSE2CSX_HPP +#define TESTING_DENSE2CSX_HPP + +#include "hipsparse.hpp" +#include "hipsparse_test_unique_ptr.hpp" +#include "unit.hpp" +#include "utility.hpp" + +#include +#include +#include + +using namespace hipsparse; +using namespace hipsparse_test; + +#include +template +void testing_dense2csx_bad_arg(FUNC& dense2csx) +{ + +#ifdef __HIP_PLATFORM_NVCC__ + // do not test for bad args + return; +#endif + static constexpr size_t safe_size = 100; + static constexpr int M = 10; + static constexpr int N = 10; + static constexpr int LD = M; + static constexpr hipsparseDirection_t dirA = DIRA; + hipsparseStatus_t status; + + std::unique_ptr unique_ptr_handle(new handle_struct); + hipsparseHandle_t handle = unique_ptr_handle->handle; + + std::unique_ptr unique_ptr_descr(new descr_struct); + hipsparseMatDescr_t descr = unique_ptr_descr->descr; + + auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; + auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; + auto m_nnzPerRowColumn = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; + auto m_csx_row_col_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; + auto m_csx_row_col_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; + + T* d_dense_val = (T*)m_dense_val.get(); + T* d_csx_val = (T*)m_csx_val.get(); + int* d_nnzPerRowColumn = (int*)m_nnzPerRowColumn.get(); + int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); + int* d_csx_col_row_ind = (int*)m_csx_row_col_ind.get(); + + if(!d_dense_val || !d_nnzPerRowColumn || !d_csx_row_col_ptr || !d_csx_col_row_ind || !d_csx_val) + { + PRINT_IF_HIP_ERROR(hipErrorOutOfMemory); + return; + } + + // + // Testing invalid handle. + // + status = dense2csx( + nullptr, 0, 0, nullptr, (const T*)nullptr, 0, nullptr, (T*)nullptr, nullptr, nullptr); + verify_hipsparse_status_invalid_handle(status); + + // + // Testing invalid pointers. + // + status = dense2csx(handle, + M, + N, + nullptr, + d_dense_val, + LD, + d_nnzPerRowColumn, + d_csx_val, + d_csx_row_col_ptr, + d_csx_col_row_ind); + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + + status = dense2csx(handle, + M, + N, + descr, + nullptr, + LD, + d_nnzPerRowColumn, + d_csx_val, + d_csx_row_col_ptr, + d_csx_col_row_ind); + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + status = dense2csx(handle, + M, + N, + descr, + d_dense_val, + LD, + nullptr, + d_csx_val, + d_csx_row_col_ptr, + d_csx_col_row_ind); + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + + status = dense2csx(handle, + M, + N, + descr, + d_dense_val, + LD, + d_nnzPerRowColumn, + nullptr, + d_csx_row_col_ptr, + d_csx_col_row_ind); + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + status = dense2csx(handle, + M, + N, + descr, + d_dense_val, + LD, + d_nnzPerRowColumn, + d_csx_val, + nullptr, + d_csx_col_row_ind); + + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + status = dense2csx(handle, + M, + N, + descr, + d_dense_val, + LD, + d_nnzPerRowColumn, + d_csx_val, + d_csx_row_col_ptr, + nullptr); + + verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected."); + + // + // Testing invalid size on M + // + status = dense2csx(handle, + -1, + N, + descr, + d_dense_val, + LD, + d_nnzPerRowColumn, + d_csx_val, + d_csx_row_col_ptr, + d_csx_col_row_ind); + verify_hipsparse_status_invalid_size(status, "Error: An invalid size must be detected."); + // + // Testing invalid size on N + // + status = dense2csx(handle, + M, + -1, + descr, + d_dense_val, + LD, + d_nnzPerRowColumn, + d_csx_val, + d_csx_row_col_ptr, + d_csx_col_row_ind); + verify_hipsparse_status_invalid_size(status, "Error: An invalid size must be detected."); + // + // Testing invalid size on LD + // + status = dense2csx(handle, + M, + N, + descr, + d_dense_val, + M - 1, + d_nnzPerRowColumn, + d_csx_val, + d_csx_row_col_ptr, + d_csx_col_row_ind); + verify_hipsparse_status_invalid_size(status, "Error: An invalid size must be detected."); +} + +template +hipsparseStatus_t testing_dense2csx(const Arguments& argus, FUNC& dense2csx) +{ + + int M = argus.M; + int N = argus.N; + int LD = argus.lda; + hipsparseDirection_t dirA = argus.dirA; + hipsparseIndexBase_t idx_base = argus.idx_base; + + hipsparseStatus_t status; + + std::unique_ptr unique_ptr_handle(new handle_struct); + hipsparseHandle_t handle = unique_ptr_handle->handle; + + std::unique_ptr unique_ptr_descr(new descr_struct); + hipsparseMatDescr_t descr = unique_ptr_descr->descr; + CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, HIPSPARSE_INDEX_BASE_ZERO)); + + if(M <= 0 || N <= 0 || LD < M) + { +#ifdef __HIP_PLATFORM_NVCC__ + // Do not test args in cusparse + return HIPSPARSE_STATUS_SUCCESS; +#endif + hipsparseStatus_t expected_status + = (((M == 0 && N >= 0) || (M >= 0 && N == 0)) && (LD >= M)) + ? HIPSPARSE_STATUS_SUCCESS + : HIPSPARSE_STATUS_INVALID_VALUE; + status = dense2csx( + handle, M, N, descr, (const T*)nullptr, LD, nullptr, (T*)nullptr, nullptr, nullptr); + verify_hipsparse_status(status, + expected_status, + (expected_status == HIPSPARSE_STATUS_SUCCESS) + ? "Error: call with zero sizes must be succesfull." + : "Error: An invalid size must be detected."); + + return HIPSPARSE_STATUS_SUCCESS; + } + + int DIMDIR = (HIPSPARSE_DIRECTION_ROW == DIRA) ? M : N; + std::vector h_dense_val(LD * N); + std::vector h_nnzPerRowColumn(DIMDIR); + std::vector hd_nnzPerRowColumn(DIMDIR); + std::vector h_nnzTotalDevHostPtr(1); + std::vector hd_nnzTotalDevHostPtr(1); + + // + // Create the dense matrix. + // + int MN = (dirA == HIPSPARSE_DIRECTION_ROW) ? M : N; + auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * LD * N), device_free}; + auto nnzPerRowColumn_managed + = hipsparse_unique_ptr{device_malloc(sizeof(int) * MN), device_free}; + auto nnzTotalDevHostPtr_managed + = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; + + T* d_dense_val = (T*)m_dense_val.get(); + int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); + int* d_nnzTotalDevHostPtr = (int*)nnzTotalDevHostPtr_managed.get(); + if(!d_nnzPerRowColumn || !d_nnzTotalDevHostPtr || !d_dense_val) + { + verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, + "!h_nnzPerRowColumn || !d_nnzPerRowColumn || !d_dense_val"); + return HIPSPARSE_STATUS_ALLOC_FAILED; + } + + // + // Initialize the entire allocated memory. + // + for(int i = 0; i < LD; ++i) + { + for(int j = 0; j < N; ++j) + { + h_dense_val[j * LD + i] = T(-1.0); + } + } + + // + // Initialize a random dense matrix. + // + srand(0); + gen_dense_random_sparsity_pattern(M, N, h_dense_val.data(), LD, 0.2); + + // + // Transfer. + // + CHECK_HIP_ERROR( + hipMemcpy(d_dense_val, h_dense_val.data(), sizeof(T) * LD * N, hipMemcpyHostToDevice)); + + int nnz; + CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); + CHECK_HIPSPARSE_ERROR( + hipsparseXnnz(handle, DIRA, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, &nnz)); + + // + // Transfer. + // + CHECK_HIP_ERROR(hipMemcpy( + h_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * DIMDIR, hipMemcpyDeviceToHost)); + + auto m_csx_row_col_ptr + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (DIMDIR + 1)), device_free}; + auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; + auto m_csx_col_row_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; + + int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); + int* d_csx_col_row_ind = (int*)m_csx_col_row_ind.get(); + T* d_csx_val = (T*)m_csx_val.get(); + + if(!d_csx_row_col_ptr || !d_csx_val || !d_csx_col_row_ind) + { + CHECK_HIP_ERROR(hipErrorOutOfMemory); + return HIPSPARSE_STATUS_ALLOC_FAILED; + } + + std::vector cpu_csx_row_col_ptr(DIMDIR + 1); + std::vector cpu_csx_val(nnz); + std::vector cpu_csx_col_row_ind(nnz); + if(!cpu_csx_row_col_ptr.data() || !cpu_csx_val.data() || !cpu_csx_col_row_ind.data()) + { + CHECK_HIP_ERROR(hipErrorOutOfMemory); + return HIPSPARSE_STATUS_ALLOC_FAILED; + } + + if(argus.unit_check) + { + + // + // Compute the reference host first. + // + + host_dense2csx(M, + N, + hipsparseGetMatIndexBase(descr), + h_dense_val.data(), + LD, + h_nnzPerRowColumn.data(), + cpu_csx_val.data(), + cpu_csx_row_col_ptr.data(), + cpu_csx_col_row_ind.data()); + + if(DIRA == HIPSPARSE_DIRECTION_ROW) + { + CHECK_HIPSPARSE_ERROR(dense2csx(handle, + M, + N, + descr, + d_dense_val, + LD, + d_nnzPerRowColumn, + d_csx_val, + d_csx_row_col_ptr, + d_csx_col_row_ind)); + } + else + { + CHECK_HIPSPARSE_ERROR(dense2csx(handle, + M, + N, + descr, + d_dense_val, + LD, + d_nnzPerRowColumn, + d_csx_val, + d_csx_col_row_ind, + d_csx_row_col_ptr)); + } + + void* buffer = malloc(std::max(sizeof(T), sizeof(int)) * std::max(DIMDIR + 1, nnz)); + // + // Transfer and check results. + // + CHECK_HIP_ERROR(hipMemcpy(buffer, d_csx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); + unit_check_general(1, nnz, 1, cpu_csx_val.data(), (T*)buffer); + CHECK_HIP_ERROR( + hipMemcpy(buffer, d_csx_col_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); + unit_check_general(1, nnz, 1, cpu_csx_col_row_ind.data(), (int*)buffer); + + CHECK_HIP_ERROR(hipMemcpy( + buffer, d_csx_row_col_ptr, sizeof(int) * (DIMDIR + 1), hipMemcpyDeviceToHost)); + + unit_check_general(1, (DIMDIR + 1), 1, cpu_csx_row_col_ptr.data(), (int*)buffer); + + free(buffer); + buffer = nullptr; + } + + return HIPSPARSE_STATUS_SUCCESS; +} + +#endif // TESTING_DENSE2CSX_HPP diff --git a/clients/include/testing_nnz.hpp b/clients/include/testing_nnz.hpp index a3341c38..4a8a9da5 100644 --- a/clients/include/testing_nnz.hpp +++ b/clients/include/testing_nnz.hpp @@ -1,5 +1,5 @@ /* ************************************************************************ - * Copyright (c) 2018 Advanced Micro Devices, Inc. + * Copyright (c) 2020 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/clients/include/utility.hpp b/clients/include/utility.hpp index dc5130a9..5520b8e2 100644 --- a/clients/include/utility.hpp +++ b/clients/include/utility.hpp @@ -865,14 +865,14 @@ static inline hipDoubleComplex testing_neg(hipDoubleComplex val) } template -hipsparseStatus_t host_nnz(hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const T* A, - int lda, - int* nnzPerRowColumn, - int* nnzTotalDevHostPtr) +void host_nnz(hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const T* A, + int lda, + int* nnzPerRowColumn, + int* nnzTotalDevHostPtr) { int mn = (dirA == HIPSPARSE_DIRECTION_ROW) ? m : n; #ifdef _OPENMP @@ -910,7 +910,118 @@ hipsparseStatus_t host_nnz(hipsparseDirection_t dirA, sum = sum + nnzPerRowColumn[j]; } nnzTotalDevHostPtr[0] = sum; - return HIPSPARSE_STATUS_SUCCESS; +} + +template +void host_dense2csx(int m, + int n, + hipsparseIndexBase_t base, + const T* A, + int ld, + const int* nnz_per_row_columns, + T* csx_val, + int* csx_row_col_ptr, + int* csx_col_row_ind) +{ + static constexpr T s_zero = {}; + int len = (HIPSPARSE_DIRECTION_ROW == DIRA) ? m : n; + *csx_row_col_ptr = base; + for(int i = 0; i < len; ++i) + { + csx_row_col_ptr[i + 1] = nnz_per_row_columns[i] + csx_row_col_ptr[i]; + } + + switch(DIRA) + { + case HIPSPARSE_DIRECTION_COLUMN: + { + for(int j = 0; j < n; ++j) + { + for(int i = 0; i < m; ++i) + { + if(A[j * ld + i] != s_zero) + { + *csx_val++ = A[j * ld + i]; + *csx_col_row_ind++ = i + base; + } + } + } + break; + } + + case HIPSPARSE_DIRECTION_ROW: + { + // + // Does not matter having an orthogonal traversal ... testing only. + // Otherwise, we would use csxRowPtrA to store the shifts. + // and once the job is done a simple memory move would reinitialize the csxRowPtrA to its initial state) + // + for(int i = 0; i < m; ++i) + { + for(int j = 0; j < n; ++j) + { + if(A[j * ld + i] != s_zero) + { + *csx_val++ = A[j * ld + i]; + *csx_col_row_ind++ = j + base; + } + } + } + break; + } + } +} + +template +void host_csx2dense(int m, + int n, + hipsparseIndexBase_t base, + const T* csx_val, + const int* csx_row_col_ptr, + const int* csx_col_row_ind, + T* A, + int ld) +{ + static constexpr T s_zero = {}; + switch(DIRA) + { + case HIPSPARSE_DIRECTION_COLUMN: + { + static constexpr T s_zero = {}; + for(int col = 0; col < n; ++col) + { + for(int row = 0; row < m; ++row) + { + A[row + ld * col] = s_zero; + } + const int bound = csx_row_col_ptr[col + 1] - base; + for(int at = csx_row_col_ptr[col] - base; at < bound; ++at) + { + A[(csx_col_row_ind[at] - base) + ld * col] = csx_val[at]; + } + } + break; + } + + case HIPSPARSE_DIRECTION_ROW: + { + static constexpr T s_zero = {}; + for(int row = 0; row < m; ++row) + { + for(int col = 0; col < n; ++col) + { + A[col * ld + row] = s_zero; + } + + const int bound = csx_row_col_ptr[row + 1] - base; + for(int at = csx_row_col_ptr[row] - base; at < bound; ++at) + { + A[(csx_col_row_ind[at] - base) * ld + row] = csx_val[at]; + } + } + break; + } + } } template @@ -1037,8 +1148,8 @@ inline void host_csr_to_bsr(hipsparseDirection_t direction, std::vector temp(nb, 0); for(int j = start; j < end; j++) { - int blockCol = (csr_col_ind[j] - csr_base) / block_dim; - temp[blockCol] = 1; + int blockCol = (csr_col_ind[j] - csr_base) / block_dim; + temp[blockCol] = 1; } int sum = 0; @@ -1072,8 +1183,8 @@ inline void host_csr_to_bsr(hipsparseDirection_t direction, for(int j = start; j < end; j++) { - int blockCol = (csr_col_ind[j] - csr_base) / block_dim; - temp[blockCol] = 1; + int blockCol = (csr_col_ind[j] - csr_base) / block_dim; + temp[blockCol] = 1; } for(int j = 0; j < nb; j++) @@ -1099,8 +1210,7 @@ inline void host_csr_to_bsr(hipsparseDirection_t direction, int blockCol = (csr_col_ind[j] - csr_base) / block_dim; colIndex = -1; - for(int k = bsr_row_ptr[blockRow] - bsr_base; - k < bsr_row_ptr[blockRow + 1] - bsr_base; + for(int k = bsr_row_ptr[blockRow] - bsr_base; k < bsr_row_ptr[blockRow + 1] - bsr_base; k++) { if(bsr_col_ind[k] - bsr_base == blockCol) @@ -1124,7 +1234,7 @@ inline void host_csr_to_bsr(hipsparseDirection_t direction, } int index = (bsr_row_ptr[blockRow] - bsr_base) * block_dim * block_dim - + colIndex * block_dim * block_dim + blockIndex; + + colIndex * block_dim * block_dim + blockIndex; bsr_val[index] = csr_val[j]; } @@ -1207,9 +1317,8 @@ inline void host_bsr_to_csr(hipsparseDirection_t direction, for(int j = bsr_row_ptr[i] - bsr_base; j < bsr_row_ptr[i + 1] - bsr_base; j++) { - int col = bsr_col_ind[j] - bsr_base; - int offset - = entries_in_row_sum + block_dim * (j - (bsr_row_ptr[i] - bsr_base)); + int col = bsr_col_ind[j] - bsr_base; + int offset = entries_in_row_sum + block_dim * (j - (bsr_row_ptr[i] - bsr_base)); for(int k = 0; k < block_dim; k++) { @@ -2407,10 +2516,10 @@ double get_time_us_sync(hipStream_t stream); class Arguments { public: - int M = 128; - int N = 128; - int K = 128; - int nnz = 32; + int M = 128; + int N = 128; + int K = 128; + int nnz = 32; int block_dim = 1; int lda; diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index 370330dd..436e37eb 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -94,6 +94,10 @@ set(HIPSPARSE_TEST_SOURCES test_csrilu02.cpp test_csric02.cpp test_nnz.cpp + test_csr2dense.cpp + test_csc2dense.cpp + test_dense2csr.cpp + test_dense2csc.cpp test_csr2coo.cpp test_csr2csc.cpp test_csr2bsr.cpp diff --git a/clients/tests/test_bsr2csr.cpp b/clients/tests/test_bsr2csr.cpp index 4d16313d..5857fc74 100644 --- a/clients/tests/test_bsr2csr.cpp +++ b/clients/tests/test_bsr2csr.cpp @@ -29,31 +29,29 @@ #include #include -typedef std::tuple bsr2csr_tuple; -typedef std::tuple bsr2csr_bin_tuple; +typedef std::tuple + bsr2csr_tuple; +typedef std:: + tuple + bsr2csr_bin_tuple; // Random matrices -int bsr2csr_M_range[] = {-1, 0, 872, 13095, 21453}; -int bsr2csr_N_range[] = {-3, 0, 623, 12766, 29285}; +int bsr2csr_M_range[] = {-1, 0, 872, 13095, 21453}; +int bsr2csr_N_range[] = {-3, 0, 623, 12766, 29285}; int bsr2csr_block_dim_range[] = {-1, 0, 1, 2, 4, 7, 16}; -hipsparseIndexBase_t bsr2csr_csr_base_range[] - = {HIPSPARSE_INDEX_BASE_ZERO}; +hipsparseIndexBase_t bsr2csr_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; -hipsparseIndexBase_t bsr2csr_bsr_base_range[] - = {HIPSPARSE_INDEX_BASE_ONE}; +hipsparseIndexBase_t bsr2csr_bsr_base_range[] = {HIPSPARSE_INDEX_BASE_ONE}; -hipsparseDirection_t bsr2csr_dir_range[] - = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; +hipsparseDirection_t bsr2csr_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; // Matrices from files (float and double) int bsr2csr_block_dim_range_bin[] = {5}; -hipsparseIndexBase_t bsr2csr_csr_base_range_bin[] - = {HIPSPARSE_INDEX_BASE_ONE}; +hipsparseIndexBase_t bsr2csr_csr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; -hipsparseIndexBase_t bsr2csr_bsr_base_range_bin[] - = {HIPSPARSE_INDEX_BASE_ONE}; +hipsparseIndexBase_t bsr2csr_bsr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t bsr2csr_dir_range_bin[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; @@ -97,26 +95,26 @@ class parameterized_bsr2csr_bin : public testing::TestWithParam(tup); - arg.N = std::get<1>(tup); + arg.M = std::get<0>(tup); + arg.N = std::get<1>(tup); arg.block_dim = std::get<2>(tup); - arg.idx_base = std::get<3>(tup); + arg.idx_base = std::get<3>(tup); arg.idx_base2 = std::get<4>(tup); - arg.dirA = std::get<5>(tup); - arg.timing = 0; + arg.dirA = std::get<5>(tup); + arg.timing = 0; return arg; } Arguments setup_bsr2csr_arguments(bsr2csr_bin_tuple tup) { Arguments arg; - arg.M = -99; - arg.N = -99; + arg.M = -99; + arg.N = -99; arg.block_dim = std::get<0>(tup); - arg.idx_base = std::get<1>(tup); + arg.idx_base = std::get<1>(tup); arg.idx_base2 = std::get<2>(tup); - arg.dirA = std::get<3>(tup); - arg.timing = 0; + arg.dirA = std::get<3>(tup); + arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<4>(tup); diff --git a/clients/tests/test_csc2dense.cpp b/clients/tests/test_csc2dense.cpp new file mode 100644 index 00000000..2f15911f --- /dev/null +++ b/clients/tests/test_csc2dense.cpp @@ -0,0 +1,100 @@ +/* ************************************************************************ + * Copyright (c) 2020 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ + +#include "testing_csc2dense.hpp" +#include "utility.hpp" + +#include +#include +#include +#include +typedef hipsparseIndexBase_t base; +typedef std::tuple csc2dense_tuple; + +int csc2dense_M_range[] = {-1, 0, 10, 500, 872, 1000}; +int csc2dense_N_range[] = {-3, 0, 33, 242, 623, 1000}; +int csc2dense_LD_range[] = {5, 500, 1000}; +base csc2dense_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; + +class parameterized_csc2dense : public testing::TestWithParam +{ +protected: + parameterized_csc2dense() {} + virtual ~parameterized_csc2dense() {} + virtual void SetUp() {} + virtual void TearDown() {} +}; + +Arguments setup_csc2dense_arguments(csc2dense_tuple tup) +{ + Arguments arg; + arg.M = std::get<0>(tup); + arg.N = std::get<1>(tup); + arg.lda = std::get<2>(tup); + arg.idx_base = std::get<3>(tup); + return arg; +} + +TEST(csc2dense_bad_arg, csc2dense) +{ + testing_csc2dense_bad_arg(); +} + +TEST_P(parameterized_csc2dense, csc2dense_float) +{ + Arguments arg = setup_csc2dense_arguments(GetParam()); + + hipsparseStatus_t status = testing_csc2dense(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_csc2dense, csc2dense_double) +{ + Arguments arg = setup_csc2dense_arguments(GetParam()); + + hipsparseStatus_t status = testing_csc2dense(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_csc2dense, csc2dense_float_complex) +{ + Arguments arg = setup_csc2dense_arguments(GetParam()); + + hipsparseStatus_t status = testing_csc2dense(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_csc2dense, csc2dense_double_complex) +{ + Arguments arg = setup_csc2dense_arguments(GetParam()); + + hipsparseStatus_t status = testing_csc2dense(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +INSTANTIATE_TEST_CASE_P(csc2dense, + parameterized_csc2dense, + testing::Combine(testing::ValuesIn(csc2dense_M_range), + testing::ValuesIn(csc2dense_N_range), + testing::ValuesIn(csc2dense_LD_range), + testing::ValuesIn(csc2dense_idx_base_range))); diff --git a/clients/tests/test_csr2bsr.cpp b/clients/tests/test_csr2bsr.cpp index b75ff111..4347ec46 100644 --- a/clients/tests/test_csr2bsr.cpp +++ b/clients/tests/test_csr2bsr.cpp @@ -29,31 +29,29 @@ #include #include -typedef std::tuple csr2bsr_tuple; -typedef std::tuple csr2bsr_bin_tuple; +typedef std::tuple + csr2bsr_tuple; +typedef std:: + tuple + csr2bsr_bin_tuple; // Random matrices -int csr2bsr_M_range[] = {-1, 0, 872, 13095, 21453}; -int csr2bsr_N_range[] = {-3, 0, 623, 12766, 29285}; +int csr2bsr_M_range[] = {-1, 0, 872, 13095, 21453}; +int csr2bsr_N_range[] = {-3, 0, 623, 12766, 29285}; int csr2bsr_block_dim_range[] = {-1, 0, 1, 2, 4, 7, 16}; -hipsparseIndexBase_t csr2bsr_csr_base_range[] - = {HIPSPARSE_INDEX_BASE_ZERO}; +hipsparseIndexBase_t csr2bsr_csr_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; -hipsparseIndexBase_t csr2bsr_bsr_base_range[] - = {HIPSPARSE_INDEX_BASE_ONE}; +hipsparseIndexBase_t csr2bsr_bsr_base_range[] = {HIPSPARSE_INDEX_BASE_ONE}; -hipsparseDirection_t csr2bsr_dir_range[] - = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; +hipsparseDirection_t csr2bsr_dir_range[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; // Matrices from files (float and double) int csr2bsr_block_dim_range_bin[] = {5}; -hipsparseIndexBase_t csr2bsr_csr_base_range_bin[] - = {HIPSPARSE_INDEX_BASE_ONE}; +hipsparseIndexBase_t csr2bsr_csr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; -hipsparseIndexBase_t csr2bsr_bsr_base_range_bin[] - = {HIPSPARSE_INDEX_BASE_ONE}; +hipsparseIndexBase_t csr2bsr_bsr_base_range_bin[] = {HIPSPARSE_INDEX_BASE_ONE}; hipsparseDirection_t csr2bsr_dir_range_bin[] = {HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN}; @@ -97,26 +95,26 @@ class parameterized_csr2bsr_bin : public testing::TestWithParam(tup); - arg.N = std::get<1>(tup); + arg.M = std::get<0>(tup); + arg.N = std::get<1>(tup); arg.block_dim = std::get<2>(tup); - arg.idx_base = std::get<3>(tup); + arg.idx_base = std::get<3>(tup); arg.idx_base2 = std::get<4>(tup); - arg.dirA = std::get<5>(tup); - arg.timing = 0; + arg.dirA = std::get<5>(tup); + arg.timing = 0; return arg; } Arguments setup_csr2bsr_arguments(csr2bsr_bin_tuple tup) { Arguments arg; - arg.M = -99; - arg.N = -99; + arg.M = -99; + arg.N = -99; arg.block_dim = std::get<0>(tup); - arg.idx_base = std::get<1>(tup); + arg.idx_base = std::get<1>(tup); arg.idx_base2 = std::get<2>(tup); - arg.dirA = std::get<3>(tup); - arg.timing = 0; + arg.dirA = std::get<3>(tup); + arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<4>(tup); diff --git a/clients/tests/test_csr2dense.cpp b/clients/tests/test_csr2dense.cpp new file mode 100644 index 00000000..30d846fd --- /dev/null +++ b/clients/tests/test_csr2dense.cpp @@ -0,0 +1,100 @@ +/* ************************************************************************ + * Copyright (c) 2020 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ + +#include "testing_csr2dense.hpp" +#include "utility.hpp" + +#include +#include +#include +#include +typedef hipsparseIndexBase_t base; +typedef std::tuple csr2dense_tuple; + +int csr2dense_M_range[] = {-1, 0, 10, 500, 872, 1000}; +int csr2dense_N_range[] = {-3, 0, 33, 242, 623, 1000}; +int csr2dense_LD_range[] = {5, 500, 1000}; +base csr2dense_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; + +class parameterized_csr2dense : public testing::TestWithParam +{ +protected: + parameterized_csr2dense() {} + virtual ~parameterized_csr2dense() {} + virtual void SetUp() {} + virtual void TearDown() {} +}; + +Arguments setup_csr2dense_arguments(csr2dense_tuple tup) +{ + Arguments arg; + arg.M = std::get<0>(tup); + arg.N = std::get<1>(tup); + arg.lda = std::get<2>(tup); + arg.idx_base = std::get<3>(tup); + return arg; +} + +TEST(csr2dense_bad_arg, csr2dense) +{ + testing_csr2dense_bad_arg(); +} + +TEST_P(parameterized_csr2dense, csr2dense_float) +{ + Arguments arg = setup_csr2dense_arguments(GetParam()); + + hipsparseStatus_t status = testing_csr2dense(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_csr2dense, csr2dense_double) +{ + Arguments arg = setup_csr2dense_arguments(GetParam()); + + hipsparseStatus_t status = testing_csr2dense(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_csr2dense, csr2dense_float_complex) +{ + Arguments arg = setup_csr2dense_arguments(GetParam()); + + hipsparseStatus_t status = testing_csr2dense(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_csr2dense, csr2dense_double_complex) +{ + Arguments arg = setup_csr2dense_arguments(GetParam()); + + hipsparseStatus_t status = testing_csr2dense(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +INSTANTIATE_TEST_CASE_P(csr2dense, + parameterized_csr2dense, + testing::Combine(testing::ValuesIn(csr2dense_M_range), + testing::ValuesIn(csr2dense_N_range), + testing::ValuesIn(csr2dense_LD_range), + testing::ValuesIn(csr2dense_idx_base_range))); diff --git a/clients/tests/test_dense2csc.cpp b/clients/tests/test_dense2csc.cpp new file mode 100644 index 00000000..090d1290 --- /dev/null +++ b/clients/tests/test_dense2csc.cpp @@ -0,0 +1,99 @@ +/* ************************************************************************ + * Copyright (c) 2020 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ + +#include "testing_dense2csc.hpp" +#include "utility.hpp" + +#include +#include +#include +#include + +typedef hipsparseIndexBase_t base; +typedef std::tuple dense2csc_tuple; +int dense2csc_M_range[] = {-1, 0, 10, 500, 872, 1000}; +int dense2csc_N_range[] = {-3, 0, 33, 242, 623, 1000}; +int dense2csc_LD_range[] = {5, 500, 1000}; +base dense2csc_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; + +class parameterized_dense2csc : public testing::TestWithParam +{ +protected: + parameterized_dense2csc() {} + virtual ~parameterized_dense2csc() {} + virtual void SetUp() {} + virtual void TearDown() {} +}; + +Arguments setup_dense2csc_arguments(dense2csc_tuple tup) +{ + Arguments arg; + arg.M = std::get<0>(tup); + arg.N = std::get<1>(tup); + arg.lda = std::get<2>(tup); + return arg; +} + +TEST(dense2csc_bad_arg, dense2csc) +{ + testing_dense2csc_bad_arg(); +} + +TEST_P(parameterized_dense2csc, dense2csc_float) +{ + Arguments arg = setup_dense2csc_arguments(GetParam()); + + hipsparseStatus_t status = testing_dense2csc(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_dense2csc, dense2csc_double) +{ + Arguments arg = setup_dense2csc_arguments(GetParam()); + + hipsparseStatus_t status = testing_dense2csc(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_dense2csc, dense2csc_float_complex) +{ + Arguments arg = setup_dense2csc_arguments(GetParam()); + + hipsparseStatus_t status = testing_dense2csc(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_dense2csc, dense2csc_double_complex) +{ + Arguments arg = setup_dense2csc_arguments(GetParam()); + + hipsparseStatus_t status = testing_dense2csc(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +INSTANTIATE_TEST_CASE_P(dense2csc, + parameterized_dense2csc, + testing::Combine(testing::ValuesIn(dense2csc_M_range), + testing::ValuesIn(dense2csc_N_range), + testing::ValuesIn(dense2csc_LD_range), + testing::ValuesIn(dense2csc_idx_base_range))); diff --git a/clients/tests/test_dense2csr.cpp b/clients/tests/test_dense2csr.cpp new file mode 100644 index 00000000..8835c596 --- /dev/null +++ b/clients/tests/test_dense2csr.cpp @@ -0,0 +1,100 @@ +/* ************************************************************************ + * Copyright (c) 2018 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * ************************************************************************ */ + +#include "testing_dense2csr.hpp" +#include "utility.hpp" + +#include +#include +#include +#include + +typedef hipsparseIndexBase_t base; +typedef std::tuple dense2csr_tuple; +int dense2csr_M_range[] = {-1, 0, 10, 500, 872, 1000}; +int dense2csr_N_range[] = {-3, 0, 33, 242, 623, 1000}; +int dense2csr_LD_range[] = {5, 500, 1000}; +base dense2csr_idx_base_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; + +class parameterized_dense2csr : public testing::TestWithParam +{ +protected: + parameterized_dense2csr() {} + virtual ~parameterized_dense2csr() {} + virtual void SetUp() {} + virtual void TearDown() {} +}; + +Arguments setup_dense2csr_arguments(dense2csr_tuple tup) +{ + Arguments arg; + arg.M = std::get<0>(tup); + arg.N = std::get<1>(tup); + arg.lda = std::get<2>(tup); + arg.idx_base = std::get<3>(tup); + return arg; +} + +TEST(dense2csr_bad_arg, dense2csr) +{ + testing_dense2csr_bad_arg(); +} + +TEST_P(parameterized_dense2csr, dense2csr_float) +{ + Arguments arg = setup_dense2csr_arguments(GetParam()); + + hipsparseStatus_t status = testing_dense2csr(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_dense2csr, dense2csr_double) +{ + Arguments arg = setup_dense2csr_arguments(GetParam()); + + hipsparseStatus_t status = testing_dense2csr(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_dense2csr, dense2csr_float_complex) +{ + Arguments arg = setup_dense2csr_arguments(GetParam()); + + hipsparseStatus_t status = testing_dense2csr(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +TEST_P(parameterized_dense2csr, dense2csr_double_complex) +{ + Arguments arg = setup_dense2csr_arguments(GetParam()); + + hipsparseStatus_t status = testing_dense2csr(arg); + EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); +} + +INSTANTIATE_TEST_CASE_P(dense2csr, + parameterized_dense2csr, + testing::Combine(testing::ValuesIn(dense2csr_M_range), + testing::ValuesIn(dense2csr_N_range), + testing::ValuesIn(dense2csr_LD_range), + testing::ValuesIn(dense2csr_idx_base_range))); diff --git a/library/include/hipsparse.h b/library/include/hipsparse.h index abe79391..e90c111c 100644 --- a/library/include/hipsparse.h +++ b/library/include/hipsparse.h @@ -1873,20 +1873,208 @@ hipsparseStatus_t hipsparseZnnz(hipsparseHandle_t handle, int* nnzTotalDevHostPtr); /* Description: + This function converts the matrix A in dense format into a sparse matrix in CSR format. */ +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseSdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* A, + int ld, + const int* nnz_per_rows, + float* csr_val, + int* csr_row_ptr, + int* csr_col_ind); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseDdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* A, + int ld, + const int* nnz_per_rows, + double* csr_val, + int* csr_row_ptr, + int* csr_col_ind); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseCdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* A, + int ld, + const int* nnz_per_rows, + hipComplex* csr_val, + int* csr_row_ptr, + int* csr_col_ind); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseZdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* A, + int ld, + const int* nnz_per_rows, + hipDoubleComplex* csr_val, + int* csr_row_ptr, + int* csr_col_ind); +/* Description: + This function converts the matrix A in dense format into a sparse matrix in CSC format */ +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseSdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* A, + int ld, + const int* nnz_per_columns, + float* csc_val, + int* csc_row_ind, + int* csc_col_ptr); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseDdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* A, + int ld, + const int* nnz_per_columns, + double* csc_val, + int* csc_row_ind, + int* csc_col_ptr); +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseCdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* A, + int ld, + const int* nnz_per_columns, + hipComplex* csc_val, + int* csc_row_ind, + int* csc_col_ptr); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseZdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* A, + int ld, + const int* nnz_per_columns, + hipDoubleComplex* csc_val, + int* csc_row_ind, + int* csc_col_ptr); +/* Description: + This function converts the sparse matrix in CSR format into a dense matrix */ +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseScsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* csr_val, + const int* csr_row_ptr, + const int* csr_col_ind, + float* A, + int ld); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseDcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* csr_val, + const int* csr_row_ptr, + const int* csr_col_ind, + double* A, + int ld); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseCcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* csr_val, + const int* csr_row_ptr, + const int* csr_col_ind, + hipComplex* A, + int ld); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseZcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* csr_val, + const int* csr_row_ptr, + const int* csr_col_ind, + hipDoubleComplex* A, + int ld); + +/* Description: + This function converts the sparse matrix in CSC format into a dense matrix. */ +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseScsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* csc_val, + const int* csc_row_ind, + const int* csc_col_ptr, + float* A, + int ld); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseDcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* csc_val, + const int* csc_row_ind, + const int* csc_col_ptr, + double* A, + int ld); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseCcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* csc_val, + const int* csc_row_ind, + const int* csc_col_ptr, + hipComplex* A, + int ld); + +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseZcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* csc_val, + const int* csc_row_ind, + const int* csc_col_ptr, + hipDoubleComplex* A, + int ld); +/* Description: This function computes the number of nonzero block columns per block row and the total number of blocks in the BSR matrix where the BSR matrix is formed by converting the input CSR matrix. */ HIPSPARSE_EXPORT -hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - int* bsrRowPtrC, - int* bsrNnzb); +hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + int* bsrRowPtrC, + int* bsrNnzb); /* Description: This routine converts a sparse matrix in CSR storage format to a sparse matrix in COO storage format. */ @@ -2003,120 +2191,120 @@ hipsparseStatus_t hipsparseZcsr2hyb(hipsparseHandle_t handle, /* Description: This routine converts a sparse matrix in CSR storage format to a sparse matrix in BSR storage format. */ HIPSPARSE_EXPORT -hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const float* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - float* bsrValC, - int* bsrRowPtrC, - int * bsrColIndC); -HIPSPARSE_EXPORT -hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const double* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - double* bsrValC, - int* bsrRowPtrC, - int * bsrColIndC); -HIPSPARSE_EXPORT -hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const hipComplex* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipComplex* bsrValC, - int* bsrRowPtrC, - int * bsrColIndC); -HIPSPARSE_EXPORT -hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const hipDoubleComplex* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipDoubleComplex* bsrValC, - int* bsrRowPtrC, - int * bsrColIndC); +hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const float* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + float* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC); +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const double* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + double* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC); +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const hipComplex* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipComplex* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC); +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const hipDoubleComplex* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipDoubleComplex* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC); /* Description: This routine converts a sparse matrix in BSR storage format to a sparse matrix in CSR storage format. */ HIPSPARSE_EXPORT -hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const float* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - float* csrValC, - int* csrRowPtrC, - int * csrColIndC); -HIPSPARSE_EXPORT -hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const double* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - double* csrValC, - int* csrRowPtrC, - int * csrColIndC); -HIPSPARSE_EXPORT -hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const hipComplex* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipComplex* csrValC, - int* csrRowPtrC, - int * csrColIndC); -HIPSPARSE_EXPORT -hipsparseStatus_t hipsparseZbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const hipDoubleComplex* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipDoubleComplex* csrValC, - int* csrRowPtrC, - int * csrColIndC); +hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const float* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + float* csrValC, + int* csrRowPtrC, + int* csrColIndC); +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const double* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + double* csrValC, + int* csrRowPtrC, + int* csrColIndC); +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const hipComplex* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipComplex* csrValC, + int* csrRowPtrC, + int* csrColIndC); +HIPSPARSE_EXPORT +hipsparseStatus_t hipsparseZbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const hipDoubleComplex* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipDoubleComplex* csrValC, + int* csrRowPtrC, + int* csrColIndC); /* Description: This routine converts a sparse matrix in HYB storage format to a sparse matrix in CSR storage format. */ diff --git a/library/src/hcc_detail/hipsparse.cpp b/library/src/hcc_detail/hipsparse.cpp index c6ecca46..afc40e9c 100644 --- a/library/src/hcc_detail/hipsparse.cpp +++ b/library/src/hcc_detail/hipsparse.cpp @@ -4788,19 +4788,19 @@ hipsparseStatus_t hipsparseZcsr2hyb(hipsparseHandle_t handle, hipHybPartToHCCHybPart(partitionType))); } -hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const float* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - float* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) +hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const float* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + float* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_scsr2bsr((rocsparse_handle)handle, hipDirectionToHCCDirection(dirA), @@ -4818,19 +4818,19 @@ hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, return HIPSPARSE_STATUS_SUCCESS; } -hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const double* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - double* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) +hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const double* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + double* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dcsr2bsr((rocsparse_handle)handle, hipDirectionToHCCDirection(dirA), @@ -4848,19 +4848,19 @@ hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, return HIPSPARSE_STATUS_SUCCESS; } -hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const hipComplex* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipComplex* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) +hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const hipComplex* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipComplex* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_ccsr2bsr((rocsparse_handle)handle, hipDirectionToHCCDirection(dirA), @@ -4878,19 +4878,19 @@ hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, return HIPSPARSE_STATUS_SUCCESS; } -hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const hipDoubleComplex* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipDoubleComplex* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) +hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const hipDoubleComplex* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipDoubleComplex* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zcsr2bsr((rocsparse_handle)handle, hipDirectionToHCCDirection(dirA), @@ -4908,19 +4908,19 @@ hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, return HIPSPARSE_STATUS_SUCCESS; } -hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const float* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - float* csrValC, - int* csrRowPtrC, - int* csrColIndC) +hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const float* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + float* csrValC, + int* csrRowPtrC, + int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sbsr2csr((rocsparse_handle)handle, hipDirectionToHCCDirection(dirA), @@ -4938,19 +4938,19 @@ hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, return HIPSPARSE_STATUS_SUCCESS; } -hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const double* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - double* csrValC, - int* csrRowPtrC, - int* csrColIndC) +hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const double* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + double* csrValC, + int* csrRowPtrC, + int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dbsr2csr((rocsparse_handle)handle, hipDirectionToHCCDirection(dirA), @@ -4968,19 +4968,19 @@ hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, return HIPSPARSE_STATUS_SUCCESS; } -hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const hipComplex* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipComplex* csrValC, - int* csrRowPtrC, - int* csrColIndC) +hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const hipComplex* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipComplex* csrValC, + int* csrRowPtrC, + int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_cbsr2csr((rocsparse_handle)handle, hipDirectionToHCCDirection(dirA), @@ -4998,19 +4998,19 @@ hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, return HIPSPARSE_STATUS_SUCCESS; } -hipsparseStatus_t hipsparseZbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const hipDoubleComplex* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipDoubleComplex* csrValC, - int* csrRowPtrC, - int* csrColIndC) +hipsparseStatus_t hipsparseZbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const hipDoubleComplex* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipDoubleComplex* csrValC, + int* csrRowPtrC, + int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zbsr2csr((rocsparse_handle)handle, hipDirectionToHCCDirection(dirA), @@ -5252,17 +5252,384 @@ hipsparseStatus_t hipsparseZnnz(hipsparseHandle_t handle, return HIPSPARSE_STATUS_SUCCESS; } -hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - int* bsrRowPtrC, - int* bsrNnzb) +hipsparseStatus_t hipsparseSdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* A, + int ld, + const int* nnzPerRow, + float* csrVal, + int* csrRowPtr, + int* csrColInd) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_sdense2csr((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + A, + ld, + nnzPerRow, + csrVal, + csrRowPtr, + csrColInd)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseDdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* A, + int ld, + const int* nnzPerRow, + double* csrVal, + int* csrRowPtr, + int* csrColInd) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_ddense2csr((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + A, + ld, + nnzPerRow, + csrVal, + csrRowPtr, + csrColInd)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseCdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* A, + int ld, + const int* nnzPerRow, + hipComplex* csrVal, + int* csrRowPtr, + int* csrColInd) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_cdense2csr((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + (const rocsparse_float_complex*)A, + ld, + nnzPerRow, + (rocsparse_float_complex*)csrVal, + csrRowPtr, + csrColInd)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseZdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* A, + int ld, + const int* nnzPerRow, + hipDoubleComplex* csrVal, + int* csrRowPtr, + int* csrColInd) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_zdense2csr((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + (const rocsparse_double_complex*)A, + ld, + nnzPerRow, + (rocsparse_double_complex*)csrVal, + csrRowPtr, + csrColInd)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseSdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* A, + int ld, + const int* nnz_per_columns, + float* cscVal, + int* cscRowInd, + int* cscColPtr) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_sdense2csc((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + A, + ld, + nnz_per_columns, + cscVal, + cscColPtr, + cscRowInd)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseDdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* A, + int ld, + const int* nnz_per_columns, + double* cscVal, + int* cscRowInd, + int* cscColPtr) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_ddense2csc((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + A, + ld, + nnz_per_columns, + cscVal, + cscColPtr, + cscRowInd)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseCdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* A, + int ld, + const int* nnz_per_columns, + hipComplex* cscVal, + int* cscRowInd, + int* cscColPtr) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_cdense2csc((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + (const rocsparse_float_complex*)A, + ld, + nnz_per_columns, + (rocsparse_float_complex*)cscVal, + cscColPtr, + cscRowInd)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseZdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* A, + int ld, + const int* nnz_per_columns, + hipDoubleComplex* cscVal, + int* cscRowInd, + int* cscColPtr) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_zdense2csc((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + (const rocsparse_double_complex*)A, + ld, + nnz_per_columns, + (rocsparse_double_complex*)cscVal, + cscColPtr, + cscRowInd)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseScsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* csrVal, + const int* csrRowPtr, + const int* csrColInd, + float* A, + int ld) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_scsr2dense((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + csrVal, + csrRowPtr, + csrColInd, + A, + ld)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseDcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* csrVal, + const int* csrRowPtr, + const int* csrColInd, + double* A, + int ld) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_dcsr2dense((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + csrVal, + csrRowPtr, + csrColInd, + A, + ld)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseCcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* csrVal, + const int* csrRowPtr, + const int* csrColInd, + hipComplex* A, + int ld) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_ccsr2dense((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + (const rocsparse_float_complex*)csrVal, + csrRowPtr, + csrColInd, + (rocsparse_float_complex*)A, + ld)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseZcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* csrVal, + const int* csrRowPtr, + const int* csrColInd, + hipDoubleComplex* A, + int ld) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_zcsr2dense((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + (const rocsparse_double_complex*)csrVal, + csrRowPtr, + csrColInd, + (rocsparse_double_complex*)A, + ld)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseScsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* cscVal, + const int* cscRowInd, + const int* cscColPtr, + float* A, + int ld) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_scsc2dense((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + cscVal, + cscColPtr, + cscRowInd, + A, + ld)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseDcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* cscVal, + const int* cscRowInd, + const int* cscColPtr, + double* A, + int ld) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_dcsc2dense((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + cscVal, + cscColPtr, + cscRowInd, + A, + ld)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseCcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* cscVal, + const int* cscRowInd, + const int* cscColPtr, + hipComplex* A, + int ld) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_ccsc2dense((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + (const rocsparse_float_complex*)cscVal, + cscColPtr, + cscRowInd, + (rocsparse_float_complex*)A, + ld)); + return HIPSPARSE_STATUS_SUCCESS; +} + +hipsparseStatus_t hipsparseZcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* cscVal, + const int* cscRowInd, + const int* cscColPtr, + hipDoubleComplex* A, + int ld) +{ + RETURN_IF_ROCSPARSE_ERROR(rocsparse_zcsc2dense((rocsparse_handle)handle, + m, + n, + (const rocsparse_mat_descr)descr, + (const rocsparse_double_complex*)cscVal, + cscColPtr, + cscRowInd, + (rocsparse_double_complex*)A, + ld)); +} + +hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + int* bsrRowPtrC, + int* bsrNnzb) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_csr2bsr_nnz((rocsparse_handle)handle, hipDirectionToHCCDirection(dirA), @@ -5275,6 +5642,7 @@ hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, (const rocsparse_mat_descr)descrC, bsrRowPtrC, bsrNnzb)); + return HIPSPARSE_STATUS_SUCCESS; } diff --git a/library/src/nvcc_detail/hipsparse.cpp b/library/src/nvcc_detail/hipsparse.cpp index af067193..5a8bac06 100644 --- a/library/src/nvcc_detail/hipsparse.cpp +++ b/library/src/nvcc_detail/hipsparse.cpp @@ -3628,17 +3628,369 @@ hipsparseStatus_t hipsparseZnnz(hipsparseHandle_t handle, nnzTotalDevHostPtr)); } -hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - int* bsrRowPtrC, - int* bsrNnzb) +hipsparseStatus_t hipsparseSdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* A, + int ld, + const int* nnzPerRow, + float* csrVal, + int* csrRowPtr, + int* csrColInd) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseSdense2csr((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + A, + ld, + nnzPerRow, + csrVal, + csrRowPtr, + csrColInd)); +} + +hipsparseStatus_t hipsparseDdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* A, + int ld, + const int* nnzPerRow, + double* csrVal, + int* csrRowPtr, + int* csrColInd) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseDdense2csr((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + A, + ld, + nnzPerRow, + csrVal, + csrRowPtr, + csrColInd)); +} + +hipsparseStatus_t hipsparseCdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* A, + int ld, + const int* nnzPerRow, + hipComplex* csrVal, + int* csrRowPtr, + int* csrColInd) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseCdense2csr((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + (const cuComplex*)A, + ld, + nnzPerRow, + (cuComplex*)csrVal, + csrRowPtr, + csrColInd)); +} + +hipsparseStatus_t hipsparseZdense2csr(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* A, + int ld, + const int* nnzPerRow, + hipDoubleComplex* csrVal, + int* csrRowPtr, + int* csrColInd) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseZdense2csr((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + (const cuDoubleComplex*)A, + ld, + nnzPerRow, + (const cuDoubleComplex*)csrVal, + csrRowPtr, + csrColInd)); +} + +hipsparseStatus_t hipsparseSdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* A, + int ld, + const int* nnzPerColumn, + float* cscVal, + int* cscRowInd, + int* cscColPtr) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseSdense2csc((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + A, + ld, + nnzPerColumn, + cscVal, + cscRowInd, + cscColPtr)); +} + +hipsparseStatus_t hipsparseDdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* A, + int ld, + const int* nnzPerColumn, + double* cscVal, + int* cscRowInd, + int* cscColPtr) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseDdense2csc((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + A, + ld, + nnzPerColumn, + cscVal, + cscRowInd, + cscColPtr)); +} + +hipsparseStatus_t hipsparseCdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* A, + int ld, + const int* nnzPerColumn, + hipComplex* cscVal, + int* cscRowInd, + int* cscColPtr) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseCdense2csc((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + (const cuComplex*)A, + ld, + nnzPerColumn, + (cuComplex*)cscVal, + cscRowInd, + cscColPtr)); +} + +hipsparseStatus_t hipsparseZdense2csc(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* A, + int ld, + const int* nnzPerColumn, + hipDoubleComplex* cscVal, + int* cscRowInd, + int* cscColPtr) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseZdense2csc((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + (const cuDoubleComplex*)A, + ld, + nnzPerColumn, + (cuDoubleComplex*)cscVal, + cscRowInd, + cscColPtr)); +} + +hipsparseStatus_t hipsparseScsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* csrVal, + const int* csrRowPtr, + const int* csrColInd, + float* A, + int ld) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseScsr2dense((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + csrVal, + csrRowPtr, + csrColInd, + A, + ld)); +} + +hipsparseStatus_t hipsparseDcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* csrVal, + const int* csrRowPtr, + const int* csrColInd, + double* A, + int ld) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseDcsr2dense((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + csrVal, + csrRowPtr, + csrColInd, + A, + ld)); +} + +hipsparseStatus_t hipsparseCcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* csrVal, + const int* csrRowPtr, + const int* csrColInd, + hipComplex* A, + int ld) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseCcsr2dense((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + (const hipComplex*)csrVal, + csrRowPtr, + csrColInd, + (hipComplex*)A, + ld)); +} + +hipsparseStatus_t hipsparseZcsr2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* csrVal, + const int* csrRowPtr, + const int* csrColInd, + hipDoubleComplex* A, + int ld) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseZcsr2dense((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + (const cuDoubleComplex*)csrVal, + csrRowPtr, + csrColInd, + (cuDoubleComplex*)A, + ld)); +} + +hipsparseStatus_t hipsparseScsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const float* cscVal, + const int* cscRowInd, + const int* cscColPtr, + float* A, + int ld) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseScsc2dense((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + cscVal, + cscRowInd, + cscColPtr, + A, + ld)); +} + +hipsparseStatus_t hipsparseDcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const double* cscVal, + const int* cscRowInd, + const int* cscColPtr, + double* A, + int ld) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseDcsc2dense((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + cscVal, + cscRowInd, + cscColPtr, + A, + ld)); +} + +hipsparseStatus_t hipsparseCcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipComplex* cscVal, + const int* cscRowInd, + const int* cscColPtr, + hipComplex* A, + int ld) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseCcsc2dense((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + (const cuComplex*)cscVal, + cscRowInd, + cscColPtr, + (const cuComplex*)A, + ld)); +} + +hipsparseStatus_t hipsparseZcsc2dense(hipsparseHandle_t handle, + int m, + int n, + const hipsparseMatDescr_t descr, + const hipDoubleComplex* cscVal, + const int* cscRowInd, + const int* cscColPtr, + hipDoubleComplex* A, + int ld) +{ + return hipCUSPARSEStatusToHIPStatus(cusparseZcsc2dense((cusparseHandle_t)handle, + m, + n, + (const cusparseMatDescr_t)descr, + (const cuDoubleComplex*)cscVal, + cscRowInd, + cscColPtr, + (cuDoubleComplex*)A, + ld)); +} + +hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + int* bsrRowPtrC, + int* bsrNnzb) { return hipCUSPARSEStatusToHIPStatus(cusparseXcsr2bsrNnz((cusparseHandle_t)handle, hipDirectionToCudaDirection(dirA), @@ -3872,19 +4224,19 @@ hipsparseStatus_t hipsparseZcsr2hyb(hipsparseHandle_t handle, hipHybPartitionToCudaHybPartition(partitionType))); } -hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const float* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - float* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) +hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const float* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + float* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { return hipCUSPARSEStatusToHIPStatus(cusparseScsr2bsr((cusparseHandle_t)handle, hipDirectionToCudaDirection(dirA), @@ -3901,19 +4253,19 @@ hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, bsrColIndC)); } -hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const double* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - double* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) +hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const double* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + double* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { return hipCUSPARSEStatusToHIPStatus(cusparseDcsr2bsr((cusparseHandle_t)handle, hipDirectionToCudaDirection(dirA), @@ -3930,19 +4282,19 @@ hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, bsrColIndC)); } -hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const hipComplex* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipComplex* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) +hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const hipComplex* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipComplex* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { return hipCUSPARSEStatusToHIPStatus(cusparseCcsr2bsr((cusparseHandle_t)handle, hipDirectionToCudaDirection(dirA), @@ -3959,19 +4311,19 @@ hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, bsrColIndC)); } -hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int m, - int n, - const hipsparseMatDescr_t descrA, - const hipDoubleComplex* csrValA, - const int* csrRowPtrA, - const int* csrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipDoubleComplex* bsrValC, - int* bsrRowPtrC, - int* bsrColIndC) +hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int m, + int n, + const hipsparseMatDescr_t descrA, + const hipDoubleComplex* csrValA, + const int* csrRowPtrA, + const int* csrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipDoubleComplex* bsrValC, + int* bsrRowPtrC, + int* bsrColIndC) { return hipCUSPARSEStatusToHIPStatus(cusparseZcsr2bsr((cusparseHandle_t)handle, hipDirectionToCudaDirection(dirA), @@ -3988,19 +4340,19 @@ hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, bsrColIndC)); } -hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const float* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - float* csrValC, - int* csrRowPtrC, - int* csrColIndC) +hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const float* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + float* csrValC, + int* csrRowPtrC, + int* csrColIndC) { return hipCUSPARSEStatusToHIPStatus(cusparseSbsr2csr((cusparseHandle_t)handle, hipDirectionToCudaDirection(dirA), @@ -4017,19 +4369,19 @@ hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, csrColIndC)); } -hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const double* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - double* csrValC, - int* csrRowPtrC, - int* csrColIndC) +hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const double* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + double* csrValC, + int* csrRowPtrC, + int* csrColIndC) { return hipCUSPARSEStatusToHIPStatus(cusparseDbsr2csr((cusparseHandle_t)handle, hipDirectionToCudaDirection(dirA), @@ -4046,19 +4398,19 @@ hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, csrColIndC)); } -hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const hipComplex* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipComplex* csrValC, - int* csrRowPtrC, - int* csrColIndC) +hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const hipComplex* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipComplex* csrValC, + int* csrRowPtrC, + int* csrColIndC) { return hipCUSPARSEStatusToHIPStatus(cusparseCbsr2csr((cusparseHandle_t)handle, hipDirectionToCudaDirection(dirA), @@ -4075,19 +4427,19 @@ hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, csrColIndC)); } -hipsparseStatus_t hipsparseZbsr2csr(hipsparseHandle_t handle, - hipsparseDirection_t dirA, - int mb, - int nb, - const hipsparseMatDescr_t descrA, - const hipDoubleComplex* bsrValA, - const int* bsrRowPtrA, - const int* bsrColIndA, - int blockDim, - const hipsparseMatDescr_t descrC, - hipDoubleComplex* csrValC, - int* csrRowPtrC, - int* csrColIndC) +hipsparseStatus_t hipsparseZbsr2csr(hipsparseHandle_t handle, + hipsparseDirection_t dirA, + int mb, + int nb, + const hipsparseMatDescr_t descrA, + const hipDoubleComplex* bsrValA, + const int* bsrRowPtrA, + const int* bsrColIndA, + int blockDim, + const hipsparseMatDescr_t descrC, + hipDoubleComplex* csrValC, + int* csrRowPtrC, + int* csrColIndC) { return hipCUSPARSEStatusToHIPStatus(cusparseZbsr2csr((cusparseHandle_t)handle, hipDirectionToCudaDirection(dirA),