Skip to content

[SYCL] Make swizzle::operator vec available for 1-elem swizzles #17870

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

Merged
merged 3 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions sycl/include/sycl/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,13 @@ template <typename Self> class ConversionToVecMixin {

public:
operator vec_ty() const {
vec_ty res{*static_cast<const Self *>(this)};
return res;
auto &self = *static_cast<const Self *>(this);
if constexpr (vec_ty::size() == 1)
// Avoid recursion by explicitly going through `vec(const DataT &)` ctor.
return vec_ty{static_cast<typename vec_ty::element_type>(self)};
else
// Uses `vec`'s variadic ctor.
return vec_ty{self};
}
};

Expand Down Expand Up @@ -398,9 +403,8 @@ class __SYCL_EBO Swizzle
public ApplyIf<sizeof...(Indexes) == 1,
ScalarConversionOperatorsMixIn<
Swizzle<IsConstVec, DataT, VecSize, Indexes...>>>,
public ApplyIf<sizeof...(Indexes) != 1,
ConversionToVecMixin<
Swizzle<IsConstVec, DataT, VecSize, Indexes...>>>,
public ConversionToVecMixin<
Swizzle<IsConstVec, DataT, VecSize, Indexes...>>,
public NamedSwizzlesMixinBoth<
Swizzle<IsConstVec, DataT, VecSize, Indexes...>> {
using Base = SwizzleBase<Swizzle<IsConstVec, DataT, VecSize, Indexes...>>;
Expand Down
4 changes: 2 additions & 2 deletions sycl/test/basic_tests/vectors/cxx_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ using sw_double_2 = decltype(std::declval<vec<double, 4>>().swizzle<1, 2>());
static_assert( std::is_invocable_v<decltype(f_half_v1), half>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), float>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), double>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), sw_half_1>);
static_assert( std::is_invocable_v<decltype(f_half_v1), sw_half_1>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), sw_float_1>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_half_v1), sw_double_1>);
static_assert( std::is_invocable_v<decltype(f_half_v1), vec<half, 1>>);
Expand All @@ -64,7 +64,7 @@ static_assert(EXCEPT_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(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), sw_half_1>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), sw_float_1>);
static_assert( std::is_invocable_v<decltype(f_float_v1), sw_float_1>);
static_assert(EXCEPT_IN_PREVIEW std::is_invocable_v<decltype(f_float_v1), sw_double_1>);
static_assert(EXCEPT_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>>);
Expand Down