11// RUN: %{build} -o %t.out
22// RUN: %{run} %t.out
33
4- #include < sycl/detail/core.hpp>
5-
4+ #include < algorithm>
65#include < cassert>
76#include < cstdint>
87
9- namespace syclex = sycl::ext::oneapi::experimental;
10- using namespace sycl ::info::device;
11- using namespace sycl ::info::kernel_device_specific;
8+ #include < sycl/detail/core.hpp>
129
1310using value_type = int64_t ;
11+ static constexpr value_type TestValue{42 };
1412
1513namespace kernels {
1614
@@ -27,7 +25,7 @@ class TestKernel {
2725
2826 void operator ()(sycl::nd_item<1 > item) const {
2927 const auto gtid = item.get_global_linear_id ();
30- acc_[gtid] = gtid + 42 ;
28+ acc_[gtid] = gtid + TestValue ;
3129 }
3230
3331private:
@@ -46,7 +44,7 @@ class TestLocalMemoryKernel {
4644 const auto ltid = item.get_local_linear_id ();
4745 const auto gtid = item.get_global_linear_id ();
4846 if (ltid < loc_acc_.size ()) {
49- loc_acc_[ltid] = ltid + 42 ;
47+ loc_acc_[ltid] = ltid + TestValue ;
5048 item.barrier (sycl::access::fence_space::local_space);
5149 acc_[gtid] = loc_acc_[ltid];
5250 } else {
@@ -65,6 +63,10 @@ namespace {
6563
6664template <class KernelName >
6765int test_max_num_work_groups (sycl::queue &q, const sycl::device &dev) {
66+ using namespace sycl ::info::device;
67+ using namespace sycl ::info::kernel_device_specific;
68+ namespace syclex = sycl::ext::oneapi::experimental;
69+
6870 const auto ctx = q.get_context ();
6971 auto bundle = sycl::get_kernel_bundle<sycl::bundle_state::executable>(ctx);
7072 auto kernel = bundle.template get_kernel <KernelName>();
@@ -115,7 +117,7 @@ int test_max_num_work_groups(sycl::queue &q, const sycl::device &dev) {
115117 cgh.parallel_for (launch_range, KernelName{acc});
116118 }
117119 }).wait ();
118- assert (sycl::host_accessor{buf}[0 ] == 42 );
120+ assert (sycl::host_accessor{buf}[0 ] == TestValue );
119121
120122 // ========================== //
121123 // Test 3 - use max resources //
@@ -147,7 +149,7 @@ int test_max_num_work_groups(sycl::queue &q, const sycl::device &dev) {
147149 cgh.parallel_for (launch_range, KernelName{acc});
148150 }
149151 }).wait ();
150- assert (sycl::host_accessor{buf}[0 ] == 42 );
152+ assert (sycl::host_accessor{buf}[0 ] == TestValue );
151153
152154 // =============================== //
153155 // Test 4 - exceed resource limits //
@@ -187,7 +189,12 @@ int test_max_num_work_groups(sycl::queue &q, const sycl::device &dev) {
187189 } else {
188190 cgh.parallel_for (launch_range, KernelName{acc});
189191 }
190- }).wait ();
192+ }).wait_and_throw ();
193+ if constexpr (KernelName::HasLocalMemory)
194+ std::cerr << " Test (LocalMemory) with exceeded resource limits failed\n " ;
195+ else
196+ std::cerr << " Test with exceed resource limits failed\n " ;
197+ return 1 ; // We shouldn't be here, exception is expected
191198 } catch (const sycl::exception &e) {
192199 // 'nd_range' error is the expected outcome from the above launch config.
193200 if (e.code () == sycl::make_error_code (sycl::errc::nd_range)) {
@@ -204,13 +211,14 @@ int test_max_num_work_groups(sycl::queue &q, const sycl::device &dev) {
204211} // namespace
205212
206213int main () {
207- sycl::queue q{};
214+ auto asynch = [](sycl::exception_list el) {
215+ std::for_each (el.begin (), el.end (), std::rethrow_exception);
216+ };
217+ sycl::queue q{asynch};
208218 sycl::device dev = q.get_device ();
209219
210- using namespace kernels ;
211-
212220 int ret{0 };
213- ret & = test_max_num_work_groups<TestKernel>(q, dev);
214- ret & = test_max_num_work_groups<TestLocalMemoryKernel>(q, dev);
221+ ret | = test_max_num_work_groups<kernels:: TestKernel>(q, dev);
222+ ret | = test_max_num_work_groups<kernels:: TestLocalMemoryKernel>(q, dev);
215223 return ret;
216224}
0 commit comments