diff --git a/sycl/include/CL/sycl/handler.hpp b/sycl/include/CL/sycl/handler.hpp index 370abcfb0b013..198519cff1e9e 100644 --- a/sycl/include/CL/sycl/handler.hpp +++ b/sycl/include/CL/sycl/handler.hpp @@ -641,9 +641,7 @@ class __SYCL_EXPORT handler { range Range = Src.get_range(); parallel_for> (Range, [=](id Index) { - size_t LinearIndex = Index[0]; - for (int I = 1; I < Dim; ++I) - LinearIndex += Range[I] * Index[I]; + const size_t LinearIndex = detail::getLinearIndex(Index, Range); using TSrcNonConst = typename std::remove_const::type; (reinterpret_cast(Dst))[LinearIndex] = Src[Index]; }); @@ -678,9 +676,7 @@ class __SYCL_EXPORT handler { range Range = Dst.get_range(); parallel_for> (Range, [=](id Index) { - size_t LinearIndex = Index[0]; - for (int I = 1; I < Dim; ++I) - LinearIndex += Range[I] * Index[I]; + const size_t LinearIndex = detail::getLinearIndex(Index, Range); Dst[Index] = (reinterpret_cast(Src))[LinearIndex]; }); } diff --git a/sycl/test/basic_tests/handler/handler_mem_op.cpp b/sycl/test/basic_tests/handler/handler_mem_op.cpp index c0d3b1b10d4e8..ee7f262013e37 100644 --- a/sycl/test/basic_tests/handler/handler_mem_op.cpp +++ b/sycl/test/basic_tests/handler/handler_mem_op.cpp @@ -34,7 +34,9 @@ template struct point { template void test_fill(T Val); template void test_copy_ptr_acc(); +template void test_3D_copy_ptr_acc(); template void test_copy_acc_ptr(); +template void test_3D_copy_acc_ptr(); template void test_copy_shared_ptr_acc(); template void test_copy_shared_ptr_const_acc(); template void test_copy_acc_shared_ptr(); @@ -72,6 +74,14 @@ int main() { test_copy_ptr_acc>(); test_copy_ptr_acc>(); } + // handler.copy(ptr, acc) 3D + { + test_3D_copy_ptr_acc(); + test_3D_copy_ptr_acc(); + test_3D_copy_ptr_acc>(); + test_3D_copy_ptr_acc>(); + test_3D_copy_ptr_acc>(); + } // handler.copy(acc, ptr) { test_copy_acc_ptr(); @@ -80,6 +90,14 @@ int main() { test_copy_acc_ptr>(); test_copy_acc_ptr>(); } + // handler.copy(acc, ptr) 3D + { + test_3D_copy_acc_ptr(); + test_3D_copy_acc_ptr(); + test_3D_copy_acc_ptr>(); + test_3D_copy_acc_ptr>(); + test_3D_copy_acc_ptr>(); + } // handler.copy(shared_ptr, acc) { test_copy_shared_ptr_acc(); @@ -277,6 +295,28 @@ template void test_copy_ptr_acc() { assert(DstValue == 99); } +template void test_3D_copy_ptr_acc() { + const range<3> Range{2, 3, 4}; + const size_t Size = 2 * 3 * 4; + T Data[Size] = {0}; + T Values[Size] = {0}; + for (size_t I = 0; I < Size; ++I) + Values[I] = I; + + { + buffer Buffer(Data, Range); + queue Queue; + Queue.submit([&](handler &Cgh) { + accessor + Accessor(Buffer, Cgh, Range); + Cgh.copy(Values, Accessor); + }); + } + + for (int I = 0; I < Size; ++I) + assert(Data[I] == Values[I]); +} + template void test_copy_acc_ptr() { const size_t Size = 10; T Data[Size] = {0}; @@ -345,6 +385,28 @@ template void test_copy_acc_ptr() { assert(DstValue == 77); } +template void test_3D_copy_acc_ptr() { + const range<3> Range{2, 3, 4}; + const size_t Size = 2 * 3 * 4; + T Data[Size] = {0}; + T Values[Size] = {0}; + for (size_t I = 0; I < Size; ++I) + Data[I] = I; + + { + buffer Buffer(Data, Range); + queue Queue; + Queue.submit([&](handler &Cgh) { + accessor + Accessor(Buffer, Cgh, Range); + Cgh.copy(Accessor, Values); + }); + } + + for (size_t I = 0; I < Size; ++I) + assert(Data[I] == Values[I]); +} + template void test_copy_shared_ptr_acc() { const size_t Size = 10; T Data[Size] = {0};