Skip to content

Commit 19c327f

Browse files
authored
[ESIMD] Add esimd::merge free function. (#5308)
* [ESIMD] Add esimd::merge free function. Also, remove deprecation note from the 'simd_mask_impl(const simd<T, N> &Val)' constructor, as it is used when loading a mask from memory, and is otherwise useful constructor. Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent 50ccce9 commit 19c327f

File tree

5 files changed

+112
-5
lines changed

5 files changed

+112
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/// \defgroup sycl_esimd DPC++ Explicit SIMD API
1414

15+
#include <sycl/ext/intel/experimental/esimd/alt_ui.hpp>
1516
#include <sycl/ext/intel/experimental/esimd/common.hpp>
1617
#include <sycl/ext/intel/experimental/esimd/math.hpp>
1718
#include <sycl/ext/intel/experimental/esimd/memory.hpp>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//==-------------- alt_ui.hpp - DPC++ Explicit SIMD API ------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
// "Alternative" convenience Explicit SIMD APIs.
9+
//===----------------------------------------------------------------------===//
10+
11+
#include <sycl/ext/intel/experimental/esimd/simd.hpp>
12+
#include <sycl/ext/intel/experimental/esimd/simd_view.hpp>
13+
14+
__SYCL_INLINE_NAMESPACE(cl) {
15+
namespace sycl {
16+
namespace ext {
17+
namespace intel {
18+
namespace experimental {
19+
namespace esimd {
20+
21+
/// "Merges" elements of the input vectors according to the merge mask.
22+
/// @param a the first vector
23+
/// @param b the second vector
24+
/// @param m the merge mask
25+
/// @return a vector, where each element equals to corresponding element from
26+
/// \c a (if corresponding mask element is zero) or \c b (otherwise)
27+
/// \ingroup sycl_esimd
28+
template <class T, int N>
29+
__ESIMD_API simd<T, N> merge(simd<T, N> a, simd<T, N> b, simd_mask<N> m) {
30+
a.merge(b, m);
31+
return a;
32+
}
33+
34+
/// "Merges" elements of the input masks according to the merge mask.
35+
template <int N>
36+
__ESIMD_API simd_mask<N> merge(simd_mask<N> a, simd_mask<N> b, simd_mask<N> m) {
37+
a.merge(b, m);
38+
return a;
39+
}
40+
41+
/// "Merges" elements of vectors referenced by the input views.
42+
/// Available only when all of the following holds:
43+
/// - the length and the element type of the sub-regions referenced by both
44+
/// input views are the same.
45+
template <class BaseT1, class BaseT2, class RegionT1, class RegionT2,
46+
class = std::enable_if_t<
47+
(shape_type<RegionT1>::length == shape_type<RegionT2>::length) &&
48+
std::is_same_v<detail::element_type_t<BaseT1>,
49+
detail::element_type_t<BaseT2>>>>
50+
__ESIMD_API auto merge(simd_view<BaseT1, RegionT1> v1,
51+
simd_view<BaseT2, RegionT2> v2,
52+
simd_mask<shape_type<RegionT1>::length> m) {
53+
return merge(v1.read(), v2.read(), m);
54+
}
55+
56+
} // namespace esimd
57+
} // namespace experimental
58+
} // namespace intel
59+
} // namespace ext
60+
} // namespace sycl
61+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/sycl/ext/intel/experimental/esimd/detail/simd_mask_impl.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class simd_mask_impl
6262
}
6363

6464
/// Implicit conversion from simd.
65-
__SYCL_DEPRECATED(__ESIMD_MASK_DEPRECATION_MSG)
6665
simd_mask_impl(const simd<T, N> &Val) : base_type(Val.data()) {}
6766

6867
/// Implicit conversion from simd_view<simd,...>.

sycl/test/esimd/esimd_merge.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// RUN: %clangxx -fsycl -fsycl-device-only -fsyntax-only -Xclang -verify %s
2+
// expected-no-diagnostics
3+
4+
#include <sycl/ext/intel/experimental/esimd.hpp>
5+
6+
using namespace sycl::ext::intel::experimental::esimd;
7+
using namespace sycl::ext::intel::experimental;
8+
using namespace cl::sycl;
9+
10+
using simd_mask_elem_t = simd_mask<1>::element_type;
11+
12+
template <class T, int N> struct SimdMergeTest {
13+
inline void test(T *in_a, T *in_b, simd_mask_elem_t *in_mask, T *out)
14+
__attribute__((sycl_device)) {
15+
simd<T, N> a(in_a);
16+
simd<T, N> b(in_b);
17+
simd_mask<N> m(in_mask);
18+
simd<T, N> c = esimd::merge(a, b, m);
19+
c.copy_to(out);
20+
}
21+
};
22+
23+
template <class T, int N> struct SimdViewMergeTest {
24+
inline void test(T *in_a, T *in_b, simd_mask_elem_t *in_mask, T *out)
25+
__attribute__((sycl_device)) {
26+
simd<T, N> a(in_a);
27+
simd<T, N> b(in_b);
28+
simd_mask<N / 2> m(in_mask);
29+
simd<T, N / 2> c = esimd::merge(a.template select<N / 2, 1>(1),
30+
b.template select<N / 2, 2>(0), m);
31+
c.copy_to(out);
32+
}
33+
};
34+
35+
template <class T, int N> struct SimdView2MergeTest {
36+
inline void test(T *in_a, T *in_b, simd_mask_elem_t *in_mask, T *out)
37+
__attribute__((sycl_device)) {
38+
simd<T, N> a(in_a);
39+
simd<T, N> b(in_b);
40+
simd_mask<N / 4> m(in_mask);
41+
simd<T, N / 4> c = esimd::merge(
42+
a.template select<N / 2, 1>(1).template select<N / 4, 1>(),
43+
b.template select<N / 2, 2>(0).template select<N / 4, 1>(), m);
44+
c.copy_to(out);
45+
}
46+
};
47+
48+
template struct SimdMergeTest<float, 8>;
49+
template struct SimdViewMergeTest<float, 8>;
50+
template struct SimdView2MergeTest<sycl::half, 8>;

sycl/test/esimd/simd_mask.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,12 @@ SYCL_EXTERNAL SYCL_ESIMD_FUNCTION void compat_test(float *ptr) {
6363
simd<int, 8> pred1(1);
6464
auto pred2 = pred1.bit_cast_view<unsigned short>();
6565

66-
// expected-warning@+1 {{deprecated}}
6766
auto x1 = gather<float, 16>(ptr, offsets, pred);
6867
// expected-warning@+1 {{deprecated}}
6968
auto x11 = gather<float, 16>(ptr, offsets, pred2);
70-
// expected-warning@+1 {{deprecated}}
7169
auto x2 = gather<float, 16>(ptr, offsets, simd<unsigned short, 16>{});
7270
simd_mask<16> m1(0);
73-
// expected-warning@+1 {{deprecated}}
7471
m1 = pred;
7572
simd_mask<16> m2(0);
76-
// expected-warning@+1 {{deprecated}}
7773
m2 = std::move(pred);
7874
}

0 commit comments

Comments
 (0)