From fde9c7ddf7623bc7f15af2e880bd211056eecb1e Mon Sep 17 00:00:00 2001 From: Nico <31079890+ntrost57@users.noreply.github.com> Date: Mon, 27 Feb 2023 18:48:27 +0100 Subject: [PATCH] safe size of csrmv, csr2bsr, bsr2csr, gebsr2csr and csr2gebsr test must be at least max(100, max(nrow, ncol)) (#312) --- CMakeLists.txt | 2 +- clients/include/testing_bsr2csr.hpp | 9 ++++++--- clients/include/testing_csr2bsr.hpp | 9 ++++++--- clients/include/testing_csr2gebsr.hpp | 9 ++++++--- clients/include/testing_csrmv.hpp | 7 +++++-- clients/include/testing_gebsr2csr.hpp | 9 ++++++--- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 521eddaf..97a256d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,7 +113,7 @@ endif() # Setup version -rocm_setup_version(VERSION 2.3.5) +rocm_setup_version(VERSION 2.3.6) set(hipsparse_SOVERSION 0.1) # hipSPARSE library diff --git a/clients/include/testing_bsr2csr.hpp b/clients/include/testing_bsr2csr.hpp index c6e81e11..88e514d1 100644 --- a/clients/include/testing_bsr2csr.hpp +++ b/clients/include/testing_bsr2csr.hpp @@ -288,7 +288,7 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu - int safe_size = 100; + int safe_size = std::max(100, std::max(m, n)); if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; @@ -330,13 +330,13 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) if(mb <= 0 || nb <= 0 || block_dim <= 0) { auto dbsr_row_ptr_managed - = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dcsr_row_ptr_managed - = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_managed @@ -349,6 +349,9 @@ hipsparseStatus_t testing_bsr2csr(Arguments argus) int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); + // row pointer array must be valid + CHECK_HIP_ERROR(hipMemset(dbsr_row_ptr, 0, sizeof(int) * (safe_size + 1))); + if(!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) { diff --git a/clients/include/testing_csr2bsr.hpp b/clients/include/testing_csr2bsr.hpp index cdb6f0b7..c121945a 100644 --- a/clients/include/testing_csr2bsr.hpp +++ b/clients/include/testing_csr2bsr.hpp @@ -412,7 +412,7 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu - int safe_size = 100; + int safe_size = std::max(100, std::max(m, n)); if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; @@ -450,13 +450,13 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) return HIPSPARSE_STATUS_SUCCESS; #endif auto dcsr_row_ptr_managed - = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbsr_row_ptr_managed - = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_val_managed @@ -469,6 +469,9 @@ hipsparseStatus_t testing_csr2bsr(Arguments argus) int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); + // row pointer need to be valid + CHECK_HIP_ERROR(hipMemset(dcsr_row_ptr, 0, sizeof(int) * (safe_size + 1))); + if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbsr_row_ptr || !dbsr_col_ind || !dbsr_val) { diff --git a/clients/include/testing_csr2gebsr.hpp b/clients/include/testing_csr2gebsr.hpp index 6b626b49..91050880 100644 --- a/clients/include/testing_csr2gebsr.hpp +++ b/clients/include/testing_csr2gebsr.hpp @@ -450,7 +450,7 @@ hipsparseStatus_t testing_csr2gebsr(Arguments argus) // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu - int safe_size = 100; + int safe_size = std::max(100, std::max(m, n)); if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; @@ -488,13 +488,13 @@ hipsparseStatus_t testing_csr2gebsr(Arguments argus) return HIPSPARSE_STATUS_SUCCESS; #endif auto dcsr_row_ptr_managed - = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbsr_row_ptr_managed - = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_val_managed @@ -510,6 +510,9 @@ hipsparseStatus_t testing_csr2gebsr(Arguments argus) T* dbsr_val = (T*)dbsr_val_managed.get(); void* dbuffer = dbuffer_managed.get(); + // row pointer must be valid + CHECK_HIP_ERROR(hipMemset(dcsr_row_ptr, 0, sizeof(int) * (safe_size + 1))); + if(!dcsr_row_ptr || !dcsr_col_ind || !dcsr_val || !dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dbuffer) { diff --git a/clients/include/testing_csrmv.hpp b/clients/include/testing_csrmv.hpp index 231481ee..7c10114b 100644 --- a/clients/include/testing_csrmv.hpp +++ b/clients/include/testing_csrmv.hpp @@ -154,9 +154,9 @@ void testing_csrmv_bad_arg(void) template hipsparseStatus_t testing_csrmv(Arguments argus) { - int safe_size = 100; int nrow = argus.M; int ncol = argus.N; + int safe_size = std::max(100, std::max(nrow, ncol)); T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; @@ -203,7 +203,7 @@ hipsparseStatus_t testing_csrmv(Arguments argus) return HIPSPARSE_STATUS_SUCCESS; #endif auto dptr_managed - = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; @@ -216,6 +216,9 @@ hipsparseStatus_t testing_csrmv(Arguments argus) T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); + // row pointer should be valid + CHECK_HIP_ERROR(hipMemset(dptr, 0, sizeof(int) * (safe_size + 1))); + if(!dval || !dptr || !dcol || !dx || !dy) { verify_hipsparse_status_success(HIPSPARSE_STATUS_ALLOC_FAILED, diff --git a/clients/include/testing_gebsr2csr.hpp b/clients/include/testing_gebsr2csr.hpp index 4f93598a..f0d38204 100644 --- a/clients/include/testing_gebsr2csr.hpp +++ b/clients/include/testing_gebsr2csr.hpp @@ -321,7 +321,7 @@ hipsparseStatus_t testing_gebsr2csr(Arguments argus) // When in testing mode, M == N == -99 indicates that we are testing with a real // matrix from cise.ufl.edu - int safe_size = 100; + int safe_size = std::max(100, std::max(m, n)); if(m == -99 && n == -99 && argus.timing == 0) { binfile = argus.filename; @@ -355,13 +355,13 @@ hipsparseStatus_t testing_gebsr2csr(Arguments argus) if(mb <= 0 || nb <= 0 || row_block_dim <= 0 || col_block_dim <= 0) { auto dbsr_row_ptr_managed - = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dcsr_row_ptr_managed - = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; + = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_managed @@ -374,6 +374,9 @@ hipsparseStatus_t testing_gebsr2csr(Arguments argus) int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); + // row pointer must be valid + CHECK_HIP_ERROR(hipMemset(dbsr_row_ptr, 0, sizeof(int) * (safe_size + 1))); + if(!dbsr_row_ptr || !dbsr_col_ind || !dbsr_val || !dcsr_row_ptr || !dcsr_col_ind || !dcsr_val) {