From 16f8991006c83e74236341972667239e0826e1fd Mon Sep 17 00:00:00 2001 From: rdeodhar Date: Mon, 13 Sep 2021 13:52:23 -0700 Subject: [PATCH 1/3] [SYCL] Correction to accessor range indexing. Signed-off-by: rdeodhar --- sycl/include/CL/sycl/accessor.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/include/CL/sycl/accessor.hpp b/sycl/include/CL/sycl/accessor.hpp index 5bad3b36e1ede..c786b36c38208 100755 --- a/sycl/include/CL/sycl/accessor.hpp +++ b/sycl/include/CL/sycl/accessor.hpp @@ -592,7 +592,7 @@ class image_accessor template > range<3> get_range() const { cl_int3 Range = getRangeInternal(); - return range<3>(Range[0], Range[1], Range[3]); + return range<3>(Range[0], Range[1], Range[2]); } #else From 1faa3a5bb2428dc7ccc1fcbe607714612ff9cae5 Mon Sep 17 00:00:00 2001 From: Rajiv Deodhar Date: Tue, 21 Sep 2021 15:30:27 -0700 Subject: [PATCH 2/3] Added test. Currently expected to fail on L0. --- .../test/basic_tests/image_accessor_range.cpp | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 sycl/test/basic_tests/image_accessor_range.cpp diff --git a/sycl/test/basic_tests/image_accessor_range.cpp b/sycl/test/basic_tests/image_accessor_range.cpp new file mode 100755 index 0000000000000..88df3507d8ad6 --- /dev/null +++ b/sycl/test/basic_tests/image_accessor_range.cpp @@ -0,0 +1,117 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER +// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER + +// XFAIL: level_zero + +#include +#include +#include +using namespace sycl; +#define N 4 // dimensin +#define M 128 // dimension +#define C 4 // 4 channel +#define L 2 // 2 images + +void try_1D(queue &Q) { + int X = -55; + buffer BX{&X, 1}; + int *host_array = new int[M * C]; + image im1(host_array, image_channel_order::rgba, + image_channel_type::unsigned_int8, range{M}); + + Q.submit([&](handler &h) { + accessor acs1(im1, h); + accessor ABX{BX, h}; + auto R = acs1.get_range(); + std::cout << "Host acs1.get_range()=" << R[0] << "\n"; + assert(R[0] == M); + h.parallel_for(nd_range{range{M}, range{N}}, [=](nd_item<1> it) { + int idx = it.get_global_linear_id(); + if (idx == 0) { + auto R = acs1.get_range(); + ABX[0] = R[0]; + } + }); + }); + { + host_accessor HABX{BX, read_only}; + std::cout << "From Device acs1.get_range()=" << X << "\n"; + assert(X == M); + } +} + +void try_2D(queue &Q) { + range<2> X = {55, 66}; + buffer, 1> BX{&X, 1}; + int *host_array = new int[M * N * C]; + image im2(host_array, image_channel_order::rgba, + image_channel_type::unsigned_int8, range{M, N}); + + Q.submit([&](handler &h) { + accessor acs2(im2, h); + accessor ABX{BX, h}; + auto R = acs2.get_range(); + std::cout << "Host acs2.get_range()=" << R[0] << "," << R[1] << "\n"; + assert(R[0] == M); + assert(R[1] == N); + h.parallel_for(nd_range{range{M, N}, range{N, N}}, [=](nd_item<2> it) { + int idx = it.get_global_linear_id(); + if (idx == 0) { + ABX[0] = acs2.get_range(); + } + }); + }); + { + host_accessor HABX{BX, read_only}; + std::cout << "From Device acs2.get_range()=" << HABX[0][0] << "," + << HABX[0][1] << "\n"; + assert(HABX[0][0] == M); + assert(HABX[0][1] == N); + } +} + +void try_3D(queue &Q) { + range<3> X{55, 66, 77}; + buffer, 1> BX{&X, 1}; + int *host_array3_2 = malloc_host(N * M * C * L, Q); + image im3(host_array3_2, image_channel_order::rgba, + image_channel_type::unsigned_int8, range{M, N, L}); + + Q.submit([&](handler &h) { + accessor acs3(im3, + h); + accessor ABX{BX, h}; + auto R = acs3.get_range(); + std::cout << "Host acs3.get_range()=" << R[0] << "," << R[1] << "," << R[2] + << "\n"; + assert(R[0] == M); + assert(R[1] == N); + assert(R[2] == L); + h.parallel_for(nd_range{range{M, N, L}, range{N, N, L}}, + [=](nd_item<3> it) { + int idx = it.get_global_linear_id(); + if (idx == 0) { + ABX[0] = acs3.get_range(); + } + }); + }); + { + host_accessor HABX{BX, read_only}; + std::cout << "From Device acs3.get_range()=" << HABX[0][0] << "," + << HABX[0][1] << "," << HABX[0][2] << "\n"; + assert(HABX[0][0] == M); + assert(HABX[0][1] == N); + assert(HABX[0][2] == L); + } +} + +int main() { + queue Q; + + try_1D(Q); + try_2D(Q); + try_3D(Q); + + return 0; +} \ No newline at end of file From 740bee6fa26417a01bf4b71bae7c70109ef6230e Mon Sep 17 00:00:00 2001 From: Rajiv Deodhar Date: Wed, 22 Sep 2021 11:08:15 -0700 Subject: [PATCH 3/3] Removed test, which will be added to llvm_test_suite. --- .../test/basic_tests/image_accessor_range.cpp | 117 ------------------ 1 file changed, 117 deletions(-) delete mode 100755 sycl/test/basic_tests/image_accessor_range.cpp diff --git a/sycl/test/basic_tests/image_accessor_range.cpp b/sycl/test/basic_tests/image_accessor_range.cpp deleted file mode 100755 index 88df3507d8ad6..0000000000000 --- a/sycl/test/basic_tests/image_accessor_range.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER -// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER - -// XFAIL: level_zero - -#include -#include -#include -using namespace sycl; -#define N 4 // dimensin -#define M 128 // dimension -#define C 4 // 4 channel -#define L 2 // 2 images - -void try_1D(queue &Q) { - int X = -55; - buffer BX{&X, 1}; - int *host_array = new int[M * C]; - image im1(host_array, image_channel_order::rgba, - image_channel_type::unsigned_int8, range{M}); - - Q.submit([&](handler &h) { - accessor acs1(im1, h); - accessor ABX{BX, h}; - auto R = acs1.get_range(); - std::cout << "Host acs1.get_range()=" << R[0] << "\n"; - assert(R[0] == M); - h.parallel_for(nd_range{range{M}, range{N}}, [=](nd_item<1> it) { - int idx = it.get_global_linear_id(); - if (idx == 0) { - auto R = acs1.get_range(); - ABX[0] = R[0]; - } - }); - }); - { - host_accessor HABX{BX, read_only}; - std::cout << "From Device acs1.get_range()=" << X << "\n"; - assert(X == M); - } -} - -void try_2D(queue &Q) { - range<2> X = {55, 66}; - buffer, 1> BX{&X, 1}; - int *host_array = new int[M * N * C]; - image im2(host_array, image_channel_order::rgba, - image_channel_type::unsigned_int8, range{M, N}); - - Q.submit([&](handler &h) { - accessor acs2(im2, h); - accessor ABX{BX, h}; - auto R = acs2.get_range(); - std::cout << "Host acs2.get_range()=" << R[0] << "," << R[1] << "\n"; - assert(R[0] == M); - assert(R[1] == N); - h.parallel_for(nd_range{range{M, N}, range{N, N}}, [=](nd_item<2> it) { - int idx = it.get_global_linear_id(); - if (idx == 0) { - ABX[0] = acs2.get_range(); - } - }); - }); - { - host_accessor HABX{BX, read_only}; - std::cout << "From Device acs2.get_range()=" << HABX[0][0] << "," - << HABX[0][1] << "\n"; - assert(HABX[0][0] == M); - assert(HABX[0][1] == N); - } -} - -void try_3D(queue &Q) { - range<3> X{55, 66, 77}; - buffer, 1> BX{&X, 1}; - int *host_array3_2 = malloc_host(N * M * C * L, Q); - image im3(host_array3_2, image_channel_order::rgba, - image_channel_type::unsigned_int8, range{M, N, L}); - - Q.submit([&](handler &h) { - accessor acs3(im3, - h); - accessor ABX{BX, h}; - auto R = acs3.get_range(); - std::cout << "Host acs3.get_range()=" << R[0] << "," << R[1] << "," << R[2] - << "\n"; - assert(R[0] == M); - assert(R[1] == N); - assert(R[2] == L); - h.parallel_for(nd_range{range{M, N, L}, range{N, N, L}}, - [=](nd_item<3> it) { - int idx = it.get_global_linear_id(); - if (idx == 0) { - ABX[0] = acs3.get_range(); - } - }); - }); - { - host_accessor HABX{BX, read_only}; - std::cout << "From Device acs3.get_range()=" << HABX[0][0] << "," - << HABX[0][1] << "," << HABX[0][2] << "\n"; - assert(HABX[0][0] == M); - assert(HABX[0][1] == N); - assert(HABX[0][2] == L); - } -} - -int main() { - queue Q; - - try_1D(Q); - try_2D(Q); - try_3D(Q); - - return 0; -} \ No newline at end of file