forked from codeplaysoftware/syclacademy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.cpp
61 lines (43 loc) · 1.35 KB
/
solution.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
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>
#include <CL/sycl.hpp>
class hello_world;
TEST_CASE("hello_world", "sycl_03_hello_world") {
cl::sycl::default_selector selector;
cl::sycl::queue myQueue(selector);
std::cout << "Running on "
<< myQueue.get_device().get_info<cl::sycl::info::device::name>()
<< "\n";
myQueue.submit([&](cl::sycl::handler& cgh) {
cl::sycl::stream os(1024, 80, cgh);
cgh.single_task<hello_world>([=]() { os << "Hello World!\n"; });
});
myQueue.wait();
REQUIRE(true);
}
class print_ids;
TEST_CASE("print_ids", "sycl_03_hello_world") {
cl::sycl::default_selector selector;
cl::sycl::queue myQueue(selector);
std::cout << "Running on "
<< myQueue.get_device().get_info<cl::sycl::info::device::name>()
<< "\n";
myQueue.submit([&](cl::sycl::handler& cgh) {
cl::sycl::stream os(1024, 80, cgh);
cgh.parallel_for<print_ids>(cl::sycl::range<1>(1024),
[=](cl::sycl::id<1> idx) {
if (idx[0] == 999) {
os << "I am on " << idx[0] << "\n";
}
});
});
myQueue.wait();
REQUIRE(true);
}