Skip to content

Customize:Formats

NCIC-AlphaSparse edited this page Sep 30, 2024 · 16 revisions

Briefs

AlphaSparseLib provides a series of formats that widely used in various applications, including CSR, COO, CSC, BSR, etc. The formats are defined in file spmat.h and corresponding operations can be find in directory format. We show the way to customize your formats in this page.

Format definitions

To simplify the complexity of the kernel interface, we combined matrix structure and data types in the way of macro definition, and expanded matrix structure in kernel according to different data types, such as #define ALPHA_SPMAT_CSR spmat_csr_s_t,To expand the unified CSR structure into a concrete float data type matrix structure, the spmat_csr_s_t structure needs to be defined. To accommodate the data storage requirements of different computing platforms (currently multi-core HOST and HIP many-core DEVICE), the matrix structure of the specific data type contains Pointers to the data storage of different platforms, such as:

typedef struct
{
  float *values;
  int   *rows_ptr;
  int   *col_indx;

  float *d_values;
  int   *d_row_ptr;
  int   *d_col_indx;

} spmat_csr_s_t;

CSR format arrays: values,rows_ptr,col_indx are pointers for HOST memory, and arrays with d_ prefix are pointers for DEVICE memroy.

Format opeartions

In the calculation process, it is usually necessary to perform matrix creation, transposition, format transformation, and so on.These operations are defined in corresponding headers in the directoryformat, like the transposing in csr.h for CSR format:

alphasparse_status_t transpose_s_csr(const spmat_csr_s_t *s, spmat_csr_s_t **d);

New operations can be extended。

Implementation

The operations are inplemented in files of directorysrc/format. Note the naming types of files,like

alphasparse_x_create_csr.c

In order to reduce the redundancy of the code, the unified code processing is adopted for different data types. The 'x' in this file name will be generated according to the compilation options in the compilation process, and the function implementation of four data types s,d,c, and z will be generated respectively for the datatype of float,double,float complex and double complex. The function name of ONAME will be replaced as the same of the file name, such as the function of creating the CSR matrix with the float datatype 'ONAME->alphasparse_s_create_csr'.