疎行列の密行列乗算 (SpMM) を実行するために、ispc で以下のカーネルを作成しました。
// 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 (Compressed Sparse Row) 形式を使用します。疎行列には、密形式の次元 (num_rows, num_rows) があります。Ap は num_rows+1 の長さの 1D 配列ですが、Aj と Ax は num_rows * num_rows * 0.1 の 1D 配列です。これは、スパース性が 10% のスパース行列を作成しているためです。
カーネルは num_rows が 70000 以下の値で動作しているように見えますが、num_rows を 75000 以上にしようとすると、コードでセグメンテーション違反エラーが発生します。配列インデックスに int64 を使用しているため、ここで何が間違っているのかわかりません。この問題を解決するための助けをいただければ幸いです。