Skip to content

Conversation

@steffenlarsen
Copy link
Contributor

This commit avoid the use of the to-be-removed sycl::vec::vector_t in the native-cpu utilities.

This commit avoid the use of the to-be-removed sycl::vec::vector_t in
the native-cpu utilities.

Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
@steffenlarsen
Copy link
Contributor Author

@aelovikov-intel - There are no other nativecpu reviewers, but since you worked on removing the vector_t alias in times past, I was hoping you could help review this. I am open to other solutions if you can think of any.

@aelovikov-intel
Copy link
Contributor

Would

template <typename T> auto convertToOpenCLType(T &&x) {
using no_ref = std::remove_reference_t<T>;
if constexpr (is_multi_ptr_v<no_ref>) {
return convertToOpenCLType(x.get_decorated());
} else if constexpr (std::is_pointer_v<no_ref>) {
// TODO: Below ignores volatile, but we didn't have a need for it yet.
using elem_type = remove_decoration_t<std::remove_pointer_t<no_ref>>;
using converted_elem_type_no_cv = decltype(convertToOpenCLType(
std::declval<std::remove_const_t<elem_type>>()));
using converted_elem_type =
std::conditional_t<std::is_const_v<elem_type>,
const converted_elem_type_no_cv,
converted_elem_type_no_cv>;
#ifdef __SYCL_DEVICE_ONLY__
using result_type =
typename DecoratedType<converted_elem_type,
deduce_AS<no_ref>::value>::type *;
#else
using result_type = converted_elem_type *;
#endif
return reinterpret_cast<result_type>(x);
} else if constexpr (is_vec_v<no_ref>) {
using ElemTy = typename no_ref::element_type;
using ConvertedElemTy =
decltype(convertToOpenCLType(std::declval<ElemTy>()));
static constexpr int NumElements = no_ref::size();
#ifdef __SYCL_DEVICE_ONLY__
using vector_t =
std::conditional_t<NumElements == 1, ConvertedElemTy,
ConvertedElemTy
__attribute__((ext_vector_type(NumElements)))>;
return sycl::bit_cast<vector_t>(x);
#else
// sycl::half may convert to _Float16, and we would try to
// instantiate vec class with _Float16 DataType, which is not
// expected there. As such, leave vector<half, N> as-is.
using MatchingVec = vec<std::conditional_t<std::is_same_v<ElemTy, half>,
ElemTy, ConvertedElemTy>,
NumElements>;
return x.template as<MatchingVec>();
#endif
#if (!defined(_HAS_STD_BYTE) || _HAS_STD_BYTE != 0)
} else if constexpr (std::is_same_v<no_ref, std::byte>) {
return static_cast<uint8_t>(x);
#endif
} else if constexpr (std::is_integral_v<no_ref>) {
using OpenCLType = std::conditional_t<std::is_signed_v<no_ref>,
fixed_width_signed<sizeof(no_ref)>,
fixed_width_unsigned<sizeof(no_ref)>>;
static_assert(sizeof(OpenCLType) == sizeof(T));
return static_cast<OpenCLType>(x);
} else if constexpr (std::is_same_v<no_ref, half>) {
// Make it template-param-dependent to compile with incomplete `half`:
using OpenCLType =
std::enable_if_t<std::is_same_v<no_ref, half>,
sycl::detail::half_impl::BIsRepresentationT>;
static_assert(sizeof(OpenCLType) == sizeof(T));
return static_cast<OpenCLType>(x);
} else if constexpr (std::is_same_v<no_ref, ext::oneapi::bfloat16>) {
// On host, don't interpret BF16 as uint16.
#ifdef __SYCL_DEVICE_ONLY__
return sycl::bit_cast<uint16_t>(x);
#else
return std::forward<T>(x);
#endif
} else if constexpr (std::is_floating_point_v<no_ref>) {
static_assert(std::is_same_v<no_ref, float> ||
std::is_same_v<no_ref, double>,
"Other FP types are not expected/supported (yet?)");
static_assert(std::is_same_v<float, sycl::opencl::cl_float> &&
std::is_same_v<double, sycl::opencl::cl_double>);
return std::forward<T>(x);
} else {
using OpenCLType = select_cl_scalar_complex_or_T_t<no_ref>;
static_assert(sizeof(OpenCLType) == sizeof(T));
return static_cast<OpenCLType>(x);
}
}
help here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants