Sparse Conversion Functions#
This module holds all sparse conversion routines.
The sparse conversion routines describe operations on a matrix in sparse format to obtain a matrix in a different sparse format.
rocsparse_csr2coo()#
-
rocsparse_status rocsparse_csr2coo(rocsparse_handle handle, const rocsparse_int *csr_row_ptr, rocsparse_int nnz, rocsparse_int m, rocsparse_int *coo_row_ind, rocsparse_index_base idx_base)#
Convert a sparse CSR matrix into a sparse COO matrix.
rocsparse_csr2coo
converts the CSR array containing the row offsets, that point to the start of every row, into a COO array of row indices.- Example
This example converts a CSR matrix into a COO matrix.
// 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 rocsparse_int m = 3; rocsparse_int n = 5; rocsparse_int nnz = 8; csr_row_ptr[m+1] = {0, 3, 5, 8}; // device memory csr_col_ind[nnz] = {0, 1, 3, 1, 2, 0, 3, 4}; // device memory csr_val[nnz] = {1, 2, 3, 4, 5, 6, 7, 8}; // device memory // Allocate COO matrix arrays rocsparse_int* coo_row_ind; rocsparse_int* coo_col_ind; float* coo_val; hipMalloc((void**)&coo_row_ind, sizeof(rocsparse_int) * nnz); hipMalloc((void**)&coo_col_ind, sizeof(rocsparse_int) * nnz); hipMalloc((void**)&coo_val, sizeof(float) * nnz); // Convert the csr row offsets into coo row indices rocsparse_csr2coo(handle, csr_row_ptr, nnz, m, coo_row_ind, rocsparse_index_base_zero); // Copy the column and value arrays hipMemcpy(coo_col_ind, csr_col_ind, sizeof(rocsparse_int) * nnz, hipMemcpyDeviceToDevice); hipMemcpy(coo_val, csr_val, sizeof(float) * nnz, hipMemcpyDeviceToDevice);
Note
It can also be used to convert a CSC array containing the column offsets into a COO array of column indices.
Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.nnz – [in] number of non-zero entries of the sparse CSR matrix.
m – [in] number of rows of the sparse CSR matrix.
coo_row_ind – [out] array of
nnz
elements containing the row indices of the sparse COO matrix.idx_base – [in] rocsparse_index_base_zero or rocsparse_index_base_one.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
ornnz
is invalid.rocsparse_status_invalid_pointer –
csr_row_ptr
orcoo_row_ind
pointer is invalid.rocsparse_status_arch_mismatch – the device is not supported.
rocsparse_coo2csr()#
-
rocsparse_status rocsparse_coo2csr(rocsparse_handle handle, const rocsparse_int *coo_row_ind, rocsparse_int nnz, rocsparse_int m, rocsparse_int *csr_row_ptr, rocsparse_index_base idx_base)#
Convert a sparse COO matrix into a sparse CSR matrix.
rocsparse_coo2csr
converts the COO array containing the row indices into a CSR array of row offsets, that point to the start of every row. It is assumed that the COO row index array is sorted.- Example
This example converts a COO matrix into a CSR matrix.
// 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 rocsparse_int m = 3; rocsparse_int n = 5; rocsparse_int nnz = 8; coo_row_ind[nnz] = {0, 0, 0, 1, 1, 2, 2, 2}; // device memory coo_col_ind[nnz] = {0, 1, 3, 1, 2, 0, 3, 4}; // device memory coo_val[nnz] = {1, 2, 3, 4, 5, 6, 7, 8}; // device memory // Allocate CSR matrix arrays rocsparse_int* csr_row_ptr; rocsparse_int* csr_col_ind; float* csr_val; hipMalloc((void**)&csr_row_ptr, sizeof(rocsparse_int) * (m + 1)); hipMalloc((void**)&csr_col_ind, sizeof(rocsparse_int) * nnz); hipMalloc((void**)&csr_val, sizeof(float) * nnz); // Convert the coo row indices into csr row offsets rocsparse_coo2csr(handle, coo_row_ind, nnz, m, csr_row_ptr, rocsparse_index_base_zero); // Copy the column and value arrays hipMemcpy(csr_col_ind, coo_col_ind, sizeof(rocsparse_int) * nnz, hipMemcpyDeviceToDevice); hipMemcpy(csr_val, coo_val, sizeof(float) * nnz, hipMemcpyDeviceToDevice);
Note
It can also be used, to convert a COO array containing the column indices into a CSC array of column offsets, that point to the start of every column. Then, it is assumed that the COO column index array is sorted, instead.
Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
coo_row_ind – [in] array of
nnz
elements containing the row indices of the sparse COO matrix.nnz – [in] number of non-zero entries of the sparse CSR matrix.
m – [in] number of rows of the sparse CSR matrix.
csr_row_ptr – [out] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.idx_base – [in] rocsparse_index_base_zero or rocsparse_index_base_one.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
ornnz
is invalid.rocsparse_status_invalid_pointer –
coo_row_ind
orcsr_row_ptr
pointer is invalid.
rocsparse_csr2csc_buffer_size()#
-
rocsparse_status rocsparse_csr2csc_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_action copy_values, size_t *buffer_size)#
Convert a sparse CSR matrix into a sparse CSC matrix.
rocsparse_csr2csc_buffer_size
returns the size of the temporary storage buffer required by rocsparse_scsr2csc(), rocsparse_dcsr2csc(), rocsparse_ccsr2csc() and rocsparse_zcsr2csc(). The temporary storage buffer must be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
nnz – [in] number of non-zero entries of the sparse CSR matrix.
csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array of
nnz
elements containing the column indices of the sparse CSR matrix.copy_values – [in] rocsparse_action_symbolic or rocsparse_action_numeric.
buffer_size – [out] number of bytes of the temporary storage buffer required by rocsparse_scsr2csc(), rocsparse_dcsr2csc(), rocsparse_ccsr2csc() and rocsparse_zcsr2csc().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz
is invalid.rocsparse_status_invalid_pointer –
csr_row_ptr
,csr_col_ind
orbuffer_size
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_csr2csc()#
-
rocsparse_status rocsparse_scsr2csc(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const float *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, float *csc_val, rocsparse_int *csc_row_ind, rocsparse_int *csc_col_ptr, rocsparse_action copy_values, rocsparse_index_base idx_base, void *temp_buffer)#
-
rocsparse_status rocsparse_dcsr2csc(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const double *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, double *csc_val, rocsparse_int *csc_row_ind, rocsparse_int *csc_col_ptr, rocsparse_action copy_values, rocsparse_index_base idx_base, void *temp_buffer)#
-
rocsparse_status rocsparse_ccsr2csc(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_float_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_float_complex *csc_val, rocsparse_int *csc_row_ind, rocsparse_int *csc_col_ptr, rocsparse_action copy_values, rocsparse_index_base idx_base, void *temp_buffer)#
-
rocsparse_status rocsparse_zcsr2csc(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_double_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_double_complex *csc_val, rocsparse_int *csc_row_ind, rocsparse_int *csc_col_ptr, rocsparse_action copy_values, rocsparse_index_base idx_base, void *temp_buffer)#
Convert a sparse CSR matrix into a sparse CSC matrix.
rocsparse_csr2csc
converts a CSR matrix into a CSC matrix.rocsparse_csr2csc
can also be used to convert a CSC matrix into a CSR matrix.copy_values
decides whethercsc_val
is being filled during conversion (rocsparse_action_numeric) or not (rocsparse_action_symbolic).rocsparse_csr2csc
requires extra temporary storage buffer that has to be allocated by the user. Storage buffer size can be determined by rocsparse_csr2csc_buffer_size().- Example
This example computes the transpose of a CSR matrix.
// 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 rocsparse_int m_A = 3; rocsparse_int n_A = 5; rocsparse_int nnz_A = 8; csr_row_ptr_A[m+1] = {0, 3, 5, 8}; // device memory csr_col_ind_A[nnz] = {0, 1, 3, 1, 2, 0, 3, 4}; // device memory csr_val_A[nnz] = {1, 2, 3, 4, 5, 6, 7, 8}; // device memory // Allocate memory for transposed CSR matrix rocsparse_int m_T = n_A; rocsparse_int n_T = m_A; rocsparse_int nnz_T = nnz_A; rocsparse_int* csr_row_ptr_T; rocsparse_int* csr_col_ind_T; float* csr_val_T; hipMalloc((void**)&csr_row_ptr_T, sizeof(rocsparse_int) * (m_T + 1)); hipMalloc((void**)&csr_col_ind_T, sizeof(rocsparse_int) * nnz_T); hipMalloc((void**)&csr_val_T, sizeof(float) * nnz_T); // Obtain the temporary buffer size size_t buffer_size; rocsparse_csr2csc_buffer_size(handle, m_A, n_A, nnz_A, csr_row_ptr_A, csr_col_ind_A, rocsparse_action_numeric, &buffer_size); // Allocate temporary buffer void* temp_buffer; hipMalloc(&temp_buffer, buffer_size); rocsparse_scsr2csc(handle, m_A, n_A, nnz_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, csr_val_T, csr_col_ind_T, csr_row_ptr_T, rocsparse_action_numeric, rocsparse_index_base_zero, temp_buffer);
Note
The resulting matrix can also be seen as the transpose of the input matrix.
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
nnz – [in] number of non-zero entries of the sparse CSR matrix.
csr_val – [in] array of
nnz
elements of the sparse CSR matrix.csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array of
nnz
elements containing the column indices of the sparse CSR matrix.csc_val – [out] array of
nnz
elements of the sparse CSC matrix.csc_row_ind – [out] array of
nnz
elements containing the row indices of the sparse CSC matrix.csc_col_ptr – [out] array of
n+1
elements that point to the start of every column of the sparse CSC matrix.copy_values – [in] rocsparse_action_symbolic or rocsparse_action_numeric.
idx_base – [in] rocsparse_index_base_zero or rocsparse_index_base_one.
temp_buffer – [in] temporary storage buffer allocated by the user, size is returned by rocsparse_csr2csc_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz
is invalid.rocsparse_status_invalid_pointer –
csr_val
,csr_row_ptr
,csr_col_ind
,csc_val
,csc_row_ind
,csc_col_ptr
ortemp_buffer
pointer is invalid.rocsparse_status_arch_mismatch – the device is not supported.
rocsparse_status_internal_error – an internal error occurred.
rocsparse_gebsr2gebsc_buffer_size()#
-
rocsparse_status rocsparse_sgebsr2gebsc_buffer_size(rocsparse_handle handle, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const float *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, size_t *p_buffer_size)#
-
rocsparse_status rocsparse_dgebsr2gebsc_buffer_size(rocsparse_handle handle, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const double *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, size_t *p_buffer_size)#
-
rocsparse_status rocsparse_cgebsr2gebsc_buffer_size(rocsparse_handle handle, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_float_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, size_t *p_buffer_size)#
-
rocsparse_status rocsparse_zgebsr2gebsc_buffer_size(rocsparse_handle handle, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_double_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, size_t *p_buffer_size)#
Convert a sparse GEneral BSR matrix into a sparse GEneral BSC matrix.
rocsparse_gebsr2gebsc_buffer_size
returns the size of the temporary storage buffer required by rocsparse_sgebsr2gebsc(), rocsparse_dgebsr2gebsc(), rocsparse_cgebsr2gebsc() and rocsparse_zgebsr2gebsc(). The temporary storage buffer must be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
mb – [in] number of rows of the sparse GEneral BSR matrix.
nb – [in] number of columns of the sparse GEneral BSR matrix.
nnzb – [in] number of non-zero entries of the sparse GEneral BSR matrix.
bsr_val – [in] array of
nnzb*row_block_dim*col_block_dim
containing the values of the sparse GEneral BSR matrix.bsr_row_ptr – [in] array of
mb+1
elements that point to the start of every row of the sparse GEneral BSR matrix.bsr_col_ind – [in] array of
nnzb
elements containing the column indices of the sparse GEneral BSR matrix.row_block_dim – [in] row size of the blocks in the sparse general BSR matrix.
col_block_dim – [in] col size of the blocks in the sparse general BSR matrix.
p_buffer_size – [out] number of bytes of the temporary storage buffer required by rocsparse_sgebsr2gebsc(), rocsparse_dgebsr2gebsc(), rocsparse_cgebsr2gebsc() and rocsparse_zgebsr2gebsc().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
mb
,nb
ornnzb
is invalid.rocsparse_status_invalid_pointer –
bsr_row_ptr
,bsr_col_ind
orbuffer_size
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_gebsr2gebsc()#
-
rocsparse_status rocsparse_sgebsr2gebsc(rocsparse_handle handle, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const float *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, float *bsc_val, rocsparse_int *bsc_row_ind, rocsparse_int *bsc_col_ptr, rocsparse_action copy_values, rocsparse_index_base idx_base, void *temp_buffer)#
-
rocsparse_status rocsparse_dgebsr2gebsc(rocsparse_handle handle, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const double *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, double *bsc_val, rocsparse_int *bsc_row_ind, rocsparse_int *bsc_col_ptr, rocsparse_action copy_values, rocsparse_index_base idx_base, void *temp_buffer)#
-
rocsparse_status rocsparse_cgebsr2gebsc(rocsparse_handle handle, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_float_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, rocsparse_float_complex *bsc_val, rocsparse_int *bsc_row_ind, rocsparse_int *bsc_col_ptr, rocsparse_action copy_values, rocsparse_index_base idx_base, void *temp_buffer)#
-
rocsparse_status rocsparse_zgebsr2gebsc(rocsparse_handle handle, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_double_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, rocsparse_double_complex *bsc_val, rocsparse_int *bsc_row_ind, rocsparse_int *bsc_col_ptr, rocsparse_action copy_values, rocsparse_index_base idx_base, void *temp_buffer)#
Convert a sparse GEneral BSR matrix into a sparse GEneral BSC matrix.
rocsparse_gebsr2gebsc
converts a GEneral BSR matrix into a GEneral BSC matrix.rocsparse_gebsr2gebsc
can also be used to convert a GEneral BSC matrix into a GEneral BSR matrix.copy_values
decides whetherbsc_val
is being filled during conversion (rocsparse_action_numeric) or not (rocsparse_action_symbolic).rocsparse_gebsr2gebsc
requires extra temporary storage buffer that has to be allocated by the user. Storage buffer size can be determined by rocsparse_gebsr2gebsc_buffer_size().- Example
This example computes the transpose of a GEneral BSR matrix.
// 1 2 0 3 // A = 0 4 5 0 // 6 0 0 7 // 1 2 3 4 rocsparse_int mb_A = 2; rocsparse_int row_block_dim = 2; rocsparse_int col_block_dim = 2; rocsparse_int nb_A = 2; rocsparse_int nnzb_A = 4; bsr_row_ptr_A[mb_A+1] = {0, 2, 4}; // device memory bsr_col_ind_A[nnzb_A] = {0, 1, 0, 1}; // device memory bsr_val_A[nnzb_A] = {1, 0, 2, 4, 0, 5, 3, 0, 6, 1, 0, 2, 0, 3, 7, 4}; // device memory // Allocate memory for transposed BSR matrix rocsparse_int mb_T = nb_A; rocsparse_int nb_T = mb_A; rocsparse_int nnzb_T = nnzb_A; rocsparse_int* bsr_row_ptr_T; rocsparse_int* bsr_col_ind_T; float* bsr_val_T; hipMalloc((void**)&bsr_row_ptr_T, sizeof(rocsparse_int) * (mb_T + 1)); hipMalloc((void**)&bsr_col_ind_T, sizeof(rocsparse_int) * nnzb_T); hipMalloc((void**)&bsr_val_T, sizeof(float) * nnzb_T); // Obtain the temporary buffer size size_t buffer_size; rocsparse_gebsr2gebsc_buffer_size(handle, mb_A, nb_A, nnzb_A, bsr_row_ptr_A, bsr_col_ind_A, rocsparse_action_numeric, &buffer_size); // Allocate temporary buffer void* temp_buffer; hipMalloc(&temp_buffer, buffer_size); rocsparse_sgebsr2gebsc(handle, mb_A, nb_A, nnzb_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim, col_block_dim, bsr_val_T, bsr_col_ind_T, bsr_row_ptr_T, rocsparse_action_numeric, rocsparse_index_base_zero, temp_buffer);
Note
The resulting matrix can also be seen as the transpose of the input matrix.
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
mb – [in] number of rows of the sparse GEneral BSR matrix.
nb – [in] number of columns of the sparse GEneral BSR matrix.
nnzb – [in] number of non-zero entries of the sparse GEneral BSR matrix.
bsr_val – [in] array of
nnzb
*row_block_dim
*col_block_dim
elements of the sparse GEneral BSR matrix.bsr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse GEneral BSR matrix.bsr_col_ind – [in] array of
nnz
elements containing the column indices of the sparse GEneral BSR matrix.row_block_dim – [in] row size of the blocks in the sparse general BSR matrix.
col_block_dim – [in] col size of the blocks in the sparse general BSR matrix.
bsc_val – [out] array of
nnz
elements of the sparse BSC matrix.bsc_row_ind – [out] array of
nnz
elements containing the row indices of the sparse BSC matrix.bsc_col_ptr – [out] array of
n+1
elements that point to the start of every column of the sparse BSC matrix.copy_values – [in] rocsparse_action_symbolic or rocsparse_action_numeric.
idx_base – [in] rocsparse_index_base_zero or rocsparse_index_base_one.
temp_buffer – [in] temporary storage buffer allocated by the user, size is returned by rocsparse_gebsr2gebsc_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
mb
,nb
ornnzb
is invalid.rocsparse_status_invalid_pointer –
bsr_val
,bsr_row_ptr
,bsr_col_ind
,bsc_val
,bsc_row_ind
,bsc_col_ptr
ortemp_buffer
pointer is invalid.rocsparse_status_arch_mismatch – the device is not supported.
rocsparse_status_internal_error – an internal error occurred.
rocsparse_csr2ell_width()#
-
rocsparse_status rocsparse_csr2ell_width(rocsparse_handle handle, rocsparse_int m, const rocsparse_mat_descr csr_descr, const rocsparse_int *csr_row_ptr, const rocsparse_mat_descr ell_descr, rocsparse_int *ell_width)#
Convert a sparse CSR matrix into a sparse ELL matrix.
rocsparse_csr2ell_width
computes the maximum of the per row non-zero elements over all rows, the ELLwidth
, for a given CSR matrix.Note
This function is blocking with respect to the host.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSR matrix.
csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.ell_descr – [in] descriptor of the sparse ELL matrix. Currently, only rocsparse_matrix_type_general is supported.
ell_width – [out] pointer to the number of non-zero elements per row in ELL storage format.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
is invalid.rocsparse_status_invalid_pointer –
csr_descr
,csr_row_ptr
, orell_width
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_status_not_implemented – rocsparse_matrix_type != rocsparse_matrix_type_general.
rocsparse_csr2ell()#
-
rocsparse_status rocsparse_scsr2ell(rocsparse_handle handle, rocsparse_int m, const rocsparse_mat_descr csr_descr, const float *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, const rocsparse_mat_descr ell_descr, rocsparse_int ell_width, float *ell_val, rocsparse_int *ell_col_ind)#
-
rocsparse_status rocsparse_dcsr2ell(rocsparse_handle handle, rocsparse_int m, const rocsparse_mat_descr csr_descr, const double *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, const rocsparse_mat_descr ell_descr, rocsparse_int ell_width, double *ell_val, rocsparse_int *ell_col_ind)#
-
rocsparse_status rocsparse_ccsr2ell(rocsparse_handle handle, rocsparse_int m, const rocsparse_mat_descr csr_descr, const rocsparse_float_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, const rocsparse_mat_descr ell_descr, rocsparse_int ell_width, rocsparse_float_complex *ell_val, rocsparse_int *ell_col_ind)#
-
rocsparse_status rocsparse_zcsr2ell(rocsparse_handle handle, rocsparse_int m, const rocsparse_mat_descr csr_descr, const rocsparse_double_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, const rocsparse_mat_descr ell_descr, rocsparse_int ell_width, rocsparse_double_complex *ell_val, rocsparse_int *ell_col_ind)#
Convert a sparse CSR matrix into a sparse ELL matrix.
rocsparse_csr2ell
converts a CSR matrix into an ELL matrix. It is assumed, thatell_val
andell_col_ind
are allocated. Allocation size is computed by the number of rows times the number of ELL non-zero elements per row, such that \(\text{nnz}_{\text{ELL}} = m \cdot \text{ell_width}\). The number of ELL non-zero elements per row is obtained by rocsparse_csr2ell_width().- Example
This example converts a CSR matrix into an ELL matrix.
// 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 rocsparse_int m = 3; rocsparse_int n = 5; rocsparse_int nnz = 8; csr_row_ptr[m+1] = {0, 3, 5, 8}; // device memory csr_col_ind[nnz] = {0, 1, 3, 1, 2, 0, 3, 4}; // device memory csr_val[nnz] = {1, 2, 3, 4, 5, 6, 7, 8}; // device memory // Create ELL matrix descriptor rocsparse_mat_descr ell_descr; rocsparse_create_mat_descr(&ell_descr); // Obtain the ELL width rocsparse_int ell_width; rocsparse_csr2ell_width(handle, m, csr_descr, csr_row_ptr, ell_descr, &ell_width); // Compute ELL non-zero entries rocsparse_int ell_nnz = m * ell_width; // Allocate ELL column and value arrays rocsparse_int* ell_col_ind; hipMalloc((void**)&ell_col_ind, sizeof(rocsparse_int) * ell_nnz); float* ell_val; hipMalloc((void**)&ell_val, sizeof(float) * ell_nnz); // Format conversion rocsparse_scsr2ell(handle, m, csr_descr, csr_val, csr_row_ptr, csr_col_ind, ell_descr, ell_width, ell_val, ell_col_ind);
Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSR matrix.
csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_val – [in] array containing the values of the sparse CSR matrix.
csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array containing the column indices of the sparse CSR matrix.
ell_descr – [in] descriptor of the sparse ELL matrix. Currently, only rocsparse_matrix_type_general is supported.
ell_width – [in] number of non-zero elements per row in ELL storage format.
ell_val – [out] array of
m
timesell_width
elements of the sparse ELL matrix.ell_col_ind – [out] array of
m
timesell_width
elements containing the column indices of the sparse ELL matrix.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orell_width
is invalid.rocsparse_status_invalid_pointer –
csr_descr
,csr_val
,csr_row_ptr
,csr_col_ind
,ell_descr
,ell_val
orell_col_ind
pointer is invalid.rocsparse_status_not_implemented – rocsparse_matrix_type != rocsparse_matrix_type_general.
rocsparse_ell2csr_nnz()#
-
rocsparse_status rocsparse_ell2csr_nnz(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr ell_descr, rocsparse_int ell_width, const rocsparse_int *ell_col_ind, const rocsparse_mat_descr csr_descr, rocsparse_int *csr_row_ptr, rocsparse_int *csr_nnz)#
Convert a sparse ELL matrix into a sparse CSR matrix.
rocsparse_ell2csr_nnz
computes the total CSR non-zero elements and the CSR row offsets, that point to the start of every row of the sparse CSR matrix, for a given ELL matrix. It is assumed thatcsr_row_ptr
has been allocated with sizem+1
.Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse ELL matrix.
n – [in] number of columns of the sparse ELL matrix.
ell_descr – [in] descriptor of the sparse ELL matrix. Currently, only rocsparse_matrix_type_general is supported.
ell_width – [in] number of non-zero elements per row in ELL storage format.
ell_col_ind – [in] array of
m
timesell_width
elements containing the column indices of the sparse ELL matrix.csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_row_ptr – [out] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_nnz – [out] pointer to the total number of non-zero elements in CSR storage format.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
orell_width
is invalid.rocsparse_status_invalid_pointer –
ell_descr
,ell_col_ind
,csr_descr
,csr_row_ptr
orcsr_nnz
pointer is invalid.rocsparse_status_not_implemented – rocsparse_matrix_type != rocsparse_matrix_type_general.
rocsparse_ell2csr()#
-
rocsparse_status rocsparse_sell2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr ell_descr, rocsparse_int ell_width, const float *ell_val, const rocsparse_int *ell_col_ind, const rocsparse_mat_descr csr_descr, float *csr_val, const rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_dell2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr ell_descr, rocsparse_int ell_width, const double *ell_val, const rocsparse_int *ell_col_ind, const rocsparse_mat_descr csr_descr, double *csr_val, const rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_cell2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr ell_descr, rocsparse_int ell_width, const rocsparse_float_complex *ell_val, const rocsparse_int *ell_col_ind, const rocsparse_mat_descr csr_descr, rocsparse_float_complex *csr_val, const rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_zell2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr ell_descr, rocsparse_int ell_width, const rocsparse_double_complex *ell_val, const rocsparse_int *ell_col_ind, const rocsparse_mat_descr csr_descr, rocsparse_double_complex *csr_val, const rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
Convert a sparse ELL matrix into a sparse CSR matrix.
rocsparse_ell2csr
converts an ELL matrix into a CSR matrix. It is assumed thatcsr_row_ptr
has already been filled and thatcsr_val
andcsr_col_ind
are allocated by the user.csr_row_ptr
and allocation size ofcsr_col_ind
andcsr_val
is defined by the number of CSR non-zero elements. Both can be obtained by rocsparse_ell2csr_nnz().- Example
This example converts an ELL matrix into a CSR matrix.
// 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 rocsparse_int m = 3; rocsparse_int n = 5; rocsparse_int nnz = 9; rocsparse_int ell_width = 3; ell_col_ind[nnz] = {0, 1, 0, 1, 2, 3, 3, -1, 4}; // device memory ell_val[nnz] = {1, 4, 6, 2, 5, 7, 3, 0, 8}; // device memory // Create CSR matrix descriptor rocsparse_mat_descr csr_descr; rocsparse_create_mat_descr(&csr_descr); // Allocate csr_row_ptr array for row offsets rocsparse_int* csr_row_ptr; hipMalloc((void**)&csr_row_ptr, sizeof(rocsparse_int) * (m + 1)); // Obtain the number of CSR non-zero entries // and fill csr_row_ptr array with row offsets rocsparse_int csr_nnz; rocsparse_ell2csr_nnz(handle, m, n, ell_descr, ell_width, ell_col_ind, csr_descr, csr_row_ptr, &csr_nnz); // Allocate CSR column and value arrays rocsparse_int* csr_col_ind; hipMalloc((void**)&csr_col_ind, sizeof(rocsparse_int) * csr_nnz); float* csr_val; hipMalloc((void**)&csr_val, sizeof(float) * csr_nnz); // Format conversion rocsparse_sell2csr(handle, m, n, ell_descr, ell_width, ell_val, ell_col_ind, csr_descr, csr_val, csr_row_ptr, csr_col_ind);
Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse ELL matrix.
n – [in] number of columns of the sparse ELL matrix.
ell_descr – [in] descriptor of the sparse ELL matrix. Currently, only rocsparse_matrix_type_general is supported.
ell_width – [in] number of non-zero elements per row in ELL storage format.
ell_val – [in] array of
m
timesell_width
elements of the sparse ELL matrix.ell_col_ind – [in] array of
m
timesell_width
elements containing the column indices of the sparse ELL matrix.csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_val – [out] array containing the values of the sparse CSR matrix.
csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [out] array containing the column indices of the sparse CSR matrix.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
orell_width
is invalid.rocsparse_status_invalid_pointer –
csr_descr
,csr_val
,csr_row_ptr
,csr_col_ind
,ell_descr
,ell_val
orell_col_ind
pointer is invalid.rocsparse_status_not_implemented – rocsparse_matrix_type != rocsparse_matrix_type_general.
rocsparse_csr2hyb()#
-
rocsparse_status rocsparse_scsr2hyb(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const float *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_hyb_mat hyb, rocsparse_int user_ell_width, rocsparse_hyb_partition partition_type)#
-
rocsparse_status rocsparse_dcsr2hyb(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const double *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_hyb_mat hyb, rocsparse_int user_ell_width, rocsparse_hyb_partition partition_type)#
-
rocsparse_status rocsparse_ccsr2hyb(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_float_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_hyb_mat hyb, rocsparse_int user_ell_width, rocsparse_hyb_partition partition_type)#
-
rocsparse_status rocsparse_zcsr2hyb(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_double_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_hyb_mat hyb, rocsparse_int user_ell_width, rocsparse_hyb_partition partition_type)#
Convert a sparse CSR matrix into a sparse HYB matrix.
rocsparse_csr2hyb
converts a CSR matrix into a HYB matrix. It is assumed thathyb
has been initialized with rocsparse_create_hyb_mat().- Example
This example converts a CSR matrix into a HYB matrix using user defined partitioning.
// Create HYB matrix structure rocsparse_hyb_mat hyb; rocsparse_create_hyb_mat(&hyb); // User defined ell width rocsparse_int user_ell_width = 5; // Perform the conversion rocsparse_scsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, user_ell_width, rocsparse_hyb_partition_user); // Do some work // Clean up rocsparse_destroy_hyb_mat(hyb);
Note
This function requires a significant amount of storage for the HYB matrix, depending on the matrix structure.
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_val – [in] array containing the values of the sparse CSR matrix.
csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array containing the column indices of the sparse CSR matrix.
hyb – [out] sparse matrix in HYB format.
user_ell_width – [in] width of the ELL part of the HYB matrix (only required if
partition_type
== rocsparse_hyb_partition_user).partition_type – [in] rocsparse_hyb_partition_auto (recommended), rocsparse_hyb_partition_user or rocsparse_hyb_partition_max.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
oruser_ell_width
is invalid.rocsparse_status_invalid_value –
partition_type
is invalid.rocsparse_status_invalid_pointer –
descr
,hyb
,csr_val
,csr_row_ptr
orcsr_col_ind
pointer is invalid.rocsparse_status_memory_error – the buffer for the HYB matrix could not be allocated.
rocsparse_status_internal_error – an internal error occurred.
rocsparse_status_not_implemented – rocsparse_matrix_type != rocsparse_matrix_type_general.
rocsparse_hyb2csr_buffer_size()#
-
rocsparse_status rocsparse_hyb2csr_buffer_size(rocsparse_handle handle, const rocsparse_mat_descr descr, const rocsparse_hyb_mat hyb, const rocsparse_int *csr_row_ptr, size_t *buffer_size)#
Convert a sparse HYB matrix into a sparse CSR matrix.
rocsparse_hyb2csr_buffer_size
returns the size of the temporary storage buffer required by rocsparse_shyb2csr(), rocsparse_dhyb2csr(), rocsparse_chyb2csr() and rocsparse_dhyb2csr(). The temporary storage buffer must be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
descr – [in] descriptor of the sparse HYB matrix. Currently, only rocsparse_matrix_type_general is supported.
hyb – [in] sparse matrix in HYB format.
csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.buffer_size – [out] number of bytes of the temporary storage buffer required by rocsparse_shyb2csr(), rocsparse_dhyb2csr(), rocsparse_chyb2csr() and rocsparse_zhyb2csr().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_pointer –
descr
,hyb
,csr_row_ptr
orbuffer_size
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_status_not_implemented – rocsparse_matrix_type != rocsparse_matrix_type_general.
rocsparse_hyb2csr()#
-
rocsparse_status rocsparse_shyb2csr(rocsparse_handle handle, const rocsparse_mat_descr descr, const rocsparse_hyb_mat hyb, float *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind, void *temp_buffer)#
-
rocsparse_status rocsparse_dhyb2csr(rocsparse_handle handle, const rocsparse_mat_descr descr, const rocsparse_hyb_mat hyb, double *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind, void *temp_buffer)#
-
rocsparse_status rocsparse_chyb2csr(rocsparse_handle handle, const rocsparse_mat_descr descr, const rocsparse_hyb_mat hyb, rocsparse_float_complex *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind, void *temp_buffer)#
-
rocsparse_status rocsparse_zhyb2csr(rocsparse_handle handle, const rocsparse_mat_descr descr, const rocsparse_hyb_mat hyb, rocsparse_double_complex *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind, void *temp_buffer)#
Convert a sparse HYB matrix into a sparse CSR matrix.
rocsparse_hyb2csr
converts a HYB matrix into a CSR matrix.rocsparse_hyb2csr
requires extra temporary storage buffer that has to be allocated by the user. Storage buffer size can be determined by rocsparse_hyb2csr_buffer_size().- Example
This example converts a HYB matrix into a CSR matrix.
// Create CSR matrix arrays rocsparse_int* csr_row_ptr; rocsparse_int* csr_col_ind; float* csr_val; hipMalloc((void**)&csr_row_ptr, sizeof(rocsparse_int) * (m + 1)); hipMalloc((void**)&csr_col_ind, sizeof(rocsparse_int) * nnz); hipMalloc((void**)&csr_val, sizeof(float) * nnz); // Get required size of temporary buffer size_t size; rocsparse_hyb2csr_buffer_size(handle, descr, hyb, csr_row_ptr, &size); // Allocate temporary buffer void* buffer; hipMalloc(&buffer, size); // Perform the conversion rocsparse_shyb2csr(handle, descr, hyb, csr_val, csr_row_ptr, csr_col_ind, buffer);
Note
This function is blocking with respect to the host.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
descr – [in] descriptor of the sparse HYB matrix. Currently, only rocsparse_matrix_type_general is supported.
hyb – [in] sparse matrix in HYB format.
csr_val – [out] array containing the values of the sparse CSR matrix.
csr_row_ptr – [out] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [out] array containing the column indices of the sparse CSR matrix.
temp_buffer – [in] temporary storage buffer allocated by the user, size is returned by rocsparse_hyb2csr_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_pointer –
descr
,hyb
,csr_val
,csr_row_ptr
,csr_col_ind
ortemp_buffer
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_status_not_implemented – rocsparse_matrix_type != rocsparse_matrix_type_general.
rocsparse_bsr2csr()#
-
rocsparse_status rocsparse_sbsr2csr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, const rocsparse_mat_descr bsr_descr, const float *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int block_dim, const rocsparse_mat_descr csr_descr, float *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_dbsr2csr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, const rocsparse_mat_descr bsr_descr, const double *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int block_dim, const rocsparse_mat_descr csr_descr, double *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_cbsr2csr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, const rocsparse_mat_descr bsr_descr, const rocsparse_float_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int block_dim, const rocsparse_mat_descr csr_descr, rocsparse_float_complex *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_zbsr2csr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, const rocsparse_mat_descr bsr_descr, const rocsparse_double_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int block_dim, const rocsparse_mat_descr csr_descr, rocsparse_double_complex *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
Convert a sparse BSR matrix into a sparse CSR matrix.
rocsparse_bsr2csr
converts a BSR matrix into a CSR matrix. It is assumed, thatcsr_val
,csr_col_ind
andcsr_row_ptr
are allocated. Allocation size forcsr_row_ptr
is computed by the number of block rows multiplied by the block dimension plus one. Allocation forcsr_val
andcsr_col_ind
is computed by the the number of blocks in the BSR matrix multiplied by the block dimension squared.- Example
This example converts a BSR matrix into an CSR matrix.
// 1 4 0 0 0 0 // A = 0 2 3 0 0 0 // 5 0 0 7 8 0 // 0 0 9 0 6 0 rocsparse_int mb = 2; rocsparse_int nb = 3; rocsparse_int block_dim = 2; rocsparse_int m = Mb * block_dim; rocsparse_int n = Nb * block_dim; bsr_row_ptr[mb+1] = {0, 2, 5}; // device memory bsr_col_ind[nnzb] = {0, 1, 0, 1, 2}; // device memory bsr_val[nnzb*block_dim*block_dim] = {1, 0, 4, 2, 0, 3, 0, 0, 5, 0, 0, 0, 0, 9, 7, 0, 8, 6, 0, 0}; // device memory rocsparse_int nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; // Create CSR arrays on device rocsparse_int* csr_row_ptr; rocsparse_int* csr_col_ind; float* csr_val; hipMalloc((void**)&csr_row_ptr, sizeof(rocsparse_int) * (m + 1)); hipMalloc((void**)&csr_col_ind, sizeof(rocsparse_int) * nnzb * block_dim * block_dim); hipMalloc((void**)&csr_val, sizeof(float) * nnzb * block_dim * block_dim); // Create rocsparse handle rocsparse_local_handle handle; rocsparse_mat_descr bsr_descr = nullptr; rocsparse_create_mat_descr(&bsr_descr); rocsparse_mat_descr csr_descr = nullptr; rocsparse_create_mat_descr(&csr_descr); rocsparse_set_mat_index_base(bsr_descr, rocsparse_index_base_zero); rocsparse_set_mat_index_base(csr_descr, rocsparse_index_base_zero); // Format conversion rocsparse_sbsr2csr(handle, rocsparse_direction_column, mb, nb, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind);
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] the storage format of the blocks, rocsparse_direction_row or rocsparse_direction_column
mb – [in] number of block rows in the sparse BSR matrix.
nb – [in] number of block columns in the sparse BSR matrix.
bsr_descr – [in] descriptor of the sparse BSR matrix. Currently, only rocsparse_matrix_type_general is supported.
bsr_val – [in] array of
nnzb*block_dim*block_dim
containing the values of the sparse BSR matrix.bsr_row_ptr – [in] array of
mb+1
elements that point to the start of every block row of the sparse BSR matrix.bsr_col_ind – [in] array of
nnzb
elements containing the block column indices of the sparse BSR matrix.block_dim – [in] size of the blocks in the sparse BSR matrix.
csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_val – [out] array of
nnzb*block_dim*block_dim
elements containing the values of the sparse CSR matrix.csr_row_ptr – [out] array of
m+1
wherem=mb*block_dim
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [out] array of
nnzb*block_dim*block_dim
elements containing the column indices of the sparse CSR matrix.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
mb
ornb
orblock_dim
is invalid.rocsparse_status_invalid_pointer –
bsr_val
,bsr_row_ptr
,bsr_col_ind
,csr_val
,csr_row_ptr
orcsr_col_ind
pointer is invalid.
rocsparse_gebsr2csr()#
-
rocsparse_status rocsparse_sgebsr2csr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, const rocsparse_mat_descr bsr_descr, const float *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, const rocsparse_mat_descr csr_descr, float *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_dgebsr2csr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, const rocsparse_mat_descr bsr_descr, const double *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, const rocsparse_mat_descr csr_descr, double *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_cgebsr2csr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, const rocsparse_mat_descr bsr_descr, const rocsparse_float_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, const rocsparse_mat_descr csr_descr, rocsparse_float_complex *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_zgebsr2csr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, const rocsparse_mat_descr bsr_descr, const rocsparse_double_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, const rocsparse_mat_descr csr_descr, rocsparse_double_complex *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
Convert a sparse general BSR matrix into a sparse CSR matrix.
rocsparse_gebsr2csr
converts a BSR matrix into a CSR matrix. It is assumed, thatcsr_val
,csr_col_ind
andcsr_row_ptr
are allocated. Allocation size forcsr_row_ptr
is computed by the number of block rows multiplied by the block dimension plus one. Allocation forcsr_val
andcsr_col_ind
is computed by the the number of blocks in the BSR matrix multiplied by the product of the block dimensions.- Example
This example converts a general BSR matrix into an CSR matrix.
// 1 4 0 0 0 0 // A = 0 2 3 0 0 0 // 5 0 0 7 8 0 // 0 0 9 0 6 0 rocsparse_int mb = 2; rocsparse_int nb = 2; rocsparse_int row_block_dim = 2; rocsparse_int col_block_dim = 3; rocsparse_int m = Mb * row_block_dim; rocsparse_int n = Nb * col_block_dim; bsr_row_ptr[mb+1] = {0, 1, 3}; // device memory bsr_col_ind[nnzb] = {0, 0, 1}; // device memory bsr_val[nnzb*block_dim*block_dim] = {1, 0, 4, 2, 0, 3, 5, 0, 0, 0, 0, 9, 7, 0, 8, 6, 0, 0}; // device memory rocsparse_int nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; // Create CSR arrays on device rocsparse_int* csr_row_ptr; rocsparse_int* csr_col_ind; float* csr_val; hipMalloc((void**)&csr_row_ptr, sizeof(rocsparse_int) * (m + 1)); hipMalloc((void**)&csr_col_ind, sizeof(rocsparse_int) * nnzb * row_block_dim * col_block_dim); hipMalloc((void**)&csr_val, sizeof(float) * nnzb * row_block_dim * col_block_dim); // Create rocsparse handle rocsparse_local_handle handle; rocsparse_mat_descr bsr_descr = nullptr; rocsparse_create_mat_descr(&bsr_descr); rocsparse_mat_descr csr_descr = nullptr; rocsparse_create_mat_descr(&csr_descr); rocsparse_set_mat_index_base(bsr_descr, rocsparse_index_base_zero); rocsparse_set_mat_index_base(csr_descr, rocsparse_index_base_zero); // Format conversion rocsparse_sgebsr2csr(handle, rocsparse_direction_column, mb, nb, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind);
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] the storage format of the blocks, rocsparse_direction_row or rocsparse_direction_column
mb – [in] number of block rows in the sparse general BSR matrix.
nb – [in] number of block columns in the sparse general BSR matrix.
bsr_descr – [in] descriptor of the sparse general BSR matrix. Currently, only rocsparse_matrix_type_general is supported.
bsr_val – [in] array of
nnzb*row_block_dim*col_block_dim
containing the values of the sparse BSR matrix.bsr_row_ptr – [in] array of
mb+1
elements that point to the start of every block row of the sparse BSR matrix.bsr_col_ind – [in] array of
nnzb
elements containing the block column indices of the sparse BSR matrix.row_block_dim – [in] row size of the blocks in the sparse general BSR matrix.
col_block_dim – [in] column size of the blocks in the sparse general BSR matrix.
csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_val – [out] array of
nnzb*row_block_dim*col_block_dim
elements containing the values of the sparse CSR matrix.csr_row_ptr – [out] array of
m+1
wherem=mb*row_block_dim
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [out] array of
nnzb*block_dim*block_dim
elements containing the column indices of the sparse CSR matrix.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
mb
ornb
orblock_dim
is invalid.rocsparse_status_invalid_pointer –
bsr_val
,bsr_row_ptr
,bsr_col_ind
,csr_val
,csr_row_ptr
orcsr_col_ind
pointer is invalid.
rocsparse_gebsr2gebsr_buffer_size()#
-
rocsparse_status rocsparse_sgebsr2gebsr_buffer_size(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_mat_descr descr_A, const float *bsr_val_A, const rocsparse_int *bsr_row_ptr_A, const rocsparse_int *bsr_col_ind_A, rocsparse_int row_block_dim_A, rocsparse_int col_block_dim_A, rocsparse_int row_block_dim_C, rocsparse_int col_block_dim_C, size_t *buffer_size)#
-
rocsparse_status rocsparse_dgebsr2gebsr_buffer_size(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_mat_descr descr_A, const double *bsr_val_A, const rocsparse_int *bsr_row_ptr_A, const rocsparse_int *bsr_col_ind_A, rocsparse_int row_block_dim_A, rocsparse_int col_block_dim_A, rocsparse_int row_block_dim_C, rocsparse_int col_block_dim_C, size_t *buffer_size)#
-
rocsparse_status rocsparse_cgebsr2gebsr_buffer_size(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_mat_descr descr_A, const rocsparse_float_complex *bsr_val_A, const rocsparse_int *bsr_row_ptr_A, const rocsparse_int *bsr_col_ind_A, rocsparse_int row_block_dim_A, rocsparse_int col_block_dim_A, rocsparse_int row_block_dim_C, rocsparse_int col_block_dim_C, size_t *buffer_size)#
-
rocsparse_status rocsparse_zgebsr2gebsr_buffer_size(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_mat_descr descr_A, const rocsparse_double_complex *bsr_val_A, const rocsparse_int *bsr_row_ptr_A, const rocsparse_int *bsr_col_ind_A, rocsparse_int row_block_dim_A, rocsparse_int col_block_dim_A, rocsparse_int row_block_dim_C, rocsparse_int col_block_dim_C, size_t *buffer_size)#
This function computes the the size of the user allocated temporary storage buffer used when converting a sparse general BSR matrix to another sparse general BSR matrix.
rocsparse_gebsr2gebsr_buffer_size
returns the size of the temporary storage buffer that is required by rocsparse_gebsr2gebsr_nnz(), rocsparse_sgebsr2gebsr(), rocsparse_dgebsr2gebsr(), rocsparse_cgebsr2gebsr(), and rocsparse_zgebsr2gebsr(). The temporary storage buffer must be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] the storage format of the blocks, rocsparse_direction_row or rocsparse_direction_column
mb – [in] number of block rows of the general BSR sparse matrix
A
.nb – [in] number of block columns of the general BSR sparse matrix
A
.nnzb – [in] number of blocks in the general BSR sparse matrix
A
.descr_A – [in] the descriptor of the general BSR sparse matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.bsr_val_A – [in] array of
nnzb*row_block_dim_A*col_block_dim_A
containing the values of the sparse general BSR matrixA
.bsr_row_ptr_A – [in] array of
mb+1
elements that point to the start of every block row of the sparse general BSR matrixA
.bsr_col_ind_A – [in] array of
nnzb
elements containing the block column indices of the sparse general BSR matrixA
.row_block_dim_A – [in] row size of the blocks in the sparse general BSR matrix
A
.col_block_dim_A – [in] column size of the blocks in the sparse general BSR matrix
A
.row_block_dim_C – [in] row size of the blocks in the sparse general BSR matrix
C
.col_block_dim_C – [in] column size of the blocks in the sparse general BSR matrix
C
.buffer_size – [out] number of bytes of the temporary storage buffer required by rocsparse_gebsr2gebsr_nnz(), rocsparse_sgebsr2gebsr(), rocsparse_dgebsr2gebsr(), rocsparse_cgebsr2gebsr(), and rocsparse_zgebsr2gebsr().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
mb
ornb
ornnzb
orrow_block_dim_A
orcol_block_dim_A
orrow_block_dim_C
orcol_block_dim_C
is invalid.rocsparse_status_invalid_pointer –
bsr_row_ptr_A
orbsr_col_ind_A
ordescr_A
orbuffer_size
pointer is invalid.
rocsparse_gebsr2gebsr_nnz()#
-
rocsparse_status rocsparse_gebsr2gebsr_nnz(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_mat_descr descr_A, const rocsparse_int *bsr_row_ptr_A, const rocsparse_int *bsr_col_ind_A, rocsparse_int row_block_dim_A, rocsparse_int col_block_dim_A, const rocsparse_mat_descr descr_C, rocsparse_int *bsr_row_ptr_C, rocsparse_int row_block_dim_C, rocsparse_int col_block_dim_C, rocsparse_int *nnz_total_dev_host_ptr, void *temp_buffer)#
This function is used when converting a general BSR sparse matrix
A
to another general BSR sparse matrixC
. Specifically, this function determines the number of non-zero blocks that will exist inC
(stored using either a host or device pointer), and computes the row pointer array forC
.Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] the storage format of the blocks, rocsparse_direction_row or rocsparse_direction_column
mb – [in] number of block rows of the general BSR sparse matrix
A
.nb – [in] number of block columns of the general BSR sparse matrix
A
.nnzb – [in] number of blocks in the general BSR sparse matrix
A
.descr_A – [in] the descriptor of the general BSR sparse matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.bsr_row_ptr_A – [in] array of
mb+1
elements that point to the start of every block row of the sparse general BSR matrixA
.bsr_col_ind_A – [in] array of
nnzb
elements containing the block column indices of the sparse general BSR matrixA
.row_block_dim_A – [in] row size of the blocks in the sparse general BSR matrix
A
.col_block_dim_A – [in] column size of the blocks in the sparse general BSR matrix
A
.descr_C – [in] the descriptor of the general BSR sparse matrix
C
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.bsr_row_ptr_C – [in] array of
mb_C+1
elements that point to the start of every block row of the sparse general BSR matrixC
wheremb_C=
(m+row_block_dim_C-1)/row_block_dim_C.row_block_dim_C – [in] row size of the blocks in the sparse general BSR matrix
C
.col_block_dim_C – [in] column size of the blocks in the sparse general BSR matrix
C
.nnz_total_dev_host_ptr – [out] total number of nonzero blocks in general BSR sparse matrix
C
stored using device or host memory.temp_buffer – [out] buffer allocated by the user whose size is determined by calling rocsparse_xgebsr2gebsr_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
mb
ornb
ornnzb
orrow_block_dim_A
orcol_block_dim_A
orrow_block_dim_C
orcol_block_dim_C
is invalid.rocsparse_status_invalid_pointer –
bsr_row_ptr_A
orbsr_col_ind_A
orbsr_row_ptr_C
ordescr_A
ordescr_C
ortemp_buffer
pointer is invalid.
rocsparse_gebsr2gebsr()#
-
rocsparse_status rocsparse_sgebsr2gebsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_mat_descr descr_A, const float *bsr_val_A, const rocsparse_int *bsr_row_ptr_A, const rocsparse_int *bsr_col_ind_A, rocsparse_int row_block_dim_A, rocsparse_int col_block_dim_A, const rocsparse_mat_descr descr_C, float *bsr_val_C, rocsparse_int *bsr_row_ptr_C, rocsparse_int *bsr_col_ind_C, rocsparse_int row_block_dim_C, rocsparse_int col_block_dim_C, void *temp_buffer)#
-
rocsparse_status rocsparse_dgebsr2gebsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_mat_descr descr_A, const double *bsr_val_A, const rocsparse_int *bsr_row_ptr_A, const rocsparse_int *bsr_col_ind_A, rocsparse_int row_block_dim_A, rocsparse_int col_block_dim_A, const rocsparse_mat_descr descr_C, double *bsr_val_C, rocsparse_int *bsr_row_ptr_C, rocsparse_int *bsr_col_ind_C, rocsparse_int row_block_dim_C, rocsparse_int col_block_dim_C, void *temp_buffer)#
-
rocsparse_status rocsparse_cgebsr2gebsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_mat_descr descr_A, const rocsparse_float_complex *bsr_val_A, const rocsparse_int *bsr_row_ptr_A, const rocsparse_int *bsr_col_ind_A, rocsparse_int row_block_dim_A, rocsparse_int col_block_dim_A, const rocsparse_mat_descr descr_C, rocsparse_float_complex *bsr_val_C, rocsparse_int *bsr_row_ptr_C, rocsparse_int *bsr_col_ind_C, rocsparse_int row_block_dim_C, rocsparse_int col_block_dim_C, void *temp_buffer)#
-
rocsparse_status rocsparse_zgebsr2gebsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int mb, rocsparse_int nb, rocsparse_int nnzb, const rocsparse_mat_descr descr_A, const rocsparse_double_complex *bsr_val_A, const rocsparse_int *bsr_row_ptr_A, const rocsparse_int *bsr_col_ind_A, rocsparse_int row_block_dim_A, rocsparse_int col_block_dim_A, const rocsparse_mat_descr descr_C, rocsparse_double_complex *bsr_val_C, rocsparse_int *bsr_row_ptr_C, rocsparse_int *bsr_col_ind_C, rocsparse_int row_block_dim_C, rocsparse_int col_block_dim_C, void *temp_buffer)#
This function converts the general BSR sparse matrix
A
to another general BSR sparse matrixC
.The conversion uses three steps. First, the user calls rocsparse_xgebsr2gebsr_buffer_size() to determine the size of the required temporary storage buffer. The user then allocates this buffer. Secondly, the user then allocates
mb_C+1
integers for the row pointer array forC
wheremb_C=
(m+row_block_dim_C-1)/row_block_dim_C. The user then calls rocsparse_xgebsr2gebsr_nnz() to fill in the row pointer array forC
(bsr_row_ptr_C
) and determine the number of non-zero blocks that will exist inC
. Finally, the user allocates space for the colimn indices array ofC
to havennzb_C
elements and space for the values array ofC
to havennzb_C*roc_block_dim_C*col_block_dim_C
and then calls rocsparse_xgebsr2gebsr() to complete the conversion.Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] the storage format of the blocks, rocsparse_direction_row or rocsparse_direction_column
mb – [in] number of block rows of the general BSR sparse matrix
A
.nb – [in] number of block columns of the general BSR sparse matrix
A
.nnzb – [in] number of blocks in the general BSR sparse matrix
A
.descr_A – [in] the descriptor of the general BSR sparse matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.bsr_val_A – [in] array of
nnzb*row_block_dim_A*col_block_dim_A
containing the values of the sparse general BSR matrixA
.bsr_row_ptr_A – [in] array of
mb+1
elements that point to the start of every block row of the sparse general BSR matrixA
.bsr_col_ind_A – [in] array of
nnzb
elements containing the block column indices of the sparse general BSR matrixA
.row_block_dim_A – [in] row size of the blocks in the sparse general BSR matrix
A
.col_block_dim_A – [in] column size of the blocks in the sparse general BSR matrix
A
.descr_C – [in] the descriptor of the general BSR sparse matrix
C
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.bsr_val_C – [in] array of
nnzb_C*row_block_dim_C*col_block_dim_C
containing the values of the sparse general BSR matrixC
.bsr_row_ptr_C – [in] array of
mb_C+1
elements that point to the start of every block row of the sparse general BSR matrixC
.bsr_col_ind_C – [in] array of
nnzb_C
elements containing the block column indices of the sparse general BSR matrixC
.row_block_dim_C – [in] row size of the blocks in the sparse general BSR matrix
C
.col_block_dim_C – [in] column size of the blocks in the sparse general BSR matrix
C
.temp_buffer – [out] buffer allocated by the user whose size is determined by calling rocsparse_xgebsr2gebsr_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
mb
ornb
ornnzb
orrow_block_dim_A
orcol_block_dim_A
orrow_block_dim_C
orcol_block_dim_C
is invalid.rocsparse_status_invalid_pointer –
bsr_row_ptr_A
orbsr_col_ind_A
orbsr_val_A
orbsr_row_ptr_C
orbsr_col_ind_C
orbsr_val_C
ordescr_A
ordescr_C
ortemp_buffer
pointer is invalid.
rocsparse_csr2bsr_nnz()#
-
rocsparse_status rocsparse_csr2bsr_nnz(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_int block_dim, const rocsparse_mat_descr bsr_descr, rocsparse_int *bsr_row_ptr, rocsparse_int *bsr_nnz)#
This function computes the number of nonzero block columns per row and the total number of nonzero blocks in a sparse BSR matrix given a sparse CSR matrix as input.
The routine does support asynchronous execution if the pointer mode is set to device.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] direction that specified whether to count nonzero elements by rocsparse_direction_row or by rocsparse_direction_row.
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_row_ptr – [in] integer array containing
m+1
elements that point to the start of each row of the CSR matrixcsr_col_ind – [in] integer array of the column indices for each non-zero element in the CSR matrix
block_dim – [in] the block dimension of the BSR matrix. Between 1 and min(m, n)
bsr_descr – [in] descriptor of the sparse BSR matrix. Currently, only rocsparse_matrix_type_general is supported.
bsr_row_ptr – [out] integer array containing
mb+1
elements that point to the start of each block row of the BSR matrixbsr_nnz – [out] total number of nonzero elements in device or host memory.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orblock_dim
is invalid.rocsparse_status_invalid_pointer –
csr_row_ptr
orcsr_col_ind
orbsr_row_ptr
orbsr_nnz
pointer is invalid.
rocsparse_csr2bsr()#
-
rocsparse_status rocsparse_scsr2bsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const float *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_int block_dim, const rocsparse_mat_descr bsr_descr, float *bsr_val, rocsparse_int *bsr_row_ptr, rocsparse_int *bsr_col_ind)#
-
rocsparse_status rocsparse_dcsr2bsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const double *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_int block_dim, const rocsparse_mat_descr bsr_descr, double *bsr_val, rocsparse_int *bsr_row_ptr, rocsparse_int *bsr_col_ind)#
-
rocsparse_status rocsparse_ccsr2bsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const rocsparse_float_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_int block_dim, const rocsparse_mat_descr bsr_descr, rocsparse_float_complex *bsr_val, rocsparse_int *bsr_row_ptr, rocsparse_int *bsr_col_ind)#
-
rocsparse_status rocsparse_zcsr2bsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const rocsparse_double_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_int block_dim, const rocsparse_mat_descr bsr_descr, rocsparse_double_complex *bsr_val, rocsparse_int *bsr_row_ptr, rocsparse_int *bsr_col_ind)#
Convert a sparse CSR matrix into a sparse BSR matrix.
rocsparse_csr2bsr
converts a CSR matrix into a BSR matrix. It is assumed, thatbsr_val
,bsr_col_ind
andbsr_row_ptr
are allocated. Allocation size forbsr_row_ptr
is computed asmb+1
wheremb
is the number of block rows in the BSR matrix. Allocation size forbsr_val
andbsr_col_ind
is computed usingcsr2bsr_nnz()
which also fills inbsr_row_ptr
.rocsparse_csr2bsr
requires extra temporary storage that is allocated internally ifblock_dim>16
- Example
This example converts a CSR matrix into an BSR matrix.
// 1 4 0 0 0 0 // A = 0 2 3 0 0 0 // 5 0 0 7 8 0 // 0 0 9 0 6 0 rocsparse_int m = 4; rocsparse_int n = 6; rocsparse_int block_dim = 2; rocsparse_int nnz = 9; rocsparse_int mb = (m + block_dim - 1) / block_dim; rocsparse_int nb = (n + block_dim - 1) / block_dim; csr_row_ptr[m+1] = {0, 2, 4, 7, 9}; // device memory csr_col_ind[nnz] = {0, 1, 1, 2, 0, 3, 4, 2, 4}; // device memory csr_val[nnz] = {1, 4, 2, 3, 5, 7, 8, 9, 6}; // device memory hipMalloc(&bsr_row_ptr, sizeof(rocsparse_int) *(mb + 1)); rocsparse_int nnzb; rocsparse_int* nnzTotalHostPtr = &nnzb; csr2bsr_nnz(handle, rocsparse_direction_row, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, nnzTotalHostPtr); nnzb = *nnzTotalDevHostPtr; hipMalloc(&bsr_col_ind, sizeof(int)*nnzb); hipMalloc(&bsr_val, sizeof(float)*(block_dim * block_dim) * nnzb); scsr2bsr(handle, rocsparse_direction_row, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind);
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] the storage format of the blocks, rocsparse_direction_row or rocsparse_direction_column
m – [in] number of rows in the sparse CSR matrix.
n – [in] number of columns in the sparse CSR matrix.
csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_val – [in] array of
nnz
elements containing the values of the sparse CSR matrix.csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array of
nnz
elements containing the column indices of the sparse CSR matrix.block_dim – [in] size of the blocks in the sparse BSR matrix.
bsr_descr – [in] descriptor of the sparse BSR matrix. Currently, only rocsparse_matrix_type_general is supported.
bsr_val – [out] array of
nnzb*block_dim*block_dim
containing the values of the sparse BSR matrix.bsr_row_ptr – [out] array of
mb+1
elements that point to the start of every block row of the sparse BSR matrix.bsr_col_ind – [out] array of
nnzb
elements containing the block column indices of the sparse BSR matrix.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orblock_dim
is invalid.rocsparse_status_invalid_pointer –
bsr_val
,bsr_row_ptr
,bsr_col_ind
,csr_val
,csr_row_ptr
orcsr_col_ind
pointer is invalid.
rocsparse_csr2gebsr_nnz()#
-
rocsparse_status rocsparse_csr2gebsr_nnz(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, const rocsparse_mat_descr bsr_descr, rocsparse_int *bsr_row_ptr, rocsparse_int row_block_dim, rocsparse_int col_block_dim, rocsparse_int *bsr_nnz_devhost, void *temp_buffer)#
This function computes the number of nonzero block columns per row and the total number of nonzero blocks in a sparse GEneral BSR matrix given a sparse CSR matrix as input.
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] direction that specified whether to count nonzero elements by rocsparse_direction_row or by rocsparse_direction_row.
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_row_ptr – [in] integer array containing
m+1
elements that point to the start of each row of the CSR matrixcsr_col_ind – [in] integer array of the column indices for each non-zero element in the CSR matrix
bsr_descr – [in] descriptor of the sparse GEneral BSR matrix. Currently, only rocsparse_matrix_type_general is supported.
bsr_row_ptr – [out] integer array containing
mb+1
elements that point to the start of each block row of the General BSR matrixrow_block_dim – [in] the row block dimension of the GEneral BSR matrix. Between 1 and min(m, n)
col_block_dim – [in] the col block dimension of the GEneral BSR matrix. Between 1 and min(m, n)
bsr_nnz_devhost – [out] total number of nonzero elements in device or host memory.
temp_buffer – [in] buffer allocated by the user whose size is determined by calling
rocsparse_xcsr2gebsr_buffer_size
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orrow_block_dim
col_block_dim
is invalid.rocsparse_status_invalid_pointer –
csr_row_ptr
orcsr_col_ind
orbsr_row_ptr
orbsr_nnz_devhost
pointer is invalid.
rocsparse_csr2gebsr_buffer_size()#
-
rocsparse_status rocsparse_scsr2gebsr_buffer_size(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const float *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, size_t *buffer_size)#
-
rocsparse_status rocsparse_dcsr2gebsr_buffer_size(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const double *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, size_t *buffer_size)#
-
rocsparse_status rocsparse_ccsr2gebsr_buffer_size(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const rocsparse_float_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, size_t *buffer_size)#
-
rocsparse_status rocsparse_zcsr2gebsr_buffer_size(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const rocsparse_double_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, size_t *buffer_size)#
rocsparse_csr2gebsr_buffer_size
returns the size of the temporary buffer that is required byrocsparse_csr2gebcsr_nnz
,rocsparse_scsr2gebcsr
,rocsparse_dcsr2gebsr
,rocsparse_ccsr2gebsr
androcsparse_zcsr2gebsr
. The temporary storage buffer must be allocated by the user.This function computes the number of nonzero block columns per row and the total number of nonzero blocks in a sparse GEneral BSR matrix given a sparse CSR matrix as input.
Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] direction that specified whether to count nonzero elements by rocsparse_direction_row or by rocsparse_direction_row.
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_val – [in] array of
nnz
elements containing the values of the sparse CSR matrix.csr_row_ptr – [in] integer array containing
m+1
elements that point to the start of each row of the CSR matrixcsr_col_ind – [in] integer array of the column indices for each non-zero element in the CSR matrix
row_block_dim – [in] the row block dimension of the GEneral BSR matrix. Between 1 and
m
col_block_dim – [in] the col block dimension of the GEneral BSR matrix. Between 1 and
n
buffer_size – [out] number of bytes of the temporary storage buffer required by
rocsparse_csr2gebsr_nnz
androcsparse_Xcsr2gebsr
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orrow_block_dim
col_block_dim
is invalid.rocsparse_status_invalid_pointer –
csr_val
orcsr_row_ptr
orcsr_col_ind
orbsr_row_ptr
orbuffer_size
pointer is invalid.
rocsparse_csr2gebsr()#
-
rocsparse_status rocsparse_scsr2gebsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const float *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, const rocsparse_mat_descr bsr_descr, float *bsr_val, rocsparse_int *bsr_row_ptr, rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, void *temp_buffer)#
-
rocsparse_status rocsparse_dcsr2gebsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const double *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, const rocsparse_mat_descr bsr_descr, double *bsr_val, rocsparse_int *bsr_row_ptr, rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, void *temp_buffer)#
-
rocsparse_status rocsparse_ccsr2gebsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const rocsparse_float_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, const rocsparse_mat_descr bsr_descr, rocsparse_float_complex *bsr_val, rocsparse_int *bsr_row_ptr, rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, void *temp_buffer)#
-
rocsparse_status rocsparse_zcsr2gebsr(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr csr_descr, const rocsparse_double_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, const rocsparse_mat_descr bsr_descr, rocsparse_double_complex *bsr_val, rocsparse_int *bsr_row_ptr, rocsparse_int *bsr_col_ind, rocsparse_int row_block_dim, rocsparse_int col_block_dim, void *temp_buffer)#
Convert a sparse CSR matrix into a sparse GEneral BSR matrix.
rocsparse_csr2gebsr
converts a CSR matrix into a GEneral BSR matrix. It is assumed, thatbsr_val
,bsr_col_ind
andbsr_row_ptr
are allocated. Allocation size forbsr_row_ptr
is computed asmb+1
wheremb
is the number of block rows in the GEneral BSR matrix. Allocation size forbsr_val
andbsr_col_ind
is computed usingcsr2gebsr_nnz()
which also fills inbsr_row_ptr
.- Example
This example converts a CSR matrix into an BSR matrix.
// 1 4 0 0 0 0 // A = 0 2 3 0 0 0 // 5 0 0 7 8 0 // 0 0 9 0 6 0 rocsparse_int m = 4; rocsparse_int n = 6; rocsparse_int row_block_dim = 2; rocsparse_int col_block_dim = 3; rocsparse_int nnz = 9; rocsparse_int mb = (m + row_block_dim - 1) / row_block_dim; rocsparse_int nb = (n + col_block_dim - 1) / col_block_dim; csr_row_ptr[m+1] = {0, 2, 4, 7, 9}; // device memory csr_col_ind[nnz] = {0, 1, 1, 2, 0, 3, 4, 2, 4}; // device memory csr_val[nnz] = {1, 4, 2, 3, 5, 7, 8, 9, 6}; // device memory hipMalloc(&bsr_row_ptr, sizeof(rocsparse_int) *(mb + 1)); rocsparse_int nnzb; rocsparse_int* nnzTotalHostPtr = &nnzb; csr2gebsr_nnz(handle, rocsparse_direction_row, m, n, csr_descr, csr_row_ptr, csr_col_ind, row_block_dim, col_block_dim, bsr_descr, bsr_row_ptr, nnzTotalHostPtr); nnzb = *nnzTotalHostPtr; hipMalloc(&bsr_col_ind, sizeof(int)*nnzb); hipMalloc(&bsr_val, sizeof(float)*(row_block_dim * col_block_dim) * nnzb); scsr2gebsr(handle, rocsparse_direction_row, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, row_block_dim, col_block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind);
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] the storage format of the blocks, rocsparse_direction_row or rocsparse_direction_column
m – [in] number of rows in the sparse CSR matrix.
n – [in] number of columns in the sparse CSR matrix.
csr_descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_val – [in] array of
nnz
elements containing the values of the sparse CSR matrix.csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array of
nnz
elements containing the column indices of the sparse CSR matrix.bsr_descr – [in] descriptor of the sparse BSR matrix. Currently, only rocsparse_matrix_type_general is supported.
bsr_val – [out] array of
nnzb*
row_block_dim*
col_block_dim
containing the values of the sparse BSR matrix.bsr_row_ptr – [out] array of
mb+1
elements that point to the start of every block row of the sparse BSR matrix.bsr_col_ind – [out] array of
nnzb
elements containing the block column indices of the sparse BSR matrix.row_block_dim – [in] row size of the blocks in the sparse GEneral BSR matrix.
col_block_dim – [in] col size of the blocks in the sparse GEneral BSR matrix.
temp_buffer – [in] buffer allocated by the user whose size is determined by calling
rocsparse_xcsr2gebsr_buffer_size
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orrow_block_dim
orcol_block_dim
is invalid.rocsparse_status_invalid_pointer –
bsr_val
,bsr_row_ptr
,bsr_col_ind
,csr_val
,csr_row_ptr
orcsr_col_ind
pointer is invalid.
rocsparse_csr2csr_compress()#
-
rocsparse_status rocsparse_scsr2csr_compress(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr_A, const float *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, rocsparse_int nnz_A, const rocsparse_int *nnz_per_row, float *csr_val_C, rocsparse_int *csr_row_ptr_C, rocsparse_int *csr_col_ind_C, float tol)#
-
rocsparse_status rocsparse_dcsr2csr_compress(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr_A, const double *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, rocsparse_int nnz_A, const rocsparse_int *nnz_per_row, double *csr_val_C, rocsparse_int *csr_row_ptr_C, rocsparse_int *csr_col_ind_C, double tol)#
-
rocsparse_status rocsparse_ccsr2csr_compress(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr_A, const rocsparse_float_complex *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, rocsparse_int nnz_A, const rocsparse_int *nnz_per_row, rocsparse_float_complex *csr_val_C, rocsparse_int *csr_row_ptr_C, rocsparse_int *csr_col_ind_C, rocsparse_float_complex tol)#
-
rocsparse_status rocsparse_zcsr2csr_compress(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr_A, const rocsparse_double_complex *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, rocsparse_int nnz_A, const rocsparse_int *nnz_per_row, rocsparse_double_complex *csr_val_C, rocsparse_int *csr_row_ptr_C, rocsparse_int *csr_col_ind_C, rocsparse_double_complex tol)#
Convert a sparse CSR matrix into a compressed sparse CSR matrix.
rocsparse_csr2csr_compress
converts a CSR matrix into a compressed CSR matrix by removing entries in the input CSR matrix that are below a non-negative thresholdtol
- Example
This example demonstrates how to compress a CSR matrix. Compressing a CSR matrix involves two steps. First we use nnz_compress() to determine how many entries will be in the final compressed CSR matrix. Then we call csr2csr_compress() to finish the compression and fill in the column indices and values arrays of the compressed CSR matrix.
// 1 2 0 3 0 // A = 0 4 5 0 0 // 6 0 0 7 8 float tol = 0.0f; rocsparse_int m = 3; rocsparse_int n = 5; rocsparse_int nnz_A = 8; csr_row_ptr_A[m+1] = {0, 3, 5, 8}; // device memory csr_col_ind_A[nnz_A] = {0, 1, 3, 1, 2, 0, 3, 4}; // device memory csr_val_A[nnz_A] = {1, 0, 3, 4, 0, 6, 7, 0}; // device memory // Allocate memory for the row pointer array of the compressed CSR matrix rocsparse_int* csr_row_ptr_C; hipMalloc(csr_row_ptr_C, sizeof(rocsparse_int) * (m + 1)); // Allocate memory for the nnz_per_row array rocsparse_int* nnz_per_row; hipMalloc(nnz_per_row, sizeof(rocsparse_int) * m); // Call nnz_compress() which fills in nnz_per_row array and finds the number // of entries that will be in the compressed CSR matrix rocsparse_int nnz_C; nnz_compress(handle, m, descr_A, csr_val_A, csr_row_ptr_A, nnz_per_row, &nnz_C, tol); // Allocate column indices and values array for the compressed CSR matrix rocsparse_int* csr_col_ind_C; rocsparse_int* csr_val_C; hipMalloc(csr_col_ind_C, sizeof(rocsparse_int) * nnz_C; hipMalloc(csr_val_C, sizeof(rocsparse_int) * nnz_C; // Finish compression by calling csr2csr_compress() csr2csr_compress(handle, m, n, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, nnz_A, nnz_per_row, csr_val_C, csr_row_ptr_C, csr_col_ind_C, tol);
Note
In the case of complex matrices only the magnitude of the real part of
tol
is used.Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
descr_A – [in] matrix descriptor for the CSR matrix
csr_val_A – [in] array of
nnz_A
elements of the sparse CSR matrix.csr_row_ptr_A – [in] array of
m+1
elements that point to the start of every row of the uncompressed sparse CSR matrix.csr_col_ind_A – [in] array of
nnz_A
elements containing the column indices of the uncompressed sparse CSR matrix.nnz_A – [in] number of elements in the column indices and values arrays of the uncompressed sparse CSR matrix.
nnz_per_row – [in] array of length
m
containing the number of entries that will be kept per row in the final compressed CSR matrix.csr_val_C – [out] array of
nnz_C
elements of the compressed sparse CSC matrix.csr_row_ptr_C – [out] array of
m+1
elements that point to the start of every column of the compressed sparse CSR matrix.csr_col_ind_C – [out] array of
nnz_C
elements containing the row indices of the compressed sparse CSR matrix.tol – [in] the non-negative tolerance used for compression. If
tol
is complex then only the magnitude of the real part is used. Entries in the input uncompressed CSR array that are below the tolerance are removed in output compressed CSR matrix.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz_A
is invalid.rocsparse_status_invalid_value –
tol
is invalid.rocsparse_status_invalid_pointer –
csr_val_A
,csr_row_ptr_A
,csr_col_ind_A
,csr_val_C
,csr_row_ptr_C
,csr_col_ind_C
ornnz_per_row
pointer is invalid.
rocsparse_inverse_permutation()#
Warning
doxygenfunction: Cannot find function “rocsparse_inverse_permutation” in doxygen xml output for project “rocSPARSE Documentation” from directory: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-rocsparse/checkouts/docs-5.7.1/docs/doxygen/docBin/xml
rocsparse_create_identity_permutation()#
-
rocsparse_status rocsparse_create_identity_permutation(rocsparse_handle handle, rocsparse_int n, rocsparse_int *p)#
Create the identity map.
rocsparse_create_identity_permutation
stores the identity map inp
, such that \(p = 0:1:(n-1)\).for(i = 0; i < n; ++i) { p[i] = i; }
- Example
The following example creates an identity permutation.
rocsparse_int size = 200; // Allocate memory to hold the identity map rocsparse_int* perm; hipMalloc((void**)&perm, sizeof(rocsparse_int) * size); // Fill perm with the identity permutation rocsparse_create_identity_permutation(handle, size, perm);
Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
n – [in] size of the map
p
.p – [out] array of
n
integers containing the map.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
n
is invalid.rocsparse_status_invalid_pointer –
p
pointer is invalid.
rocsparse_csrsort_buffer_size()#
-
rocsparse_status rocsparse_csrsort_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, size_t *buffer_size)#
Sort a sparse CSR matrix.
rocsparse_csrsort_buffer_size
returns the size of the temporary storage buffer required by rocsparse_csrsort(). The temporary storage buffer must be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
nnz – [in] number of non-zero entries of the sparse CSR matrix.
csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [in] array of
nnz
elements containing the column indices of the sparse CSR matrix.buffer_size – [out] number of bytes of the temporary storage buffer required by rocsparse_csrsort().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz
is invalid.rocsparse_status_invalid_pointer –
csr_row_ptr
,csr_col_ind
orbuffer_size
pointer is invalid.
rocsparse_csrsort()#
-
rocsparse_status rocsparse_csrsort(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_mat_descr descr, const rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind, rocsparse_int *perm, void *temp_buffer)#
Sort a sparse CSR matrix.
rocsparse_csrsort
sorts a matrix in CSR format. The sorted permutation vectorperm
can be used to obtain sortedcsr_val
array. In this case,perm
must be initialized as the identity permutation, see rocsparse_create_identity_permutation().rocsparse_csrsort
requires extra temporary storage buffer that has to be allocated by the user. Storage buffer size can be determined by rocsparse_csrsort_buffer_size().- Example
The following example sorts a \(3 \times 3\) CSR matrix.
// 1 2 3 // A = 4 5 6 // 7 8 9 rocsparse_int m = 3; rocsparse_int n = 3; rocsparse_int nnz = 9; csr_row_ptr[m + 1] = {0, 3, 6, 9}; // device memory csr_col_ind[nnz] = {2, 0, 1, 0, 1, 2, 0, 2, 1}; // device memory csr_val[nnz] = {3, 1, 2, 4, 5, 6, 7, 9, 8}; // device memory // Create permutation vector perm as the identity map rocsparse_int* perm; hipMalloc((void**)&perm, sizeof(rocsparse_int) * nnz); rocsparse_create_identity_permutation(handle, nnz, perm); // Allocate temporary buffer size_t buffer_size; void* temp_buffer; rocsparse_csrsort_buffer_size(handle, m, n, nnz, csr_row_ptr, csr_col_ind, &buffer_size); hipMalloc(&temp_buffer, buffer_size); // Sort the CSR matrix rocsparse_csrsort(handle, m, n, nnz, descr, csr_row_ptr, csr_col_ind, perm, temp_buffer); // Gather sorted csr_val array float* csr_val_sorted; hipMalloc((void**)&csr_val_sorted, sizeof(float) * nnz); rocsparse_sgthr(handle, nnz, csr_val, csr_val_sorted, perm, rocsparse_index_base_zero); // Clean up hipFree(temp_buffer); hipFree(perm); hipFree(csr_val);
Note
perm
can beNULL
if a sorted permutation vector is not required.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSR matrix.
n – [in] number of columns of the sparse CSR matrix.
nnz – [in] number of non-zero entries of the sparse CSR matrix.
descr – [in] descriptor of the sparse CSR matrix. Currently, only rocsparse_matrix_type_general is supported.
csr_row_ptr – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix.csr_col_ind – [inout] array of
nnz
elements containing the column indices of the sparse CSR matrix.perm – [inout] array of
nnz
integers containing the unsorted map indices, can beNULL
.temp_buffer – [in] temporary storage buffer allocated by the user, size is returned by rocsparse_csrsort_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz
is invalid.rocsparse_status_invalid_pointer –
descr
,csr_row_ptr
,csr_col_ind
ortemp_buffer
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_status_not_implemented – rocsparse_matrix_type != rocsparse_matrix_type_general.
rocsparse_cscsort_buffer_size()#
-
rocsparse_status rocsparse_cscsort_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_int *csc_col_ptr, const rocsparse_int *csc_row_ind, size_t *buffer_size)#
Sort a sparse CSC matrix.
rocsparse_cscsort_buffer_size
returns the size of the temporary storage buffer required by rocsparse_cscsort(). The temporary storage buffer must be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSC matrix.
n – [in] number of columns of the sparse CSC matrix.
nnz – [in] number of non-zero entries of the sparse CSC matrix.
csc_col_ptr – [in] array of
n+1
elements that point to the start of every column of the sparse CSC matrix.csc_row_ind – [in] array of
nnz
elements containing the row indices of the sparse CSC matrix.buffer_size – [out] number of bytes of the temporary storage buffer required by rocsparse_cscsort().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz
is invalid.rocsparse_status_invalid_pointer –
csc_col_ptr
,csc_row_ind
orbuffer_size
pointer is invalid.
rocsparse_cscsort()#
-
rocsparse_status rocsparse_cscsort(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_mat_descr descr, const rocsparse_int *csc_col_ptr, rocsparse_int *csc_row_ind, rocsparse_int *perm, void *temp_buffer)#
Sort a sparse CSC matrix.
rocsparse_cscsort
sorts a matrix in CSC format. The sorted permutation vectorperm
can be used to obtain sortedcsc_val
array. In this case,perm
must be initialized as the identity permutation, see rocsparse_create_identity_permutation().rocsparse_cscsort
requires extra temporary storage buffer that has to be allocated by the user. Storage buffer size can be determined by rocsparse_cscsort_buffer_size().- Example
The following example sorts a \(3 \times 3\) CSC matrix.
// 1 2 3 // A = 4 5 6 // 7 8 9 rocsparse_int m = 3; rocsparse_int n = 3; rocsparse_int nnz = 9; csc_col_ptr[m + 1] = {0, 3, 6, 9}; // device memory csc_row_ind[nnz] = {2, 0, 1, 0, 1, 2, 0, 2, 1}; // device memory csc_val[nnz] = {7, 1, 4, 2, 5, 8, 3, 9, 6}; // device memory // Create permutation vector perm as the identity map rocsparse_int* perm; hipMalloc((void**)&perm, sizeof(rocsparse_int) * nnz); rocsparse_create_identity_permutation(handle, nnz, perm); // Allocate temporary buffer size_t buffer_size; void* temp_buffer; rocsparse_cscsort_buffer_size(handle, m, n, nnz, csc_col_ptr, csc_row_ind, &buffer_size); hipMalloc(&temp_buffer, buffer_size); // Sort the CSC matrix rocsparse_cscsort(handle, m, n, nnz, descr, csc_col_ptr, csc_row_ind, perm, temp_buffer); // Gather sorted csc_val array float* csc_val_sorted; hipMalloc((void**)&csc_val_sorted, sizeof(float) * nnz); rocsparse_sgthr(handle, nnz, csc_val, csc_val_sorted, perm, rocsparse_index_base_zero); // Clean up hipFree(temp_buffer); hipFree(perm); hipFree(csc_val);
Note
perm
can beNULL
if a sorted permutation vector is not required.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSC matrix.
n – [in] number of columns of the sparse CSC matrix.
nnz – [in] number of non-zero entries of the sparse CSC matrix.
descr – [in] descriptor of the sparse CSC matrix. Currently, only rocsparse_matrix_type_general is supported.
csc_col_ptr – [in] array of
n+1
elements that point to the start of every column of the sparse CSC matrix.csc_row_ind – [inout] array of
nnz
elements containing the row indices of the sparse CSC matrix.perm – [inout] array of
nnz
integers containing the unsorted map indices, can beNULL
.temp_buffer – [in] temporary storage buffer allocated by the user, size is returned by rocsparse_cscsort_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz
is invalid.rocsparse_status_invalid_pointer –
descr
,csc_col_ptr
,csc_row_ind
ortemp_buffer
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_status_not_implemented – rocsparse_matrix_type != rocsparse_matrix_type_general.
rocsparse_coosort_buffer_size()#
-
rocsparse_status rocsparse_coosort_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_int *coo_row_ind, const rocsparse_int *coo_col_ind, size_t *buffer_size)#
Sort a sparse COO matrix.
coosort_buffer_size
returns the size of the temporary storage buffer that is required by rocsparse_coosort_by_row() and rocsparse_coosort_by_column(). The temporary storage buffer has to be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse COO matrix.
n – [in] number of columns of the sparse COO matrix.
nnz – [in] number of non-zero entries of the sparse COO matrix.
coo_row_ind – [in] array of
nnz
elements containing the row indices of the sparse COO matrix.coo_col_ind – [in] array of
nnz
elements containing the column indices of the sparse COO matrix.buffer_size – [out] number of bytes of the temporary storage buffer required by rocsparse_coosort_by_row() and rocsparse_coosort_by_column().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz
is invalid.rocsparse_status_invalid_pointer –
coo_row_ind
,coo_col_ind
orbuffer_size
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_coosort_by_row()#
-
rocsparse_status rocsparse_coosort_by_row(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, rocsparse_int *coo_row_ind, rocsparse_int *coo_col_ind, rocsparse_int *perm, void *temp_buffer)#
Sort a sparse COO matrix by row.
rocsparse_coosort_by_row
sorts a matrix in COO format by row. The sorted permutation vectorperm
can be used to obtain sortedcoo_val
array. In this case,perm
must be initialized as the identity permutation, see rocsparse_create_identity_permutation().rocsparse_coosort_by_row
requires extra temporary storage buffer that has to be allocated by the user. Storage buffer size can be determined by rocsparse_coosort_buffer_size().- Example
The following example sorts a \(3 \times 3\) COO matrix by row indices.
// 1 2 3 // A = 4 5 6 // 7 8 9 rocsparse_int m = 3; rocsparse_int n = 3; rocsparse_int nnz = 9; coo_row_ind[nnz] = {0, 1, 2, 0, 1, 2, 0, 1, 2}; // device memory coo_col_ind[nnz] = {0, 0, 0, 1, 1, 1, 2, 2, 2}; // device memory coo_val[nnz] = {1, 4, 7, 2, 5, 8, 3, 6, 9}; // device memory // Create permutation vector perm as the identity map rocsparse_int* perm; hipMalloc((void**)&perm, sizeof(rocsparse_int) * nnz); rocsparse_create_identity_permutation(handle, nnz, perm); // Allocate temporary buffer size_t buffer_size; void* temp_buffer; rocsparse_coosort_buffer_size(handle, m, n, nnz, coo_row_ind, coo_col_ind, &buffer_size); hipMalloc(&temp_buffer, buffer_size); // Sort the COO matrix rocsparse_coosort_by_row(handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, temp_buffer); // Gather sorted coo_val array float* coo_val_sorted; hipMalloc((void**)&coo_val_sorted, sizeof(float) * nnz); rocsparse_sgthr(handle, nnz, coo_val, coo_val_sorted, perm, rocsparse_index_base_zero); // Clean up hipFree(temp_buffer); hipFree(perm); hipFree(coo_val);
Note
perm
can beNULL
if a sorted permutation vector is not required.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse COO matrix.
n – [in] number of columns of the sparse COO matrix.
nnz – [in] number of non-zero entries of the sparse COO matrix.
coo_row_ind – [inout] array of
nnz
elements containing the row indices of the sparse COO matrix.coo_col_ind – [inout] array of
nnz
elements containing the column indices of the sparse COO matrix.perm – [inout] array of
nnz
integers containing the unsorted map indices, can beNULL
.temp_buffer – [in] temporary storage buffer allocated by the user, size is returned by rocsparse_coosort_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz
is invalid.rocsparse_status_invalid_pointer –
coo_row_ind
,coo_col_ind
ortemp_buffer
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_coosort_by_column()#
-
rocsparse_status rocsparse_coosort_by_column(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, rocsparse_int *coo_row_ind, rocsparse_int *coo_col_ind, rocsparse_int *perm, void *temp_buffer)#
Sort a sparse COO matrix by column.
rocsparse_coosort_by_column
sorts a matrix in COO format by column. The sorted permutation vectorperm
can be used to obtain sortedcoo_val
array. In this case,perm
must be initialized as the identity permutation, see rocsparse_create_identity_permutation().rocsparse_coosort_by_column
requires extra temporary storage buffer that has to be allocated by the user. Storage buffer size can be determined by rocsparse_coosort_buffer_size().- Example
The following example sorts a \(3 \times 3\) COO matrix by column indices.
// 1 2 3 // A = 4 5 6 // 7 8 9 rocsparse_int m = 3; rocsparse_int n = 3; rocsparse_int nnz = 9; coo_row_ind[nnz] = {0, 0, 0, 1, 1, 1, 2, 2, 2}; // device memory coo_col_ind[nnz] = {0, 1, 2, 0, 1, 2, 0, 1, 2}; // device memory coo_val[nnz] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; // device memory // Create permutation vector perm as the identity map rocsparse_int* perm; hipMalloc((void**)&perm, sizeof(rocsparse_int) * nnz); rocsparse_create_identity_permutation(handle, nnz, perm); // Allocate temporary buffer size_t buffer_size; void* temp_buffer; rocsparse_coosort_buffer_size(handle, m, n, nnz, coo_row_ind, coo_col_ind, &buffer_size); hipMalloc(&temp_buffer, buffer_size); // Sort the COO matrix rocsparse_coosort_by_column(handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, temp_buffer); // Gather sorted coo_val array float* coo_val_sorted; hipMalloc((void**)&coo_val_sorted, sizeof(float) * nnz); rocsparse_sgthr(handle, nnz, coo_val, coo_val_sorted, perm, rocsparse_index_base_zero); // Clean up hipFree(temp_buffer); hipFree(perm); hipFree(coo_val);
Note
perm
can beNULL
if a sorted permutation vector is not required.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse COO matrix.
n – [in] number of columns of the sparse COO matrix.
nnz – [in] number of non-zero entries of the sparse COO matrix.
coo_row_ind – [inout] array of
nnz
elements containing the row indices of the sparse COO matrix.coo_col_ind – [inout] array of
nnz
elements containing the column indices of the sparse COO matrix.perm – [inout] array of
nnz
integers containing the unsorted map indices, can beNULL
.temp_buffer – [in] temporary storage buffer allocated by the user, size is returned by rocsparse_coosort_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,n
ornnz
is invalid.rocsparse_status_invalid_pointer –
coo_row_ind
,coo_col_ind
ortemp_buffer
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_nnz_compress()#
-
rocsparse_status rocsparse_snnz_compress(rocsparse_handle handle, rocsparse_int m, const rocsparse_mat_descr descr_A, const float *csr_val_A, const rocsparse_int *csr_row_ptr_A, rocsparse_int *nnz_per_row, rocsparse_int *nnz_C, float tol)#
-
rocsparse_status rocsparse_dnnz_compress(rocsparse_handle handle, rocsparse_int m, const rocsparse_mat_descr descr_A, const double *csr_val_A, const rocsparse_int *csr_row_ptr_A, rocsparse_int *nnz_per_row, rocsparse_int *nnz_C, double tol)#
-
rocsparse_status rocsparse_cnnz_compress(rocsparse_handle handle, rocsparse_int m, const rocsparse_mat_descr descr_A, const rocsparse_float_complex *csr_val_A, const rocsparse_int *csr_row_ptr_A, rocsparse_int *nnz_per_row, rocsparse_int *nnz_C, rocsparse_float_complex tol)#
-
rocsparse_status rocsparse_znnz_compress(rocsparse_handle handle, rocsparse_int m, const rocsparse_mat_descr descr_A, const rocsparse_double_complex *csr_val_A, const rocsparse_int *csr_row_ptr_A, rocsparse_int *nnz_per_row, rocsparse_int *nnz_C, rocsparse_double_complex tol)#
Given a sparse CSR matrix and a non-negative tolerance, this function computes how many entries would be left in each row of the matrix if elements less than the tolerance were removed. It also computes the total number of remaining elements in the matrix.
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse CSR matrix.
descr_A – [in] the descriptor of the sparse CSR matrix.
csr_val_A – [in] array of
nnz_A
elements of the sparse CSR matrix.csr_row_ptr_A – [in] array of
m+1
elements that point to the start of every row of the uncompressed sparse CSR matrix.nnz_per_row – [out] array of length
m
containing the number of entries that will be kept per row in the final compressed CSR matrix.nnz_C – [out] number of elements in the column indices and values arrays of the compressed sparse CSR matrix. Can be either host or device pointer.
tol – [in] the non-negative tolerance used for compression. If
tol
is complex then only the magnitude of the real part is used. Entries in the input uncompressed CSR array that are below the tolerance are removed in output compressed CSR matrix.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
is invalid.rocsparse_status_invalid_value –
tol
is invalid.rocsparse_status_invalid_pointer –
csr_val_A
orcsr_row_ptr_A
ornnz_per_row
ornnz_C
pointer is invalid.
rocsparse_nnz()#
-
rocsparse_status rocsparse_snnz(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const float *A, rocsparse_int ld, rocsparse_int *nnz_per_row_columns, rocsparse_int *nnz_total_dev_host_ptr)#
-
rocsparse_status rocsparse_dnnz(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const double *A, rocsparse_int ld, rocsparse_int *nnz_per_row_columns, rocsparse_int *nnz_total_dev_host_ptr)#
-
rocsparse_status rocsparse_cnnz(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_float_complex *A, rocsparse_int ld, rocsparse_int *nnz_per_row_columns, rocsparse_int *nnz_total_dev_host_ptr)#
-
rocsparse_status rocsparse_znnz(rocsparse_handle handle, rocsparse_direction dir, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_double_complex *A, rocsparse_int ld, rocsparse_int *nnz_per_row_columns, rocsparse_int *nnz_total_dev_host_ptr)#
This function computes the number of nonzero elements per row or column and the total number of nonzero elements in a dense matrix.
The routine does support asynchronous execution if the pointer mode is set to device.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
dir – [in] direction that specified whether to count nonzero elements by rocsparse_direction_row or by rocsparse_direction_row.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.descr – [in] the descriptor of the dense matrix
A
.A – [in] array of dimensions (
ld
,n
)ld – [in] leading dimension of dense array
A
.nnz_per_row_columns – [out] array of size
m
orn
containing the number of nonzero elements per row or column, respectively.nnz_total_dev_host_ptr – [out] total number of nonzero elements in device or host memory.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orld
is invalid.rocsparse_status_invalid_pointer –
A
ornnz_per_row_columns
ornnz_total_dev_host_ptr
pointer is invalid.
rocsparse_dense2csr()#
-
rocsparse_status rocsparse_sdense2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const float *A, rocsparse_int ld, const rocsparse_int *nnz_per_rows, float *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_ddense2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const double *A, rocsparse_int ld, const rocsparse_int *nnz_per_rows, double *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_cdense2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_float_complex *A, rocsparse_int ld, const rocsparse_int *nnz_per_rows, rocsparse_float_complex *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
-
rocsparse_status rocsparse_zdense2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_double_complex *A, rocsparse_int ld, const rocsparse_int *nnz_per_rows, rocsparse_double_complex *csr_val, rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind)#
This function converts the matrix A in dense format into a sparse matrix in CSR format. All the parameters are assumed to have been pre-allocated by the user and the arrays are filled in based on nnz_per_row, which can be pre-computed with rocsparse_xnnz().
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.A – [in] array of dimensions (
ld
,n
)ld – [in] leading dimension of dense array
A
.nnz_per_rows – [in] array of size
n
containing the number of non-zero elements per row.csr_val – [out] array of nnz ( =
csr_row_ptr
[m] -csr_row_ptr
[0] ) nonzero elements of matrixA
.csr_row_ptr – [out] integer array of m+1 elements that contains the start of every row and the end of the last row plus one.
csr_col_ind – [out] integer array of nnz ( =
csr_row_ptr
[m] - csr_row_ptr[0] ) column indices of the non-zero elements of matrixA
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orld
is invalid.rocsparse_status_invalid_pointer –
A
ornnz_per_rows
orcsr_val
csr_row_ptr
orcsr_col_ind
pointer is invalid.
rocsparse_dense2csc()#
-
rocsparse_status rocsparse_sdense2csc(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const float *A, rocsparse_int ld, const rocsparse_int *nnz_per_columns, float *csc_val, rocsparse_int *csc_col_ptr, rocsparse_int *csc_row_ind)#
-
rocsparse_status rocsparse_ddense2csc(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const double *A, rocsparse_int ld, const rocsparse_int *nnz_per_columns, double *csc_val, rocsparse_int *csc_col_ptr, rocsparse_int *csc_row_ind)#
-
rocsparse_status rocsparse_cdense2csc(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_float_complex *A, rocsparse_int ld, const rocsparse_int *nnz_per_columns, rocsparse_float_complex *csc_val, rocsparse_int *csc_col_ptr, rocsparse_int *csc_row_ind)#
-
rocsparse_status rocsparse_zdense2csc(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_double_complex *A, rocsparse_int ld, const rocsparse_int *nnz_per_columns, rocsparse_double_complex *csc_val, rocsparse_int *csc_col_ptr, rocsparse_int *csc_row_ind)#
This function converts the matrix A in dense format into a sparse matrix in CSC format. All the parameters are assumed to have been pre-allocated by the user and the arrays are filled in based on nnz_per_columns, which can be pre-computed with rocsparse_xnnz().
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.A – [in] array of dimensions (
ld
,n
)ld – [in] leading dimension of dense array
A
.nnz_per_columns – [in] array of size
n
containing the number of non-zero elements per column.csc_val – [out] array of nnz ( =
csc_col_ptr
[m] -csc_col_ptr
[0] ) nonzero elements of matrixA
.csc_col_ptr – [out] integer array of m+1 elements that contains the start of every column and the end of the last column plus one.
csc_row_ind – [out] integer array of nnz ( =
csc_col_ptr
[m] - csc_col_ptr[0] ) column indices of the non-zero elements of matrixA
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orld
is invalid.rocsparse_status_invalid_pointer –
A
ornnz_per_columns
orcsc_val
csc_col_ptr
orcsc_row_ind
pointer is invalid.
rocsparse_dense2coo()#
-
rocsparse_status rocsparse_sdense2coo(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const float *A, rocsparse_int ld, const rocsparse_int *nnz_per_rows, float *coo_val, rocsparse_int *coo_row_ind, rocsparse_int *coo_col_ind)#
-
rocsparse_status rocsparse_ddense2coo(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const double *A, rocsparse_int ld, const rocsparse_int *nnz_per_rows, double *coo_val, rocsparse_int *coo_row_ind, rocsparse_int *coo_col_ind)#
-
rocsparse_status rocsparse_cdense2coo(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_float_complex *A, rocsparse_int ld, const rocsparse_int *nnz_per_rows, rocsparse_float_complex *coo_val, rocsparse_int *coo_row_ind, rocsparse_int *coo_col_ind)#
-
rocsparse_status rocsparse_zdense2coo(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_double_complex *A, rocsparse_int ld, const rocsparse_int *nnz_per_rows, rocsparse_double_complex *coo_val, rocsparse_int *coo_row_ind, rocsparse_int *coo_col_ind)#
This function converts the matrix A in dense format into a sparse matrix in COO format. All the parameters are assumed to have been pre-allocated by the user and the arrays are filled in based on nnz_per_rows, which can be pre-computed with rocsparse_xnnz().
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.A – [in] array of dimensions (
ld
,n
)ld – [in] leading dimension of dense array
A
.nnz_per_rows – [in] array of size
n
containing the number of non-zero elements per row.coo_val – [out] array of nnz nonzero elements of matrix
A
.coo_row_ind – [out] integer array of nnz row indices of the non-zero elements of matrix
A
.coo_col_ind – [out] integer array of nnz column indices of the non-zero elements of matrix
A
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orld
is invalid.rocsparse_status_invalid_pointer –
A
ornnz_per_rows
orcoo_val
coo_col_ind
orcoo_row_ind
pointer is invalid.
rocsparse_csr2dense()#
-
rocsparse_status rocsparse_scsr2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const float *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, float *A, rocsparse_int ld)#
-
rocsparse_status rocsparse_dcsr2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const double *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, double *A, rocsparse_int ld)#
-
rocsparse_status rocsparse_ccsr2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_float_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_float_complex *A, rocsparse_int ld)#
-
rocsparse_status rocsparse_zcsr2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_double_complex *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_double_complex *A, rocsparse_int ld)#
This function converts the sparse matrix in CSR format into a dense matrix.
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.csr_val – [in] array of nnz ( =
csr_row_ptr
[m] -csr_row_ptr
[0] ) nonzero elements of matrixA
.csr_row_ptr – [in] integer array of m+1 elements that contains the start of every row and the end of the last row plus one.
csr_col_ind – [in] integer array of nnz ( =
csr_row_ptr
[m] - csr_row_ptr[0] ) column indices of the non-zero elements of matrixA
.A – [out] array of dimensions (
ld
,n
)ld – [out] leading dimension of dense array
A
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orld
is invalid.rocsparse_status_invalid_pointer –
A
orcsr_val
csr_row_ptr
orcsr_col_ind
pointer is invalid.
rocsparse_csc2dense()#
-
rocsparse_status rocsparse_scsc2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const float *csc_val, const rocsparse_int *csc_col_ptr, const rocsparse_int *csc_row_ind, float *A, rocsparse_int ld)#
-
rocsparse_status rocsparse_dcsc2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const double *csc_val, const rocsparse_int *csc_col_ptr, const rocsparse_int *csc_row_ind, double *A, rocsparse_int ld)#
-
rocsparse_status rocsparse_ccsc2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_float_complex *csc_val, const rocsparse_int *csc_col_ptr, const rocsparse_int *csc_row_ind, rocsparse_float_complex *A, rocsparse_int ld)#
-
rocsparse_status rocsparse_zcsc2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const rocsparse_mat_descr descr, const rocsparse_double_complex *csc_val, const rocsparse_int *csc_col_ptr, const rocsparse_int *csc_row_ind, rocsparse_double_complex *A, rocsparse_int ld)#
This function converts the sparse matrix in CSC format into a dense matrix.
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.csc_val – [in] array of nnz ( =
csc_col_ptr
[m] -csc_col_ptr
[0] ) nonzero elements of matrixA
.csc_col_ptr – [in] integer array of m+1 elements that contains the start of every row and the end of the last row plus one.
csc_row_ind – [in] integer array of nnz ( =
csc_col_ptr
[m] - csc_col_ptr[0] ) column indices of the non-zero elements of matrixA
.A – [out] array of dimensions (
ld
,n
)ld – [out] leading dimension of dense array
A
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orld
is invalid.rocsparse_status_invalid_pointer –
A
orcsc_val
csc_col_ptr
orcsc_row_ind
pointer is invalid.
rocsparse_coo2dense()#
-
rocsparse_status rocsparse_scoo2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_mat_descr descr, const float *coo_val, const rocsparse_int *coo_row_ind, const rocsparse_int *coo_col_ind, float *A, rocsparse_int ld)#
-
rocsparse_status rocsparse_dcoo2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_mat_descr descr, const double *coo_val, const rocsparse_int *coo_row_ind, const rocsparse_int *coo_col_ind, double *A, rocsparse_int ld)#
-
rocsparse_status rocsparse_ccoo2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_mat_descr descr, const rocsparse_float_complex *coo_val, const rocsparse_int *coo_row_ind, const rocsparse_int *coo_col_ind, rocsparse_float_complex *A, rocsparse_int ld)#
-
rocsparse_status rocsparse_zcoo2dense(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz, const rocsparse_mat_descr descr, const rocsparse_double_complex *coo_val, const rocsparse_int *coo_row_ind, const rocsparse_int *coo_col_ind, rocsparse_double_complex *A, rocsparse_int ld)#
This function converts the sparse matrix in COO format into a dense matrix.
Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.nnz – [in] number of non-zero entries of the sparse COO matrix.
descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.coo_val – [in] array of nnz nonzero elements of matrix
A
.coo_row_ind – [in] integer array of nnz row indices of the non-zero elements of matrix
A
.coo_col_ind – [in] integer array of nnz column indices of the non-zero elements of matrix
A
.A – [out] array of dimensions (
ld
,n
)ld – [out] leading dimension of dense array
A
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
ornnz
orld
is invalid.rocsparse_status_invalid_pointer –
A
orcoo_val
coo_col_ind
orcoo_row_ind
pointer is invalid.
rocsparse_prune_dense2csr_buffer_size()#
-
rocsparse_status rocsparse_sprune_dense2csr_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const float *A, rocsparse_int lda, const float *threshold, const rocsparse_mat_descr descr, const float *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, size_t *buffer_size)#
-
rocsparse_status rocsparse_dprune_dense2csr_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const double *A, rocsparse_int lda, const double *threshold, const rocsparse_mat_descr descr, const double *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, size_t *buffer_size)#
This function computes the the size of the user allocated temporary storage buffer used when converting and pruning a dense matrix to a CSR matrix.
rocsparse_prune_dense2csr_buffer_size
returns the size of the temporary storage buffer that is required by rocsparse_sprune_dense2csr_nnz(), rocsparse_dprune_dense2csr_nnz(), rocsparse_sprune_dense2csr(), and rocsparse_dprune_dense2csr(). The temporary storage buffer must be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.A – [in] array of dimensions (
lda
,n
)lda – [in] leading dimension of dense array
A
.threshold – [in] pointer to the pruning non-negative threshold which can exist in either host or device memory.
descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.csr_val – [in] array of nnz ( =
csr_row_ptr
[m] -csr_row_ptr
[0] ) nonzero elements of matrixA
.csr_row_ptr – [in] integer array of
m+1
elements that contains the start of every row and the end of the last row plus one.csr_col_ind – [in] integer array of nnz ( =
csr_row_ptr
[m] - csr_row_ptr[0] ) column indices of the non-zero elements of matrixA
.buffer_size – [out] number of bytes of the temporary storage buffer required by rocsparse_sprune_dense2csr_nnz(), rocsparse_dprune_dense2csr_nnz(), rocsparse_sprune_dense2csr() and rocsparse_dprune_dense2csr().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_pointer –
buffer_size
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_prune_dense2csr_nnz()#
-
rocsparse_status rocsparse_sprune_dense2csr_nnz(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const float *A, rocsparse_int lda, const float *threshold, const rocsparse_mat_descr descr, rocsparse_int *csr_row_ptr, rocsparse_int *nnz_total_dev_host_ptr, void *temp_buffer)#
-
rocsparse_status rocsparse_dprune_dense2csr_nnz(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const double *A, rocsparse_int lda, const double *threshold, const rocsparse_mat_descr descr, rocsparse_int *csr_row_ptr, rocsparse_int *nnz_total_dev_host_ptr, void *temp_buffer)#
This function computes the number of nonzero elements per row and the total number of nonzero elements in a dense matrix once elements less than the threshold are pruned from the matrix.
The routine does support asynchronous execution if the pointer mode is set to device.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.A – [in] array of dimensions (
lda
,n
)lda – [in] leading dimension of dense array
A
.threshold – [in] pointer to the pruning non-negative threshold which can exist in either host or device memory.
descr – [in] the descriptor of the dense matrix
A
.csr_row_ptr – [out] integer array of
m+1
elements that contains the start of every row and the end of the last row plus one.nnz_total_dev_host_ptr – [out] total number of nonzero elements in device or host memory.
temp_buffer – [out] buffer allocated by the user whose size is determined by calling rocsparse_xprune_dense2csr_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orlda
is invalid.rocsparse_status_invalid_pointer –
A
orthreshold
ordescr
orcsr_row_ptr
ornnz_total_dev_host_ptr
ortemp_buffer
pointer is invalid.
rocsparse_prune_dense2csr()#
-
rocsparse_status rocsparse_sprune_dense2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const float *A, rocsparse_int lda, const float *threshold, const rocsparse_mat_descr descr, float *csr_val, const rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind, void *temp_buffer)#
-
rocsparse_status rocsparse_dprune_dense2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const double *A, rocsparse_int lda, const double *threshold, const rocsparse_mat_descr descr, double *csr_val, const rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind, void *temp_buffer)#
This function converts the matrix A in dense format into a sparse matrix in CSR format while pruning values that are less than the threshold. All the parameters are assumed to have been pre-allocated by the user.
The user first allocates
csr_row_ptr
to havem+1
elements and then calls rocsparse_xprune_dense2csr_nnz() which fills in thecsr_row_ptr
array and stores the number of elements that are larger than the pruning threshold innnz_total_dev_host_ptr
. The user then allocatescsr_col_ind
andcsr_val
to have sizennz_total_dev_host_ptr
and completes the conversion by calling rocsparse_xprune_dense2csr(). A temporary storage buffer is used by both rocsparse_xprune_dense2csr_nnz() and rocsparse_xprune_dense2csr() and must be allocated by the user and whose size is determined by rocsparse_xprune_dense2csr_buffer_size().Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.A – [in] array of dimensions (
lda
,n
)lda – [in] leading dimension of dense array
A
.threshold – [in] pointer to the non-negative pruning threshold which can exist in either host or device memory.
descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.csr_val – [out] array of nnz ( =
csr_row_ptr
[m] -csr_row_ptr
[0] ) nonzero elements of matrixA
.csr_row_ptr – [in] integer array of
m+1
elements that contains the start of every row and the end of the last row plus one.csr_col_ind – [out] integer array of nnz ( =
csr_row_ptr
[m] - csr_row_ptr[0] ) column indices of the non-zero elements of matrixA
.temp_buffer – [in] temporary storage buffer allocated by the user, size is returned by rocsparse_xprune_dense2csr_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orlda
is invalid.rocsparse_status_invalid_pointer –
A
ordescr
orthreshold
orcsr_val
orcsr_row_ptr
orcsr_col_ind
ortemp_buffer
pointer is invalid.
rocsparse_prune_csr2csr_buffer_size()#
-
rocsparse_status rocsparse_sprune_csr2csr_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const float *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, const float *threshold, const rocsparse_mat_descr csr_descr_C, const float *csr_val_C, const rocsparse_int *csr_row_ptr_C, const rocsparse_int *csr_col_ind_C, size_t *buffer_size)#
-
rocsparse_status rocsparse_dprune_csr2csr_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const double *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, const double *threshold, const rocsparse_mat_descr csr_descr_C, const double *csr_val_C, const rocsparse_int *csr_row_ptr_C, const rocsparse_int *csr_col_ind_C, size_t *buffer_size)#
Convert and prune sparse CSR matrix into a sparse CSR matrix.
rocsparse_prune_csr2csr_buffer_size
returns the size of the temporary buffer that is required byrocsparse_sprune_csr2csr_nnz
,rocsparse_dprune_csr2csr_nnz
,rocsparse_sprune_csr2csr
, androcsparse_dprune_csr2csr
. The temporary storage buffer must be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows in the sparse CSR matrix.
n – [in] number of columns in the sparse CSR matrix.
nnz_A – [in] number of non-zeros in the sparse CSR matrix A.
csr_descr_A – [in] descriptor of the sparse CSR matrix A. Currently, only rocsparse_matrix_type_general is supported.
csr_val_A – [in] array of
nnz_A
elements containing the values of the sparse CSR matrix A.csr_row_ptr_A – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix A.csr_col_ind_A – [in] array of
nnz_A
elements containing the column indices of the sparse CSR matrix A.threshold – [in] pointer to the non-negative pruning threshold which can exist in either host or device memory.
csr_descr_C – [in] descriptor of the sparse CSR matrix C. Currently, only rocsparse_matrix_type_general is supported.
csr_val_C – [in] array of
nnz_C
elements containing the values of the sparse CSR matrix C.csr_row_ptr_C – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix C.csr_col_ind_C – [in] array of
nnz_C
elements containing the column indices of the sparse CSR matrix C.buffer_size – [out] number of bytes of the temporary storage buffer required by
rocsparse_sprune_csr2csr_nnz
,rocsparse_dprune_csr2csr_nnz
,rocsparse_sprune_csr2csr
, androcsparse_dprune_csr2csr
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_pointer –
buffer_size
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_prune_csr2csr_nnz()#
-
rocsparse_status rocsparse_sprune_csr2csr_nnz(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const float *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, const float *threshold, const rocsparse_mat_descr csr_descr_C, rocsparse_int *csr_row_ptr_C, rocsparse_int *nnz_total_dev_host_ptr, void *temp_buffer)#
-
rocsparse_status rocsparse_dprune_csr2csr_nnz(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const double *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, const double *threshold, const rocsparse_mat_descr csr_descr_C, rocsparse_int *csr_row_ptr_C, rocsparse_int *nnz_total_dev_host_ptr, void *temp_buffer)#
Convert and prune sparse CSR matrix into a sparse CSR matrix.
rocsparse_prune_csr2csr_nnz
computes the number of nonzero elements per row and the total number of nonzero elements in a sparse CSR matrix once elements less than the threshold are pruned from the matrix.Note
The routine does support asynchronous execution if the pointer mode is set to device.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows in the sparse CSR matrix.
n – [in] number of columns in the sparse CSR matrix.
nnz_A – [in] number of non-zeros in the sparse CSR matrix A.
csr_descr_A – [in] descriptor of the sparse CSR matrix A. Currently, only rocsparse_matrix_type_general is supported.
csr_val_A – [in] array of
nnz_A
elements containing the values of the sparse CSR matrix A.csr_row_ptr_A – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix A.csr_col_ind_A – [in] array of
nnz_A
elements containing the column indices of the sparse CSR matrix A.threshold – [in] pointer to the non-negative pruning threshold which can exist in either host or device memory.
csr_descr_C – [in] descriptor of the sparse CSR matrix C. Currently, only rocsparse_matrix_type_general is supported.
csr_row_ptr_C – [out] array of
m+1
elements that point to the start of every row of the sparse CSR matrix C.nnz_total_dev_host_ptr – [out] total number of nonzero elements in device or host memory.
temp_buffer – [out] buffer allocated by the user whose size is determined by calling
rocsparse_xprune_csr2csr_buffer_size()
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
ornnz_A
is invalid.rocsparse_status_invalid_pointer –
threshold
orcsr_descr_A
orcsr_descr_C
orcsr_val_A
orcsr_row_ptr_A
orcsr_col_ind_A
orcsr_row_ptr_C
ornnz_total_dev_host_ptr
ortemp_buffer
pointer is invalid.
rocsparse_prune_csr2csr()#
-
rocsparse_status rocsparse_sprune_csr2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const float *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, const float *threshold, const rocsparse_mat_descr csr_descr_C, float *csr_val_C, const rocsparse_int *csr_row_ptr_C, rocsparse_int *csr_col_ind_C, void *temp_buffer)#
-
rocsparse_status rocsparse_dprune_csr2csr(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const double *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, const double *threshold, const rocsparse_mat_descr csr_descr_C, double *csr_val_C, const rocsparse_int *csr_row_ptr_C, rocsparse_int *csr_col_ind_C, void *temp_buffer)#
Convert and prune sparse CSR matrix into a sparse CSR matrix.
This function converts the sparse CSR matrix A into a sparse CSR matrix C by pruning values in A that are less than the threshold. All the parameters are assumed to have been pre-allocated by the user. The user first calls rocsparse_xprune_csr2csr_buffer_size() to determine the size of the buffer used by rocsparse_xprune_csr2csr_nnz() and rocsparse_xprune_csr2csr() which the user then allocates. The user then allocates
csr_row_ptr_C
to havem+1
elements and then calls rocsparse_xprune_csr2csr_nnz() which fills in thecsr_row_ptr_C
array stores then number of elements that are larger than the pruning threshold innnz_total_dev_host_ptr
. The user then calls rocsparse_xprune_csr2csr() to complete the conversion.Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows in the sparse CSR matrix.
n – [in] number of columns in the sparse CSR matrix.
nnz_A – [in] number of non-zeros in the sparse CSR matrix A.
csr_descr_A – [in] descriptor of the sparse CSR matrix A. Currently, only rocsparse_matrix_type_general is supported.
csr_val_A – [in] array of
nnz_A
elements containing the values of the sparse CSR matrix A.csr_row_ptr_A – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix A.csr_col_ind_A – [in] array of
nnz_A
elements containing the column indices of the sparse CSR matrix A.threshold – [in] pointer to the non-negative pruning threshold which can exist in either host or device memory.
csr_descr_C – [in] descriptor of the sparse CSR matrix C. Currently, only rocsparse_matrix_type_general is supported.
csr_val_C – [out] array of
nnz_C
elements containing the values of the sparse CSR matrix C.csr_row_ptr_C – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix C.csr_col_ind_C – [out] array of
nnz_C
elements containing the column indices of the sparse CSR matrix C.temp_buffer – [in] buffer allocated by the user whose size is determined by calling
rocsparse_xprune_csr2csr_buffer_size()
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
ornnz_A
is invalid.rocsparse_status_invalid_pointer –
threshold
orcsr_descr_A
orcsr_descr_C
orcsr_val_A
orcsr_row_ptr_A
orcsr_col_ind_A
orcsr_val_C
orcsr_row_ptr_C
orcsr_col_ind_C
ortemp_buffer
pointer is invalid.
rocsparse_prune_dense2csr_by_percentage_buffer_size()#
-
rocsparse_status rocsparse_sprune_dense2csr_by_percentage_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const float *A, rocsparse_int lda, float percentage, const rocsparse_mat_descr descr, const float *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_mat_info info, size_t *buffer_size)#
-
rocsparse_status rocsparse_dprune_dense2csr_by_percentage_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const double *A, rocsparse_int lda, double percentage, const rocsparse_mat_descr descr, const double *csr_val, const rocsparse_int *csr_row_ptr, const rocsparse_int *csr_col_ind, rocsparse_mat_info info, size_t *buffer_size)#
This function computes the size of the user allocated temporary storage buffer used when converting and pruning by percentage a dense matrix to a CSR matrix.
When converting and pruning a dense matrix A to a CSR matrix by percentage the following steps are performed. First the user calls
rocsparse_prune_dense2csr_by_percentage_buffer_size
which determines the size of the temporary storage buffer. Once determined, this buffer must be allocated by the user. Next the user allocates the csr_row_ptr array to havem+1
elements and callsrocsparse_prune_dense2csr_nnz_by_percentage
. Finally the user finishes the conversion by allocating the csr_col_ind and csr_val arrays (whos size is determined by the value at nnz_total_dev_host_ptr) and callingrocsparse_prune_dense2csr_by_percentage
.The pruning by percentage works by first sorting the absolute values of the dense matrix
A
. We then determine a position in this sorted array by\[ pos = ceil(m*n*(percentage/100)) - 1 pos = min(pos, m*n-1) pos = max(pos, 0) threshold = sorted_A[pos] \]Once we have this threshold we prune values in the dense matrixA
as inrocsparse_prune_dense2csr
.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.A – [in] array of dimensions (
lda
,n
)lda – [in] leading dimension of dense array
A
.percentage – [in] percentage >= 0 and percentage <= 100.
descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.csr_val – [in] array of nnz ( =
csr_row_ptr
[m] -csr_row_ptr
[0] ) nonzero elements of matrixA
.csr_row_ptr – [in] integer array of
m+1
elements that contains the start of every row and the end of the last row plus one.csr_col_ind – [in] integer array of nnz ( =
csr_row_ptr
[m] - csr_row_ptr[0] ) column indices of the non-zero elements of matrixA
.info – [in] prune information structure
buffer_size – [out] number of bytes of the temporary storage buffer required by rocsparse_sprune_dense2csr_nnz_by_percentage(), rocsparse_dprune_dense2csr_nnz_by_percentage(), rocsparse_sprune_dense2csr_by_percentage() and rocsparse_dprune_dense2csr_by_percentage().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_pointer –
buffer_size
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_prune_dense2csr_nnz_by_percentage()#
-
rocsparse_status rocsparse_sprune_dense2csr_nnz_by_percentage(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const float *A, rocsparse_int lda, float percentage, const rocsparse_mat_descr descr, rocsparse_int *csr_row_ptr, rocsparse_int *nnz_total_dev_host_ptr, rocsparse_mat_info info, void *temp_buffer)#
-
rocsparse_status rocsparse_dprune_dense2csr_nnz_by_percentage(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const double *A, rocsparse_int lda, double percentage, const rocsparse_mat_descr descr, rocsparse_int *csr_row_ptr, rocsparse_int *nnz_total_dev_host_ptr, rocsparse_mat_info info, void *temp_buffer)#
This function computes the number of nonzero elements per row and the total number of nonzero elements in a dense matrix when converting and pruning by percentage a dense matrix to a CSR matrix.
When converting and pruning a dense matrix A to a CSR matrix by percentage the following steps are performed. First the user calls
rocsparse_prune_dense2csr_by_percentage_buffer_size
which determines the size of the temporary storage buffer. Once determined, this buffer must be allocated by the user. Next the user allocates the csr_row_ptr array to havem+1
elements and callsrocsparse_prune_dense2csr_nnz_by_percentage
. Finally the user finishes the conversion by allocating the csr_col_ind and csr_val arrays (whos size is determined by the value at nnz_total_dev_host_ptr) and callingrocsparse_prune_dense2csr_by_percentage
.The pruning by percentage works by first sorting the absolute values of the dense matrix
A
. We then determine a position in this sorted array by\[ pos = ceil(m*n*(percentage/100)) - 1 pos = min(pos, m*n-1) pos = max(pos, 0) threshold = sorted_A[pos] \]Once we have this threshold we prune values in the dense matrixA
as inrocsparse_prune_dense2csr
.Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.A – [in] array of dimensions (
lda
,n
)lda – [in] leading dimension of dense array
A
.percentage – [in] percentage >= 0 and percentage <= 100.
descr – [in] the descriptor of the dense matrix
A
.csr_row_ptr – [out] integer array of
m+1
elements that contains the start of every row and the end of the last row plus one.nnz_total_dev_host_ptr – [out] total number of nonzero elements in device or host memory.
info – [in] prune information structure
temp_buffer – [out] buffer allocated by the user whose size is determined by calling rocsparse_xprune_dense2csr_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orlda
orpercentage
is invalid.rocsparse_status_invalid_pointer –
A
ordescr
orinfo
orcsr_row_ptr
ornnz_total_dev_host_ptr
ortemp_buffer
pointer is invalid.
rocsparse_prune_dense2csr_by_percentage()#
-
rocsparse_status rocsparse_sprune_dense2csr_by_percentage(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const float *A, rocsparse_int lda, float percentage, const rocsparse_mat_descr descr, float *csr_val, const rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind, rocsparse_mat_info info, void *temp_buffer)#
-
rocsparse_status rocsparse_dprune_dense2csr_by_percentage(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, const double *A, rocsparse_int lda, double percentage, const rocsparse_mat_descr descr, double *csr_val, const rocsparse_int *csr_row_ptr, rocsparse_int *csr_col_ind, rocsparse_mat_info info, void *temp_buffer)#
This function converts the matrix A in dense format into a sparse matrix in CSR format while pruning values based on percentage.
When converting and pruning a dense matrix A to a CSR matrix by percentage the following steps are performed. First the user calls
rocsparse_prune_dense2csr_by_percentage_buffer_size
which determines the size of the temporary storage buffer. Once determined, this buffer must be allocated by the user. Next the user allocates the csr_row_ptr array to havem+1
elements and callsrocsparse_prune_dense2csr_nnz_by_percentage
. Finally the user finishes the conversion by allocating the csr_col_ind and csr_val arrays (whos size is determined by the value at nnz_total_dev_host_ptr) and callingrocsparse_prune_dense2csr_by_percentage
.The pruning by percentage works by first sorting the absolute values of the dense matrix
A
. We then determine a position in this sorted array by\[ pos = ceil(m*n*(percentage/100)) - 1 pos = min(pos, m*n-1) pos = max(pos, 0) threshold = sorted_A[pos] \]Once we have this threshold we prune values in the dense matrixA
as inrocsparse_prune_dense2csr
.Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the dense matrix
A
.n – [in] number of columns of the dense matrix
A
.A – [in] array of dimensions (
lda
,n
)lda – [in] leading dimension of dense array
A
.percentage – [in] percentage >= 0 and percentage <= 100.
descr – [in] the descriptor of the dense matrix
A
, the supported matrix type is rocsparse_matrix_type_general and also any valid value of the rocsparse_index_base.csr_val – [out] array of nnz ( =
csr_row_ptr
[m] -csr_row_ptr
[0] ) nonzero elements of matrixA
.csr_row_ptr – [in] integer array of
m+1
elements that contains the start of every row and the end of the last row plus one.csr_col_ind – [out] integer array of nnz ( =
csr_row_ptr
[m] - csr_row_ptr[0] ) column indices of the non-zero elements of matrixA
.info – [in] prune information structure
temp_buffer – [in] temporary storage buffer allocated by the user, size is returned by rocsparse_xprune_dense2csr_buffer_size().
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
orlda
orpercentage
is invalid.rocsparse_status_invalid_pointer –
A
ordescr
orinfo
orcsr_val
orcsr_row_ptr
orcsr_col_ind
ortemp_buffer
pointer is invalid.
rocsparse_prune_csr2csr_by_percentage_buffer_size()#
-
rocsparse_status rocsparse_sprune_csr2csr_by_percentage_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const float *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, float percentage, const rocsparse_mat_descr csr_descr_C, const float *csr_val_C, const rocsparse_int *csr_row_ptr_C, const rocsparse_int *csr_col_ind_C, rocsparse_mat_info info, size_t *buffer_size)#
-
rocsparse_status rocsparse_dprune_csr2csr_by_percentage_buffer_size(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const double *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, double percentage, const rocsparse_mat_descr csr_descr_C, const double *csr_val_C, const rocsparse_int *csr_row_ptr_C, const rocsparse_int *csr_col_ind_C, rocsparse_mat_info info, size_t *buffer_size)#
Convert and prune by percentage a sparse CSR matrix into a sparse CSR matrix.
rocsparse_prune_csr2csr__by_percentage_buffer_size
returns the size of the temporary buffer that is required byrocsparse_sprune_csr2csr_nnz_by_percentage
,rocsparse_dprune_csr2csr_nnz_by_percentage
,rocsparse_sprune_csr2csr_by_percentage
, androcsparse_dprune_csr2csr_by_percentage
. The temporary storage buffer must be allocated by the user.Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows in the sparse CSR matrix.
n – [in] number of columns in the sparse CSR matrix.
nnz_A – [in] number of non-zeros in the sparse CSR matrix A.
csr_descr_A – [in] descriptor of the sparse CSR matrix A. Currently, only rocsparse_matrix_type_general is supported.
csr_val_A – [in] array of
nnz_A
elements containing the values of the sparse CSR matrix A.csr_row_ptr_A – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix A.csr_col_ind_A – [in] array of
nnz_A
elements containing the column indices of the sparse CSR matrix A.percentage – [in] percentage >= 0 and percentage <= 100.
csr_descr_C – [in] descriptor of the sparse CSR matrix C. Currently, only rocsparse_matrix_type_general is supported.
csr_val_C – [in] array of
nnz_C
elements containing the values of the sparse CSR matrix C.csr_row_ptr_C – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix C.csr_col_ind_C – [in] array of
nnz_C
elements containing the column indices of the sparse CSR matrix C.info – [in] prune info structure.
buffer_size – [out] number of bytes of the temporary storage buffer required by
rocsparse_sprune_csr2csr_nnz_by_percentage
,rocsparse_dprune_csr2csr_nnz_by_percentage
,rocsparse_sprune_csr2csr_by_percentage
, androcsparse_dprune_csr2csr_by_percentage
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_pointer –
buffer_size
pointer is invalid.rocsparse_status_internal_error – an internal error occurred.
rocsparse_prune_csr2csr_nnz_by_percentage()#
-
rocsparse_status rocsparse_sprune_csr2csr_nnz_by_percentage(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const float *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, float percentage, const rocsparse_mat_descr csr_descr_C, rocsparse_int *csr_row_ptr_C, rocsparse_int *nnz_total_dev_host_ptr, rocsparse_mat_info info, void *temp_buffer)#
-
rocsparse_status rocsparse_dprune_csr2csr_nnz_by_percentage(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const double *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, double percentage, const rocsparse_mat_descr csr_descr_C, rocsparse_int *csr_row_ptr_C, rocsparse_int *nnz_total_dev_host_ptr, rocsparse_mat_info info, void *temp_buffer)#
Convert and prune by percentage a sparse CSR matrix into a sparse CSR matrix.
rocsparse_prune_csr2csr_nnz_by_percentage
computes the number of nonzero elements per row and the total number of nonzero elements in a sparse CSR matrix once elements less than the threshold are pruned from the matrix.Note
The routine does support asynchronous execution if the pointer mode is set to device.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows in the sparse CSR matrix.
n – [in] number of columns in the sparse CSR matrix.
nnz_A – [in] number of non-zeros in the sparse CSR matrix A.
csr_descr_A – [in] descriptor of the sparse CSR matrix A. Currently, only rocsparse_matrix_type_general is supported.
csr_val_A – [in] array of
nnz_A
elements containing the values of the sparse CSR matrix A.csr_row_ptr_A – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix A.csr_col_ind_A – [in] array of
nnz_A
elements containing the column indices of the sparse CSR matrix A.percentage – [in] percentage >= 0 and percentage <= 100.
csr_descr_C – [in] descriptor of the sparse CSR matrix C. Currently, only rocsparse_matrix_type_general is supported.
csr_row_ptr_C – [out] array of
m+1
elements that point to the start of every row of the sparse CSR matrix C.nnz_total_dev_host_ptr – [out] total number of nonzero elements in device or host memory.
info – [in] prune info structure.
temp_buffer – [out] buffer allocated by the user whose size is determined by calling
rocsparse_xprune_csr2csr_by_percentage_buffer_size()
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
ornnz_A
orpercentage
is invalid.rocsparse_status_invalid_pointer –
csr_descr_A
orcsr_descr_C
orinfo
orcsr_val_A
orcsr_row_ptr_A
orcsr_col_ind_A
orcsr_row_ptr_C
ornnz_total_dev_host_ptr
ortemp_buffer
pointer is invalid.
rocsparse_prune_csr2csr_by_percentage()#
-
rocsparse_status rocsparse_sprune_csr2csr_by_percentage(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const float *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, float percentage, const rocsparse_mat_descr csr_descr_C, float *csr_val_C, const rocsparse_int *csr_row_ptr_C, rocsparse_int *csr_col_ind_C, rocsparse_mat_info info, void *temp_buffer)#
-
rocsparse_status rocsparse_dprune_csr2csr_by_percentage(rocsparse_handle handle, rocsparse_int m, rocsparse_int n, rocsparse_int nnz_A, const rocsparse_mat_descr csr_descr_A, const double *csr_val_A, const rocsparse_int *csr_row_ptr_A, const rocsparse_int *csr_col_ind_A, double percentage, const rocsparse_mat_descr csr_descr_C, double *csr_val_C, const rocsparse_int *csr_row_ptr_C, rocsparse_int *csr_col_ind_C, rocsparse_mat_info info, void *temp_buffer)#
Convert and prune by percentage a sparse CSR matrix into a sparse CSR matrix.
This function converts the sparse CSR matrix A into a sparse CSR matrix C by pruning values in A that are less than the threshold. All the parameters are assumed to have been pre-allocated by the user. The user first calls rocsparse_xprune_csr2csr_buffer_size() to determine the size of the buffer used by rocsparse_xprune_csr2csr_nnz() and rocsparse_xprune_csr2csr() which the user then allocates. The user then allocates
csr_row_ptr_C
to havem+1
elements and then calls rocsparse_xprune_csr2csr_nnz() which fills in thecsr_row_ptr_C
array stores then number of elements that are larger than the pruning threshold innnz_total_dev_host_ptr
. The user then calls rocsparse_xprune_csr2csr() to complete the conversion.Note
This function is blocking with respect to the host.
Note
This routine does not support execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows in the sparse CSR matrix.
n – [in] number of columns in the sparse CSR matrix.
nnz_A – [in] number of non-zeros in the sparse CSR matrix A.
csr_descr_A – [in] descriptor of the sparse CSR matrix A. Currently, only rocsparse_matrix_type_general is supported.
csr_val_A – [in] array of
nnz_A
elements containing the values of the sparse CSR matrix A.csr_row_ptr_A – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix A.csr_col_ind_A – [in] array of
nnz_A
elements containing the column indices of the sparse CSR matrix A.percentage – [in] percentage >= 0 and percentage <= 100.
csr_descr_C – [in] descriptor of the sparse CSR matrix C. Currently, only rocsparse_matrix_type_general is supported.
csr_val_C – [out] array of
nnz_C
elements containing the values of the sparse CSR matrix C.csr_row_ptr_C – [in] array of
m+1
elements that point to the start of every row of the sparse CSR matrix C.csr_col_ind_C – [out] array of
nnz_C
elements containing the column indices of the sparse CSR matrix C.info – [in] prune info structure.
temp_buffer – [in] buffer allocated by the user whose size is determined by calling
rocsparse_xprune_csr2csr_buffer_size()
.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
orn
ornnz_A
orpercentage
is invalid.rocsparse_status_invalid_pointer –
csr_descr_A
orcsr_descr_C
orinfo
orcsr_val_A
orcsr_row_ptr_A
orcsr_col_ind_A
orcsr_val_C
orcsr_row_ptr_C
orcsr_col_ind_C
ortemp_buffer
pointer is invalid.
rocsparse_rocsparse_bsrpad_value()#
-
rocsparse_status rocsparse_sbsrpad_value(rocsparse_handle handle, rocsparse_int m, rocsparse_int mb, rocsparse_int nnzb, rocsparse_int block_dim, float value, const rocsparse_mat_descr bsr_descr, float *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind)#
-
rocsparse_status rocsparse_dbsrpad_value(rocsparse_handle handle, rocsparse_int m, rocsparse_int mb, rocsparse_int nnzb, rocsparse_int block_dim, double value, const rocsparse_mat_descr bsr_descr, double *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind)#
-
rocsparse_status rocsparse_cbsrpad_value(rocsparse_handle handle, rocsparse_int m, rocsparse_int mb, rocsparse_int nnzb, rocsparse_int block_dim, rocsparse_float_complex value, const rocsparse_mat_descr bsr_descr, rocsparse_float_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind)#
-
rocsparse_status rocsparse_zbsrpad_value(rocsparse_handle handle, rocsparse_int m, rocsparse_int mb, rocsparse_int nnzb, rocsparse_int block_dim, rocsparse_double_complex value, const rocsparse_mat_descr bsr_descr, rocsparse_double_complex *bsr_val, const rocsparse_int *bsr_row_ptr, const rocsparse_int *bsr_col_ind)#
Pads a value to the diagonal of the last block (if the last block is a diagonal block) in the sparse BSR matrix when the matrix expands outside m x m.
When converting from a CSR matrix to a BSR matrix the resulting BSR matrix will be larger when m < mb * block_dim. In these situations, the CSR to BSR conversion will expand the BSR matrix to have zeros when outside m x m. This routine converts the resulting BSR matrix to one that has a value on the last diagonal blocks diagonal if this last block is a diagonal block in the BSR matrix.
Note
This function is non blocking and executed asynchronously with respect to the host. It may return before the actual computation has finished.
Note
This routine supports execution in a hipGraph context.
- Parameters:
handle – [in] handle to the rocsparse library context queue.
m – [in] number of rows of the sparse BSR matrix.
mb – [in] number of block rows of the sparse BSR matrix.
nnzb – [in] number of non-zero blocks of the sparse BSR matrix.
block_dim – [in] block dimension of the sparse BSR matrix.
value – [in] scalar value that is set on the diagonal of the last block when the matrix expands outside of
m
xm
bsr_descr – [in] descriptor of the sparse BSR matrix. Currently, only rocsparse_matrix_type_general is supported.
bsr_val – [inout] array of
nnzb
blocks of the sparse BSR matrix.bsr_row_ptr – [in] array of
mb+1
elements that point to the start of every block row of the sparse BSR matrix.bsr_col_ind – [in] array of
nnzb
elements containing the block column indices of the sparse BSR matrix.
- Return values:
rocsparse_status_success – the operation completed successfully.
rocsparse_status_invalid_handle – the library context was not initialized.
rocsparse_status_invalid_size –
m
,mb
,nnzb
orblock_dim
is invalid.rocsparse_status_invalid_pointer –
bsr_descr
,bsr_val
,bsr_row_ind
,bsr_col_ind
, pointer is invalid.