rocsparse_scsrgemm_numeric Interface Reference

rocsparse_scsrgemm_numeric Interface Reference#

HIPFORT API Reference: hipfort_rocsparse::rocsparse_scsrgemm_numeric Interface Reference
hipfort_rocsparse::rocsparse_scsrgemm_numeric Interface Reference

Sparse matrix sparse matrix numeric multiplication using the CSR storage format. More...

Public Member Functions

integer(kind(rocsparse_status_success)) function rocsparse_scsrgemm_numeric_ (handle, trans_a, trans_b, m, n, k, alpha, descr_a, nnz_a, csr_val_a, csr_row_ptr_a, csr_col_ind_a, descr_b, nnz_b, csr_val_b, csr_row_ptr_b, csr_col_ind_b, beta, descr_d, nnz_d, csr_val_d, csr_row_ptr_d, csr_col_ind_d, descr_c, nnz_c, csr_val_c, csr_row_ptr_c, csr_col_ind_c, info_c, temp_buffer)
 

Detailed Description

Sparse matrix sparse matrix numeric multiplication using the CSR storage format.

rocsparse_csrgemm_numeric multiplies the scalar \(\alpha\) with the sparse \(m \times k\) matrix \(A\), defined in CSR storage format, and the sparse \(k \times n\) matrix \(B\), defined in CSR storage format, and adds the result to the sparse \(m \times n\) matrix \(D\) that is multiplied by \(\beta\). The final result is stored in the sparse \(m \times n\) matrix \(C\), predefined in CSR storage format, such that

\[ C := \alpha \cdot op(A) \cdot op(B) + \beta \cdot D, \]

with

\[ op(A) = \left\{ \begin{array}{ll} A, & \text{if trans_A == rocsparse_operation_none} \\% A^T, & \text{if trans_A == rocsparse_operation_transpose} \\% A^H, & \text{if trans_A == rocsparse_operation_conjugate_transpose} \end{array} \right. \]

and

\[ op(B) = \left\{ \begin{array}{ll} B, & \text{if trans_B == rocsparse_operation_none} \\% B^T, & \text{if trans_B == rocsparse_operation_transpose} \\% B^H, & \text{if trans_B == rocsparse_operation_conjugate_transpose} \end{array} \right. \]

Note
This function does not produce deterministic results.

The symbolic part of the csr matrix C can be obtained by rocsparse_csrgemm_symbolic(). It is assumed that csr_row_ptr_C and csr_col_ind_C have already been filled and that csr_val_C is allocated by the user. csr_row_ptr_C and the allocation size of csr_col_ind_C and csr_val_C are defined by the number of non-zero elements of the sparse CSR matrix C. Both can be obtained by rocsparse_csrgemm_nnz(). The required buffer size for the computation can be obtained by rocsparse_scsrgemm_buffer_size(), rocsparse_dcsrgemm_buffer_size(), rocsparse_ccsrgemm_buffer_size(), and rocsparse_zcsrgemm_buffer_size(), respectively.

Note
If \(\alpha == 0\), then \(C = \beta \cdot D\) will be computed.
If \(\beta == 0\), then \(C = \alpha \cdot op(A) \cdot op(B)\) will be computed.
\(\alpha == beta == 0\) is invalid.
Currently, only trans_A == rocsparse_operation_none is supported.
Currently, only trans_B == rocsparse_operation_none is supported.
Currently, only rocsparse_matrix_type_general is supported.
Note that for matrix products with more than 4096 non-zero entries per row, an additional temporary storage buffer is allocated by the algorithm.
This function is blocking with respect to the host.
This routine does not support execution in a hipGraph context.
Parameters
[in]handle- handle to the rocSPARSE library context queue.
[in]trans_A- matrix \(A\) operation type.
[in]trans_B- matrix \(B\) operation type.
[in]m- number of rows of the sparse CSR matrix \(op(A)\) and \(C\).
[in]n- number of columns of the sparse CSR matrix \(op(B)\) and \(C\).
[in]k- number of columns of the sparse CSR matrix \(op(A)\) and number of rows of the sparse CSR matrix \(op(B)\).
[in]alpha- scalar \(\alpha\).
[in]descr_A- descriptor of the sparse CSR matrix \(A\). Currently, only rocsparse_matrix_type_general is supported.
[in]nnz_A- number of non-zero entries of the sparse CSR matrix \(A\).
[in]csr_val_A- array of nnz_A elements of the sparse CSR matrix \(A\).
[in]csr_row_ptr_A- array of m+1 elements ( \(op(A) == A\), k+1 otherwise) that point to the start of every row of the sparse CSR matrix \(op(A)\).
[in]csr_col_ind_A- array of nnz_A elements containing the column indices of the sparse CSR matrix \(A\).
[in]descr_B- descriptor of the sparse CSR matrix \(B\). Currently, only rocsparse_matrix_type_general is supported.
[in]nnz_B- number of non-zero entries of the sparse CSR matrix \(B\).
[in]csr_val_B- array of nnz_B elements of the sparse CSR matrix \(B\).
[in]csr_row_ptr_B- array of k+1 elements ( \(op(B) == B\), m+1 otherwise) that point to the start of every row of the sparse CSR matrix \(op(B)\).
[in]csr_col_ind_B- array of nnz_B elements containing the column indices of the sparse CSR matrix \(B\).
[in]beta- scalar \(\beta\).
[in]descr_D- descriptor of the sparse CSR matrix \(D\). Currently, only rocsparse_matrix_type_general is supported.
[in]nnz_D- number of non-zero entries of the sparse CSR matrix \(D\).
[in]csr_val_D- array of nnz_D elements of the sparse CSR matrix \(D\).
[in]csr_row_ptr_D- array of m+1 elements that point to the start of every row of the sparse CSR matrix \(D\).
[in]csr_col_ind_D- array of nnz_D elements containing the column indices of the sparse CSR matrix \(D\).
[in]descr_C- descriptor of the sparse CSR matrix \(C\). Currently, only rocsparse_matrix_type_general is supported.
[in]nnz_C- number of non-zero entries of the sparse CSR matrix \(C\).
[out]csr_val_C- array of nnz_C elements of the sparse CSR matrix \(C\).
[in]csr_row_ptr_C- array of m+1 elements that point to the start of every row of the sparse CSR matrix \(C\).
[in]csr_col_ind_C- array of nnz_C elements containing the column indices of the sparse CSR matrix \(C\).
[in]info_C- structure that holds metadata for the sparse CSR matrix \(C\).
[in]temp_buffer- temporary storage buffer allocated by the user. The size is returned by rocsparse_scsrgemm_buffer_size(), rocsparse_dcsrgemm_buffer_size(), rocsparse_ccsrgemm_buffer_size(), or rocsparse_zcsrgemm_buffer_size().
Return values
rocsparse_status_successthe operation completed successfully.
rocsparse_status_invalid_handlethe library context was not initialized.
rocsparse_status_invalid_sizem, n, k, nnz_A, nnz_B, or nnz_D is invalid.
rocsparse_status_invalid_pointeralpha and beta are invalid, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, descr_B, csr_val_B, csr_row_ptr_B, or csr_col_ind_B are invalid if alpha is valid, descr_D, csr_val_D, csr_row_ptr_D, or csr_col_ind_D is invalid if beta is valid, or csr_val_C, csr_row_ptr_C, csr_col_ind_C, info_C, or temp_buffer is invalid.
rocsparse_status_memory_erroradditional buffer for long rows could not be allocated.
rocsparse_status_not_implementedtrans_A != rocsparse_operation_none, trans_B != rocsparse_operation_none, or rocsparse_matrix_type != rocsparse_matrix_type_general.
Example
This example multiplies two CSR matrices with a scalar alpha and adds the result to another CSR matrix.
// Initialize scalar multipliers
float alpha = 2.0f;
float beta = 1.0f;
// Create matrix descriptors
rocsparse_mat_descr descr_A;
rocsparse_mat_descr descr_B;
rocsparse_mat_descr descr_C;
rocsparse_mat_descr descr_D;
// Create matrix info structure
rocsparse_mat_info info_C;
// Set pointer mode
// Query rocsparse for the required buffer size
size_t buffer_size;
m,
n,
k,
&alpha,
descr_A,
nnz_A,
csr_row_ptr_A,
csr_col_ind_A,
descr_B,
nnz_B,
csr_row_ptr_B,
csr_col_ind_B,
&beta,
descr_D,
nnz_D,
csr_row_ptr_D,
csr_col_ind_D,
info_C,
&buffer_size);
// Allocate buffer
void* buffer;
hipMalloc(&buffer, buffer_size);
// Obtain number of total non-zero entries in C and row pointers of C
rocsparse_int nnz_C;
hipMalloc((void**)&csr_row_ptr_C, sizeof(rocsparse_int) * (m + 1));
m,
n,
k,
descr_A,
nnz_A,
csr_row_ptr_A,
csr_col_ind_A,
descr_B,
nnz_B,
csr_row_ptr_B,
csr_col_ind_B,
descr_D,
nnz_D,
csr_row_ptr_D,
csr_col_ind_D,
descr_C,
csr_row_ptr_C,
&nnz_C,
info_C,
buffer);
// Compute column indices and values of C
hipMalloc((void**)&csr_col_ind_C, sizeof(rocsparse_int) * nnz_C);
m,
n,
k,
descr_A,
nnz_A,
csr_row_ptr_A,
csr_col_ind_A,
descr_B,
nnz_B,
csr_row_ptr_B,
csr_col_ind_B,
descr_D,
nnz_D,
csr_row_ptr_D,
csr_col_ind_D,
descr_C,
nnz_C,
csr_row_ptr_C,
csr_col_ind_C,
info_C,
buffer);
hipMalloc((void**)&csr_val_C, sizeof(float) * nnz_C);
m,
n,
k,
&alpha,
descr_A,
nnz_A,
csr_val_A,
csr_row_ptr_A,
csr_col_ind_A,
descr_B,
nnz_B,
csr_val_B,
csr_row_ptr_B,
csr_col_ind_B,
&beta,
descr_D,
nnz_D,
csr_val_D,
csr_row_ptr_D,
csr_col_ind_D,
descr_C,
nnz_C,
csr_val_C,
csr_row_ptr_C,
csr_col_ind_C,
info_C,
buffer);
Create a matrix descriptor.
Definition hipfort_rocsparse.F90:436
Create a matrix info structure.
Definition hipfort_rocsparse.F90:795
Sparse matrix sparse matrix multiplication using the CSR storage format.
Definition hipfort_rocsparse.F90:13233
Sparse matrix sparse matrix symbolic multiplication using the CSR storage format.
Definition hipfort_rocsparse.F90:13968
Definition hipfort_rocsparse.F90:12963
Sparse matrix sparse matrix numeric multiplication using the CSR storage format.
Definition hipfort_rocsparse.F90:14275
Specify the pointer mode.
Definition hipfort_rocsparse.F90:320
@ rocsparse_operation_none
Definition hipfort_rocsparse_enums.F90:35
@ rocsparse_pointer_mode_host
Definition hipfort_rocsparse_enums.F90:104

Member Function/Subroutine Documentation

◆ rocsparse_scsrgemm_numeric_()

integer(kind(rocsparse_status_success)) function hipfort_rocsparse::rocsparse_scsrgemm_numeric::rocsparse_scsrgemm_numeric_ ( type(c_ptr), value  handle,
integer(kind(rocsparse_operation_none)), value  trans_a,
integer(kind(rocsparse_operation_none)), value  trans_b,
integer(c_int), value  m,
integer(c_int), value  n,
integer(c_int), value  k,
real(c_float)  alpha,
type(c_ptr), value  descr_a,
integer(c_int), value  nnz_a,
type(c_ptr), value  csr_val_a,
type(c_ptr), value  csr_row_ptr_a,
type(c_ptr), value  csr_col_ind_a,
type(c_ptr), value  descr_b,
integer(c_int), value  nnz_b,
type(c_ptr), value  csr_val_b,
type(c_ptr), value  csr_row_ptr_b,
type(c_ptr), value  csr_col_ind_b,
real(c_float)  beta,
type(c_ptr), value  descr_d,
integer(c_int), value  nnz_d,
type(c_ptr), value  csr_val_d,
type(c_ptr), value  csr_row_ptr_d,
type(c_ptr), value  csr_col_ind_d,
type(c_ptr), value  descr_c,
integer(c_int), value  nnz_c,
type(c_ptr), value  csr_val_c,
type(c_ptr), value  csr_row_ptr_c,
type(c_ptr), value  csr_col_ind_c,
type(c_ptr), value  info_c,
type(c_ptr), value  temp_buffer 
)

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