Performance 稀疏矩阵乘法OpenCL vs英特尔MKL性能 我试图提高C++程序的性能,它能执行相当多的稀疏矩阵-密集矩阵乘法。该程序最初使用“英特尔MKL SparseBLAS”函数进行稀疏格式CSR矩阵乘法,对于小矩阵的乘法结果良好,但对于大矩阵(1024 x 1024以上)的大量乘法效果不佳

Performance 稀疏矩阵乘法OpenCL vs英特尔MKL性能 我试图提高C++程序的性能,它能执行相当多的稀疏矩阵-密集矩阵乘法。该程序最初使用“英特尔MKL SparseBLAS”函数进行稀疏格式CSR矩阵乘法,对于小矩阵的乘法结果良好,但对于大矩阵(1024 x 1024以上)的大量乘法效果不佳,performance,opencl,sparse-matrix,gpgpu,matrix-multiplication,Performance,Opencl,Sparse Matrix,Gpgpu,Matrix Multiplication,我尝试使用OpenCL实现在GPU(AMD Radeon R9 200)上运行乘法运算。我从中使用了相同的实现。然而,MKL函数在每一次试验中都以小于1024×1024的矩阵几乎击败了OpenCL,并且在那之后几乎是标准的。 我使用的OpenCL实现如下所示: __kernel void mat_mult_row_row(__global const unsigned int * sp_mat_row_indices, __global const unsigned int * sp_m

我尝试使用OpenCL实现在GPU(AMD Radeon R9 200)上运行乘法运算。我从中使用了相同的实现。然而,MKL函数在每一次试验中都以小于1024×1024的矩阵几乎击败了OpenCL,并且在那之后几乎是标准的。 我使用的OpenCL实现如下所示:

__kernel void mat_mult_row_row(__global const unsigned int * sp_mat_row_indices,
    __global const unsigned int * sp_mat_col_indices,
    __global const float * sp_mat_elements,
    __global const float * d_mat,
    unsigned int d_mat_row_start,
    unsigned int d_mat_col_start,
    unsigned int d_mat_row_inc,
    unsigned int d_mat_col_inc,
    unsigned int d_mat_row_size,
    unsigned int d_mat_col_size,
    unsigned int d_mat_internal_rows,
    unsigned int d_mat_internal_cols,
    __global float * result,
    unsigned int result_row_start,
    unsigned int result_col_start,
    unsigned int result_row_inc,
    unsigned int result_col_inc,
    unsigned int result_row_size,
    unsigned int result_col_size,
    unsigned int result_internal_rows,
    unsigned int result_internal_cols)
{
    for (unsigned int row = get_group_id(0); row < result_row_size; row += get_num_groups(0))
    {
        unsigned int row_start = sp_mat_row_indices[row];
        unsigned int row_end = sp_mat_row_indices[row + 1];
        for (unsigned int col = get_local_id(0); col < result_col_size; col += get_local_size(0))
        {
            float r = 0;
            for (unsigned int k = row_start; k < row_end; k++)
            {
                unsigned int j = sp_mat_col_indices[k];
                float x = sp_mat_elements[k];
                float y = d_mat[(d_mat_row_start + j * d_mat_row_inc) * d_mat_internal_cols + d_mat_col_start + col * d_mat_col_inc];
                r += x * y;
            }
            result[(result_row_start + row * result_row_inc) * result_internal_cols + result_col_start + col * result_col_inc] = r;
        }
    }
}
\uuuuuuuu内核无效mat\u mult\u行(\uuuuu全局常量unsigned int*sp\u mat\u行索引,
__全局常量无符号整数*sp_mat_col_索引,
__全局常量浮点*sp_mat_元素,
__全局常量浮点*d_mat,
未签名的整数数据行开始,
无符号整数d_mat_col_start,
未签名的int d_mat_row_公司,
未签名的int d_mat_col_公司,
无符号整数数据行大小,
无符号整数d_mat_col_size,
无符号整数d_mat_internal_行,
无符号整数d_mat_internal_cols,
__全球浮动*结果,
无符号整数结果\u行\u开始,
无符号整数结果\u列\u开始,
无符号整数结果行有限公司,
无符号整数结果列公司,
无符号整数结果\行\大小,
无符号整数结果列大小,
无符号整数结果\内部\行,
无符号整数结果(内部列)
{
for(unsigned int row=get\u group\u id(0);row
我将对内核的调用与结果矩阵中元素的数量一样多的工作项排队(或者64的最小倍数大于大小,因为据我所知,64是AMD设备的波前大小)。OpenCL代码用于填充,但我没有使用任何填充

我创建了200个随机稀疏和密集矩阵,并用这两种方法将它们相乘,每次相乘都计时。对于1024 x 1024的矩阵,MKL和OpenCL实现的时间平均为每次乘法15毫秒。我知道使用OpenCL进行内存传输会很费力,但是对于大型矩阵,计算性能应该更好


我对OpenCL不是很有经验,这是我第二次尝试OpenCL。有什么关于性能问题的提示吗?或者这是我目前能得到的最好的吗如果可能的话,我如何加快稀疏矩阵-超出“英特尔MKL稀疏BLAS”函数的密集矩阵乘法速度?非常感谢所有帮助。

没有人回答我的问题:(Egeng library在csr*密集型产品中表现不错。但不确定它是否能击败MKL。