@@ -36,12 +36,10 @@ class test_3d_class;
36
36
namespace s = cl::sycl;
37
37
38
38
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,
40
40
dataT expectedColour) {
41
41
dataT resultData;
42
42
43
- s::default_selector selector;
44
-
45
43
{ // Scope everything to force destruction
46
44
s::image<1 > image (hostPtr, s::image_channel_order::rgba,
47
45
channelType, s::range<1 >{3 });
@@ -50,7 +48,6 @@ bool test1d_coord(dataT *hostPtr, coordT coord,
50
48
s::range<1 >(1 ));
51
49
52
50
// Do the test by reading a single pixel from the image
53
- s::queue myQueue (selector);
54
51
myQueue.submit ([&](s::handler &cgh) {
55
52
auto imageAcc =
56
53
image.get_access <dataT, s::access::mode::read>(cgh);
@@ -82,12 +79,10 @@ bool test1d_coord(dataT *hostPtr, coordT coord,
82
79
}
83
80
84
81
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,
86
83
dataT expectedColour) {
87
84
dataT resultData;
88
85
89
- s::default_selector selector;
90
-
91
86
{ // Scope everything to force destruction
92
87
s::image<2 > image (hostPtr, s::image_channel_order::rgba,
93
88
channelType, s::range<2 >{3 , 3 });
@@ -96,7 +91,6 @@ bool test2d_coord(dataT *hostPtr, coordT coord,
96
91
s::range<1 >(1 ));
97
92
98
93
// Do the test by reading a single pixel from the image
99
- s::queue myQueue (selector);
100
94
myQueue.submit ([&](s::handler &cgh) {
101
95
auto imageAcc =
102
96
image.get_access <dataT, s::access::mode::read>(cgh);
@@ -109,10 +103,12 @@ bool test2d_coord(dataT *hostPtr, coordT coord,
109
103
});
110
104
});
111
105
}
106
+
112
107
#ifdef DEBUG_OUTPUT
113
- std::cout << " Got: " << resultData.r () << " , " << resultData.g ()
108
+ std::cout << " Got: " << resultData.r () << " , " << resultData.g ();
114
109
#endif // DEBUG_OUTPUT
115
- bool correct = true ;
110
+
111
+ bool correct = true ;
116
112
if (resultData.r () != expectedColour.r ())
117
113
correct = false ;
118
114
if (resultData.g () != expectedColour.g ())
@@ -125,12 +121,10 @@ bool test2d_coord(dataT *hostPtr, coordT coord,
125
121
}
126
122
127
123
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,
129
125
dataT expectedColour) {
130
126
dataT resultData;
131
127
132
- s::default_selector selector;
133
-
134
128
{ // Scope everything to force destruction
135
129
s::image<3 > image (hostPtr, s::image_channel_order::rgba,
136
130
channelType, s::range<3 >{3 , 3 , 3 });
@@ -139,7 +133,6 @@ bool test3d_coord(dataT *hostPtr, coordT coord,
139
133
s::range<1 >(1 ));
140
134
141
135
// Do the test by reading a single pixel from the image
142
- s::queue myQueue (selector);
143
136
myQueue.submit ([&](s::handler &cgh) {
144
137
auto imageAcc =
145
138
image.get_access <dataT, s::access::mode::read>(cgh);
@@ -171,95 +164,114 @@ bool test3d_coord(dataT *hostPtr, coordT coord,
171
164
}
172
165
173
166
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) {
175
168
dataT hostPtr[3 ];
176
169
for (int i = 0 ; i < 3 ; i++)
177
170
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);
179
173
}
180
174
181
175
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) {
183
177
dataT hostPtr[9 ];
184
178
for (int i = 0 ; i < 9 ; i++)
185
179
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);
187
182
}
188
183
189
184
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) {
191
186
dataT hostPtr[27 ];
192
187
for (int i = 0 ; i < 27 ; i++)
193
188
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);
195
191
}
196
192
197
193
template <typename dataT, s::image_channel_type channelType>
198
- bool test () {
194
+ bool test (s::queue myQueue ) {
199
195
bool passed = true ;
200
-
201
196
// 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 )))
203
198
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 )))
205
201
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 )))
207
204
passed = false ;
208
205
209
206
// 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 )))
211
208
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 )))
213
211
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 )))
215
214
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 )))
217
217
passed = false ;
218
218
219
219
// 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 )))
222
222
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 )))
225
226
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 )))
228
230
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 )))
231
234
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 )))
234
238
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 )))
237
242
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 )))
240
247
passed = false ;
241
248
242
249
return passed;
243
250
}
244
251
245
252
int main () {
246
253
254
+ s::default_selector selector;
255
+ s::queue myQueue (selector);
256
+
247
257
bool passed = true ;
248
258
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
+ }
252
264
253
265
// Float image
254
- if (!test<s::float4, s::image_channel_type::fp32>())
266
+ if (!test<s::float4, s::image_channel_type::fp32>(myQueue ))
255
267
passed = false ;
256
268
257
269
// 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 ))
259
271
passed = false ;
260
272
261
273
// 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 ))
263
275
passed = false ;
264
276
265
277
return passed ? 0 : -1 ;
0 commit comments