Skip to content

Commit 1f5e1dc

Browse files
authored
[SYCL][ESIMD] Add simd constructor from simd_view (#15174)
1 parent 3ff3a28 commit 1f5e1dc

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

sycl/include/sycl/ext/intel/esimd/simd.hpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,19 @@ class simd : public detail::simd_obj_impl<
7777
}
7878

7979
// Implicit conversion constructor from sycl::ext::oneapi::experimental::simd
80-
template <
81-
int N1 = N, class Ty1 = Ty,
82-
class SFINAE = std::enable_if_t<
83-
(N1 == N) && (N1 <= std::experimental::simd_abi::max_fixed_size<
84-
Ty>)&&!detail::is_wrapper_elem_type_v<Ty1>>>
80+
template <int N1 = N, class Ty1 = Ty,
81+
class SFINAE = std::enable_if_t<
82+
(N1 == N) &&
83+
(N1 <= std::experimental::simd_abi::max_fixed_size<Ty>) &&
84+
!detail::is_wrapper_elem_type_v<Ty1>>>
8585
simd(const sycl::ext::oneapi::experimental::simd<Ty, N1> &v)
8686
: simd(static_cast<raw_vector_type>(v)) {}
8787

88+
// Implicit conversion constructor from 1D simd_view
89+
template <typename BaseTy, int Stride>
90+
simd(simd_view<BaseTy, region_base<false, Ty, 1, 1, N, Stride>> &v)
91+
: simd(v.read()) {}
92+
8893
/// Broadcast constructor with conversion. Converts given value to
8994
/// #element_type and replicates it in all elements.
9095
/// Available when \c T1 is a valid simd element type.
@@ -113,11 +118,11 @@ class simd : public detail::simd_obj_impl<
113118
/// object. Available when the number of elements does not exceed maximum
114119
/// fixed size of the oneapi's simd_abi and (TODO, temporary limitation) the
115120
/// element type is a primitive type (e.g. can't be sycl::half).
116-
template <
117-
int N1, class Ty1 = Ty,
118-
class SFINAE = std::enable_if_t<
119-
(N1 == N) && (N1 <= std::experimental::simd_abi::max_fixed_size<
120-
Ty>)&&!detail::is_wrapper_elem_type_v<Ty1>>>
121+
template <int N1, class Ty1 = Ty,
122+
class SFINAE = std::enable_if_t<
123+
(N1 == N) &&
124+
(N1 <= std::experimental::simd_abi::max_fixed_size<Ty>) &&
125+
!detail::is_wrapper_elem_type_v<Ty1>>>
121126
operator sycl::ext::oneapi::experimental::simd<Ty, N1>() {
122127
return sycl::ext::oneapi::experimental::simd<Ty, N1>(base_type::data());
123128
}
@@ -210,7 +215,8 @@ template <int N> using simd_mask = detail::simd_mask_type<N>;
210215
template <typename Ty, int N>
211216
std::ostream &operator<<(std::ostream &OS, const __ESIMD_NS::simd<Ty, N> &V)
212217
#ifdef __SYCL_DEVICE_ONLY__
213-
{}
218+
{
219+
}
214220
#else
215221
{
216222
__ESIMD_UNSUPPORTED_ON_HOST;

sycl/test/esimd/simd.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,15 @@ void test_simd_binop_honor_int_promo() SYCL_ESIMD_FUNCTION {
376376
static_assert(std::is_same<decltype(c + c), simd<int, 32>>::value, "");
377377
static_assert(std::is_same<decltype(d + d), simd<int, 32>>::value, "");
378378
}
379+
380+
template <class T> bool test_simd_view_ctors() SYCL_ESIMD_FUNCTION {
381+
simd<T, 8> vec8;
382+
auto view4 = vec8.template select<4, 1>(0);
383+
384+
simd<T, 4> vec4 = view4;
385+
simd vec41 = view4;
386+
return true;
387+
}
388+
389+
template bool test_simd_view_ctors<int>() SYCL_ESIMD_FUNCTION;
390+
template bool test_simd_view_ctors<sycl::half>() SYCL_ESIMD_FUNCTION;

0 commit comments

Comments
 (0)