Skip to content

Commit cba7371

Browse files
committed
[SYCL] Fix host_image_accessor_read
Avoid having two host accessor simultaneously. Signed-off-by: Vlad Romanov <[email protected]>
1 parent 53f89f4 commit cba7371

File tree

1 file changed

+51
-39
lines changed

1 file changed

+51
-39
lines changed

sycl/test/basic_tests/host_image_accessor_read.cpp

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,66 @@ int foo(float *image_data) {
2222
{
2323
cl::sycl::buffer<int, 1> ResultBuf(result, cl::sycl::range<1>(2));
2424
cl::sycl::queue Q;
25-
cl::sycl::image<3> Image_1(image_data, channelOrder, channelType, r);
25+
cl::sycl::image<3> Image(image_data, channelOrder, channelType, r);
2626

27-
cl::sycl::range<2> pitch = Image_1.get_pitch();
27+
cl::sycl::range<2> pitch = Image.get_pitch();
2828

29-
auto host_image_acc =
30-
Image_1.template get_access<cl::sycl::float4,
29+
cl::sycl::cl_int4 Coords{0, 1, 2, 0};
30+
{
31+
auto host_image_acc =
32+
Image.template get_access<cl::sycl::float4,
3133
cl::sycl::access::mode::read>();
3234

33-
auto Sampler = cl::sycl::sampler(
34-
cl::sycl::coordinate_normalization_mode::unnormalized,
35-
cl::sycl::addressing_mode::none, cl::sycl::filtering_mode::nearest);
36-
cl::sycl::cl_int4 Coords{0, 1, 2, 0};
37-
// Test image read function.
38-
cl::sycl::cl_float4 Ret_data = host_image_acc.read(Coords);
39-
assert((float)Ret_data.x() == 85);
40-
assert((float)Ret_data.y() == 86);
41-
assert((float)Ret_data.z() == 87);
42-
assert((float)Ret_data.w() == 88);
35+
auto Sampler = cl::sycl::sampler(
36+
cl::sycl::coordinate_normalization_mode::unnormalized,
37+
cl::sycl::addressing_mode::none, cl::sycl::filtering_mode::nearest);
38+
// Test image read function.
39+
cl::sycl::cl_float4 Ret_data = host_image_acc.read(Coords);
40+
assert((float)Ret_data.x() == 85);
41+
assert((float)Ret_data.y() == 86);
42+
assert((float)Ret_data.z() == 87);
43+
assert((float)Ret_data.w() == 88);
4344

44-
// Test image read with sampler.
45-
cl::sycl::cl_float4 Ret_data2 = host_image_acc.read(Coords, Sampler);
46-
assert((float)Ret_data2.x() == 85);
47-
assert((float)Ret_data2.y() == 86);
48-
assert((float)Ret_data2.z() == 87);
49-
assert((float)Ret_data2.w() == 88);
45+
// Test image read with sampler.
46+
cl::sycl::cl_float4 Ret_data2 = host_image_acc.read(Coords, Sampler);
47+
assert((float)Ret_data2.x() == 85);
48+
assert((float)Ret_data2.y() == 86);
49+
assert((float)Ret_data2.z() == 87);
50+
assert((float)Ret_data2.w() == 88);
51+
}
5052

51-
auto host_image_acc2 =
52-
Image_1.template get_access<cl::sycl::float4,
53+
{
54+
auto host_image_acc =
55+
Image.template get_access<cl::sycl::float4,
5356
cl::sycl::access::mode::write>();
5457

55-
// Test image write function.
56-
host_image_acc2.write(Coords, cl::sycl::cl_float4{120, 121, 122, 123});
57-
Ret_data = host_image_acc.read(Coords);
58-
assert((float)Ret_data.x() == 120);
59-
assert((float)Ret_data.y() == 121);
60-
assert((float)Ret_data.z() == 122);
61-
assert((float)Ret_data.w() == 123);
58+
// Test image write function.
59+
host_image_acc.write(Coords, cl::sycl::cl_float4{120, 121, 122, 123});
60+
}
61+
62+
{
63+
auto host_image_acc =
64+
Image.template get_access<cl::sycl::float4,
65+
cl::sycl::access::mode::read>();
66+
cl::sycl::cl_float4 Ret_data = host_image_acc.read(Coords);
67+
assert((float)Ret_data.x() == 120);
68+
assert((float)Ret_data.y() == 121);
69+
assert((float)Ret_data.z() == 122);
70+
assert((float)Ret_data.w() == 123);
6271

63-
// Test Out-of-bounds access for clamp_to_edge Addressing Mode.
64-
auto Sampler2 = cl::sycl::sampler(
65-
cl::sycl::coordinate_normalization_mode::unnormalized,
66-
cl::sycl::addressing_mode::clamp_to_edge, cl::sycl::filtering_mode::nearest);
67-
cl::sycl::cl_int4 OutBnds_Coords{2, 2, 3, 0};
68-
cl::sycl::cl_float4 OutBnds_RetData = host_image_acc.read(OutBnds_Coords, Sampler2);
69-
assert((float)OutBnds_RetData.x() == 105);
70-
assert((float)OutBnds_RetData.y() == 106);
71-
assert((float)OutBnds_RetData.z() == 107);
72-
assert((float)OutBnds_RetData.w() == 108);
72+
// Test Out-of-bounds access for clamp_to_edge Addressing Mode.
73+
auto Sampler = cl::sycl::sampler(
74+
cl::sycl::coordinate_normalization_mode::unnormalized,
75+
cl::sycl::addressing_mode::clamp_to_edge,
76+
cl::sycl::filtering_mode::nearest);
77+
cl::sycl::cl_int4 OutBnds_Coords{2, 2, 3, 0};
78+
cl::sycl::cl_float4 OutBnds_RetData =
79+
host_image_acc.read(OutBnds_Coords, Sampler);
80+
assert((float)OutBnds_RetData.x() == 105);
81+
assert((float)OutBnds_RetData.y() == 106);
82+
assert((float)OutBnds_RetData.z() == 107);
83+
assert((float)OutBnds_RetData.w() == 108);
84+
}
7385

7486
}
7587
return 0;

0 commit comments

Comments
 (0)