kml_sparse_?csrmm
Compute the product of matrices. One of them is a sparse matrix in the CSR format. The operation is defined as follows:
- C = alpha * A*B + beta * C
- C = alpha * AT * B + beta * C
- C = alpha * AH * B + beta * C
B and C are dense matrices, and A is a sparse matrix (m x k) stored in the CSR format.
Table 1 describes the relationship between layout and sparse matrix indexing.
Sparse matrix indexing |
Dense matrix layout |
|---|---|
KML_SPARSE_INDEX_BASE_ZERO |
KML_SPARSE_LAYOUT_ROW_MAJOR |
KML_SPARSE_INDEX_BASE_ONE |
KML_SPARSE_LAYOUT_COLUMN_MAJOR |
Interface Definition
C interface:
kml_sparse_status_t kml_sparse_scsrmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const float alpha, const char *matdescra,
const float *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const float *b, const KML_INT ldb, const float beta , float *c , const KML_INT ldc);
kml_sparse_status_t kml_sparse_dcsrmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const double alpha, const char *matdescra,
const double *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const double *b, const KML_INT ldb, const double beta , double *c , const KML_INT ldc);
kml_sparse_status_t kml_sparse_ccsrmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex8 alpha, const char *matdescra, const KML_Complex8 *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const KML_Complex8 *b, const KML_INT ldb, const KML_Complex8 beta , KML_Complex8 *c , const KML_INT ldc);
kml_sparse_status_t kml_sparse_zcsrmm(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex16 alpha, const char *matdescra, const KML_Complex16 *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const KML_Complex16 *b, const KML_INT ldb, const KML_Complex16 beta , KML_Complex16 *c , const KML_INT ldc);
Fortran interface:
RES = KML_SPARSE_SCSRMM(OPT, M, N K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, B, LDB, BETA, C, LDC);
RES = KML_SPARSE_DCSRMM(OPT, M, N K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, B, LDB, BETA, C, LDC);
RES = KML_SPARSE_CCSRMM(OPT, M, N K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, B, LDB, BETA, C, LDC);
RES = KML_SPARSE_ZCSRMM(OPT, M, N K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, B, LDB, BETA, C, LDC);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
opt |
Enumeration type kml_sparse_operation_t |
Indicates whether to transpose.
|
Input |
m |
Integer |
Number of rows in matrix A. The value range is [1, MAX_KML_INT]. |
Input |
n |
Integer |
Number of columns in matrix C. The value range is [1, MAX_KML_INT]. |
Input |
k |
Integer |
Number of columns in matrix A. The value range is [1, MAX_KML_INT]. |
Input |
alpha |
|
Scalar alpha |
Input |
matdescra |
Char pointer |
Matrix operation attribute. For details, see the description of matdescra. |
Input |
val |
|
Array values storing non-zero elements of matrix A in the CSR format. The length is pntre[m-1] - pntrb[0]. |
Input |
indx |
Integer array |
Array columns in the CSR format, which contains the column indices for non-zero elements in matrix A |
Input |
pntrb |
Integer array |
Array of length m, containing row indices of matrix A. pntrb[i] - pntrb[0] indicates the subscript of the first non-zero element in row i in the val and indx arrays. |
Input |
pntre |
Integer array |
Array of length m, containing row indices of matrix A. pntre[i] - pntrb[0]-1 indicates the subscript of the last non-zero element in row i in the val and indx arrays. |
Input |
b |
|
Array value of matrix B |
Input |
ldb |
Integer |
|
Input |
beta |
|
Scalar beta |
Input |
c |
|
Array value of matrix C |
Input/Output |
ldc |
Integer |
|
Input |
Table 2 describes the parameter constraints on matrix B.
opt |
Matrix Scale |
Data Layout |
Value Range |
|---|---|---|---|
op(A) = A |
k x n |
Row-major order |
k * ldb |
op(A) = A |
k x n |
Column-major order |
ldb * n |
op(A) = AT or AH |
m x n |
Row-major order |
m * ldb |
op(A) = AT or AH |
m x n |
Column-major order |
ldb * n |
Table 3 describes the parameter constraints on matrix C.
opt |
Matrix Scale |
Data Layout |
Value Range |
|---|---|---|---|
op(A) = A |
m x n |
Row-major order |
m * ldc |
op(A) = A |
m x n |
Column-major order |
ldc * n |
op(A) = AT or AH |
k x n |
Row-major order |
k * ldc |
op(A) = AT or AH |
k x n |
Column-major order |
ldc * n |
Return Value
Function execution status. The enumeration type is kml_sparse_status_t.
Dependencies
C: "kspblas.h"
Fortran: "kspblas.f03"
Examples
C interface:
kml_sparse_operation_t opt = KML_SPARSE_OPERATION_NON_TRANSPOSE;
KML_INT m = 3;
KML_INT n = 3;
KML_INT k = 3;
float alpha = 1.0;
float beta = 1.0;
char *matdescra = "G00C"; // General matrix with zero-based indexing
float val[4] = {9, 8, 5, 2};
KML_INT indx[4] = {2, 1, 2, 2};
KML_INT pntrb[3] = {0, 2, 3};
KML_INT pntre[3] = {2, 3, 4};
float b[9] = {1, 5, 7, 4, 7, 7, 3, 3, 7};
float c[9] = {0, 8, 8, 0, 2, 8, 3, 5, 6};
KML_INT ldb = 3;
KML_INT ldc = 3;
kml_sparse_status_t status = kml_sparse_scsrmm(opt, m, n, k, alpha, matdescra, val, indx, pntrb, pntre, b, ldb, beta, c, ldc);
/*
* Output c:
* 59.00 91.00 127.00 15.00 17.00 43.00 9.00 11.00 20.00
*
*/
Fortran interface:
INTEGER(C_INT) :: OPT = KML_SPARSE_OPERATION_NON_TRANSPOSE
INTEGER(C_INT) :: M = 3
INTEGER(C_INT) :: N = 3
INTEGER(C_INT) :: K = 3
REAL(C_FLOAT) :: ALPHA = 1.0
REAL(C_FLOAT) :: BETA = 1.0
INTEGER(C_INT) :: LDB = 3
INTEGER(C_INT) :: LDC = 3
INTEGER(C_INT) :: STATUS
CHARACTER(KIND=C_CHAR, LEN=4) :: MATDESCRA = "G00C" ! General matrix with zero-based indexing
REAL(C_FLOAT) :: VAL(4), B(9), C(9)
INTEGER(C_INT) :: INDX(4), PNTRB(4), PNTRE(3)
DATA VAL/9, 8, 5, 2/
DATA B /1, 5, 7, 4, 7, 7, 3, 3, 7/
DATA C /0, 8, 8, 0, 2, 8, 3, 5, 6/
DATA INDX/2, 1, 2, 2/
DATA PNTRB/0, 2, 3/
DATA PNTRE/2, 3, 4/
STATUS = KML_SPARSE_SCSRMM(OPT, M, N, K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, B, LDB, BETA, C, LDC)
!
! OUTPUT C:
! 59.00 91.00 127.00 15.00 17.00 43.00 9.00 11.00 20.00
!
