-
Notifications
You must be signed in to change notification settings - Fork 109
Add sycl quick refs #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sycl quick refs #179
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,7 +6,37 @@ | |||||
|
||||||
You should have received a copy of the license along with this | ||||||
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>. | ||||||
*/ | ||||||
|
||||||
* | ||||||
* SYCL Quick Reference | ||||||
* ~~~~~~~~~~~~~~~~~~~~ | ||||||
* | ||||||
* // Include SYCL header | ||||||
* #if __has_include(<SYCL/sycl.hpp>) | ||||||
* #include <SYCL/sycl.hpp> | ||||||
* #else | ||||||
* #include <CL/sycl.hpp> | ||||||
* #endif | ||||||
* | ||||||
* | ||||||
* // Default construct a queue | ||||||
* auto q = sycl::queue{}; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* // Submit work to the queue | ||||||
* q.submit([&](sycl::handler &cgh) { | ||||||
* // COMMAND GROUP | ||||||
* }); | ||||||
* | ||||||
* // Within the command group you can | ||||||
* // 1. Enqueue a command: | ||||||
* cgh.single_task<class mykernel>([=] { | ||||||
* // Do something | ||||||
* }); | ||||||
* | ||||||
* 2. Declare a sycl::stream for printing from device: | ||||||
* auto os = sycl::stream{buf_size, wi_size, cgh}; | ||||||
* | ||||||
*/ | ||||||
|
||||||
#define CATCH_CONFIG_MAIN | ||||||
#include <catch2/catch.hpp> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,46 @@ | |
|
||
You should have received a copy of the license along with this | ||
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>. | ||
* | ||
* SYCL Quick Reference | ||
* ~~~~~~~~~~~~~~~~~~~~ | ||
* | ||
* // Make a child class of sycl::device_selector | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obsolete. Use lambda instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry actually implemented here intel/llvm#6486. Will change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this was introduced very recently in DPC++, so if all implementations support that now we should switch to that, if you want we could have a separate issue/PR for this as we'll likely want to update the lecture on device selection as well. |
||
* class my_functor_selector : public sycl::device_selector { | ||
* // Overload operator() for sycl::device. | ||
* int operator()(const sycl::device& dev) const override { | ||
* ... | ||
* } | ||
* } | ||
* ... | ||
* auto q = sycl::queue{my_functor_selector{}}; | ||
* | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* | ||
* // Or use a function selector | ||
* int my_function_selector(const sycl::device &d) { | ||
* ... | ||
* } | ||
* ... | ||
* auto q = sycl::queue{my_function_selector}; | ||
* | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* | ||
* // Or use a lambda selector | ||
* auto my_lambda_selector = [](const sycl::device &d) { | ||
* ... | ||
* }; | ||
* ... | ||
* auto q = sycl::queue{my_lambda_selector}; | ||
* | ||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* | ||
* // Query a device for some things: | ||
* std::string vendor = dev.get_info<sycl::info::device::vendor>(); | ||
* std::string dev_name = dev.get_info<sycl::info::device::name>(); | ||
* std::string dev_driver_ver = dev.get_info<sycl::info::device::driver_version>(); | ||
* | ||
* | ||
*/ | ||
|
||
#define CATCH_CONFIG_MAIN | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,36 @@ | |
|
||
You should have received a copy of the license along with this | ||
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>. | ||
|
||
* SYCL Quick Reference | ||
* ~~~~~~~~~~~~~~~~~~~~ | ||
* | ||
* // Default construct a queue | ||
* auto q = sycl::queue{}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem |
||
* | ||
* // Declare a buffer pointing to ptr | ||
* auto buf = sycl::buffer{ptr, sycl::range{n}}; | ||
* | ||
* // Submit work to the queue | ||
* q.submit([&](sycl::handler &cgh) { | ||
* // COMMAND GROUP | ||
* }); | ||
* | ||
* // Within the command group you can | ||
* // 1. Declare an accessor to a buffer | ||
* auto read_write_acc = sycl::accessor{buf, cgh}; | ||
* auto read_acc = sycl::accessor{buf, cgh, sycl::read_only}; | ||
* auto write_acc = sycl::accessor{buf, cgh, sycl::write_only}; | ||
* auto no_init_acc = sycl::accessor{buf, cgh, sycl::no_init}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not clear what is the value of using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a little bit biased - personally I feel that this notation is the easiest to read and make sense of. If we write:
I think the name of the variable is not as readable as the above notation. Using the notation:
is very consistent and readable. The start of the var name is always at the same (relative) col and always before an equals sign. I know this is a bit pedantic but I think it is justified! :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also for learning reasons we only want to use auto if the type of the obj is self evident. So something like:
Is not very useful. Moreover using the accessor constructor instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you can write as you want anyway, at the end this is your code. :-) |
||
* // 2. Enqueue a single task: | ||
* cgh.single_task<class mykernel>([=]() { | ||
* // Do something | ||
* }); | ||
* // 3. Enqueue a parallel for: | ||
* cgh.parallel_for<class mykernel>(sycl::range{n}, [=](sycl::id<1> i) { | ||
* // Do something | ||
* }); | ||
* | ||
*/ | ||
|
||
#define CATCH_CONFIG_MAIN | ||
|
Uh oh!
There was an error while loading. Please reload this page.