rocsparse_dense_to_sparse Interface Reference

rocsparse_dense_to_sparse Interface Reference#

hipFORT API Reference: hipfort_rocsparse::rocsparse_dense_to_sparse Interface Reference
hipfort_rocsparse::rocsparse_dense_to_sparse Interface Reference

Dense matrix to sparse matrix conversion. More...

Public Member Functions

integer(c_int) function rocsparse_dense_to_sparse_ (handle, mat_a, mat_b, alg, buffer_size, temp_buffer)
 
integer(kind(rocsparse_status_success)) function rocsparse_dense_to_sparse_typed (handle, mat_a, mat_b, alg, buffer_size, temp_buffer)
 

Detailed Description

Dense matrix to sparse matrix conversion.

rocsparse_dense_to_sparse performs the conversion of a dense matrix to a sparse matrix in CSR, CSC, or COO format.

rocsparse_dense_to_sparse requires multiple steps to complete. First, call rocsparse_dense_to_sparse with nullptr passed into temp_buffer:

// Call dense_to_sparse to get required buffer size
size_t buffer_size = 0;
matA,
matB,
&buffer_size,
nullptr);
Dense matrix to sparse matrix conversion.
Definition hipfort_rocsparse.F90:14909
@ rocsparse_dense_to_sparse_alg_default
Definition hipfort_rocsparse_enums.F90:361

After this is called, the buffer_size will be filled with the size of the required buffer that must be allocated. Next, call rocsparse_dense_to_sparse with the newly allocated temp_buffer and nullptr passed into buffer_size:

// Call dense_to_sparse to perform analysis
matA,
matB,
nullptr,
temp_buffer);

This will determine the number of non-zeros that will exist in the sparse matrix, which can be queried using the rocsparse_spmat_get_size routine. With this, allocate the sparse matrix device arrays and set them on the sparse matrix descriptor using rocsparse_csr_set_pointers (CSR format), rocsparse_csc_set_pointers (for CSC format), or rocsparse_coo_set_pointers (for COO format). Finally, the conversion is completed by calling rocsparse_dense_to_sparse with both the buffer_size and temp_buffer :

// Call dense_to_sparse to complete conversion
matA,
matB,
&buffer_size,
temp_buffer);

Currently, rocsparse_dense_to_sparse only supports the algorithm rocsparse_dense_to_sparse_alg_default. See the full example below.

rocsparse_dense_to_sparse supports rocsparse_datatype_f16_r, rocsparse_datatype_bf16_r, rocsparse_datatype_f32_r, rocsparse_datatype_f64_r, rocsparse_datatype_f32_c, and rocsparse_datatype_f64_c for values arrays in the sparse matrix (stored in CSR, CSC, or COO format) and the dense matrix. For the row/column offset and row/column index arrays of the sparse matrix, rocsparse_dense_to_sparse supports the precisions rocsparse_indextype_i32 and rocsparse_indextype_i64.

Uniform Precisions:
Uniform Precisions
A / B
rocsparse_datatype_f16_r
rocsparse_datatype_bf16_r
rocsparse_datatype_f32_r
rocsparse_datatype_f64_r
rocsparse_datatype_f32_c
rocsparse_datatype_f64_c
Note
This function writes the required allocation size (in bytes) to buffer_size and returns without performing the dense to sparse operation, when a nullptr is passed for temp_buffer.
This function is blocking with respect to the host.
This routine does not support execution in a hipGraph context.
This routine does not support batched computation.
Parameters
[in]handle- handle to the rocSPARSE library context queue.
[in]mat_A- dense matrix descriptor.
[in]mat_B- sparse matrix descriptor.
[in]alg- algorithm for the dense to sparse computation.
[out]buffer_size- number of bytes of the temporary storage buffer. buffer_size is set when temp_buffer is nullptr.
[in]temp_buffer- temporary storage buffer allocated by the user. When a nullptr is passed, the required allocation size (in bytes) is written to buffer_size and the function returns without performing the dense to sparse operation.
Return values
rocsparse_status_successthe operation completed successfully.
rocsparse_status_invalid_handlethe library context was not initialized.
rocsparse_status_invalid_pointermat_A, mat_B, or buffer_size pointer is invalid.
Example

Member Function/Subroutine Documentation

◆ rocsparse_dense_to_sparse_()

integer(c_int) function hipfort_rocsparse::rocsparse_dense_to_sparse::rocsparse_dense_to_sparse_ ( type(c_ptr), value  handle,
type(c_ptr), value  mat_a,
type(c_ptr), value  mat_b,
integer(c_int), value  alg,
type(c_ptr), value  buffer_size,
type(c_ptr), value  temp_buffer 
)

◆ rocsparse_dense_to_sparse_typed()

integer(kind(rocsparse_status_success)) function hipfort_rocsparse::rocsparse_dense_to_sparse::rocsparse_dense_to_sparse_typed ( type(c_ptr), value  handle,
type(c_ptr), value  mat_a,
type(c_ptr), value  mat_b,
integer(kind(rocsparse_dense_to_sparse_alg_default))  alg,
integer(c_size_t), target  buffer_size,
type(c_ptr), value  temp_buffer 
)

The documentation for this interface was generated from the following file: