大数组的 ISPC spmm 操作

问题描述

我在 ispc 中编写了以下内核来执行稀疏矩阵密集矩阵乘法 (SpMM)

// assume same number of rows and columns in the sparse matrix
export void __spmm_csr_ispc_naive(uniform int64 num_rows,// num_rows and columns in the sparse matrix
                            uniform int64 num_cols,// num_cols in the dense matrix
                            uniform int64 Ap[],// row pointers
                            uniform int32 Aj[],// column indices
                            uniform float Ax[],// values
                            uniform float B[],// dense matrix
                            uniform float C[])  { // result matrix

    // foreach (i = 0 ... num_rows) {
    for (int64 i = 0; i < num_rows; i++) {
        int32 row_start = Ap[i];
        int32 row_end   = Ap[i+1];
        // for (int j = 0; j < num_cols; j++) {
        foreach (j = 0 ... num_cols) {
            float sum = 0.0f;
            for (int64 jj = row_start; jj < row_end; jj++) {            
                int32 k = Aj[jj];                     // column index
                int64 b_idx = k*num_cols + j;
                float aValue = Ax[jj];              // a mat value from column index
                float bValue = B[b_idx];
                sum += aValue * bValue;
            }
            int64 c_idx = i*num_cols + j;
            C[c_idx] = sum; 
        }
    }
}

这里的稀疏矩阵使用 CSR(压缩稀疏行)格式。稀疏矩阵在其密集格式中具有维度 (num_rows,num_rows)。 Ap 是 num_rows+1 长度的一维数组,而 Aj 和 Ax 是 num_rows * num_rows * 0.1 的一维数组,因为我正在创建稀疏度为 10% 的稀疏矩阵

内核似乎适用于 num_rows 等于 70000 及以下的值,但是当我尝试使 num_rows 等于 75000 或更高时,代码给出了分段错误错误。由于我使用 int64 作为数组索引,我不确定我在这里做错了什么。感谢您对解决此问题的任何帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)