-
Notifications
You must be signed in to change notification settings - Fork 796
[SYCL][Docs] Allow copy-construction of device_global #15075
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
Changes from 2 commits
2df6194
bbf50c4
c83c716
27b2129
fdaf3f6
d35e68e
86df6b5
6e204da
bf0a40d
d1c4ac2
09c7d4b
376185b
eca9cad
a9b3acd
10d207e
a531a18
c66d01d
67df6e8
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 |
|---|---|---|
|
|
@@ -244,7 +244,14 @@ public: | |
| device_global() = default; | ||
| #endif // __cpp_consteval | ||
|
|
||
| device_global(const device_global &) = delete; | ||
| // Available if has_property<device_image_scope> is false | ||
| constexpr device_global(const device_global &other); | ||
|
|
||
| // Available if has_property<device_image_scope> is false and OtherT is | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //convertible to T | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| template <typename OtherT, typename OtherProps> | ||
| constexpr device_global(const device_global<OtherT, OtherProps> &other) {} | ||
|
|
||
| device_global(const device_global &&) = delete; | ||
| device_global &operator=(const device_global &) = delete; | ||
| device_global &operator=(const device_global &&) = delete; | ||
|
|
@@ -324,6 +331,37 @@ The object of type `T` is initialized from the `args` parameter pack using list | |
|
|
||
| `T` must be trivially destructible. | ||
|
|
||
| // --- ROW BREAK --- | ||
| a| | ||
| [source,c++] | ||
| ---- | ||
| constexpr device_global(const device_global &other); | ||
Pennycook marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ---- | ||
| | | ||
| Available if `has_property<device_image_scope> == false`. | ||
|
|
||
| Constructs a `device_global` object, and implicit storage for `T` in the global address space on each device that may access it. | ||
|
|
||
| The storage on each device for `T` is initialized with a copy of the storage in `other`. | ||
|
|
||
| `T` must be copy constructible and trivially destructible. | ||
|
|
||
| // --- ROW BREAK --- | ||
| a| | ||
| [source,c++] | ||
| ---- | ||
| template <typename OtherT, typename OtherProps> | ||
| constexpr device_global(const device_global<OtherT, OtherProps> &other) {} | ||
| ---- | ||
| | | ||
| Available if `has_property<device_image_scope> == false`. | ||
Pennycook marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Constructs a `device_global` object, and implicit storage for `T` in the global address space on each device that may access it. | ||
|
|
||
| The storage on each device for `T` is initialized with a storage in `other`. | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| `OtherT` must be convertible to `T` and `T` must be trivially destructible. | ||
|
||
|
|
||
| // --- ROW BREAK --- | ||
| a| | ||
| [source,c++] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // RUN: %{build} -std=c++23 -o %t.out | ||
| // RUN: %{run} %t.out | ||
| // | ||
| // The OpenCL GPU backends do not currently support device_global backend | ||
| // calls. | ||
| // UNSUPPORTED: opencl && gpu | ||
| // | ||
| // Tests the copy ctor on device_global without device_image_scope. | ||
|
|
||
| #include <sycl/detail/core.hpp> | ||
|
|
||
| namespace oneapiext = sycl::ext::oneapi::experimental; | ||
|
|
||
| oneapiext::device_global<const int> DGInit1{3}; | ||
| oneapiext::device_global<const int> DGCopy1{DGInit1}; | ||
|
|
||
| oneapiext::device_global<int> DGInit2{4}; | ||
| oneapiext::device_global<int> DGCopy2{DGInit2}; | ||
|
|
||
| oneapiext::device_global<float> DGInit3{5.0f}; | ||
| oneapiext::device_global<int> DGCopy3{DGInit3}; | ||
|
|
||
| oneapiext::device_global<const int, decltype(oneapiext::properties{oneapiext::device_image_scope})> DGInit4{6}; | ||
| oneapiext::device_global<const int> DGCopy4{DGInit4}; | ||
|
|
||
| oneapiext::device_global<const int> DGInit5{7}; | ||
| oneapiext::device_global<const int, decltype(oneapiext::properties{oneapiext::host_access_read})> DGCopy5{DGInit5}; | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
|
|
||
| int ReadVals[2] = {0, 0}; | ||
| { | ||
| sycl::buffer<int, 10> ReadValsBuff{ReadVals, 2}; | ||
|
|
||
| Q.submit([&](sycl::handler &CGH) { | ||
| sycl::accessor ReadValsAcc{ReadValsBuff, CGH, sycl::write_only}; | ||
| CGH.single_task([=]() { | ||
| ReadValsAcc[0] = DGInit1.get(); | ||
| ReadValsAcc[1] = DGCopy1.get(); | ||
| ReadValsAcc[2] = DGInit2.get(); | ||
| ReadValsAcc[3] = DGCopy2.get(); | ||
| ReadValsAcc[4] = DGInit3.get(); | ||
| ReadValsAcc[5] = DGCopy3.get(); | ||
| ReadValsAcc[6] = DGInit4.get(); | ||
| ReadValsAcc[7] = DGCopy4.get(); | ||
| ReadValsAcc[8] = DGInit5.get(); | ||
| ReadValsAcc[9] = DGCopy5.get(); | ||
| }); | ||
| }).wait_and_throw(); | ||
| } | ||
|
|
||
| assert(ReadVals[0] == 3); | ||
| assert(ReadVals[1] == 3); | ||
| assert(ReadVals[2] == 4); | ||
| assert(ReadVals[3] == 4); | ||
| assert(ReadVals[4] == 5); | ||
| assert(ReadVals[5] == 5); | ||
| assert(ReadVals[6] == 6); | ||
| assert(ReadVals[7] == 6); | ||
| assert(ReadVals[8] == 7); | ||
| assert(ReadVals[9] == 7); | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // RUN: %clangxx -std=c++23 -fsycl -fsycl-targets=%sycl_triple -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s | ||
| // | ||
| // Tests that the copy ctor on device_global with device_image_scope is | ||
| // unavailable. | ||
|
|
||
| #include <sycl/sycl.hpp> | ||
|
|
||
| namespace oneapiext = sycl::ext::oneapi::experimental; | ||
|
|
||
| using device_image_properties = | ||
| decltype(oneapiext::properties{oneapiext::device_image_scope}); | ||
|
|
||
| // expected-error@sycl/ext/oneapi/device_global/device_global.hpp:* {{call to deleted constructor}} | ||
| oneapiext::device_global<const int, device_image_properties> DGInit1{3}; | ||
| oneapiext::device_global<const int, device_image_properties> DGCopy1{DGInit1}; | ||
|
|
||
| // expected-error@sycl/ext/oneapi/device_global/device_global.hpp:* {{call to deleted constructor}} | ||
| oneapiext::device_global<int, device_image_properties> DGInit2{3}; | ||
| oneapiext::device_global<int, device_image_properties> DGCopy2{DGInit2}; | ||
|
|
||
| // expected-error@+2 {{call to deleted constructor}} | ||
| oneapiext::device_global<int, device_image_properties> DGInit3{3}; | ||
| oneapiext::device_global<float, device_image_properties> DGCopy3{DGInit3}; | ||
|
|
||
| // expected-error@+2 {{call to deleted constructor}} | ||
| oneapiext::device_global<const int> DGInit4{3}; | ||
| oneapiext::device_global<const int, device_image_properties> DGCopy4{DGInit4}; | ||
|
Comment on lines
+25
to
+27
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. What about the other way around, from one with 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. That case is covered in sycl/test-e2e/DeviceGlobal/device_global_copy.cpp. I personally don't think it should be in a negative test. |
||
|
|
||
|
|
||
| int main() { return 0; } | ||
Uh oh!
There was an error while loading. Please reload this page.