Conversion Functions - Conversion Functions - 5.0 English - 63865

AOCL Sparse Library (63865)

Document ID
63865
Release Date
2024-10-09
Version
5.0 English

Conversion Functions#

aoclsparse_convert.h provides sparse format conversion functions.

aoclsparse_csr2ell_width()#

aoclsparse_status aoclsparse_csr2ell_width(aoclsparse_int m, aoclsparse_int nnz, const aoclsparse_int *csr_row_ptr, aoclsparse_int *ell_width)#

Convert a sparse CSR matrix into a sparse ELL matrix.

aoclsparse_csr2ell_width computes the maximum of the per row non-zero elements over all rows, the ELL width, for a given CSR matrix.

Parameters
  • m[in] number of rows 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.

  • ell_width[out] pointer to the number of non-zero elements per row in ELL storage format.

Return values
  • aoclsparse_status_success – the operation completed successfully.

  • aoclsparse_status_invalid_sizem is invalid.

  • aoclsparse_status_invalid_pointercsr_row_ptr, or ell_width pointer is invalid.

  • aoclsparse_status_internal_error – an internal error occurred.

aoclsparse_?csr2ell()#

aoclsparse_status aoclsparse_scsr2ell(aoclsparse_int m, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const float *csr_val, aoclsparse_int *ell_col_ind, float *ell_val, aoclsparse_int ell_width)#
aoclsparse_status aoclsparse_dcsr2ell(aoclsparse_int m, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const double *csr_val, aoclsparse_int *ell_col_ind, double *ell_val, aoclsparse_int ell_width)#

Convert a sparse CSR matrix into a sparse ELLPACK matrix.

aoclsparse_?csr2ell converts a CSR matrix into an ELL matrix. It is assumed, that ell_val and ell_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}} \) is equal to m times ell_width. The number of ELL non-zero elements per row is obtained by aoclsparse_csr2ell_width(). The index base is preserved during the conversion.

Parameters
  • m[in] number of rows of the sparse CSR matrix.

  • descr[in] descriptor of the input sparse CSR matrix. Only the base index is used in the conversion process, the remaining descriptor elements are ignored.

  • 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_width[in] number of non-zero elements per row in ELL storage format.

  • ell_val[out] array of m times ell_width elements of the sparse ELL matrix.

  • ell_col_ind[out] array of m times ell_width elements containing the column indices of the sparse ELL matrix.

Return values
  • aoclsparse_status_success – the operation completed successfully.

  • aoclsparse_status_invalid_handle – the library context was not initialized.

  • aoclsparse_status_invalid_sizem or ell_width is invalid.

  • aoclsparse_status_invalid_pointercsr_val, csr_row_ptr, csr_col_ind, ell_val or ell_col_ind pointer is invalid.

aoclsparse_csr2dia_ndiag()#

aoclsparse_status aoclsparse_csr2dia_ndiag(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, aoclsparse_int nnz, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_int *dia_num_diag)#

Convert a sparse CSR matrix into a sparse DIA matrix.

aoclsparse_csr2dia_ndiag computes number of diagonals for a given CSR matrix.

Parameters
  • 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 input sparse CSR matrix. Only the base index is used in computing the diagonals, the remaining descriptor elements are ignored.

  • 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 containing the column indices of the sparse CSR matrix.

  • dia_num_diag[out] pointer to the number of diagonals with non-zeroes in DIA storage format.

Return values
  • aoclsparse_status_success – the operation completed successfully.

  • aoclsparse_status_invalid_sizem is invalid.

  • aoclsparse_status_invalid_pointercsr_row_ptr, or ell_width pointer is invalid.

  • aoclsparse_status_internal_error – an internal error occurred.

aoclsparse_?csr2dia()#

aoclsparse_status aoclsparse_scsr2dia(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const float *csr_val, aoclsparse_int dia_num_diag, aoclsparse_int *dia_offset, float *dia_val)#
aoclsparse_status aoclsparse_dcsr2dia(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const double *csr_val, aoclsparse_int dia_num_diag, aoclsparse_int *dia_offset, double *dia_val)#

Convert a sparse CSR matrix into a sparse DIA matrix.

aoclsparse_?csr2dia converts a CSR matrix into an DIA matrix. It is assumed, that dia_val and dia_offset are allocated. Allocation size is computed by the number of rows times the number of diagonals. The number of DIA diagonals is obtained by aoclsparse_csr2dia_ndiag().The index base is preserved during the conversion.

Parameters
  • m[in] number of rows of the sparse CSR matrix.

  • n[in] number of cols of the sparse CSR matrix.

  • descr[in] descriptor of the input sparse CSR matrix. Only the base index is used in the conversion process, the remaining descriptor elements are ignored.

  • 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.

  • csr_val[in] array containing the values of the sparse CSR matrix.

  • dia_num_diag[in] number of diagoanls in ELL storage format.

  • dia_offset[out] array of dia_num_diag elements containing the diagonal offsets from main diagonal.

  • dia_val[out] array of m times dia_num_diag elements of the sparse DIA matrix.

Return values
  • aoclsparse_status_success – the operation completed successfully.

  • aoclsparse_status_invalid_handle – the library context was not initialized.

  • aoclsparse_status_invalid_sizem or ell_width is invalid.

  • aoclsparse_status_invalid_pointercsr_val, csr_row_ptr, csr_col_ind, ell_val or ell_col_ind pointer is invalid.

aoclsparse_csr2bsr_nnz()#

aoclsparse_status aoclsparse_csr2bsr_nnz(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_int block_dim, aoclsparse_int *bsr_row_ptr, aoclsparse_int *bsr_nnz)#

aoclsparse_csr2bsr_nnz 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.

Parameters
  • 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 input sparse CSR matrix. Only the base index is used in computing the nnz blocks, the remaining descriptor elements are ignored.

  • csr_row_ptr[in] integer array containing m +1 elements that point to the start of each row of the CSR matrix

  • csr_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_row_ptr[out] integer array containing mb +1 elements that point to the start of each block row of the BSR matrix

  • bsr_nnz[out] total number of nonzero elements in device or host memory.

Return values
  • aoclsparse_status_success – the operation completed successfully.

  • aoclsparse_status_invalid_sizem or n or block_dim is invalid.

  • aoclsparse_status_invalid_pointercsr_row_ptr or csr_col_ind or bsr_row_ptr or bsr_nnz pointer is invalid.

aoclsparse_?csr2bsr()#

aoclsparse_status aoclsparse_scsr2bsr(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const float *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_int block_dim, float *bsr_val, aoclsparse_int *bsr_row_ptr, aoclsparse_int *bsr_col_ind)#
aoclsparse_status aoclsparse_dcsr2bsr(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const double *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_int block_dim, double *bsr_val, aoclsparse_int *bsr_row_ptr, aoclsparse_int *bsr_col_ind)#

Convert a sparse CSR matrix into a sparse BSR matrix.

aoclsparse_?csr2bsr converts a CSR matrix into a BSR matrix. It is assumed, that bsr_val, bsr_col_ind and bsr_row_ptr are allocated. Allocation size for bsr_row_ptr is computed as mb+1 where mb is the number of block rows in the BSR matrix. Allocation size for bsr_val and bsr_col_ind is computed using this function which also fills in bsr_row_ptr. The index base is preserved during the conversion.

Parameters
  • m[in] number of rows in the sparse CSR matrix.

  • n[in] number of columns in the sparse CSR matrix.

  • descr[in] descriptor of the input sparse CSR matrix. Only the base index is used in the conversion process, the remaining descriptor elements are ignored.

  • 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_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
  • aoclsparse_status_success – the operation completed successfully.

  • aoclsparse_status_invalid_sizem, or n, or block_dim is invalid.

  • aoclsparse_status_invalid_pointerbsr_val, bsr_row_ptr, bsr_col_ind, csr_val, csr_row_ptr or csr_col_ind pointer is invalid.

aoclsparse_?csr2csc()#

aoclsparse_status aoclsparse_scsr2csc(aoclsparse_int m, aoclsparse_int n, aoclsparse_int nnz, const aoclsparse_mat_descr descr, aoclsparse_index_base baseCSC, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const float *csr_val, aoclsparse_int *csc_row_ind, aoclsparse_int *csc_col_ptr, float *csc_val)#
aoclsparse_status aoclsparse_dcsr2csc(aoclsparse_int m, aoclsparse_int n, aoclsparse_int nnz, const aoclsparse_mat_descr descr, aoclsparse_index_base baseCSC, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const double *csr_val, aoclsparse_int *csc_row_ind, aoclsparse_int *csc_col_ptr, double *csc_val)#
aoclsparse_status aoclsparse_ccsr2csc(aoclsparse_int m, aoclsparse_int n, aoclsparse_int nnz, const aoclsparse_mat_descr descr, aoclsparse_index_base baseCSC, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const aoclsparse_float_complex *csr_val, aoclsparse_int *csc_row_ind, aoclsparse_int *csc_col_ptr, aoclsparse_float_complex *csc_val)#
aoclsparse_status aoclsparse_zcsr2csc(aoclsparse_int m, aoclsparse_int n, aoclsparse_int nnz, const aoclsparse_mat_descr descr, aoclsparse_index_base baseCSC, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, const aoclsparse_double_complex *csr_val, aoclsparse_int *csc_row_ind, aoclsparse_int *csc_col_ptr, aoclsparse_double_complex *csc_val)#

Convert a sparse CSR matrix into a sparse CSC matrix.

aoclsparse_?csr2csc converts a CSR matrix into a CSC matrix. These functions can also be used to convert a CSC matrix into a CSR matrix. The index base can be modified during the conversion.

Note

The resulting matrix can also be seen as the transpose of the input matrix.

Parameters
  • 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 input sparse CSR matrix. Only the base index is used in the conversion process, the remaining descriptor elements are ignored.

  • baseCSC[in] the desired index base (zero or one) for the converted 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. aoclsparse_csr2csc_buffer_size().

Return values
  • aoclsparse_status_success – the operation completed successfully.

  • aoclsparse_status_invalid_sizem, n or nnz is invalid.

  • aoclsparse_status_invalid_pointercsr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr is invalid.

aoclsparse_?csr2dense()#

aoclsparse_status aoclsparse_scsr2dense(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const float *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, float *A, aoclsparse_int ld, aoclsparse_order order)#
aoclsparse_status aoclsparse_dcsr2dense(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const double *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, double *A, aoclsparse_int ld, aoclsparse_order order)#
aoclsparse_status aoclsparse_ccsr2dense(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_float_complex *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_float_complex *A, aoclsparse_int ld, aoclsparse_order order)#
aoclsparse_status aoclsparse_zcsr2dense(aoclsparse_int m, aoclsparse_int n, const aoclsparse_mat_descr descr, const aoclsparse_double_complex *csr_val, const aoclsparse_int *csr_row_ptr, const aoclsparse_int *csr_col_ind, aoclsparse_double_complex *A, aoclsparse_int ld, aoclsparse_order order)#

This function converts the sparse matrix in CSR format into a dense matrix.

Parameters
  • 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 aoclsparse_matrix_type_general. Base index from the descriptor is used in the conversion process.

  • csr_val[in] array of size at least nnz nonzero elements of matrix A.

  • csr_row_ptr[in] CSR row pointer array of size (m +1).

  • csr_col_ind[in] An array of CSR column indices of at least nnz column indices of the nonzero elements of matrix A.

  • A[out] array of dimensions (lda, n)

  • ld[in] leading dimension of dense array A.

  • order[in] memory layout of a dense matrix A. It can be either aoclsparse_order_column or aoclsparse_order_row.

Return values
  • aoclsparse_status_success – the operation completed successfully.

  • aoclsparse_status_invalid_sizem or n or ld is invalid.

  • aoclsparse_status_invalid_pointerA, csr_val, csr_row_ptr, or csr_col_ind pointers are invalid.

aoclsparse_convert_csr()#

aoclsparse_status aoclsparse_convert_csr(const aoclsparse_matrix src_mat, const aoclsparse_operation op, aoclsparse_matrix *dest_mat)#

Convert internal representation of matrix into a sparse CSR matrix.

aoclsparse_convert_csr converts any supported matrix format into a CSR format matrix and returns it as a new aoclsparse_matrix. The new matrix can also be transposed, or conjugated and transposed during the conversion. It should be freed by calling aoclsparse_destroy(). The source matrix needs to be initalized using e.g. aoclsparse_create_scoo(), aoclsparse_create_scsr(), aoclsparse_create_scsc() or any of their variants.

Parameters
  • src_mat[in] source matrix used for conversion.

  • op[in] operation to be performed on destination matrix

  • dest_mat[out] destination matrix output in CSR Format of the src_mat.

Return values
  • aoclsparse_status_success – the operation completed successfully

  • aoclsparse_status_invalid_size – matrix dimension are invalid

  • aoclsparse_status_invalid_valuesrc_mat contains invalid value type

  • aoclsparse_status_invalid_pointer – pointers in src_mat or dest_mat are invalid

  • aoclsparse_status_not_implemented – conversion of the src_mat format given is not implemented

  • aoclsparse_status_memory_error – memory allocation for destination matrix failed