-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL] Extends support for SYCL 2020 implicitly device copyable types #8195
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
[SYCL] Extends support for SYCL 2020 implicitly device copyable types #8195
Conversation
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
sycl/include/sycl/types.hpp
Outdated
// std::variant<> is implicitly device copyable type | ||
template <> struct is_device_copyable<std::variant<>> : std::true_type {}; | ||
|
||
// std::variant<Ts...> is implicitly device copyable type if each type T of | ||
// Ts... is device copyable, and it is not trivially copyable (if it is | ||
// trivially copyable it is device copyable by default) | ||
template <typename T, typename... Ts> | ||
struct is_device_copyable<std::variant<T, Ts...>, | ||
std::enable_if_t<!std::is_trivially_copyable< | ||
std::variant<T, Ts...>>::value>> | ||
: detail::bool_constant<is_device_copyable<T>::value && | ||
is_device_copyable<std::variant<Ts...>>::value> {}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer it written using fold expressions.
@@ -0,0 +1,161 @@ | |||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to have more runtime checks that the values of those types actually match between host/device, i.e. check the content of pair.first and/or pair.second.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify - this is my main concern, two other comments are more subjective in nature and thus optional to implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest that we perhaps have two test cases: one which simply contains a bunch of static_assert(sycl::is_device_copyable_v<some_type_here>)
to check that we properly specialize the trait and another one, which checks runtime behavior, i.e. that we are actually able to properly copy values of those types to kernels and read them back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have submitted a PR to llvm-test-suite repo adding tests that check the runtime behavior for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this test is supposed to be compile-only, then I suggest to remove -o %t.out
and add -fsyntax-only
, see docs for some BKMs. You can also remove any code which submits kernels, because that will be checked in the E2E test you have
// std::variant with complex types relies on virtual functions, so | ||
// they cannot be used within sycl kernels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we verify it anywhere? If not, I'd suggest to modify this test as
// RUN: compile and run
// RUN: compile-only -fsyntax-only -Xclang <enable error/warning verification in clang> -DCOMPILE_ONLY
...
#if COMPILE_ONLY
{
std::variant<ACopyable>
// try to pass it to device
// expected-error: ...
}
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I developed this test and tried both in Linux and Windows. Turns out there's no error in Windows (I guess MSVC doesn't require virtual functions to implement std::variant
), so I don't think we should have this test. Also, I will update my comment to say that this only happens in some implementations of std::variant
.
@@ -0,0 +1,161 @@ | |||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest that we perhaps have two test cases: one which simply contains a bunch of static_assert(sycl::is_device_copyable_v<some_type_here>)
to check that we properly specialize the trait and another one, which checks runtime behavior, i.e. that we are actually able to properly copy values of those types to kernels and read them back.
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
/verify with intel/llvm-test-suite#1583 |
…t-device-copyable-types
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
Signed-off-by: Maronas, Marcos <[email protected]>
/verify with intel/llvm-test-suite#1583 |
1 similar comment
/verify with intel/llvm-test-suite#1583 |
@AlexeySachkov is out of office but he marked all his questions/requests as resolved, so I am going LGTM this one. @AlexeySachkov , please finish your review post-commit once you're back. |
/verify with intel/llvm-test-suite#1583 |
Extends support for SYCL2020 implicitly device copyable types and adds new tests to check correct behavior.