-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL] Fix vec constructors #17712
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] Fix vec constructors #17712
Changes from 2 commits
80c6fe3
a0979df
0d7c6dd
cb22962
a6bb094
d16dd21
ed681fb
79e0e15
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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // TODO: Remove `__SYCL_USE_PREVIEW_VEC_IMPL` once it's auto-set. | ||
| // RUN: %clangxx -fsycl -fsyntax-only %s -fpreview-breaking-changes -D__SYCL_USE_PREVIEW_VEC_IMPL=1 | ||
| // RUN: %clangxx -fsycl -fsyntax-only %s | ||
|
|
||
| #include <sycl/sycl.hpp> | ||
|
|
||
| using sycl::half; | ||
| using sycl::vec; | ||
| using sw_half_1 = decltype(std::declval<vec<half, 4>>().swizzle<1>()); | ||
| using sw_half_2 = decltype(std::declval<vec<half, 4>>().swizzle<1, 2>()); | ||
|
|
||
| using sw_float_1 = decltype(std::declval<vec<float, 4>>().swizzle<1>()); | ||
| using sw_float_2 = decltype(std::declval<vec<float, 4>>().swizzle<1, 2>()); | ||
|
|
||
| using sw_double_1 = decltype(std::declval<vec<double, 4>>().swizzle<1>()); | ||
| using sw_double_2 = decltype(std::declval<vec<double, 4>>().swizzle<1, 2>()); | ||
|
|
||
| #if __INTEL_PREVIEW_BREAKING_CHANGES | ||
| #define NOT_IN_PREVIEW ! | ||
|
||
| #else | ||
| #define NOT_IN_PREVIEW | ||
| #endif | ||
|
|
||
| // clang-format off | ||
|
|
||
| static_assert( std::is_assignable_v<vec<half, 1>, half>); | ||
| static_assert(NOT_IN_PREVIEW std::is_assignable_v<vec<half, 1>, float>); | ||
| static_assert(NOT_IN_PREVIEW std::is_assignable_v<vec<half, 1>, double>); | ||
| static_assert( std::is_assignable_v<vec<half, 1>, vec<half, 1>>); | ||
| static_assert(NOT_IN_PREVIEW std::is_assignable_v<vec<half, 1>, vec<float, 1>>); | ||
| static_assert(NOT_IN_PREVIEW std::is_assignable_v<vec<half, 1>, vec<double, 1>>); | ||
| static_assert( std::is_assignable_v<vec<half, 1>, sw_half_1>); | ||
| static_assert( std::is_assignable_v<vec<half, 1>, sw_float_1>); | ||
| static_assert( std::is_assignable_v<vec<half, 1>, sw_double_1>); | ||
| static_assert( !std::is_assignable_v<vec<half, 1>, sw_half_2>); | ||
| static_assert( !std::is_assignable_v<vec<half, 1>, sw_float_2>); | ||
| static_assert( !std::is_assignable_v<vec<half, 1>, sw_double_2>); | ||
|
|
||
| static_assert( std::is_assignable_v<vec<half, 2>, half>); | ||
| static_assert( std::is_assignable_v<vec<half, 2>, float>); | ||
| static_assert( std::is_assignable_v<vec<half, 2>, double>); | ||
| static_assert( std::is_assignable_v<vec<half, 2>, vec<half, 1>>); | ||
| static_assert( !std::is_assignable_v<vec<half, 2>, vec<float, 1>>); | ||
| static_assert( !std::is_assignable_v<vec<half, 2>, vec<double, 1>>); | ||
| static_assert( std::is_assignable_v<vec<half, 2>, sw_half_1>); | ||
| static_assert( std::is_assignable_v<vec<half, 2>, sw_float_1>); | ||
| static_assert( std::is_assignable_v<vec<half, 2>, sw_double_1>); | ||
| static_assert( std::is_assignable_v<vec<half, 2>, sw_half_2>); | ||
| static_assert( !std::is_assignable_v<vec<half, 2>, sw_float_2>); | ||
| static_assert( !std::is_assignable_v<vec<half, 2>, sw_double_2>); | ||
|
|
||
| static_assert( std::is_assignable_v<vec<float, 1>, half>); | ||
| static_assert( std::is_assignable_v<vec<float, 1>, float>); | ||
| static_assert( std::is_assignable_v<vec<float, 1>, double>); | ||
| #if __SYCL_DEVICE_ONLY__ | ||
| static_assert( std::is_assignable_v<vec<float, 1>, vec<half, 1>>); | ||
| #else | ||
| static_assert(NOT_IN_PREVIEW std::is_assignable_v<vec<float, 1>, vec<half, 1>>); | ||
| #endif | ||
uditagarwal97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| static_assert( std::is_assignable_v<vec<float, 1>, vec<float, 1>>); | ||
| static_assert( std::is_assignable_v<vec<float, 1>, vec<double, 1>>); | ||
| static_assert( std::is_assignable_v<vec<float, 1>, sw_half_1>); | ||
| static_assert( std::is_assignable_v<vec<float, 1>, sw_float_1>); | ||
| static_assert( std::is_assignable_v<vec<float, 1>, sw_double_1>); | ||
| static_assert( !std::is_assignable_v<vec<float, 1>, sw_half_2>); | ||
| static_assert( !std::is_assignable_v<vec<float, 1>, sw_float_2>); | ||
| static_assert( !std::is_assignable_v<vec<float, 1>, sw_double_2>); | ||
|
|
||
| static_assert( std::is_assignable_v<vec<float, 2>, half>); | ||
| static_assert( std::is_assignable_v<vec<float, 2>, float>); | ||
| static_assert( std::is_assignable_v<vec<float, 2>, double>); | ||
| #if __SYCL_DEVICE_ONLY__ | ||
| static_assert( std::is_assignable_v<vec<float, 2>, vec<half, 1>>); | ||
| #else | ||
| static_assert( !std::is_assignable_v<vec<float, 2>, vec<half, 1>>); | ||
| #endif | ||
| static_assert( std::is_assignable_v<vec<float, 2>, vec<float, 1>>); | ||
| static_assert( std::is_assignable_v<vec<float, 2>, vec<double, 1>>); | ||
| static_assert( std::is_assignable_v<vec<float, 2>, sw_half_1>); | ||
| static_assert( std::is_assignable_v<vec<float, 2>, sw_float_1>); | ||
| static_assert( std::is_assignable_v<vec<float, 2>, sw_double_1>); | ||
| static_assert( !std::is_assignable_v<vec<float, 2>, sw_half_2>); | ||
| static_assert( std::is_assignable_v<vec<float, 2>, sw_float_2>); | ||
| static_assert( !std::is_assignable_v<vec<float, 2>, sw_double_2>); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // TODO: Remove `__SYCL_USE_PREVIEW_VEC_IMPL` once it's auto-set. | ||
| // RUN: %clangxx -fsycl -fsyntax-only %s -fpreview-breaking-changes -D__SYCL_USE_PREVIEW_VEC_IMPL=1 | ||
| // RUN: %clangxx -fsycl -fsyntax-only %s | ||
|
|
||
| #include <sycl/sycl.hpp> | ||
|
|
||
| template <class From, class To, class = void> | ||
| struct is_explicitly_convertible_to_impl : std::false_type {}; | ||
|
|
||
| template <class From, class To> | ||
| struct is_explicitly_convertible_to_impl< | ||
| From, To, std::void_t<decltype(static_cast<To>(std::declval<From>()))>> | ||
| : std::true_type {}; | ||
|
|
||
| template <class From, class To> | ||
| struct is_explicitly_convertible_to | ||
| : is_explicitly_convertible_to_impl<From, To> {}; | ||
|
|
||
| template <class From, class To> | ||
| inline constexpr bool is_explicitly_convertible_to_v = | ||
| is_explicitly_convertible_to<From, To>::value; | ||
|
|
||
| using sycl::half; | ||
| using sycl::vec; | ||
|
|
||
| void f_half_v1(vec<half, 1>); | ||
| void f_half_v4(vec<half, 4>); | ||
| void f_float_v1(vec<float, 1>); | ||
| void f_float_v4(vec<float, 4>); | ||
|
|
||
| using sw_half_1 = decltype(std::declval<vec<half, 4>>().swizzle<1>()); | ||
| using sw_half_2 = decltype(std::declval<vec<half, 4>>().swizzle<1, 2>()); | ||
|
|
||
| using sw_float_1 = decltype(std::declval<vec<float, 4>>().swizzle<1>()); | ||
| using sw_float_2 = decltype(std::declval<vec<float, 4>>().swizzle<1, 2>()); | ||
|
|
||
| using sw_double_1 = decltype(std::declval<vec<double, 4>>().swizzle<1>()); | ||
| using sw_double_2 = decltype(std::declval<vec<double, 4>>().swizzle<1, 2>()); | ||
|
|
||
| #if __INTEL_PREVIEW_BREAKING_CHANGES | ||
| #define NOT_IN_PREVIEW ! | ||
| #else | ||
| #define NOT_IN_PREVIEW | ||
| #endif | ||
|
|
||
| // clang-format off | ||
|
|
||
| static_assert( std::is_invocable_v<decltype(f_half_v1), half>); | ||
| static_assert(NOT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), float>); | ||
| static_assert(NOT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), double>); | ||
| static_assert( std::is_invocable_v<decltype(f_half_v1), sw_half_1>); | ||
| static_assert( std::is_invocable_v<decltype(f_half_v1), sw_float_1>); | ||
| static_assert( std::is_invocable_v<decltype(f_half_v1), sw_double_1>); | ||
| static_assert( std::is_invocable_v<decltype(f_half_v1), vec<half, 1>>); | ||
| static_assert(NOT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), vec<float, 1>>); | ||
| static_assert(NOT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), vec<double, 1>>); | ||
|
|
||
| static_assert(NOT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), half>); | ||
| static_assert( std::is_invocable_v<decltype(f_float_v1), float>); | ||
| static_assert( std::is_invocable_v<decltype(f_float_v1), double>); | ||
| static_assert( std::is_invocable_v<decltype(f_float_v1), sw_half_1>); | ||
| static_assert( std::is_invocable_v<decltype(f_float_v1), sw_float_1>); | ||
| static_assert( std::is_invocable_v<decltype(f_float_v1), sw_double_1>); | ||
| static_assert(NOT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), vec<half, 1>>); | ||
| static_assert( std::is_invocable_v<decltype(f_float_v1), vec<float, 1>>); | ||
| static_assert(NOT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), vec<double, 1>>); | ||
|
|
||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), half>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), float>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), double>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), sw_half_1>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), sw_float_1>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), sw_double_1>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), sw_half_2, sw_half_2>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), sw_float_2, sw_float_2>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), sw_double_2, sw_double_2>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), sw_half_2, sw_float_2>); | ||
| static_assert( !std::is_invocable_v<decltype(f_half_v4), sw_half_2, sw_double_2>); | ||
|
|
||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), half>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), float>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), double>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), sw_half_1>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), sw_float_1>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), sw_double_1>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), sw_half_2, sw_half_2>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), sw_float_2, sw_float_2>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), sw_double_2, sw_double_2>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), sw_float_2, sw_float_2>); | ||
| static_assert( !std::is_invocable_v<decltype(f_float_v4), sw_float_2, sw_double_2>); | ||
|
|
||
| static_assert( is_explicitly_convertible_to_v<half, vec<half, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<float, vec<half, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<double, vec<half, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_half_1, vec<half, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_float_1, vec<half, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_double_1, vec<half, 1>>); | ||
|
|
||
| static_assert( is_explicitly_convertible_to_v<half, vec<float, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<float, vec<float, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<double, vec<float, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_half_1, vec<float, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_float_1, vec<float, 1>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_double_1, vec<float, 1>>); | ||
|
|
||
| static_assert( is_explicitly_convertible_to_v<half, vec<half, 4>>); | ||
| static_assert( is_explicitly_convertible_to_v<float, vec<half, 4>>); | ||
| static_assert( is_explicitly_convertible_to_v<double, vec<half, 4>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_half_1, vec<half, 4>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_float_1, vec<half, 4>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_double_1, vec<half, 4>>); | ||
| static_assert( !is_explicitly_convertible_to_v<sw_half_2, vec<half, 4>>); | ||
| static_assert( !is_explicitly_convertible_to_v<sw_float_2, vec<half, 4>>); | ||
| static_assert( !is_explicitly_convertible_to_v<sw_double_2, vec<half, 4>>); | ||
| static_assert( !is_explicitly_convertible_to_v<sw_half_2, vec<half, 4>>); | ||
| static_assert( !is_explicitly_convertible_to_v<sw_half_2, vec<half, 4>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_half_2, vec<half, 2>>); | ||
| static_assert( !is_explicitly_convertible_to_v<sw_float_2, vec<half, 2>>); | ||
| static_assert( !is_explicitly_convertible_to_v<sw_double_2, vec<half, 2>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_half_2, vec<half, 2>>); | ||
| static_assert( is_explicitly_convertible_to_v<sw_half_2, vec<half, 2>>); | ||
|
|
||
| static_assert( is_explicitly_convertible_to_v<vec<half, 1>, half>); | ||
| #if __SYCL_DEVICE_ONLY__ | ||
| static_assert( is_explicitly_convertible_to_v<vec<half, 1>, float>); | ||
| static_assert( is_explicitly_convertible_to_v<vec<half, 1>, double>); | ||
| #else | ||
| static_assert( !is_explicitly_convertible_to_v<vec<half, 1>, float>); | ||
| static_assert( !is_explicitly_convertible_to_v<vec<half, 1>, double>); | ||
| #endif | ||
|
|
||
| static_assert( is_explicitly_convertible_to_v<vec<float, 1>, half>); | ||
| static_assert( is_explicitly_convertible_to_v<vec<float, 1>, float>); | ||
| static_assert( is_explicitly_convertible_to_v<vec<float, 1>, double>); |
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.
@AlexeySachkov , any better suggestions for the naming here?
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.
One issue is that we want to preserve current/"old" version after next major release, when the meaning of "preview" would change. On the other hand, we can rename the macro at that time, maybe.
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 we plan to expose the macro to users so that they could do a switch back (for whichever reason), then it is better not to rename it later, but agree on a name from the beginning - otherwise renaming would be an API change by itself.
What about something like
__SYCL_USE_SYCL2020_CONFORMANT_IMPL? I.e. indicate the intent instead of old/new where the meaning of old/new changes in time.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.
SYCL2020 has had several different specifications for vec. I've come up with
__SYCL_USE_LEGACY_VEC_IMPL(meaning the current default). Alternatively, we can use the current major version (__SYCL_USE_SYCL8_VEC_IMPL).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.
@AlexeySachkov , can you take another look?