forked from codeplaysoftware/syclacademy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.cpp
41 lines (29 loc) · 1.07 KB
/
source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
SYCL Academy (c)
SYCL Academy is licensed under a Creative Commons
Attribution-ShareAlike 4.0 International License.
You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
*/
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
TEST_CASE("handling_errors", "handling_errors_source") {
// This program computes r = a + b
int a = 18, b = 24, r = 0;
// Task: catch synchronous and asynchronous exceptions
auto defaultQueue = sycl::queue{asyncHandler};
{
auto bufA = sycl::buffer{&a, sycl::range{1}};
auto bufB = sycl::buffer{&b, sycl::range{1}};
auto bufR = sycl::buffer{&r, sycl::range{1}};
defaultQueue
.submit([&](sycl::handler& cgh) {
auto accA = sycl::accessor{bufA, cgh, sycl::read_only};
auto accB = sycl::accessor{bufB, cgh, sycl::read_only};
auto accR = sycl::accessor{bufR, cgh, sycl::write_only};
cgh.single_task<scalar_add>([=]() { accR[0] = accA[0] + accB[0]; });
})
.wait();
}
REQUIRE(r == 42);
}