带有 ispc 编译器的 SPMM 内核产生错误的错误结果

问题描述

我正在尝试编写一个内核来执行稀疏矩阵-密集矩阵乘法,但是用 ispc 编写的内核没有输出正确的结果矩阵。

下面是我在没有 ispc 编译器支持的情况下正常串行执行的内核。

template <typename IndexType,typename ValueType>
void __spmm_csr_serial_host(const IndexType num_rows,const IndexType num_cols,const IndexType *Ap,const IndexType *Aj,const ValueType *Ax,const ValueType *x,ValueType *y)    
{
    for (IndexType i = 0; i < num_rows; i++){
        const IndexType row_start = Ap[i];
        const IndexType row_end   = Ap[i+1];
        for (IndexType j = 0; j < num_cols; j++) {
            IndexType idx = i*num_cols + j;
            ValueType sum = y[idx];
            for (IndexType jj = row_start; jj < row_end; jj++) {            
                const IndexType k = Aj[jj];  //column index
                sum += x[k*num_cols + j] * Ax[jj];
            }
            y[idx] = sum; 
        }
    }
}

上述串行内核工作正常并输出所需的输出。我更改了以下代码支持 ispc。

export void __spmm_csr_ispc(uniform int num_rows,uniform int num_cols,uniform int Ap[],uniform int Aj[],uniform float Ax[],uniform float B[],uniform float C[])  {

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

ispc 内核没有产生正确的结果,我在这一点上有点卡住了。 ispc 也不让我们在内核中有打印语句。感谢您帮助纠正错误或调试错误

解决方法

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

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

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