0

我在 sycl 中做矩阵乘法,但有一些问题。我正在使用 2 (4x4) 矩阵进行乘法,并且在for 循环的第一次迭代中它可以工作,但是在i = 1 的第二次迭代中,它工作正常,直到 C[11] = A[11]*B[15]但它会跳过 1乘法和前进。我知道它为什么会跳过的问题,但不幸的是我无法正确更改矩阵 B 索引。如果有人可以提供帮助,我将不胜感激。谢谢

这是代码 Matsize= 4, Blocksize = 4我也知道 for 循环将等于 matsize 它是 2 只是为了清楚地了解执行流程

{
    range<1> dimensions(matSize * matSize);
    const property_list props = { property::buffer::use_host_ptr() };
    buffer<T> A_buf(MA, dimensions, props);
    buffer<T> B_buf(MB, dimensions, props);
    buffer<T> C_buf(MC, dimensions, props);

    myQueue.submit([&](handler& cgh) {
        auto A_ptr = A_buf.template get_access<access::mode::read>(cgh);
        auto B_ptr = B_buf.template get_access<access::mode::read_write>(cgh);
        auto C_ptr = C_buf.template get_access<access::mode::write>(cgh);
        auto localRange = range<1>(blockSize* blockSize);

        accessor<T, 1, access::mode::read_write, access::target::local>
            C(matSize * matSize, cgh);

        cgh.parallel_for<mxm_kernel>(
            nd_range<2>(range<2>{matSize, matSize},   
                range<2>{blockSize, blockSize}),  
            [=](nd_item<2> item) {

            const auto id_x = item.get_global_id(0);
            const auto id_y = item.get_global_id(1);

            const auto width = item.get_group_range(0) * item.get_local_range(0);

            const auto index = id_x * width + id_y;
            const auto index2 = id_y * width + id_x;

            for (int i = 0; i < 2 ; i++) {

                C[index] += A_ptr[index] * B_ptr[index2 + i ];
            }
            out << "C is!" << C[index] << sycl::endl;

            item.barrier(cl::sycl::access::fence_space::local_space);
            C_ptr[index] = C[index];
        });
    });
}
4

0 回答 0