From c79f3f155007695974cfc9a4237591caf451d0b2 Mon Sep 17 00:00:00 2001 From: Vyacheslav N Klochkov Date: Wed, 3 Nov 2021 16:50:52 -0700 Subject: [PATCH 1/3] [ESIMD] Construct simd from simd_view using args deduction guide Signed-off-by: Vyacheslav N Klochkov --- .../experimental/esimd/detail/simd_obj_impl.hpp | 6 ++++++ .../sycl/ext/intel/experimental/esimd/simd.hpp | 16 +++++++++++++--- sycl/test/esimd/simd_view.cpp | 10 ++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) 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 8d2f1dbd545a2..38eb45155f344 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 @@ -137,6 +137,12 @@ template class simd_obj_impl { init_from_array(std::move(Arr)); } + /// Construct from simd_view object. + 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 1a1bd8098a2e2..74b3be357001f 100644 --- a/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp +++ b/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp @@ -50,8 +50,8 @@ class simd using vector_type = typename base_type::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)>> @@ -60,13 +60,19 @@ class simd __esimd_dbg_print(simd(const SimdT &RHS)); } - // Broadcast constructor with conversion. + /// Broadcast constructor with conversion. template >> simd(T1 Val) : base_type((Ty)Val) { __esimd_dbg_print(simd(T1 Val)); } + /// Construct from simd_view. + template > + simd(simd_view, RegionT> &View) + : base_type(View) {} + /// Explicit conversion for simd_obj_impl 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; From 71b6db0980f2ad2f01e411666aeeede908acd8bb Mon Sep 17 00:00:00 2001 From: Vyacheslav N Klochkov Date: Thu, 4 Nov 2021 11:47:35 -0700 Subject: [PATCH 2/3] Made the comment to the deduction guide a bit more descriptive Signed-off-by: Vyacheslav N Klochkov --- sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp b/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp index 74b3be357001f..f8dd3cab5b1e4 100644 --- a/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp +++ b/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp @@ -119,7 +119,8 @@ class simd #undef __ESIMD_DEF_SIMD_ARITH_UNARY_OP }; -// Deduction guide for simd constructor from a simd_view object. +// Deduction guide for 'simd' constructor from a 'simd_view' object. It helps +// to infer the template parameter 'N' of the class 'simd'. template simd(simd_view, RegionT>) -> simd; From b7bc4dcc4a3865f90bc13d0eff85bf9b19dc304b Mon Sep 17 00:00:00 2001 From: Vyacheslav N Klochkov Date: Thu, 4 Nov 2021 12:32:02 -0700 Subject: [PATCH 3/3] Add more comments to the new constructors Signed-off-by: Vyacheslav N Klochkov --- .../intel/experimental/esimd/detail/simd_obj_impl.hpp | 9 ++++++++- sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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 38eb45155f344..7a61c54b47582 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 @@ -137,7 +137,14 @@ template class simd_obj_impl { init_from_array(std::move(Arr)); } - /// Construct from simd_view object. + /// 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) diff --git a/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp b/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp index f8dd3cab5b1e4..a95d506d73597 100644 --- a/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp +++ b/sycl/include/sycl/ext/intel/experimental/esimd/simd.hpp @@ -67,7 +67,14 @@ class simd __esimd_dbg_print(simd(T1 Val)); } - /// Construct from simd_view. + /// 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)