如何解决大数组的 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 举报,一经查实,本站将立刻删除。