Rate This Document
Findability
Accuracy
Completeness
Readability

Migrating a Sparse Basic Linear Algebra Library (Sparse BLAS)

Replaceability

The external interfaces provided by KML_SPBLAS are different from those provided by MKL-SPBLAS in terms of interface parameters and function names. Therefore, some source code needs to be modified.

Table 1 and Table 2 show the mapping between replaceable interfaces and MKL interfaces.

Table 1 Replacement mapping of the Level 1 interfaces

MKL Interface

KML Interface

Data Type

Description

cblas_?axpyi

kml_sparse_?axpyi

s, d, c, z

Performs sparse vector scaling and addition.

cblas_?doti

kml_sparse_?doti

s, d

Computes the dot product of sparse vectors.

cblas_?dotci

kml_sparse_?dotci_sub

c, z

Computes the dot product of a conjugate sparse vector and a sparse vector.

cblas_?dotui

kml_sparse_?dotui_sub

c, z

Computes the dot product of complex sparse vectors.

cblas_?gthr

kml_sparse_?gthr

s, d, c, z

Gathers the elements specified in a full-storage sparse vector into a compressed vector.

cblas_?gthrz

kml_sparse_?gthrz

s, d, c, z

Gather the elements specified in full-storage sparse vector y into a compressed vector.

cblas_?roti

kml_sparse_?roti

s, d

Performs rotation of points in a plane.

cblas_?sctr

kml_sparse_?sctr

s, d, c, z

Writes a compressed vector into a full-storage sparse vector.

Table 2 Replacement mapping of Level 2 and Level 3 interfaces

MKL Interface

KML Interface

Data Type

Description

mkl_?csrgemv

kml_sparse_?csrgemv

s, d, c, z

Computes the product of a matrix and a vector. The sparse matrix is stored in the CSR format.

mkl_?csrsymv

kml_sparse_?csrsymv

s, d, c, z

Computes the product of a matrix and a vector. The sparse matrix is stored in the CSR format.

mkl_cspblas_?csrgemv

kml_csparse_?csrgemv

s, d, c, z

Computes the product of a matrix and a vector. The sparse matrix is stored in the CSR format.

mkl_cspblas_?csrsymv

kml_csparse_?csrsymv

s, d, c, z

Computes the product of a matrix and a vector. The sparse matrix is stored in the CSR format.

mkl_?csrmv

kml_sparse_?csrmv

s, d, c, z

Computes the product of a matrix and a vector. The matrix is a sparse matrix stored in the CSR format.

mkl_?csrsv

kml_sparse_?csrsv

s, d, c, z

Solves a system of linear equations for a triangular matrix. The sparse matrix is stored in the CSR format.

mkl_?csrmm

kml_sparse_?csrmm

s, d, c, z

Computes the product of matrices. One of them is a sparse matrix in the CSR format.

mkl_?csradd

kml_sparse_?csradd

s, d, c, z

Computes the sum of two sparse matrices that are stored in the CSR format.

mkl_?csrmultcsr

kml_sparse_?csrmultcsr

s, d, c, z

Computes the product of matrices. Three of them are 3-array sparse matrices in the CSR format.

mkl_?csrmultd

kml_sparse_?csrmultd

s, d, c, z

Computes the product of matrices. Two of them are sparse matrices in the CSR format.

Migrating the C-based Library

The following three parts need to be migrated:

  • Function names

    Replaceability shows the mapping between replaceable interfaces and MKL interfaces.

  • Function input parameters

    In MKL, parameters of some interfaces are passed using pointers, while in KML, values are directly passed. For details, see "Kunpeng Math Library Developer Guide" in Kunpeng HPCKit 26.1.RC1 Developer Guide.

  • Variable declarations

    The "MKL" prefix of some MKL variables need to be changed to "KML".

Example: csrmv interface

Before the migration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "mkl_spblas.h"

char transa = 'N';
MKL_INT m = 4;
MKL_INT k = 4;
float alpha = 0.5;
float beta = 1.2;
char *matdescra = "G00F"; // General matrix with one-based indexing
float val[9] = {2, -3, 7, 1, -6, 8, -4, 5, 9};
MKL_INT indx[9] = {1, 2, 4, 3, 4, 1, 3, 4, 1};
MKL_INT pntrb[4] = {1, 4, 6, 9};
MKL_INT pntre[4] = {4, 6, 9, 10};
float x[4] = {1, 3, -2, 5};
float y[4] = {-1, 1, 5, 3};
mkl_scsrmv(&transa, &m, &k, &alpha, matdescra, val, indx, pntrb, pntre, x, &beta, y);
return 0;
/*
*  Output Y:
*
*     12.80  -14.80  26.50   8.10
*
* */

After the migration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "kspblas.h"

kml_sparse_operation_t opt = KML_SPARSE_OPERATION_NON_TRANSPOSE;
KML_INT m = 4;
KML_INT k = 4;
float alpha = 0.5;
float beta = 1.2;
char *matdescra = "G00F"; // General matrix with one-based indexing
float val[9] = {2, -3, 7, 1, -6, 8, -4, 5, 9};
KML_INT indx[9] = {1, 2, 4, 3, 4, 1, 3, 4, 1};
KML_INT pntrb[4] = {1, 4, 6, 9};
KML_INT pntre[4] = {4, 6, 9, 10};
float x[4] = {1, 3, -2, 5};
float y[4] = {-1, 1, 5, 3};
kml_sparse_status_t status = kml_sparse_scsrmv(opt, m, k, alpha, matdescra, val, indx, pntrb, pntre, x, beta, y);
return status;
/*
*  Output Y:
*
*     12.80  -14.80  26.50   8.10
*
* */

Migrating the Fortran-based Library

See Migrating the C-based Library.