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

为简化kernel接口的复杂性,我们以宏定义的方式将矩阵结构与数据类型进行了融合,根据不同的数据类型在kernel中对矩阵结构进行展开,如#define ALPHA_SPMAT_CSR spmat_csr_s_t,将统一的CSR结构展开为具体的float数据类型的矩阵结构,spmat_csr_s_t结构体则需要具体定义。为兼容不同计算平台(目前有多核和HIP众核)的数据存储要求,具体数据类型的矩阵结构包含了指向不同平台数据存储的指针,如:

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格式的三元组values,rows_ptr,col_indx为指向主机端内存数据的指针,而有**d_**前缀的则指向设备端内存数据的指针。

Format opeartions

在计算过程中,通常需要对矩阵实施创建、转置、格式转变等,这些操作定义在目录format下对应格式名的头文件中,如csr.h头文件中,对CSR格式矩阵的转置操作:

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

可以根据需求增加新的操作定义。

Implementation

矩阵操作的实现在src/format,这里需要注意实现文件的命名规则,如

[alphasparse_x_create_csr.c](https://github.com/ALSparse/ALSparse/blob/master/src/core/format/alphasparse_x_create_csr.c)

为减少代码的冗余,对不同的数据类型采取了统一化代码处理,此文件名中**_x_在编译过程中会根据编译选项,生成s,d,c,z四种数据类型的函数实现,分别对应float,double,float complex,double complex,该操作的函数名ONAME**也会替换为与文件名相同的函数名,如单精度数据类型的CSR格式矩阵创建'ONAME->alphasparse_s_create_csr'。

Clone this wiki locally