Skip to content

[ESIMD] Add Simd constructor from simd_view #15174

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
Aug 28, 2024
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
28 changes: 17 additions & 11 deletions sycl/include/sycl/ext/intel/esimd/simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ class simd : public detail::simd_obj_impl<
}

// Implicit conversion constructor from sycl::ext::oneapi::experimental::simd
template <
int N1 = N, class Ty1 = Ty,
class SFINAE = std::enable_if_t<
(N1 == N) && (N1 <= std::experimental::simd_abi::max_fixed_size<
Ty>)&&!detail::is_wrapper_elem_type_v<Ty1>>>
template <int N1 = N, class Ty1 = Ty,
class SFINAE = std::enable_if_t<
(N1 == N) &&
(N1 <= std::experimental::simd_abi::max_fixed_size<Ty>) &&
!detail::is_wrapper_elem_type_v<Ty1>>>
simd(const sycl::ext::oneapi::experimental::simd<Ty, N1> &v)
: simd(static_cast<raw_vector_type>(v)) {}

// Implicit conversion constructor from 1D simd_view
template <typename BaseTy, int Stride>
simd(simd_view<BaseTy, region_base<false, Ty, 1, 1, N, Stride>> &v)
: simd(v.read()) {}

/// Broadcast constructor with conversion. Converts given value to
/// #element_type and replicates it in all elements.
/// Available when \c T1 is a valid simd element type.
Expand Down Expand Up @@ -113,11 +118,11 @@ class simd : public detail::simd_obj_impl<
/// object. Available when the number of elements does not exceed maximum
/// fixed size of the oneapi's simd_abi and (TODO, temporary limitation) the
/// element type is a primitive type (e.g. can't be sycl::half).
template <
int N1, class Ty1 = Ty,
class SFINAE = std::enable_if_t<
(N1 == N) && (N1 <= std::experimental::simd_abi::max_fixed_size<
Ty>)&&!detail::is_wrapper_elem_type_v<Ty1>>>
template <int N1, class Ty1 = Ty,
class SFINAE = std::enable_if_t<
(N1 == N) &&
(N1 <= std::experimental::simd_abi::max_fixed_size<Ty>) &&
!detail::is_wrapper_elem_type_v<Ty1>>>
operator sycl::ext::oneapi::experimental::simd<Ty, N1>() {
return sycl::ext::oneapi::experimental::simd<Ty, N1>(base_type::data());
}
Expand Down Expand Up @@ -210,7 +215,8 @@ template <int N> using simd_mask = detail::simd_mask_type<N>;
template <typename Ty, int N>
std::ostream &operator<<(std::ostream &OS, const __ESIMD_NS::simd<Ty, N> &V)
#ifdef __SYCL_DEVICE_ONLY__
{}
{
}
#else
{
__ESIMD_UNSUPPORTED_ON_HOST;
Expand Down
12 changes: 12 additions & 0 deletions sycl/test/esimd/simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,15 @@ void test_simd_binop_honor_int_promo() SYCL_ESIMD_FUNCTION {
static_assert(std::is_same<decltype(c + c), simd<int, 32>>::value, "");
static_assert(std::is_same<decltype(d + d), simd<int, 32>>::value, "");
}

template <class T> bool test_simd_view_ctors() SYCL_ESIMD_FUNCTION {
simd<T, 8> vec8;
auto view4 = vec8.template select<4, 1>(0);

simd<T, 4> vec4 = view4;
simd vec41 = view4;
return true;
}

template bool test_simd_view_ctors<int>() SYCL_ESIMD_FUNCTION;
template bool test_simd_view_ctors<sycl::half>() SYCL_ESIMD_FUNCTION;
Loading