From fda92f9cdcc100973100b50d0465c50eb7bb630d Mon Sep 17 00:00:00 2001 From: Gang Y Chen Date: Mon, 11 Jan 2021 14:55:38 -0800 Subject: [PATCH] [SYCL][ESIMD] Add conversion ctor and operator Signed-off-by: Gang Y Chen --- sycl/include/CL/sycl/INTEL/esimd/esimd.hpp | 22 ++++++++++++------- .../CL/sycl/INTEL/esimd/esimd_view.hpp | 10 +++++++-- sycl/test/esimd/simd.cpp | 15 +++++++++---- sycl/test/esimd/simd_view.cpp | 1 + 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/sycl/include/CL/sycl/INTEL/esimd/esimd.hpp b/sycl/include/CL/sycl/INTEL/esimd/esimd.hpp index 8fd79d9828aa0..69715ee22b4df 100644 --- a/sycl/include/CL/sycl/INTEL/esimd/esimd.hpp +++ b/sycl/include/CL/sycl/INTEL/esimd/esimd.hpp @@ -43,8 +43,18 @@ template class simd { /// @{ /// Constructors. constexpr simd() = default; - constexpr simd(const simd &other) { set(other.data()); } - constexpr simd(simd &&other) { set(other.data()); } + template constexpr simd(const simd &other) { + if constexpr (std::is_same::value) + set(other.data()); + else + set(__builtin_convertvector(other.data(), vector_type_t)); + } + template constexpr simd(simd &&other) { + if constexpr (std::is_same::value) + set(other.data()); + else + set(__builtin_convertvector(other.data(), vector_type_t)); + } constexpr simd(const vector_type &Val) { set(Val); } // TODO @rolandschulz @@ -87,6 +97,7 @@ template class simd { } /// @} + /// conversion operator operator const vector_type &() const & { return M_data; } operator vector_type &() & { return M_data; } @@ -117,12 +128,6 @@ template class simd { set(Val2.data()); } - /// {@ - /// Assignment operators. - constexpr simd &operator=(const simd &) & = default; - constexpr simd &operator=(simd &&) & = default; - /// @} - /// View this simd object in a different element type. template auto format() & { using TopRegionTy = compute_format_type_t; @@ -208,6 +213,7 @@ template class simd { DEF_BINOP(-, -=) DEF_BINOP(*, *=) DEF_BINOP(/, /=) + DEF_BINOP(%, %=) #undef DEF_BINOP diff --git a/sycl/include/CL/sycl/INTEL/esimd/esimd_view.hpp b/sycl/include/CL/sycl/INTEL/esimd/esimd_view.hpp index de4b0013ab9d9..b0636d0e63273 100644 --- a/sycl/include/CL/sycl/INTEL/esimd/esimd_view.hpp +++ b/sycl/include/CL/sycl/INTEL/esimd/esimd_view.hpp @@ -70,8 +70,13 @@ template class simd_view { : M_base(Other.M_base), M_region(Other.M_region) {} /// @} - /// Conversion to simd value type. - operator value_type() const { return read(); } + /// Conversion to simd type. + template operator simd() const { + if constexpr (std::is_same::value) + return read(); + else + return convert(read()); + } /// @{ /// Assignment operators. @@ -217,6 +222,7 @@ template class simd_view { DEF_BINOP(-, -=) DEF_BINOP(*, *=) DEF_BINOP(/, /=) + DEF_BINOP(%, %=) #undef DEF_BINOP diff --git a/sycl/test/esimd/simd.cpp b/sycl/test/esimd/simd.cpp index d6f5e1d8a2097..e1e195d28060c 100644 --- a/sycl/test/esimd/simd.cpp +++ b/sycl/test/esimd/simd.cpp @@ -15,6 +15,14 @@ bool test_simd_ctors() __attribute__((sycl_device)) { return v0[0] + v1[1] + v2[2] + v3[3] == 1 + 1 + 2 + 6; } +void test_conversion() __attribute__((sycl_device)) { + simd v = 3; + simd f = v; + simd c = f; + simd c1 = f.select<16, 1>(0); + f = v + static_cast>(c); +} + bool test_1d_select() __attribute__((sycl_device)) { simd v = 0; v.select<8, 1>(0) = 1; @@ -63,6 +71,7 @@ bool test_simd_bin_ops() __attribute__((sycl_device)) { simd v0 = 1; simd v1 = 2; v0 += v1; + v0 %= v1; v0 = 2 - v0; v0 -= v1; v0 -= 2; @@ -212,14 +221,12 @@ bool test_replicate2() __attribute__((sycl_device)) { simd v0(0, 1); auto v0_rep = v0.replicate<2, 4, 2>(1); - return v0_rep[0] == v0[1] && v0_rep[1] == v0[2] && - v0_rep[2] == v0[5]; + return v0_rep[0] == v0[1] && v0_rep[1] == v0[2] && v0_rep[2] == v0[5]; } bool test_replicate3() __attribute__((sycl_device)) { simd v0(0, 1); auto v0_rep = v0.replicate<2, 4, 2, 2>(1); - return v0_rep[0] == v0[1] && v0_rep[1] == v0[3] && - v0_rep[2] == v0[5]; + return v0_rep[0] == v0[1] && v0_rep[1] == v0[3] && v0_rep[2] == v0[5]; } diff --git a/sycl/test/esimd/simd_view.cpp b/sycl/test/esimd/simd_view.cpp index c2733837603f8..7f94b1724b6fe 100644 --- a/sycl/test/esimd/simd_view.cpp +++ b/sycl/test/esimd/simd_view.cpp @@ -26,6 +26,7 @@ bool test_simd_view_bin_ops() __attribute__((sycl_device)) { auto ref1 = v1.select<8, 2>(0); ref0 += ref1; ref0 += 2; + ref0 %= ref1; ref0 -= ref1; ref0 -= 2; ref0 *= ref1;