1
1
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2
- // RUN: %HOST_RUN_PLACEHOLDER %t.out
3
2
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4
3
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5
4
// RUN: %ACC_RUN_PLACEHOLDER %t.out
@@ -141,28 +140,26 @@ int main() {
141
140
// Device accessor with 2-dimensional subscript operators.
142
141
{
143
142
sycl::queue Queue;
144
- if (!Queue.is_host ()) {
145
- int array[2 ][3 ] = {0 };
146
- {
147
- sycl::range<2 > Range (2 , 3 );
148
- sycl::buffer<int , 2 > buf ((int *)array, Range,
149
- {sycl::property::buffer::use_host_ptr ()});
143
+ int array[2 ][3 ] = {0 };
144
+ {
145
+ sycl::range<2 > Range (2 , 3 );
146
+ sycl::buffer<int , 2 > buf ((int *)array, Range,
147
+ {sycl::property::buffer::use_host_ptr ()});
150
148
151
- Queue.submit ([&](sycl::handler &cgh) {
152
- auto acc = buf.get_access <sycl::access::mode::read_write>(cgh);
153
- cgh.parallel_for <class dim2_subscr >(Range, [=](sycl::item<2 > itemID) {
154
- acc[itemID.get_id (0 )][itemID.get_id (1 )] += itemID.get_linear_id ();
155
- });
149
+ Queue.submit ([&](sycl::handler &cgh) {
150
+ auto acc = buf.get_access <sycl::access::mode::read_write>(cgh);
151
+ cgh.parallel_for <class dim2_subscr >(Range, [=](sycl::item<2 > itemID) {
152
+ acc[itemID.get_id (0 )][itemID.get_id (1 )] += itemID.get_linear_id ();
156
153
});
157
- Queue. wait ( );
158
- }
159
- for ( int i = 0 ; i < 2 ; i++) {
160
- for (int j = 0 ; j < 3 ; j ++) {
161
- if (array[i][j] != i * 3 + j ) {
162
- std::cerr << array[i][j] << " != " << ( i * 3 + j) << std::endl;
163
- assert ( 0 ) ;
164
- return 1 ;
165
- }
154
+ } );
155
+ Queue. wait ();
156
+ }
157
+ for (int i = 0 ; i < 2 ; i ++) {
158
+ for ( int j = 0 ; j < 3 ; j++ ) {
159
+ if ( array[i][j] != i * 3 + j) {
160
+ std::cerr << array[i][j] << " != " << (i * 3 + j) << std::endl ;
161
+ assert ( 0 ) ;
162
+ return 1 ;
166
163
}
167
164
}
168
165
}
@@ -172,52 +169,48 @@ int main() {
172
169
// check compile error
173
170
{
174
171
sycl::queue queue;
175
- if (!queue.is_host ()) {
176
- sycl::range<2 > range (1 , 1 );
177
- int Arr[] = {2 };
178
- {
179
- sycl::buffer<int , 1 > Buf (Arr, 1 );
180
- queue.submit ([&](sycl::handler &cgh) {
181
- auto acc = sycl::accessor<int , 2 , sycl::access::mode::atomic,
182
- sycl::target::local>(range, cgh);
183
- cgh.parallel_for <class dim2_subscr_atomic >(
184
- sycl::nd_range<2 >{range, range}, [=](sycl::nd_item<2 >) {
185
- sycl::atomic<int , sycl::access::address_space::local_space>
186
- value = acc[0 ][0 ];
187
- });
188
- });
189
- }
172
+ sycl::range<2 > range (1 , 1 );
173
+ int Arr[] = {2 };
174
+ {
175
+ sycl::buffer<int , 1 > Buf (Arr, 1 );
176
+ queue.submit ([&](sycl::handler &cgh) {
177
+ auto acc = sycl::accessor<int , 2 , sycl::access::mode::atomic,
178
+ sycl::target::local>(range, cgh);
179
+ cgh.parallel_for <class dim2_subscr_atomic >(
180
+ sycl::nd_range<2 >{range, range}, [=](sycl::nd_item<2 >) {
181
+ sycl::atomic<int , sycl::access::address_space::local_space>
182
+ value = acc[0 ][0 ];
183
+ });
184
+ });
190
185
}
191
186
}
192
187
193
188
// Device accessor with 3-dimensional subscript operators.
194
189
{
195
190
sycl::queue Queue;
196
- if (!Queue.is_host ()) {
197
- int array[2 ][3 ][4 ] = {0 };
198
- {
199
- sycl::range<3 > Range (2 , 3 , 4 );
200
- sycl::buffer<int , 3 > buf ((int *)array, Range,
201
- {sycl::property::buffer::use_host_ptr ()});
191
+ int array[2 ][3 ][4 ] = {0 };
192
+ {
193
+ sycl::range<3 > Range (2 , 3 , 4 );
194
+ sycl::buffer<int , 3 > buf ((int *)array, Range,
195
+ {sycl::property::buffer::use_host_ptr ()});
202
196
203
- Queue.submit ([&](sycl::handler &cgh) {
204
- auto acc = buf.get_access <sycl::access::mode::read_write>(cgh);
205
- cgh.parallel_for <class dim3_subscr >(Range, [=](sycl::item<3 > itemID) {
206
- acc[itemID.get_id (0 )][itemID.get_id (1 )][itemID.get_id (2 )] +=
207
- itemID.get_linear_id ();
208
- });
197
+ Queue.submit ([&](sycl::handler &cgh) {
198
+ auto acc = buf.get_access <sycl::access::mode::read_write>(cgh);
199
+ cgh.parallel_for <class dim3_subscr >(Range, [=](sycl::item<3 > itemID) {
200
+ acc[itemID.get_id (0 )][itemID.get_id (1 )][itemID.get_id (2 )] +=
201
+ itemID.get_linear_id ();
209
202
});
210
- Queue. wait ( );
211
- }
212
- for ( int i = 0 ; i < 2 ; i++) {
213
- for (int j = 0 ; j < 3 ; j ++) {
214
- for (int k = 0 ; k < 4 ; k ++) {
215
- int expected = k + 4 * (j + 3 * i);
216
- if (array[i][j][k] != expected) {
217
- std::cerr << array[i][j][k] << " != " << expected << std::endl;
218
- assert ( 0 ) ;
219
- return 1 ;
220
- }
203
+ } );
204
+ Queue. wait ();
205
+ }
206
+ for (int i = 0 ; i < 2 ; i ++) {
207
+ for (int j = 0 ; j < 3 ; j ++) {
208
+ for ( int k = 0 ; k < 4 ; k++) {
209
+ int expected = k + 4 * (j + 3 * i);
210
+ if ( array[i][j][k] != expected) {
211
+ std::cerr << array[i][j][k] << " != " << expected << std::endl ;
212
+ assert ( 0 ) ;
213
+ return 1 ;
221
214
}
222
215
}
223
216
}
@@ -295,28 +288,26 @@ int main() {
295
288
// Check that accessor is initialized when accessor is wrapped to some class.
296
289
{
297
290
sycl::queue queue;
298
- if (!queue.is_host ()) {
299
- int array[10 ] = {0 };
300
- {
301
- sycl::buffer<int , 1 > buf ((int *)array, sycl::range<1 >(10 ),
302
- {sycl::property::buffer::use_host_ptr ()});
303
- queue.submit ([&](sycl::handler &cgh) {
304
- auto acc = buf.get_access <sycl::access::mode::read_write>(cgh);
305
- auto acc_wrapped = AccWrapper<decltype (acc)>{acc};
306
- cgh.parallel_for <class wrapped_access1 >(
307
- sycl::range<1 >(buf.get_count ()), [=](sycl::item<1 > it) {
308
- auto idx = it.get_linear_id ();
309
- acc_wrapped.accessor [idx] = 333 ;
310
- });
311
- });
312
- queue.wait ();
313
- }
314
- for (int i = 0 ; i < 10 ; i++) {
315
- if (array[i] != 333 ) {
316
- std::cerr << array[i] << " != 333" << std::endl;
317
- assert (0 );
318
- return 1 ;
319
- }
291
+ int array[10 ] = {0 };
292
+ {
293
+ sycl::buffer<int , 1 > buf ((int *)array, sycl::range<1 >(10 ),
294
+ {sycl::property::buffer::use_host_ptr ()});
295
+ queue.submit ([&](sycl::handler &cgh) {
296
+ auto acc = buf.get_access <sycl::access::mode::read_write>(cgh);
297
+ auto acc_wrapped = AccWrapper<decltype (acc)>{acc};
298
+ cgh.parallel_for <class wrapped_access1 >(
299
+ sycl::range<1 >(buf.get_count ()), [=](sycl::item<1 > it) {
300
+ auto idx = it.get_linear_id ();
301
+ acc_wrapped.accessor [idx] = 333 ;
302
+ });
303
+ });
304
+ queue.wait ();
305
+ }
306
+ for (int i = 0 ; i < 10 ; i++) {
307
+ if (array[i] != 333 ) {
308
+ std::cerr << array[i] << " != 333" << std::endl;
309
+ assert (0 );
310
+ return 1 ;
320
311
}
321
312
}
322
313
}
@@ -325,40 +316,38 @@ int main() {
325
316
// initialized in proper way and value is assigned.
326
317
{
327
318
sycl::queue queue;
328
- if (!queue. is_host ()) {
329
- int array1 [10 ] = {0 };
330
- int array2[ 10 ] = { 0 };
331
- {
332
- sycl::buffer< int , 1 > buf1 (( int *)array1, sycl::range< 1 >( 10 ),
333
- { sycl::property::buffer::use_host_ptr ()});
334
- sycl::buffer< int , 1 > buf2 (( int *)array2, sycl::range< 1 >( 10 ),
335
- { sycl::property::buffer::use_host_ptr ()});
336
- queue. submit ([&]( sycl::handler & cgh) {
337
- auto acc1 = buf1 .get_access <sycl::access::mode::read_write>(cgh);
338
- auto acc2 = buf2. get_access <sycl::access::mode::read_write>(cgh);
339
- auto acc_wrapped =
340
- AccsWrapper< decltype (acc1), decltype (acc2)>{ 10 , acc1, 5 , acc2};
341
- cgh. parallel_for < class wrapped_access2 >(
342
- sycl::range< 1 >( 10 ), [=](sycl::item< 1 > it) {
343
- auto idx = it. get_linear_id () ;
344
- acc_wrapped.accessor1 [idx] = 333 ;
345
- acc_wrapped. accessor2 [idx] = 777 ;
346
- });
347
- } );
348
- queue. wait ();
349
- }
319
+ int array1[ 10 ] = { 0 };
320
+ int array2 [10 ] = {0 };
321
+ {
322
+ sycl::buffer< int , 1 > buf1 (( int *)array1, sycl::range< 1 >( 10 ),
323
+ { sycl::property::buffer::use_host_ptr ()});
324
+ sycl::buffer< int , 1 > buf2 (( int *)array2, sycl::range< 1 >( 10 ),
325
+ { sycl::property::buffer::use_host_ptr ()});
326
+ queue. submit ([&]( sycl::handler &cgh) {
327
+ auto acc1 = buf1. get_access < sycl::access::mode::read_write>( cgh);
328
+ auto acc2 = buf2 .get_access <sycl::access::mode::read_write>(cgh);
329
+ auto acc_wrapped =
330
+ AccsWrapper< decltype (acc1), decltype (acc2)>{ 10 , acc1, 5 , acc2};
331
+ cgh. parallel_for < class wrapped_access2 >(
332
+ sycl::range< 1 >( 10 ), [=](sycl::item< 1 > it) {
333
+ auto idx = it. get_linear_id ();
334
+ acc_wrapped. accessor1 [ idx] = 333 ;
335
+ acc_wrapped.accessor2 [idx] = 777 ;
336
+ }) ;
337
+ });
338
+ queue. wait ( );
339
+ }
340
+ for ( int i = 0 ; i < 10 ; i++) {
350
341
for (int i = 0 ; i < 10 ; i++) {
351
- for (int i = 0 ; i < 10 ; i++) {
352
- if (array1[i] != 333 ) {
353
- std::cerr << array1[i] << " != 333" << std::endl;
354
- assert (0 );
355
- return 1 ;
356
- }
357
- if (array2[i] != 777 ) {
358
- std::cerr << array2[i] << " != 777" << std::endl;
359
- assert (0 );
360
- return 1 ;
361
- }
342
+ if (array1[i] != 333 ) {
343
+ std::cerr << array1[i] << " != 333" << std::endl;
344
+ assert (0 );
345
+ return 1 ;
346
+ }
347
+ if (array2[i] != 777 ) {
348
+ std::cerr << array2[i] << " != 777" << std::endl;
349
+ assert (0 );
350
+ return 1 ;
362
351
}
363
352
}
364
353
}
@@ -367,31 +356,29 @@ int main() {
367
356
// Several levels of wrappers for accessor.
368
357
{
369
358
sycl::queue queue;
370
- if (!queue.is_host ()) {
371
- int array[10 ] = {0 };
372
- {
373
- sycl::buffer<int , 1 > buf ((int *)array, sycl::range<1 >(10 ),
374
- {sycl::property::buffer::use_host_ptr ()});
375
- queue.submit ([&](sycl::handler &cgh) {
376
- auto acc = buf.get_access <sycl::access::mode::read_write>(cgh);
377
- auto acc_wrapped = AccWrapper<decltype (acc)>{acc};
378
- Wrapper1 wr1;
379
- auto wr2 = Wrapper2<decltype (acc)>{wr1, acc_wrapped};
380
- auto wr3 = Wrapper3<decltype (acc)>{wr2};
381
- cgh.parallel_for <class wrapped_access3 >(
382
- sycl::range<1 >(buf.get_count ()), [=](sycl::item<1 > it) {
383
- auto idx = it.get_linear_id ();
384
- wr3.w2 .wrapped .accessor [idx] = 333 ;
385
- });
386
- });
387
- queue.wait ();
388
- }
389
- for (int i = 0 ; i < 10 ; i++) {
390
- if (array[i] != 333 ) {
391
- std::cerr << array[i] << " != 333" << std::endl;
392
- assert (0 );
393
- return 1 ;
394
- }
359
+ int array[10 ] = {0 };
360
+ {
361
+ sycl::buffer<int , 1 > buf ((int *)array, sycl::range<1 >(10 ),
362
+ {sycl::property::buffer::use_host_ptr ()});
363
+ queue.submit ([&](sycl::handler &cgh) {
364
+ auto acc = buf.get_access <sycl::access::mode::read_write>(cgh);
365
+ auto acc_wrapped = AccWrapper<decltype (acc)>{acc};
366
+ Wrapper1 wr1;
367
+ auto wr2 = Wrapper2<decltype (acc)>{wr1, acc_wrapped};
368
+ auto wr3 = Wrapper3<decltype (acc)>{wr2};
369
+ cgh.parallel_for <class wrapped_access3 >(
370
+ sycl::range<1 >(buf.get_count ()), [=](sycl::item<1 > it) {
371
+ auto idx = it.get_linear_id ();
372
+ wr3.w2 .wrapped .accessor [idx] = 333 ;
373
+ });
374
+ });
375
+ queue.wait ();
376
+ }
377
+ for (int i = 0 ; i < 10 ; i++) {
378
+ if (array[i] != 333 ) {
379
+ std::cerr << array[i] << " != 333" << std::endl;
380
+ assert (0 );
381
+ return 1 ;
395
382
}
396
383
}
397
384
}
@@ -563,31 +550,28 @@ int main() {
563
550
sycl::queue q;
564
551
// host device executes kernels via a different method and there
565
552
// is no good way to throw an exception at this time.
566
- if (!q.is_host ()) {
567
- sycl::range<1 > r (4 );
568
- sycl::buffer<int , 1 > b (r);
569
- try {
570
- sycl::accessor<int , 1 , sycl::access::mode::read_write,
571
- sycl::access::target::device,
572
- sycl::access::placeholder::true_t >
573
- acc (b);
553
+ sycl::range<1 > r (4 );
554
+ sycl::buffer<int , 1 > b (r);
555
+ try {
556
+ sycl::accessor<int , 1 , sycl::access::mode::read_write,
557
+ sycl::access::target::device,
558
+ sycl::access::placeholder::true_t >
559
+ acc (b);
574
560
575
- q.submit ([&](sycl::handler &cgh) {
576
- // we do NOT call .require(acc) without which we should throw a
577
- // synchronous exception with errc::kernel_argument
578
- cgh.parallel_for <class ph >(
579
- r, [=](sycl::id<1 > index) { acc[index] = 0 ; });
580
- });
581
- q.wait_and_throw ();
582
- assert (false && " we should not be here, missing exception" );
583
- } catch (sycl::exception &e) {
584
- std::cout << " exception received: " << e.what () << std::endl;
585
- assert (e.code () == sycl::errc::kernel_argument &&
586
- " incorrect error code" );
587
- } catch (...) {
588
- std::cout << " some other exception" << std::endl;
589
- return 1 ;
590
- }
561
+ q.submit ([&](sycl::handler &cgh) {
562
+ // we do NOT call .require(acc) without which we should throw a
563
+ // synchronous exception with errc::kernel_argument
564
+ cgh.parallel_for <class ph >(r,
565
+ [=](sycl::id<1 > index) { acc[index] = 0 ; });
566
+ });
567
+ q.wait_and_throw ();
568
+ assert (false && " we should not be here, missing exception" );
569
+ } catch (sycl::exception &e) {
570
+ std::cout << " exception received: " << e.what () << std::endl;
571
+ assert (e.code () == sycl::errc::kernel_argument && " incorrect error code" );
572
+ } catch (...) {
573
+ std::cout << " some other exception" << std::endl;
574
+ return 1 ;
591
575
}
592
576
}
593
577
0 commit comments