Skip to content

[SYCL][NFC] Improve type traits' usage in headers & runtime #2768

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 2 commits into from
Nov 16, 2020
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: 4 additions & 5 deletions sycl/include/CL/sycl/INTEL/esimd/detail/esimd_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <CL/sycl/detail/stl_type_traits.hpp> // to define C++14,17 extensions
#include <CL/sycl/half_type.hpp>
#include <cstdint>
#include <type_traits>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
Expand Down Expand Up @@ -208,8 +207,8 @@ template <typename T1, typename T2> struct computation_type {
template <typename U> constexpr bool is_type() { return false; }

template <typename U, typename T, typename... Ts> constexpr bool is_type() {
using UU = typename std::remove_const<U>::type;
using TT = typename std::remove_const<T>::type;
using UU = typename detail::remove_const_t<U>;
using TT = typename detail::remove_const_t<T>;
return std::is_same<UU, TT>::value || is_type<UU, Ts...>();
}

Expand All @@ -228,10 +227,10 @@ struct bitcast_helper {
// Change the element type of a simd vector.
template <typename ToEltTy, typename FromEltTy, int FromN,
typename = csd::enable_if_t<is_vectorizable<ToEltTy>::value>>
ESIMD_INLINE typename std::conditional<
ESIMD_INLINE typename detail::conditional_t<
std::is_same<FromEltTy, ToEltTy>::value, vector_type_t<FromEltTy, FromN>,
vector_type_t<ToEltTy,
bitcast_helper<ToEltTy, FromEltTy, FromN>::nToElems()>>::type
bitcast_helper<ToEltTy, FromEltTy, FromN>::nToElems()>>
bitcast(vector_type_t<FromEltTy, FromN> Val) {
// Noop.
if constexpr (std::is_same<FromEltTy, ToEltTy>::value)
Expand Down
40 changes: 23 additions & 17 deletions sycl/include/CL/sycl/INTEL/esimd/detail/esimd_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ struct is_esimd_scalar
template <typename T>
struct is_dword_type
: std::integral_constant<
bool, std::is_same<int, typename std::remove_const<T>::type>::value ||
std::is_same<unsigned int,
typename std::remove_const<T>::type>::value> {
};
bool,
std::is_same<int, typename sycl::detail::remove_const_t<T>>::value ||
std::is_same<unsigned int,
typename sycl::detail::remove_const_t<T>>::value> {};

template <typename T, int N>
struct is_dword_type<sycl::INTEL::gpu::vector_type<T, N>> {
Expand All @@ -119,9 +119,10 @@ template <typename T>
struct is_word_type
: std::integral_constant<
bool,
std::is_same<short, typename std::remove_const<T>::type>::value ||
std::is_same<short,
typename sycl::detail::remove_const_t<T>>::value ||
std::is_same<unsigned short,
typename std::remove_const<T>::type>::value> {};
typename sycl::detail::remove_const_t<T>>::value> {};

template <typename T, int N>
struct is_word_type<sycl::INTEL::gpu::vector_type<T, N>> {
Expand All @@ -136,9 +137,9 @@ template <typename T>
struct is_byte_type
: std::integral_constant<
bool,
std::is_same<char, typename std::remove_const<T>::type>::value ||
std::is_same<char, typename sycl::detail::remove_const_t<T>>::value ||
std::is_same<unsigned char,
typename std::remove_const<T>::type>::value> {};
typename sycl::detail::remove_const_t<T>>::value> {};

template <typename T, int N>
struct is_byte_type<sycl::INTEL::gpu::vector_type<T, N>> {
Expand All @@ -152,31 +153,36 @@ template <typename T, int N> struct is_byte_type<sycl::INTEL::gpu::simd<T, N>> {
template <typename T>
struct is_fp_type
: std::integral_constant<
bool,
std::is_same<float, typename std::remove_const<T>::type>::value> {};
bool, std::is_same<float,
typename sycl::detail::remove_const_t<T>>::value> {
};

template <typename T>
struct is_df_type
: std::integral_constant<
bool,
std::is_same<double, typename std::remove_const<T>::type>::value> {};
bool, std::is_same<double,
typename sycl::detail::remove_const_t<T>>::value> {
};

template <typename T>
struct is_fp_or_dword_type
: std::integral_constant<
bool,
std::is_same<float, typename std::remove_const<T>::type>::value ||
std::is_same<int, typename std::remove_const<T>::type>::value ||
std::is_same<float,
typename sycl::detail::remove_const_t<T>>::value ||
std::is_same<int,
typename sycl::detail::remove_const_t<T>>::value ||
std::is_same<unsigned int,
typename std::remove_const<T>::type>::value> {};
typename sycl::detail::remove_const_t<T>>::value> {};

template <typename T>
struct is_qword_type
: std::integral_constant<
bool,
std::is_same<long long, typename std::remove_const<T>::type>::value ||
std::is_same<long long,
typename sycl::detail::remove_const_t<T>>::value ||
std::is_same<unsigned long long,
typename std::remove_const<T>::type>::value> {};
typename sycl::detail::remove_const_t<T>>::value> {};

template <typename T, int N>
struct is_qword_type<sycl::INTEL::gpu::vector_type<T, N>> {
Expand Down
10 changes: 6 additions & 4 deletions sycl/include/CL/sycl/INTEL/esimd/esimd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ template <typename Ty, int N> class simd {
//
// @return 1 if any element is set, 0 otherwise

template <typename T1 = element_type, typename T2 = Ty,
typename = std::enable_if_t<std::is_integral<T1>::value, T2>>
template <
typename T1 = element_type, typename T2 = Ty,
typename = sycl::detail::enable_if_t<std::is_integral<T1>::value, T2>>
uint16_t any() {
return __esimd_any<Ty, N>(data());
}
Expand All @@ -338,8 +339,9 @@ template <typename Ty, int N> class simd {
//
// @return 1 if all elements are set, 0 otherwise

template <typename T1 = element_type, typename T2 = Ty,
typename = std::enable_if_t<std::is_integral<T1>::value, T2>>
template <
typename T1 = element_type, typename T2 = Ty,
typename = sycl::detail::enable_if_t<std::is_integral<T1>::value, T2>>
uint16_t all() {
return __esimd_all<Ty, N>(data());
}
Expand Down
Loading