Skip to content

Commit de5b479

Browse files
authored
[SYCL][ESIMD] Allow implicit conversion from std::experimental::simd_mask to ESIMD::simd_mask (#9830)
Users of `invoke_simd` need to use `std::experimental::simd_mask` for masks as per the spec, but once they enter ESIMD code they will likely want to use the ESIMD classes. Provide an implicit conversion from `std::experimental::simd_mask` to `esimd::simd_mask` Without this change, you need to use a manual loop, as all you can do is access `std::experimental::simd_mask` element-by-element. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent f749876 commit de5b479

File tree

5 files changed

+62
-28
lines changed

5 files changed

+62
-28
lines changed

sycl/include/std/experimental/simd.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,9 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> {
854854
void __set(size_t __index, _Tp __val) noexcept {
855855
__storage_[__index] = __val;
856856
}
857+
#ifdef ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD
858+
const _StorageType& data() const noexcept { return __storage_; }
859+
#endif
857860
};
858861

859862
#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION
@@ -1666,6 +1669,10 @@ class simd_mask {
16661669
static constexpr size_t size() noexcept;
16671670
#endif // ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD
16681671

1672+
#ifdef ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD
1673+
const auto& data() const noexcept { return __s_.data(); }
1674+
#endif
1675+
16691676
simd_mask() = default;
16701677

16711678
// broadcast constructor
@@ -1756,4 +1763,4 @@ _LIBCPP_POP_MACROS
17561763

17571764
// Removed for ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD {
17581765
//#endif /* _LIBCPP_EXPERIMENTAL_SIMD */
1759-
// } Removed for ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD
1766+
// } Removed for ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD

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

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

1313
#include <sycl/ext/intel/esimd/detail/simd_obj_impl.hpp>
1414
#include <sycl/ext/intel/esimd/detail/types.hpp>
15+
#include <sycl/ext/oneapi/experimental/detail/invoke_simd_types.hpp>
1516

1617
namespace sycl {
1718
__SYCL_INLINE_VER_NAMESPACE(_V1) {
@@ -95,6 +96,11 @@ class simd_mask_impl
9596
/// Implicit conversion from simd.
9697
simd_mask_impl(const simd<T, N> &Val) : base_type(Val.data()) {}
9798

99+
/// Implicit conversion from std::experimental::simd_mask
100+
template <typename T1>
101+
simd_mask_impl(const ext::oneapi::experimental::simd_mask<T1, N> &Val)
102+
: base_type(convert_vector<T, T1, N>(Val.data())) {}
103+
98104
private:
99105
/// @cond ESIMD_DETAIL
100106
static inline constexpr bool mask_size_ok_for_mem_io() {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//==- invoke_simd_types.hpp - SYCL invoke_simd extension types --*- C++ -*-==//
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+
// Part of the implemenation of the sycl_ext_oneapi_invoke_simd extension.
9+
// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_invoke_simd.asciidoc
10+
// ===--------------------------------------------------------------------=== //
11+
12+
#pragma once
13+
14+
// SYCL extension macro definition as required by the SYCL specification.
15+
// 1 - Initial extension version. Base features are supported.
16+
#define SYCL_EXT_ONEAPI_INVOKE_SIMD 1
17+
18+
#include <std/experimental/simd.hpp>
19+
#include <sycl/detail/defines_elementary.hpp>
20+
21+
namespace sycl {
22+
__SYCL_INLINE_VER_NAMESPACE(_V1) {
23+
24+
namespace ext::oneapi::experimental {
25+
26+
// --- Basic definitions prescribed by the spec.
27+
namespace simd_abi {
28+
// "Fixed-size simd width of N" ABI based on clang vectors - used as the ABI for
29+
// SIMD objects this implementation of invoke_simd spec is based on.
30+
template <class T, int N>
31+
using native_fixed_size = typename std::experimental::__simd_abi<
32+
std::experimental::_StorageKind::_VecExt, N>;
33+
} // namespace simd_abi
34+
35+
// The SIMD object type, which is the generic std::experimental::simd type with
36+
// the native fixed size ABI.
37+
template <class T, int N>
38+
using simd = std::experimental::simd<T, simd_abi::native_fixed_size<T, N>>;
39+
40+
// The SIMD mask object type.
41+
template <class T, int N>
42+
using simd_mask =
43+
std::experimental::simd_mask<T, simd_abi::native_fixed_size<T, N>>;
44+
} // namespace ext::oneapi::experimental
45+
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
46+
} // namespace sycl

sycl/include/sycl/ext/oneapi/experimental/invoke_simd.hpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111

1212
#pragma once
1313

14-
// SYCL extension macro definition as required by the SYCL specification.
15-
// 1 - Initial extension version. Base features are supported.
16-
#define SYCL_EXT_ONEAPI_INVOKE_SIMD 1
17-
14+
#include <sycl/ext/oneapi/experimental/detail/invoke_simd_types.hpp>
1815
#include <sycl/ext/oneapi/experimental/uniform.hpp>
1916

20-
#include <std/experimental/simd.hpp>
2117
#include <sycl/detail/boost/mp11.hpp>
2218
#include <sycl/sub_group.hpp>
2319

@@ -72,25 +68,6 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) {
7268

7369
namespace ext::oneapi::experimental {
7470

75-
// --- Basic definitions prescribed by the spec.
76-
namespace simd_abi {
77-
// "Fixed-size simd width of N" ABI based on clang vectors - used as the ABI for
78-
// SIMD objects this implementation of invoke_simd spec is based on.
79-
template <class T, int N>
80-
using native_fixed_size = typename std::experimental::__simd_abi<
81-
std::experimental::_StorageKind::_VecExt, N>;
82-
} // namespace simd_abi
83-
84-
// The SIMD object type, which is the generic std::experimental::simd type with
85-
// the native fixed size ABI.
86-
template <class T, int N>
87-
using simd = std::experimental::simd<T, simd_abi::native_fixed_size<T, N>>;
88-
89-
// The SIMD mask object type.
90-
template <class T, int N>
91-
using simd_mask =
92-
std::experimental::simd_mask<T, simd_abi::native_fixed_size<T, N>>;
93-
9471
// --- Helpers
9572
namespace detail {
9673

sycl/test-e2e/InvokeSimd/Spec/simd_mask_merge.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ constexpr int VL = 16;
1717
[[intel::device_indirectly_callable]] simd<float, VL>
1818
SIMD_CALLEE(simd<float, VL> va, simd_mask<float, VL> mask) SYCL_ESIMD_FUNCTION {
1919
esimd::simd<float, VL> ret(0);
20-
esimd::simd_mask<VL> emask;
21-
for(int i = 0; i < VL; i++)
22-
emask[i] = static_cast<bool>(mask[i]);
20+
esimd::simd_mask<VL> emask = mask;
2321
ret.merge(va, !emask);
2422
return ret;
2523
}

0 commit comments

Comments
 (0)