diff --git a/sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_obj_impl.hpp b/sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_obj_impl.hpp index 862a4f8205f8c..10b7700f1819c 100644 --- a/sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_obj_impl.hpp +++ b/sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_obj_impl.hpp @@ -213,6 +213,19 @@ class simd_obj_impl { copy_from(acc, offset, Flags{}); } + /// Construct from \ref simd_view object \p View. + /// The constructed object has the same element type as the viewed simd. + /// and the size that is specified by the RegionT parameter of \p View. + /// + /// \tparam ViewedSimdLength is the size in elements of the \ref simd + /// object being viewed by \p View. + /// \tparam RegionT is the region defining \p View. + /// \param View is the object from which the \ref simd is created. + template > + simd_obj_impl(simd_view, RegionT> &View) + : M_data(View.read().M_data) {} + /// @} // Load the object's value from array. diff --git a/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp b/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp index 26803ad39f4b3..e0eb5874c583a 100644 --- a/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp +++ b/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp @@ -51,8 +51,8 @@ class simd : public detail::simd_obj_impl< using raw_vector_type = typename base_type::raw_vector_type; static constexpr int length = N; - // Implicit conversion constructor from another simd object of the same - // length. + /// Implicit conversion constructor from another simd object of the same + /// length. template && (length == SimdT::length)>> @@ -62,13 +62,26 @@ class simd : public detail::simd_obj_impl< __esimd_dbg_print(simd(const SimdT &RHS)); } - // Broadcast constructor with conversion. + /// Broadcast constructor with conversion. template >> simd(T1 Val) : base_type(Val) { __esimd_dbg_print(simd(T1 Val)); } + /// Construct \ref simd from \ref simd_view object \p View. + /// The constructed \ref simd object has the same element type as the viewed + /// simd and the size that is specified by the RegionT parameter of \p View. + /// + /// \tparam ViewedSimdLength is the size in elements of the \ref simd + /// object being viewed by \p View. + /// \tparam RegionT is the region defining the \p View. + /// \param View is the object from which the \ref simd is created. + template > + simd(simd_view, RegionT> &View) + : base_type(View) {} + /// Type conversion for simd into T. template +simd(simd_view, RegionT>) -> simd; + /// Covert from a simd object with element type \c From to a simd object with /// element type \c To. template diff --git a/sycl/test/esimd/simd_view.cpp b/sycl/test/esimd/simd_view.cpp index 602dd8fa48c20..1a159fc0a8bac 100644 --- a/sycl/test/esimd/simd_view.cpp +++ b/sycl/test/esimd/simd_view.cpp @@ -124,6 +124,16 @@ SYCL_ESIMD_FUNCTION void test_simd_view_from_vector() { simd_view sv1b(v1); } +// test deducing arguments during simd construction from simd_view. +SYCL_ESIMD_FUNCTION void test_simd_from_simd_view() { + simd v16 = 0; + auto view8 = v16.select<8,1>(0); + simd v8 = view8; + + auto view1 = v16.select<1,1>(0); + simd v1 = view1; +} + // move constructor transfers the same view of the underlying data. SYCL_ESIMD_FUNCTION void test_simd_view_move_ctor() { simd v0 = 1;