Skip to content

Commit 1faa3a5

Browse files
committed
Added test. Currently expected to fail on L0.
1 parent 58a9fad commit 1faa3a5

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER
4+
5+
// XFAIL: level_zero
6+
7+
#include <CL/sycl.hpp>
8+
#include <CL/sycl/accessor.hpp>
9+
#include <iostream>
10+
using namespace sycl;
11+
#define N 4 // dimensin
12+
#define M 128 // dimension
13+
#define C 4 // 4 channel
14+
#define L 2 // 2 images
15+
16+
void try_1D(queue &Q) {
17+
int X = -55;
18+
buffer<int, 1> BX{&X, 1};
19+
int *host_array = new int[M * C];
20+
image im1(host_array, image_channel_order::rgba,
21+
image_channel_type::unsigned_int8, range{M});
22+
23+
Q.submit([&](handler &h) {
24+
accessor<int4, 1, access::mode::read, access::target::image> acs1(im1, h);
25+
accessor ABX{BX, h};
26+
auto R = acs1.get_range();
27+
std::cout << "Host acs1.get_range()=" << R[0] << "\n";
28+
assert(R[0] == M);
29+
h.parallel_for(nd_range{range{M}, range{N}}, [=](nd_item<1> it) {
30+
int idx = it.get_global_linear_id();
31+
if (idx == 0) {
32+
auto R = acs1.get_range();
33+
ABX[0] = R[0];
34+
}
35+
});
36+
});
37+
{
38+
host_accessor HABX{BX, read_only};
39+
std::cout << "From Device acs1.get_range()=" << X << "\n";
40+
assert(X == M);
41+
}
42+
}
43+
44+
void try_2D(queue &Q) {
45+
range<2> X = {55, 66};
46+
buffer<range<2>, 1> BX{&X, 1};
47+
int *host_array = new int[M * N * C];
48+
image im2(host_array, image_channel_order::rgba,
49+
image_channel_type::unsigned_int8, range{M, N});
50+
51+
Q.submit([&](handler &h) {
52+
accessor<int4, 2, access::mode::read, access::target::image> acs2(im2, h);
53+
accessor ABX{BX, h};
54+
auto R = acs2.get_range();
55+
std::cout << "Host acs2.get_range()=" << R[0] << "," << R[1] << "\n";
56+
assert(R[0] == M);
57+
assert(R[1] == N);
58+
h.parallel_for(nd_range{range{M, N}, range{N, N}}, [=](nd_item<2> it) {
59+
int idx = it.get_global_linear_id();
60+
if (idx == 0) {
61+
ABX[0] = acs2.get_range();
62+
}
63+
});
64+
});
65+
{
66+
host_accessor HABX{BX, read_only};
67+
std::cout << "From Device acs2.get_range()=" << HABX[0][0] << ","
68+
<< HABX[0][1] << "\n";
69+
assert(HABX[0][0] == M);
70+
assert(HABX[0][1] == N);
71+
}
72+
}
73+
74+
void try_3D(queue &Q) {
75+
range<3> X{55, 66, 77};
76+
buffer<range<3>, 1> BX{&X, 1};
77+
int *host_array3_2 = malloc_host<int>(N * M * C * L, Q);
78+
image im3(host_array3_2, image_channel_order::rgba,
79+
image_channel_type::unsigned_int8, range{M, N, L});
80+
81+
Q.submit([&](handler &h) {
82+
accessor<int4, 2, access::mode::read, access::target::image_array> acs3(im3,
83+
h);
84+
accessor ABX{BX, h};
85+
auto R = acs3.get_range();
86+
std::cout << "Host acs3.get_range()=" << R[0] << "," << R[1] << "," << R[2]
87+
<< "\n";
88+
assert(R[0] == M);
89+
assert(R[1] == N);
90+
assert(R[2] == L);
91+
h.parallel_for(nd_range{range{M, N, L}, range{N, N, L}},
92+
[=](nd_item<3> it) {
93+
int idx = it.get_global_linear_id();
94+
if (idx == 0) {
95+
ABX[0] = acs3.get_range();
96+
}
97+
});
98+
});
99+
{
100+
host_accessor HABX{BX, read_only};
101+
std::cout << "From Device acs3.get_range()=" << HABX[0][0] << ","
102+
<< HABX[0][1] << "," << HABX[0][2] << "\n";
103+
assert(HABX[0][0] == M);
104+
assert(HABX[0][1] == N);
105+
assert(HABX[0][2] == L);
106+
}
107+
}
108+
109+
int main() {
110+
queue Q;
111+
112+
try_1D(Q);
113+
try_2D(Q);
114+
try_3D(Q);
115+
116+
return 0;
117+
}

0 commit comments

Comments
 (0)