@@ -696,7 +696,7 @@ int main() {
696
696
acc (b);
697
697
698
698
q.submit ([&](sycl::handler &cgh) {
699
- // we do NOT call .require(acc) without which we should throw a
699
+ // We do NOT call .require(acc) without which we should throw a
700
700
// synchronous exception with errc::kernel_argument
701
701
cgh.parallel_for <class ph1 >(r,
702
702
[=](sycl::id<1 > index) { acc[index] = 0 ; });
@@ -727,7 +727,7 @@ int main() {
727
727
AccT acc (b);
728
728
729
729
q.submit ([&](sycl::handler &cgh) {
730
- // we do NOT call .require(acc) without which we should throw a
730
+ // We do NOT call .require(acc) without which we should throw a
731
731
// synchronous exception with errc::kernel_argument
732
732
// The difference with the previous test is that the use of acc
733
733
// is usually optimized away for this particular scenario, but the
@@ -762,14 +762,14 @@ int main() {
762
762
763
763
q.submit ([&](sycl::handler &cgh) {
764
764
AccT acc2 (b, cgh);
765
- // we do NOT call .require(acc) without which we should throw a
765
+ // We do NOT call .require(acc) without which we should throw a
766
766
// synchronous exception with errc::kernel_argument
767
767
// The particularity of this test is that it passes to a command
768
768
// one bound accessor and one unbound accessor. In the past, this
769
769
// has led to throw the wrong exception.
770
770
cgh.single_task <class ph3 >([=] {
771
- volatile int x = acc[0 ];
772
- volatile int y = acc2[0 ];
771
+ int x = acc[0 ];
772
+ int y = acc2[0 ];
773
773
});
774
774
});
775
775
q.wait_and_throw ();
@@ -784,6 +784,40 @@ int main() {
784
784
}
785
785
}
786
786
787
+ // placeholder accessor exception (4) // SYCL2020 4.7.6.9
788
+ {
789
+ sycl::queue q;
790
+ // host device executes kernels via a different method and there
791
+ // is no good way to throw an exception at this time.
792
+ sycl::range<1 > r (4 );
793
+ sycl::buffer<int , 1 > b (r);
794
+ try {
795
+ using AccT = sycl::accessor<int , 1 , sycl::access::mode::read_write,
796
+ sycl::access::target::device,
797
+ sycl::access::placeholder::true_t >;
798
+ AccT acc (b);
799
+
800
+ q.submit ([&](sycl::handler &cgh) {
801
+ AccT acc2 (b, cgh);
802
+ // Pass placeholder accessor to command, but having required a different
803
+ // accessor in the command. In past versions, we used to compare the
804
+ // number of accessors with the number of requirements, and if they
805
+ // matched, we did not throw, allowing this scenario that shouldn't be
806
+ // allowed.
807
+ cgh.single_task <class ph4 >([=] { int x = acc[0 ]; });
808
+ });
809
+ q.wait_and_throw ();
810
+ assert (false && " we should not be here, missing exception" );
811
+ } catch (sycl::exception &e) {
812
+ std::cout << " exception received: " << e.what () << std::endl;
813
+ assert (e.code () == sycl::errc::kernel_argument && " incorrect error code" );
814
+ } catch (...) {
815
+ std::cout << " Some other exception (line " << __LINE__ << " )"
816
+ << std::endl;
817
+ return 1 ;
818
+ }
819
+ }
820
+
787
821
// SYCL2020 4.9.4.1: calling require() on empty accessor should throw
788
822
{
789
823
sycl::queue q;
@@ -1430,5 +1464,34 @@ int main() {
1430
1464
}
1431
1465
}
1432
1466
1467
+ // default constructed accessor is not a placeholder
1468
+ {
1469
+ AccT acc;
1470
+ assert (!acc.is_placeholder ());
1471
+ sycl::queue q;
1472
+ bool result;
1473
+ {
1474
+ sycl::buffer<bool , 1 > Buf{&result, sycl::range<1 >{1 }};
1475
+ // As a non-placeholder accessor, make sure no exception is thrown when
1476
+ // passed to a command. However, we cannot access it, because there's
1477
+ // no underlying storage.
1478
+ try {
1479
+ q.submit ([&](sycl::handler &cgh) {
1480
+ sycl::accessor res_acc{Buf, cgh};
1481
+ cgh.single_task <class def_ctor >(
1482
+ [=] { res_acc[0 ] = acc.is_placeholder (); });
1483
+ });
1484
+ q.wait_and_throw ();
1485
+ } catch (sycl::exception &e) {
1486
+ assert (" Unexpected exception" );
1487
+ } catch (...) {
1488
+ std::cout << " Some other unexpected exception (line " << __LINE__ << " )"
1489
+ << std::endl;
1490
+ return 1 ;
1491
+ }
1492
+ }
1493
+ assert (!result);
1494
+ }
1495
+
1433
1496
std::cout << " Test passed" << std::endl;
1434
1497
}
0 commit comments