Sparse Matrix APIs#
The NVPL Sparse helper functions for sparse matrix descriptor are described in this section.
See the COO, CSR , CSC , SELL sections for the detailed description of the storage formats.
Coordinate (COO)#
nvpl_sparse_create_coo()#
nvpl_sparse_status_t
nvpl_sparse_create_coo(nvpl_sparse_sp_mat_descr_t* sp_mat_descr,
int64_t rows,
int64_t cols,
int64_t nnz,
void* coo_row_ind,
void* coo_col_ind,
void* coo_values,
nvpl_sparse_index_type_t coo_idx_type,
nvpl_sparse_index_base_t idx_base,
nvpl_sparse_data_type_t value_type)
nvpl_sparse_status_t
nvpl_sparse_create_const_coo(nvpl_sparse_const_sp_mat_descr_t* sp_mat_descr,
int64_t rows,
int64_t cols,
int64_t nnz,
const void* coo_row_ind,
const void* coo_col_ind,
const void* coo_values,
nvpl_sparse_index_type_t idx_type,
nvpl_sparse_index_base_t idx_base,
nvpl_sparse_data_type_t value_type)
This function initializes the sparse matrix descriptor sp_mat_descr in the COO format (Structure of Arrays layout).
Note
This function does not copy the data.
The caller is responsible for ensuring that the data is valid and accessible until the descriptor is destroyed. While the data is not copied, certain metadata can be computed and stored in the descriptor. As a result, modifying the provided buffer after the descriptor is created might result in undefined behavior.
Param. |
In/out |
Meaning |
|---|---|---|
|
OUT |
Sparse matrix descriptor |
|
IN |
Number of rows of the sparse matrix |
|
IN |
Number of columns of the sparse matrix |
|
IN |
Number of non-zero entries of the sparse matrix |
|
IN |
Row indices of the sparse matrix. Array with |
|
IN |
Column indices of the sparse matrix. Array with |
|
IN |
Values of the sparse matrix. Array with |
|
IN |
Data type of |
|
IN |
Index base of |
|
IN |
Datatype of |
nvpl_sparse_create_coo() has the following constraints:
coo_row_ind,coo_col_ind, andcoo_valuesmust be aligned to the size of the datatypes specified bycoo_idx_type,coo_idx_type, andvalue_type. respectively. See nvpl_sparse_data_type_t for the description of the datatypes.
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_coo_get()#
nvpl_sparse_status_t
nvpl_sparse_coo_get(nvpl_sparse_sp_mat_descr_t sp_mat_descr,
int64_t* rows,
int64_t* cols,
int64_t* nnz,
void** coo_row_ind,
void** coo_col_ind,
void** coo_values,
nvpl_sparse_index_type_t* idx_type,
nvpl_sparse_index_base_t* idx_base,
nvpl_sparse_data_type_t* value_type)
nvpl_sparse_status_t
nvpl_sparse_const_coo_get(nvpl_sparse_const_sp_mat_descr_t sp_mat_descr,
int64_t* rows,
int64_t* cols,
int64_t* nnz,
const void** coo_row_ind,
const void** coo_col_ind,
const void** coo_values,
nvpl_sparse_index_type_t* idx_type,
nvpl_sparse_index_base_t* idx_base,
nvpl_sparse_data_type_t* value_type)
This function returns the fields of the sparse matrix descriptor sp_mat_descr stored in COO format (Array of Structures layout).
Param. |
In/out |
Meaning |
|
|---|---|---|---|
|
IN |
Sparse matrix descriptor |
|
|
OUT |
Number of rows of the sparse matrix |
|
|
OUT |
Number of columns of the sparse matrix |
|
|
OUT |
Number of non-zero entries of the sparse matrix |
|
|
OUT |
Row indices of the sparse matrix. Array |
|
|
OUT |
Column indices of the sparse matrix. Array |
|
|
OUT |
Values of the sparse matrix. Array |
|
|
OUT |
Data type of |
|
|
OUT |
Index base of |
|
|
OUT |
Datatype of |
|
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_coo_set_pointers()#
nvpl_sparse_status_t
nvpl_sparse_coo_set_pointers(nvpl_sparse_sp_mat_descr_t sp_mat_descr,
void* coo_rows,
void* coo_columns,
void* coo_values)
This function sets the pointers of the sparse matrix descriptor sp_mat_descr.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
|
IN |
Row indices of the sparse matrix. Array with |
|
IN |
Column indices of the sparse matrix. Array with |
|
IN |
Values of the sparse matrix. Array with |
See nvpl_sparse_status_t for the description of the return status.
Compressed Sparse Row (CSR)#
nvpl_sparse_create_csr()#
nvpl_sparse_status_t
nvpl_sparse_create_csr(nvpl_sparse_sp_mat_descr_t* sp_mat_descr,
int64_t rows,
int64_t cols,
int64_t nnz,
void* csr_row_offsets,
void* csr_col_ind,
void* csr_values,
nvpl_sparse_index_type_t csr_row_offsets_type,
nvpl_sparse_index_type_t csr_col_ind_type,
nvpl_sparse_index_base_t idx_base,
nvpl_sparse_data_type_t value_type)
nvpl_sparse_status_t
nvpl_sparse_create_const_csr(nvpl_sparse_const_sp_mat_descr_t* sp_mat_descr,
int64_t rows,
int64_t cols,
int64_t nnz,
const void* csr_row_offsets,
const void* csr_col_ind,
const void* csr_values,
nvpl_sparse_index_type_t csr_row_offsets_type,
nvpl_sparse_index_type_t csr_col_ind_type,
nvpl_sparse_index_base_t idx_base,
nvpl_sparse_data_type_t value_type)
This function initializes the sparse matrix descriptor sp_mat_descr in the CSR format.
Note
This function does not copy the data.
The caller is responsible for ensuring that the data is valid and accessible until the descriptor is destroyed. While the data is not copied, certain metadata can be computed and stored in the descriptor. As a result, modifying the provided buffer after the descriptor is created might result in undefined behavior.
Param. |
In/out |
Meaning |
|---|---|---|
|
OUT |
Sparse matrix descriptor |
|
IN |
Number of rows of the sparse matrix |
|
IN |
Number of columns of the sparse matrix |
|
IN |
Number of non-zero entries of the sparse matrix |
|
IN |
Row offsets of the sparse matrix. Array with |
|
IN |
Column indices of the sparse matrix. Array with |
|
IN |
Values of the sparse matrix. Array with |
|
IN |
Data type of |
|
IN |
Data type of |
|
IN |
Index base of |
|
IN |
Datatype of |
nvpl_sparse_create_csr() has the following constraints:
csr_row_offsets,csr_col_ind, andcsr_valuesmust be aligned to the size of the datatypes specified bycsr_row_offsets_type,csr_col_ind_type, andvalue_type, respectively. See nvpl_sparse_data_type_t for the description of the datatypes.
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_csr_get()#
nvpl_sparse_status_t
nvpl_sparse_csr_get(nvpl_sparse_sp_mat_descr_t sp_mat_descr,
int64_t* rows,
int64_t* cols,
int64_t* nnz,
void** csr_row_offsets,
void** csr_col_ind,
void** csr_values,
nvpl_sparse_index_type_t* csr_row_offsets_type,
nvpl_sparse_index_type_t* csr_col_ind_type,
nvpl_sparse_index_base_t* idx_base,
nvpl_sparse_data_type_t* value_type)
nvpl_sparse_status_t
nvpl_sparse_const_csr_get(nvpl_sparse_const_sp_mat_descr_t sp_mat_descr,
int64_t* rows,
int64_t* cols,
int64_t* nnz,
const void** csr_row_offsets,
const void** csr_col_ind,
const void** csr_values,
nvpl_sparse_index_type_t* csr_row_offsets_type,
nvpl_sparse_index_type_t* csr_col_ind_type,
nvpl_sparse_index_base_t* idx_base,
nvpl_sparse_data_type_t* value_type)
This function returns the fields of the sparse matrix descriptor sp_mat_descr stored in CSR format.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
|
OUT |
Number of rows of the sparse matrix |
|
OUT |
Number of columns of the sparse matrix |
|
OUT |
Number of non-zero entries of the sparse matrix |
|
OUT |
Row offsets of the sparse matrix. Array with |
|
OUT |
Column indices of the sparse matrix. Array with |
|
OUT |
Values of the sparse matrix. Array with |
|
OUT |
Data type of |
|
OUT |
Data type of |
|
OUT |
Index base of |
|
OUT |
Datatype of |
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_csr_set_pointers()#
nvpl_sparse_status_t
nvpl_sparse_csr_set_pointers(nvpl_sparse_sp_mat_descr_t sp_mat_descr,
void* csr_row_offsets,
void* csr_col_ind,
void* csr_values)
This function sets the pointers of the sparse matrix descriptor sp_mat_descr.
Param. |
In/out |
Meaning |
|
|---|---|---|---|
|
IN |
Sparse matrix descriptor |
|
|
IN |
Row offsets of the sparse matrix. Array with |
|
|
IN |
Column indices of the sparse matrix. Array with |
|
|
IN |
Values of the sparse matrix. Array with |
|
See nvpl_sparse_status_t for the description of the return status.
Compressed Sparse Column (CSC)#
nvpl_sparse_create_csc()#
nvpl_sparse_status_t
nvpl_sparse_create_csc(nvpl_sparse_sp_mat_descr_t* sp_mat_descr,
int64_t rows,
int64_t cols,
int64_t nnz,
void* csc_col_offsets,
void* csc_row_ind,
void* csc_values,
nvpl_sparse_index_type_t csc_col_offsets_type,
nvpl_sparse_index_type_t csc_row_ind_type,
nvpl_sparse_index_base_t idx_base,
nvpl_sparse_data_type_t value_type)
nvpl_sparse_status_t
nvpl_sparse_create_const_csc(nvpl_sparse_const_sp_mat_descr_t* sp_mat_descr,
int64_t rows,
int64_t cols,
int64_t nnz,
const void* csc_col_offsets,
const void* csc_row_ind,
const void* csc_values,
nvpl_sparse_index_type_t csc_col_offsets_type,
nvpl_sparse_index_type_t csc_row_ind_type,
nvpl_sparse_index_base_t idx_base,
nvpl_sparse_data_type_t value_type)
This function initializes the sparse matrix descriptor sp_mat_descr in the CSC format.
Note
This function does not copy the data.
The caller is responsible for ensuring that the data is valid and accessible until the descriptor is destroyed. While the data is not copied, certain metadata can be computed and stored in the descriptor. As a result, modifying the provided buffer after the descriptor is created might result in undefined behavior.
Param. |
In/out |
Meaning |
|---|---|---|
|
OUT |
Sparse matrix descriptor |
|
IN |
Number of rows of the sparse matrix |
|
IN |
Number of columns of the sparse matrix |
|
IN |
Number of non-zero entries of the sparse matrix |
|
IN |
Column offsets of the sparse matrix. Array with |
|
IN |
Row indices of the sparse matrix. Array with |
|
IN |
Values of the sparse matrix. Array with |
|
IN |
Data type of |
|
IN |
Data type of |
|
IN |
Index base of |
|
IN |
Datatype of |
nvpl_sparse_create_csc() has the following constraints:
csc_col_offsets,csc_row_ind, andcsc_valuesmust be aligned to the size of the datatypes specified bycsc_col_offsets_type,csc_row_ind_type, andvalue_type, respectively. See nvpl_sparse_data_type_t for the description of the datatypes.
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_csc_get()#
nvpl_sparse_status_t
nvpl_sparse_csc_get(nvpl_sparse_sp_mat_descr_t sp_mat_descr,
int64_t* rows,
int64_t* cols,
int64_t* nnz,
void** csc_col_offsets,
void** csc_row_ind,
void** csc_values,
nvpl_sparse_index_type_t* csc_col_offsets_type,
nvpl_sparse_index_type_t* csc_row_ind_type,
nvpl_sparse_index_base_t* idx_base,
nvpl_sparse_data_type_t* value_type)
nvpl_sparse_status_t
nvpl_sparse_const_csc_get(nvpl_sparse_const_sp_mat_descr_t sp_mat_descr,
int64_t* rows,
int64_t* cols,
int64_t* nnz,
const void** csc_col_offsets,
const void** csc_row_ind,
const void** csc_values,
nvpl_sparse_index_type_t* csc_col_offsets_type,
nvpl_sparse_index_type_t* csc_row_ind_type,
nvpl_sparse_index_base_t* idx_base,
nvpl_sparse_data_type_t* value_type)
This function returns the fields of the sparse matrix descriptor sp_mat_descr stored in CSC format.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
|
OUT |
Number of rows of the sparse matrix |
|
OUT |
Number of columns of the sparse matrix |
|
OUT |
Number of non-zero entries of the sparse matrix |
|
OUT |
Col offsets of the sparse matrix. Array with |
|
OUT |
Row indices of the sparse matrix. Array with |
|
OUT |
Values of the sparse matrix. Array with |
|
OUT |
Data type of |
|
OUT |
Data type of |
|
OUT |
Index base of |
|
OUT |
Datatype of |
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_csc_set_pointers()#
nvpl_sparse_status_t
nvpl_sparse_csc_set_pointers(nvpl_sparse_sp_mat_descr_t sp_mat_descr,
void* csc_col_offsets,
void* csc_row_ind,
void* csc_values)
This function sets the pointers of the sparse matrix descriptor sp_mat_descr.
Param. |
In/out |
Meaning |
|
|---|---|---|---|
|
IN |
Sparse matrix descriptor |
|
|
IN |
Column offsets of the sparse matrix. Array with |
|
|
IN |
row indices of the sparse matrix. Array with |
|
|
IN |
Values of the sparse matrix. Array with |
|
See nvpl_sparse_status_t for the description of the return status.
Sliced-Ellpack (SELL)#
nvpl_sparse_create_sliced_ell()#
nvpl_sparse_status_t
nvpl_sparse_create_sliced_ell(nvpl_sparse_sp_mat_descr_t* sp_mat_descr,
int64_t rows,
int64_t cols,
int64_t nnz,
int64_t sell_values_size,
int64_t slice_size,
void* sell_slice_offsets,
void* sell_col_ind,
void* sell_values,
nvpl_sparse_index_type_t sell_slice_offsets_type,
nvpl_sparse_index_type_t sell_col_ind_type,
nvpl_sparse_index_base_t idx_base,
nvpl_sparse_data_type_t value_type)
nvpl_sparse_status_t
nvpl_sparse_create_const_sliced_ell(nvpl_sparse_const_sp_mat_descr_t* sp_mat_descr,
int64_t rows,
int64_t cols,
int64_t nnz,
int64_t sell_values_size,
int64_t slice_size,
const void* sell_slice_offsets,
const void* sell_col_ind,
const void* sell_values,
nvpl_sparse_index_type_t sell_slice_offsets_type,
nvpl_sparse_index_type_t sell_col_ind_type,
nvpl_sparse_index_base_t idx_base,
nvpl_sparse_data_type_t value_type)
This function initializes the sparse matrix descriptor sp_mat_descr for the Sliced Ellpack (SELL) format.
Note
This function does not copy the data.
The caller is responsible for ensuring that the data is valid and accessible until the descriptor is destroyed. While the data is not copied, certain metadata can be computed and stored in the descriptor. As a result, modifying the provided buffer after the descriptor is created might result in undefined behavior.
Param. |
In/out |
Meaning |
|---|---|---|
|
OUT |
Sparse matrix descriptor |
|
IN |
Number of rows of the sparse matrix |
|
IN |
Number of columns of the sparse matrix |
|
IN |
Number of nonzero elements in the sparse matrix |
|
IN |
Total number of elements in |
|
IN |
The number of rows per slice |
|
IN |
Slice offsets of the sparse matrix. Array of size \(\left \lceil{\frac{rows}{slice_size}}\right \rceil + 1\) |
|
IN |
Column indexes of the sparse matrix. Array of size |
|
IN |
Values of the sparse matrix. Array of size |
|
IN |
Data type of |
|
IN |
Data type of |
|
IN |
Index base of |
|
IN |
Data type of |
Note
Sliced Ellpack Column array sell_col_ind contains -1 values for indicating padded entries.
nvpl_sparse_create_sliced_ell() has the following constraints:
sell_slice_offsets,sell_col_ind, andsell_valuesmust be aligned to the size of the datatypes specified bysell_slice_offsets_type,sell_col_ind_type, andvalue_type, respectively. See nvpl_sparse_data_type_t for the description of the datatypes.
See nvpl_sparse_status_t for the description of the return status.
All Sparse Formats#
nvpl_sparse_destroy_sp_mat()#
nvpl_sparse_status_t
nvpl_sparse_destroy_sp_mat(nvpl_sparse_const_sp_mat_descr_t sp_mat_descr) // non-const descriptor supported
This function releases the memory allocated for the sparse matrix descriptor sp_mat_descr.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_sp_mat_get_size()#
nvpl_sparse_status_t
nvpl_sparse_sp_mat_get_size(nvpl_sparse_const_sp_mat_descr_t sp_mat_descr, // non-const descriptor supported
int64_t* rows,
int64_t* cols,
int64_t* nnz)
This function returns the sizes of the sparse matrix sp_mat_descr.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
|
OUT |
Number of rows of the sparse matrix |
|
OUT |
Number of columns of the sparse matrix |
|
OUT |
Number of non-zero entries of the sparse matrix |
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_sp_mat_get_format()#
nvpl_sparse_status_t
nvpl_sparse_sp_mat_get_format(nvpl_sparse_const_sp_mat_descr_t sp_mat_descr, // non-const descriptor supported
nvpl_sparse_format_t* format)
This function returns the format field of the sparse matrix descriptor sp_mat_descr.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
|
OUT |
Storage format of the sparse matrix |
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_sp_mat_get_index_base()#
nvpl_sparse_status_t
nvpl_sparse_sp_mat_get_index_base(nvpl_sparse_const_sp_mat_descr_t sp_mat_descr, // non-const descriptor supported
nvpl_sparse_index_base_t* idx_base)
This function returns the idx_base field of the sparse matrix descriptor sp_mat_descr.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
|
OUT |
Index base of the sparse matrix |
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_sp_mat_get_values()#
nvpl_sparse_status_t
nvpl_sparse_sp_mat_get_values(nvpl_sparse_sp_mat_descr_t sp_mat_descr,
void** values)
nvpl_sparse_status_t
nvpl_sparse_const_sp_mat_get_values(nvpl_sparse_const_sp_mat_descr_t sp_mat_descr,
const void** values)
This function returns the values field of the sparse matrix descriptor sp_mat_descr.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
|
OUT |
Values of the sparse matrix. Array with |
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_sp_mat_set_values()#
nvpl_sparse_status_t
nvpl_sparse_sp_mat_set_values(nvpl_sparse_sp_mat_descr_t sp_mat_descr,
void* values)
This function sets the values field of the sparse matrix descriptor sp_mat_descr.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
|
IN |
Values of the sparse matrix. Array with |
nvpl_sparse_sp_mat_set_values() has the following constraints:
valuesmust be aligned to the size of its corresponding datatype specified insp_mat_descr. See nvpl_sparse_data_type_t for the description of the datatypes.
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_sp_mat_get_attribute()#
nvpl_sparse_status_t
nvpl_sparse_sp_mat_get_attribute(nvpl_sparse_const_sp_mat_descr_t sp_mat_descr, // non-const descriptor supported
nvpl_sparse_sp_mat_attribute_t attribute,
void* data,
size_t dataSize)
The function gets the attributes of the sparse matrix descriptor sp_mat_descr.
Param. |
In/out |
Meaning |
|---|---|---|
|
IN |
Sparse matrix descriptor |
|
IN |
Attribute enumerator |
|
OUT |
Attribute value |
|
IN |
Size of the attribute in bytes for safety |
Attribute |
Meaning |
Possible Values |
|---|---|---|
|
Indicates if the lower or upper part of a matrix is stored in sparse storage |
|
|
Indicates if the matrix diagonal entries are unity |
|
See nvpl_sparse_status_t for the description of the return status.
nvpl_sparse_sp_mat_set_attribute()#
nvpl_sparse_status_t
nvpl_sparse_sp_mat_set_attribute(nvpl_sparse_sp_mat_descr_t sp_mat_descr,
nvpl_sparse_sp_mat_attribute_t attribute,
const void* data,
size_t dataSize)
The function sets the attributes of the sparse matrix descriptor sp_mat_descr
Param. |
In/out |
Meaning |
|---|---|---|
|
OUT |
Sparse matrix descriptor |
|
IN |
Attribute enumerator |
|
IN |
Attribute value |
|
IN |
Size of the attribute in bytes for safety |
Attribute |
Meaning |
Possible Values |
|---|---|---|
|
Indicates if the lower or upper part of a matrix is stored in sparse storage |
|
|
Indicates if the matrix diagonal entries are unity |
|
See nvpl_sparse_status_t for the description of the return status.