Skip to content

Commit a4d7736

Browse files
authored
Merge pull request #179 from hdelan/add-sycl-quick-refs
Add sycl quick refs
2 parents bf85601 + b2f4daa commit a4d7736

File tree

9 files changed

+353
-3
lines changed

9 files changed

+353
-3
lines changed

Code_Exercises/Exercise_02_Hello_World/source.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,37 @@
66
77
You should have received a copy of the license along with this
88
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
9-
*/
9+
10+
*
11+
* SYCL Quick Reference
12+
* ~~~~~~~~~~~~~~~~~~~~
13+
*
14+
* // Include SYCL header
15+
* #if __has_include(<SYCL/sycl.hpp>)
16+
* #include <SYCL/sycl.hpp>
17+
* #else
18+
* #include <CL/sycl.hpp>
19+
* #endif
20+
*
21+
*
22+
* // Default construct a queue
23+
* auto q = sycl::queue{};
24+
*
25+
* // Submit work to the queue
26+
* q.submit([&](sycl::handler &cgh) {
27+
* // COMMAND GROUP
28+
* });
29+
*
30+
* // Within the command group you can
31+
* // 1. Enqueue a command:
32+
* cgh.single_task<class mykernel>([=] {
33+
* // Do something
34+
* });
35+
*
36+
* 2. Declare a sycl::stream for printing from device:
37+
* auto os = sycl::stream{buf_size, wi_size, cgh};
38+
*
39+
*/
1040

1141
#define CATCH_CONFIG_MAIN
1242
#include <catch2/catch.hpp>

Code_Exercises/Exercise_05_Device_Selection/source.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,46 @@
66
77
You should have received a copy of the license along with this
88
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
9+
*
10+
* SYCL Quick Reference
11+
* ~~~~~~~~~~~~~~~~~~~~
12+
*
13+
* // Make a child class of sycl::device_selector
14+
* class my_functor_selector : public sycl::device_selector {
15+
* // Overload operator() for sycl::device.
16+
* int operator()(const sycl::device& dev) const override {
17+
* ...
18+
* }
19+
* }
20+
* ...
21+
* auto q = sycl::queue{my_functor_selector{}};
22+
*
23+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
*
25+
* // Or use a function selector
26+
* int my_function_selector(const sycl::device &d) {
27+
* ...
28+
* }
29+
* ...
30+
* auto q = sycl::queue{my_function_selector};
31+
*
32+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33+
*
34+
* // Or use a lambda selector
35+
* auto my_lambda_selector = [](const sycl::device &d) {
36+
* ...
37+
* };
38+
* ...
39+
* auto q = sycl::queue{my_lambda_selector};
40+
*
41+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42+
*
43+
* // Query a device for some things:
44+
* std::string vendor = dev.get_info<sycl::info::device::vendor>();
45+
* std::string dev_name = dev.get_info<sycl::info::device::name>();
46+
* std::string dev_driver_ver = dev.get_info<sycl::info::device::driver_version>();
47+
*
48+
*
949
*/
1050

1151
#define CATCH_CONFIG_MAIN

Code_Exercises/Exercise_06_Vector_Add/source.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,36 @@
66
77
You should have received a copy of the license along with this
88
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
9+
10+
* SYCL Quick Reference
11+
* ~~~~~~~~~~~~~~~~~~~~
12+
*
13+
* // Default construct a queue
14+
* auto q = sycl::queue{};
15+
*
16+
* // Declare a buffer pointing to ptr
17+
* auto buf = sycl::buffer{ptr, sycl::range{n}};
18+
*
19+
* // Submit work to the queue
20+
* q.submit([&](sycl::handler &cgh) {
21+
* // COMMAND GROUP
22+
* });
23+
*
24+
* // Within the command group you can
25+
* // 1. Declare an accessor to a buffer
26+
* auto read_write_acc = sycl::accessor{buf, cgh};
27+
* auto read_acc = sycl::accessor{buf, cgh, sycl::read_only};
28+
* auto write_acc = sycl::accessor{buf, cgh, sycl::write_only};
29+
* auto no_init_acc = sycl::accessor{buf, cgh, sycl::no_init};
30+
* // 2. Enqueue a single task:
31+
* cgh.single_task<class mykernel>([=]() {
32+
* // Do something
33+
* });
34+
* // 3. Enqueue a parallel for:
35+
* cgh.parallel_for<class mykernel>(sycl::range{n}, [=](sycl::id<1> i) {
36+
* // Do something
37+
* });
38+
*
939
*/
1040

1141
#define CATCH_CONFIG_MAIN

Code_Exercises/Exercise_09_Synchronization/source.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,53 @@
66
77
You should have received a copy of the license along with this
88
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
9+
10+
* SYCL Quick Reference
11+
* ~~~~~~~~~~~~~~~~~~~~
12+
*
13+
* // Default construct a queue
14+
* auto q = sycl::queue{};
15+
*
16+
* // Declare a buffer pointing to ptr
17+
* auto buf = sycl::buffer{ptr, sycl::range{n}};
18+
*
19+
* // Do a USM malloc_device
20+
* auto ptr = sycl::malloc_device<T>(n, q);
21+
*
22+
* // Do a USM memcpy
23+
* q.memcpy(dst_ptr, src_ptr, sizeof(T)*n);
24+
*
25+
* // Wait on a queue
26+
* q.wait();
27+
*
28+
* // Submit work to the queue
29+
* q.submit([&](sycl::handler &cgh) {
30+
* // COMMAND GROUP
31+
* });
32+
*
33+
*
34+
* // Within the command group you can
35+
* // 1. Declare an accessor to a buffer
36+
* auto read_write_acc = sycl::accessor{buf, cgh};
37+
* auto read_acc = sycl::accessor{buf, cgh, sycl::read_only};
38+
* auto write_acc = sycl::accessor{buf, cgh, sycl::write_only};
39+
* auto no_init_acc = sycl::accessor{buf, cgh, sycl::no_init};
40+
* // 2. Enqueue a parallel for:
41+
* cgh.parallel_for<class mykernel>(sycl::range{n},
42+
* [=](sycl::id<1> i) { // Do something });
43+
*
44+
*
945
*/
1046

1147
#define CATCH_CONFIG_MAIN
1248
#include <catch2/catch.hpp>
1349

14-
TEST_CASE("synchronization", "synchronization_source") {
15-
// Use your code from Exercises 6 and 8 to start
50+
TEST_CASE("synchronization_usm", "synchronization_source") {
51+
// Use your code from Exercise 3 to start
52+
REQUIRE(true);
53+
}
54+
55+
TEST_CASE("synchronization_buffer_acc", "synchronization_source") {
56+
// Use your code from Exercise 3 to start
1657
REQUIRE(true);
1758
}

Code_Exercises/Exercise_10_Managing_Dependencies/source.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,49 @@
66
77
You should have received a copy of the license along with this
88
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
9+
10+
* SYCL Quick Reference
11+
* ~~~~~~~~~~~~~~~~~~~~
12+
*
13+
* // Default construct a queue
14+
* auto q = sycl::queue{};
15+
*
16+
* // Declare a buffer pointing to ptr
17+
* auto buf = sycl::buffer{ptr, sycl::range{n}};
18+
*
19+
* // Do a USM memcpy
20+
* auto event = q.memcpy(dst_ptr, src_ptr, sizeof(T)*n);
21+
* // Do a USM memcpy with dependent events
22+
* auto event = q.memcpy(dst_ptr, src_ptr, sizeof(T)*n, {event1, event2});
23+
*
24+
* // Wait on an event
25+
* event.wait();
26+
*
27+
* // Wait on a queue
28+
* q.wait();
29+
*
30+
* // Submit work to the queue
31+
* auto event = q.submit([&](sycl::handler &cgh) {
32+
* // COMMAND GROUP
33+
* });
34+
*
35+
*
36+
* // Within the command group you can
37+
* // 1. Declare an accessor to a buffer
38+
* auto read_write_acc = sycl::accessor{buf, cgh};
39+
* auto read_acc = sycl::accessor{buf, cgh, sycl::read_only};
40+
* auto write_acc = sycl::accessor{buf, cgh, sycl::write_only};
41+
* auto no_init_acc = sycl::accessor{buf, cgh, sycl::no_init};
42+
* // 2. Enqueue a parallel for:
43+
* // i: Without dependent events
44+
* cgh.parallel_for<class mykernel>(sycl::range{n},
45+
* [=](sycl::id<1> i) { // Do something });
46+
* // ii: With dependent events
47+
* cgh.parallel_for<class mykernel>(sycl::range{n},
48+
* {event1, event2}, [=](sycl::id<1> i) {
49+
* // Do something
50+
* });
51+
*
952
*/
1053

1154
#define CATCH_CONFIG_MAIN

Code_Exercises/Exercise_11_In_Order_Queue/source.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,53 @@
66
77
You should have received a copy of the license along with this
88
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
9+
10+
* SYCL Quick Reference
11+
* ~~~~~~~~~~~~~~~~~~~~
12+
*
13+
* // Default construct a queue
14+
* auto q = sycl::queue{};
15+
*
16+
* // Construct an in-order queue
17+
* auto q = sycl::queue{sycl::default_selector{},
18+
* {sycl::property::queue::in_order{}}};
19+
*
20+
* // Declare a buffer pointing to ptr
21+
* auto buf = sycl::buffer{ptr, sycl::range{n}};
22+
*
23+
* // Do a USM memcpy
24+
* auto event = q.memcpy(dst_ptr, src_ptr, sizeof(T)*n);
25+
* // Do a USM memcpy with dependent events
26+
* auto event = q.memcpy(dst_ptr, src_ptr, sizeof(T)*n, {event1, event2});
27+
*
28+
* // Wait on an event
29+
* event.wait();
30+
*
31+
* // Wait on a queue
32+
* q.wait();
33+
*
34+
* // Submit work to the queue
35+
* auto event = q.submit([&](sycl::handler &cgh) {
36+
* // COMMAND GROUP
37+
* });
38+
*
39+
*
40+
* // Within the command group you can
41+
* // 1. Declare an accessor to a buffer
42+
* auto read_write_acc = sycl::accessor{buf, cgh};
43+
* auto read_acc = sycl::accessor{buf, cgh, sycl::read_only};
44+
* auto write_acc = sycl::accessor{buf, cgh, sycl::write_only};
45+
* auto no_init_acc = sycl::accessor{buf, cgh, sycl::no_init};
46+
* // 2. Enqueue a parallel for:
47+
* // i: Without dependent events
48+
* cgh.parallel_for<class mykernel>(sycl::range{n},
49+
* [=](sycl::id<1> i) { // Do something });
50+
* // ii: With dependent events
51+
* cgh.parallel_for<class mykernel>(sycl::range{n},
52+
* {event1, event2}, [=](sycl::id<1> i) {
53+
* // Do something
54+
* });
55+
956
*/
1057

1158
#define CATCH_CONFIG_MAIN

Code_Exercises/Exercise_12_Temporary_Data/source.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,45 @@
66
77
You should have received a copy of the license along with this
88
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
9+
10+
* SYCL Quick Reference
11+
* ~~~~~~~~~~~~~~~~~~~~
12+
*
13+
* // Default construct a queue
14+
* auto q = sycl::queue{};
15+
*
16+
* // Declare a buffer pointing to ptr
17+
* auto buf = sycl::buffer{ptr, sycl::range{n}};
18+
*
19+
* // Declare a buffer using host ptr
20+
* auto buf = sycl::buffer{ptr, sycl::range{n},
21+
* {sycl::property::buffer::use_host_ptr{}}};
22+
*
23+
* // Declare a buffer relating to no host memory
24+
* auto buf = sycl::buffer{sycl::range{n}};
25+
*
26+
* // Set final data of a buffer
27+
* buf.set_final_data(host_ptr);
28+
*
29+
* // Set final data of a buffer to nullptr
30+
* buf.set_final_data(nullptr);
31+
*
32+
* // Submit work to the queue
33+
* q.submit([&](sycl::handler &cgh) {
34+
* // COMMAND GROUP
35+
* });
36+
*
37+
* // Within the command group you can
38+
* // 1. Declare an accessor to a buffer
39+
* auto read_write_acc = sycl::accessor{buf, cgh};
40+
* auto read_acc = sycl::accessor{buf, cgh, sycl::read_only};
41+
* auto write_acc = sycl::accessor{buf, cgh, sycl::write_only};
42+
* auto no_init_acc = sycl::accessor{buf, cgh, sycl::no_init};
43+
* // 2. Enqueue a parallel for:
44+
* cgh.parallel_for<class mykernel>(sycl::range{n}, [=](sycl::id<1> i) {
45+
* // Do something
46+
* });
47+
*
948
*/
1049

1150
#define CATCH_CONFIG_MAIN

Code_Exercises/Exercise_13_Load_Balancing/source.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,40 @@
66
77
You should have received a copy of the license along with this
88
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
9+
10+
* SYCL Quick Reference
11+
* ~~~~~~~~~~~~~~~~~~~~
12+
*
13+
* // Get all available devices
14+
* auto devs = sycl::device::get_devices();
15+
*
16+
* // Construct a queue with a device
17+
* auto q = sycl::queue{my_device};
18+
*
19+
* // Declare a buffer pointing to ptr
20+
* auto buf = sycl::buffer{ptr, sycl::range{n}};
21+
*
22+
* // Submit work to the queue
23+
* q.submit([&](sycl::handler &cgh) {
24+
* // COMMAND GROUP
25+
* });
26+
*
27+
* // Within the command group you can
28+
* // 1. Declare an accessor to a buffer
29+
* auto read_write_acc = sycl::accessor{buf, cgh};
30+
* auto read_acc = sycl::accessor{buf, cgh, sycl::read_only};
31+
* auto write_acc = sycl::accessor{buf, cgh, sycl::write_only};
32+
* auto no_init_acc = sycl::accessor{buf, cgh, sycl::no_init};
33+
* // 2. Enqueue a single task:
34+
* cgh.single_task<class mykernel>([=]() {
35+
* // Do something
36+
* });
37+
* // 3. Enqueue a parallel for:
38+
* cgh.parallel_for<class mykernel>(sycl::range{n}, [=](sycl::id<1> i) {
39+
* // Do something
40+
* });
41+
*
42+
943
*/
1044

1145
#define CATCH_CONFIG_MAIN

0 commit comments

Comments
 (0)