Skip to content

[SYCL][ESIMD] Allow implicit conversion from std::experimental::simd_mask to ESIMD::simd_mask #9830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sycl/include/std/experimental/simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@ class __simd_storage<_Tp, __simd_abi<_StorageKind::_VecExt, __num_element>> {
void __set(size_t __index, _Tp __val) noexcept {
__storage_[__index] = __val;
}
#ifdef ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD
const _StorageType& data() const noexcept { return __storage_; }
#endif
};

#endif // _LIBCPP_HAS_NO_VECTOR_EXTENSION
Expand Down Expand Up @@ -1666,6 +1669,10 @@ class simd_mask {
static constexpr size_t size() noexcept;
#endif // ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD

#ifdef ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD
const auto& data() const noexcept { return __s_.data(); }
#endif

simd_mask() = default;

// broadcast constructor
Expand Down Expand Up @@ -1756,4 +1763,4 @@ _LIBCPP_POP_MACROS

// Removed for ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD {
//#endif /* _LIBCPP_EXPERIMENTAL_SIMD */
// } Removed for ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD
// } Removed for ENABLE_SYCL_EXT_ONEAPI_INVOKE_SIMD
6 changes: 6 additions & 0 deletions sycl/include/sycl/ext/intel/esimd/detail/simd_mask_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <sycl/ext/intel/esimd/detail/simd_obj_impl.hpp>
#include <sycl/ext/intel/esimd/detail/types.hpp>
#include <sycl/ext/oneapi/experimental/detail/invoke_simd_types.hpp>

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

/// Implicit conversion from std::experimental::simd_mask
template <typename T1>
simd_mask_impl(const ext::oneapi::experimental::simd_mask<T1, N> &Val)
: base_type(convert_vector<T, T1, N>(Val.data())) {}

private:
/// @cond ESIMD_DETAIL
static inline constexpr bool mask_size_ok_for_mem_io() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//==- invoke_simd_types.hpp - SYCL invoke_simd extension types --*- C++ -*-==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// ===--------------------------------------------------------------------=== //
// Part of the implemenation of the sycl_ext_oneapi_invoke_simd extension.
// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_invoke_simd.asciidoc
// ===--------------------------------------------------------------------=== //

#pragma once

// SYCL extension macro definition as required by the SYCL specification.
// 1 - Initial extension version. Base features are supported.
#define SYCL_EXT_ONEAPI_INVOKE_SIMD 1

#include <std/experimental/simd.hpp>
#include <sycl/detail/defines_elementary.hpp>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {

namespace ext::oneapi::experimental {

// --- Basic definitions prescribed by the spec.
namespace simd_abi {
// "Fixed-size simd width of N" ABI based on clang vectors - used as the ABI for
// SIMD objects this implementation of invoke_simd spec is based on.
template <class T, int N>
using native_fixed_size = typename std::experimental::__simd_abi<
std::experimental::_StorageKind::_VecExt, N>;
} // namespace simd_abi

// The SIMD object type, which is the generic std::experimental::simd type with
// the native fixed size ABI.
template <class T, int N>
using simd = std::experimental::simd<T, simd_abi::native_fixed_size<T, N>>;

// The SIMD mask object type.
template <class T, int N>
using simd_mask =
std::experimental::simd_mask<T, simd_abi::native_fixed_size<T, N>>;
} // namespace ext::oneapi::experimental
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
} // namespace sycl
25 changes: 1 addition & 24 deletions sycl/include/sycl/ext/oneapi/experimental/invoke_simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@

#pragma once

// SYCL extension macro definition as required by the SYCL specification.
// 1 - Initial extension version. Base features are supported.
#define SYCL_EXT_ONEAPI_INVOKE_SIMD 1

#include <sycl/ext/oneapi/experimental/detail/invoke_simd_types.hpp>
#include <sycl/ext/oneapi/experimental/uniform.hpp>

#include <std/experimental/simd.hpp>
#include <sycl/detail/boost/mp11.hpp>
#include <sycl/sub_group.hpp>

Expand Down Expand Up @@ -72,25 +68,6 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) {

namespace ext::oneapi::experimental {

// --- Basic definitions prescribed by the spec.
namespace simd_abi {
// "Fixed-size simd width of N" ABI based on clang vectors - used as the ABI for
// SIMD objects this implementation of invoke_simd spec is based on.
template <class T, int N>
using native_fixed_size = typename std::experimental::__simd_abi<
std::experimental::_StorageKind::_VecExt, N>;
} // namespace simd_abi

// The SIMD object type, which is the generic std::experimental::simd type with
// the native fixed size ABI.
template <class T, int N>
using simd = std::experimental::simd<T, simd_abi::native_fixed_size<T, N>>;

// The SIMD mask object type.
template <class T, int N>
using simd_mask =
std::experimental::simd_mask<T, simd_abi::native_fixed_size<T, N>>;

// --- Helpers
namespace detail {

Expand Down
4 changes: 1 addition & 3 deletions sycl/test-e2e/InvokeSimd/Spec/simd_mask_merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ constexpr int VL = 16;
[[intel::device_indirectly_callable]] simd<float, VL>
SIMD_CALLEE(simd<float, VL> va, simd_mask<float, VL> mask) SYCL_ESIMD_FUNCTION {
esimd::simd<float, VL> ret(0);
esimd::simd_mask<VL> emask;
for(int i = 0; i < VL; i++)
emask[i] = static_cast<bool>(mask[i]);
esimd::simd_mask<VL> emask = mask;
ret.merge(va, !emask);
return ret;
}
Expand Down