Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit d366158

Browse files
authored
[SYCL] Extends placeholder accessor tests (#1549)
Prior to this change there were some subtleties that made us throw the wrong exception or even don't throw an exception in cases were we should. These changes include tests for those cases. --------- Signed-off-by: Maronas, Marcos <[email protected]>
1 parent da1df22 commit d366158

File tree

1 file changed

+76
-4
lines changed

1 file changed

+76
-4
lines changed

SYCL/Basic/accessor/accessor.cpp

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ int main() {
653653
}
654654
}
655655

656-
// placeholder accessor exception // SYCL2020 4.7.6.9
656+
// placeholder accessor exception (1) // SYCL2020 4.7.6.9
657657
{
658658
sycl::queue q;
659659
// host device executes kernels via a different method and there
@@ -669,16 +669,88 @@ int main() {
669669
q.submit([&](sycl::handler &cgh) {
670670
// we do NOT call .require(acc) without which we should throw a
671671
// synchronous exception with errc::kernel_argument
672-
cgh.parallel_for<class ph>(r,
673-
[=](sycl::id<1> index) { acc[index] = 0; });
672+
cgh.parallel_for<class ph1>(r,
673+
[=](sycl::id<1> index) { acc[index] = 0; });
674674
});
675675
q.wait_and_throw();
676676
assert(false && "we should not be here, missing exception");
677677
} catch (sycl::exception &e) {
678678
std::cout << "exception received: " << e.what() << std::endl;
679679
assert(e.code() == sycl::errc::kernel_argument && "incorrect error code");
680680
} catch (...) {
681-
std::cout << "some other exception" << std::endl;
681+
std::cout << "Some other exception (line " << __LINE__ << ")"
682+
<< std::endl;
683+
return 1;
684+
}
685+
}
686+
687+
// placeholder accessor exception (2) // SYCL2020 4.7.6.9
688+
{
689+
sycl::queue q;
690+
// host device executes kernels via a different method and there
691+
// is no good way to throw an exception at this time.
692+
sycl::range<1> r(4);
693+
sycl::buffer<int, 1> b(r);
694+
try {
695+
using AccT = sycl::accessor<int, 1, sycl::access::mode::read_write,
696+
sycl::access::target::device,
697+
sycl::access::placeholder::true_t>;
698+
AccT acc(b);
699+
700+
q.submit([&](sycl::handler &cgh) {
701+
// we do NOT call .require(acc) without which we should throw a
702+
// synchronous exception with errc::kernel_argument
703+
// The difference with the previous test is that the use of acc
704+
// is usually optimized away for this particular scenario, but the
705+
// exception should be thrown because of passing it, not because of
706+
// using it
707+
cgh.single_task<class ph2>([=] { int x = acc[0]; });
708+
});
709+
q.wait_and_throw();
710+
assert(false && "we should not be here, missing exception");
711+
} catch (sycl::exception &e) {
712+
std::cout << "exception received: " << e.what() << std::endl;
713+
assert(e.code() == sycl::errc::kernel_argument && "incorrect error code");
714+
} catch (...) {
715+
std::cout << "Some other exception (line " << __LINE__ << ")"
716+
<< std::endl;
717+
return 1;
718+
}
719+
}
720+
721+
// placeholder accessor exception (3) // SYCL2020 4.7.6.9
722+
{
723+
sycl::queue q;
724+
// host device executes kernels via a different method and there
725+
// is no good way to throw an exception at this time.
726+
sycl::range<1> r(4);
727+
sycl::buffer<int, 1> b(r);
728+
try {
729+
using AccT = sycl::accessor<int, 1, sycl::access::mode::read_write,
730+
sycl::access::target::device,
731+
sycl::access::placeholder::true_t>;
732+
AccT acc(b);
733+
734+
q.submit([&](sycl::handler &cgh) {
735+
AccT acc2(b, cgh);
736+
// we do NOT call .require(acc) without which we should throw a
737+
// synchronous exception with errc::kernel_argument
738+
// The particularity of this test is that it passes to a command
739+
// one bound accessor and one unbound accessor. In the past, this
740+
// has led to throw the wrong exception.
741+
cgh.single_task<class ph3>([=] {
742+
volatile int x = acc[0];
743+
volatile int y = acc2[0];
744+
});
745+
});
746+
q.wait_and_throw();
747+
assert(false && "we should not be here, missing exception");
748+
} catch (sycl::exception &e) {
749+
std::cout << "exception received: " << e.what() << std::endl;
750+
assert(e.code() == sycl::errc::kernel_argument && "incorrect error code");
751+
} catch (...) {
752+
std::cout << "Some other exception (line " << __LINE__ << ")"
753+
<< std::endl;
682754
return 1;
683755
}
684756
}

0 commit comments

Comments
 (0)