Skip to content

Commit 0b2635c

Browse files
committed
Check for half support before running tests
1 parent fffd4a4 commit 0b2635c

File tree

2 files changed

+103
-99
lines changed

2 files changed

+103
-99
lines changed

sycl/test/basic_tests/image/image_read.cpp

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ class test_3d_class;
3636
namespace s = cl::sycl;
3737

3838
template <typename dataT, typename coordT, s::image_channel_type channelType>
39-
bool test1d_coord(dataT *hostPtr, coordT coord,
39+
bool test1d_coord(s::queue myQueue, dataT *hostPtr, coordT coord,
4040
dataT expectedColour) {
4141
dataT resultData;
4242

43-
s::default_selector selector;
44-
4543
{ // Scope everything to force destruction
4644
s::image<1> image(hostPtr, s::image_channel_order::rgba,
4745
channelType, s::range<1>{3});
@@ -50,7 +48,6 @@ bool test1d_coord(dataT *hostPtr, coordT coord,
5048
s::range<1>(1));
5149

5250
// Do the test by reading a single pixel from the image
53-
s::queue myQueue(selector);
5451
myQueue.submit([&](s::handler &cgh) {
5552
auto imageAcc =
5653
image.get_access<dataT, s::access::mode::read>(cgh);
@@ -82,12 +79,10 @@ bool test1d_coord(dataT *hostPtr, coordT coord,
8279
}
8380

8481
template <typename dataT, typename coordT, s::image_channel_type channelType>
85-
bool test2d_coord(dataT *hostPtr, coordT coord,
82+
bool test2d_coord(s::queue myQueue, dataT *hostPtr, coordT coord,
8683
dataT expectedColour) {
8784
dataT resultData;
8885

89-
s::default_selector selector;
90-
9186
{ // Scope everything to force destruction
9287
s::image<2> image(hostPtr, s::image_channel_order::rgba,
9388
channelType, s::range<2>{3, 3});
@@ -96,7 +91,6 @@ bool test2d_coord(dataT *hostPtr, coordT coord,
9691
s::range<1>(1));
9792

9893
// Do the test by reading a single pixel from the image
99-
s::queue myQueue(selector);
10094
myQueue.submit([&](s::handler &cgh) {
10195
auto imageAcc =
10296
image.get_access<dataT, s::access::mode::read>(cgh);
@@ -109,10 +103,12 @@ bool test2d_coord(dataT *hostPtr, coordT coord,
109103
});
110104
});
111105
}
106+
112107
#ifdef DEBUG_OUTPUT
113-
std::cout << "Got: " << resultData.r() << ", " << resultData.g()
108+
std::cout << "Got: " << resultData.r() << ", " << resultData.g();
114109
#endif // DEBUG_OUTPUT
115-
bool correct = true;
110+
111+
bool correct = true;
116112
if (resultData.r() != expectedColour.r())
117113
correct = false;
118114
if (resultData.g() != expectedColour.g())
@@ -125,12 +121,10 @@ bool test2d_coord(dataT *hostPtr, coordT coord,
125121
}
126122

127123
template <typename dataT, typename coordT, s::image_channel_type channelType>
128-
bool test3d_coord(dataT *hostPtr, coordT coord,
124+
bool test3d_coord(s::queue myQueue, dataT *hostPtr, coordT coord,
129125
dataT expectedColour) {
130126
dataT resultData;
131127

132-
s::default_selector selector;
133-
134128
{ // Scope everything to force destruction
135129
s::image<3> image(hostPtr, s::image_channel_order::rgba,
136130
channelType, s::range<3>{3, 3, 3});
@@ -139,7 +133,6 @@ bool test3d_coord(dataT *hostPtr, coordT coord,
139133
s::range<1>(1));
140134

141135
// Do the test by reading a single pixel from the image
142-
s::queue myQueue(selector);
143136
myQueue.submit([&](s::handler &cgh) {
144137
auto imageAcc =
145138
image.get_access<dataT, s::access::mode::read>(cgh);
@@ -171,95 +164,114 @@ bool test3d_coord(dataT *hostPtr, coordT coord,
171164
}
172165

173166
template <typename dataT, typename coordT, s::image_channel_type channelType>
174-
bool test1d(coordT coord, dataT expectedResult) {
167+
bool test1d(s::queue myQueue, coordT coord, dataT expectedResult) {
175168
dataT hostPtr[3];
176169
for (int i = 0; i < 3; i++)
177170
hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i);
178-
return test1d_coord<dataT, coordT, channelType>(hostPtr, coord, expectedResult);
171+
172+
return test1d_coord<dataT, coordT, channelType>(myQueue, hostPtr, coord, expectedResult);
179173
}
180174

181175
template <typename dataT, typename coordT, s::image_channel_type channelType>
182-
bool test2d(coordT coord, dataT expectedResult) {
176+
bool test2d(s::queue myQueue, coordT coord, dataT expectedResult) {
183177
dataT hostPtr[9];
184178
for (int i = 0; i < 9; i++)
185179
hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i);
186-
return test2d_coord<dataT, coordT, channelType>(hostPtr, coord, expectedResult);
180+
181+
return test2d_coord<dataT, coordT, channelType>(myQueue, hostPtr, coord, expectedResult);
187182
}
188183

189184
template <typename dataT, typename coordT, s::image_channel_type channelType>
190-
bool test3d(coordT coord, dataT expectedResult) {
185+
bool test3d(s::queue myQueue, coordT coord, dataT expectedResult) {
191186
dataT hostPtr[27];
192187
for (int i = 0; i < 27; i++)
193188
hostPtr[i] = dataT(0 + i, 20 + i, 40 + i, 60 + i);
194-
return test3d_coord<dataT, coordT, channelType>(hostPtr, coord, expectedResult);
189+
190+
return test3d_coord<dataT, coordT, channelType>(myQueue, hostPtr, coord, expectedResult);
195191
}
196192

197193
template <typename dataT, s::image_channel_type channelType>
198-
bool test() {
194+
bool test(s::queue myQueue) {
199195
bool passed = true;
200-
201196
// 1d image tests
202-
if (!test1d<dataT, int, channelType>(0, dataT(0, 20, 40, 60)))
197+
if (!test1d<dataT, int, channelType>(myQueue, 0, dataT(0, 20, 40, 60)))
203198
passed = false;
204-
if (!test1d<dataT, int, channelType>(1, dataT(1, 21, 41, 61)))
199+
200+
if (!test1d<dataT, int, channelType>(myQueue, 1, dataT(1, 21, 41, 61)))
205201
passed = false;
206-
if (!test1d<dataT, int, channelType>(2, dataT(2, 22, 42, 62)))
202+
203+
if (!test1d<dataT, int, channelType>(myQueue, 2, dataT(2, 22, 42, 62)))
207204
passed = false;
208205

209206
// 2d image tests
210-
if (!test2d<dataT, s::int2, channelType>(s::int2(0, 0), dataT(0, 20, 40, 60)))
207+
if (!test2d<dataT, s::int2, channelType>(myQueue, s::int2(0, 0), dataT(0, 20, 40, 60)))
211208
passed = false;
212-
if (!test2d<dataT, s::int2, channelType>(s::int2(1, 0), dataT(1, 21, 41, 61)))
209+
210+
if (!test2d<dataT, s::int2, channelType>(myQueue, s::int2(1, 0), dataT(1, 21, 41, 61)))
213211
passed = false;
214-
if (!test2d<dataT, s::int2, channelType>(s::int2(0, 1), dataT(3, 23, 43, 63)))
212+
213+
if (!test2d<dataT, s::int2, channelType>(myQueue, s::int2(0, 1), dataT(3, 23, 43, 63)))
215214
passed = false;
216-
if (!test2d<dataT, s::int2, channelType>(s::int2(1, 1), dataT(4, 24, 44, 64)))
215+
216+
if (!test2d<dataT, s::int2, channelType>(myQueue, s::int2(1, 1), dataT(4, 24, 44, 64)))
217217
passed = false;
218218

219219
// 3d image tests
220-
if (!test3d<dataT, s::int4, channelType>(
221-
s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60)))
220+
if (!test3d<dataT, s::int4, channelType>(myQueue,
221+
s::int4(0, 0, 0, 0), dataT(0, 20, 40, 60)))
222222
passed = false;
223-
if (!test3d<dataT, s::int4, channelType>(
224-
s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61)))
223+
224+
if (!test3d<dataT, s::int4, channelType>(myQueue,
225+
s::int4(1, 0, 0, 0), dataT(1, 21, 41, 61)))
225226
passed = false;
226-
if (!test3d<dataT, s::int4, channelType>(
227-
s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63)))
227+
228+
if (!test3d<dataT, s::int4, channelType>(myQueue,
229+
s::int4(0, 1, 0, 0), dataT(3, 23, 43, 63)))
228230
passed = false;
229-
if (!test3d<dataT, s::int4, channelType>(
230-
s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64)))
231+
232+
if (!test3d<dataT, s::int4, channelType>(myQueue,
233+
s::int4(1, 1, 0, 0), dataT(4, 24, 44, 64)))
231234
passed = false;
232-
if (!test3d<dataT, s::int4, channelType>(
233-
s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70)))
235+
236+
if (!test3d<dataT, s::int4, channelType>(myQueue,
237+
s::int4(1, 0, 1, 0), dataT(10, 30, 50, 70)))
234238
passed = false;
235-
if (!test3d<dataT, s::int4, channelType>(
236-
s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72)))
239+
240+
if (!test3d<dataT, s::int4, channelType>(myQueue,
241+
s::int4(0, 1, 1, 0), dataT(12, 32, 52, 72)))
237242
passed = false;
238-
if (!test3d<dataT, s::int4, channelType>(
239-
s::int4(1, 1, 1, 0), dataT(13, 33, 53, 73)))
243+
244+
if (!test3d<dataT, s::int4, channelType>(myQueue,
245+
s::int4(1, 1, 1, 0),
246+
dataT(13, 33, 53, 73)))
240247
passed = false;
241248

242249
return passed;
243250
}
244251

245252
int main() {
246253

254+
s::default_selector selector;
255+
s::queue myQueue(selector);
256+
247257
bool passed = true;
248258

249-
// Half image
250-
if (!test<s::half4, s::image_channel_type::fp16>())
251-
passed = false;
259+
if (myQueue.get_device().has_extension("cl_khr_fp16")) {
260+
// Half image
261+
if (!test<s::half4, s::image_channel_type::fp16>(myQueue))
262+
passed = false;
263+
}
252264

253265
// Float image
254-
if (!test<s::float4, s::image_channel_type::fp32>())
266+
if (!test<s::float4, s::image_channel_type::fp32>(myQueue))
255267
passed = false;
256268

257269
// 32-bit signed integer image
258-
if (!test<s::int4, s::image_channel_type::signed_int32>())
270+
if (!test<s::int4, s::image_channel_type::signed_int32>(myQueue))
259271
passed = false;
260272

261273
// 32-bit unsigned integer image
262-
if (!test<s::uint4, s::image_channel_type::unsigned_int32>())
274+
if (!test<s::uint4, s::image_channel_type::unsigned_int32>(myQueue))
263275
passed = false;
264276

265277
return passed ? 0 : -1;

0 commit comments

Comments
 (0)