Skip to content

Commit

Permalink
[NFC][SYCL] Simplify std::integral_constant<bool, ...> (#15383)
Browse files Browse the repository at this point in the history
  • Loading branch information
aelovikov-intel authored Sep 13, 2024
1 parent 9add238 commit 0f64638
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 37 deletions.
20 changes: 10 additions & 10 deletions sycl/include/std/experimental/simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,39 +1042,39 @@ inline constexpr overaligned_tag<_Np> overaligned{};

// traits [simd.traits]
template <class _Tp>
struct is_abi_tag : std::integral_constant<bool, false> {};
struct is_abi_tag : std::false_type {};

template <_StorageKind __kind, int _Np>
struct is_abi_tag<__simd_abi<__kind, _Np>>
: std::integral_constant<bool, true> {};
: std::true_type {};

template <class _Tp>
struct is_simd : std::integral_constant<bool, false> {};
struct is_simd : std::false_type {};

template <class _Tp, class _Abi>
struct is_simd<simd<_Tp, _Abi>> : std::integral_constant<bool, true> {};
struct is_simd<simd<_Tp, _Abi>> : std::true_type {};

template <class _Tp>
struct is_simd_mask : std::integral_constant<bool, false> {};
struct is_simd_mask : std::false_type {};

template <class _Tp, class _Abi>
struct is_simd_mask<simd_mask<_Tp, _Abi>> : std::integral_constant<bool, true> {
struct is_simd_mask<simd_mask<_Tp, _Abi>> : std::true_type {
};

template <class _Tp>
struct is_simd_flag_type : std::integral_constant<bool, false> {};
struct is_simd_flag_type : std::false_type {};

template <>
struct is_simd_flag_type<element_aligned_tag>
: std::integral_constant<bool, true> {};
: std::true_type {};

template <>
struct is_simd_flag_type<vector_aligned_tag>
: std::integral_constant<bool, true> {};
: std::true_type {};

template <size_t _Align>
struct is_simd_flag_type<overaligned_tag<_Align>>
: std::integral_constant<bool, true> {};
: std::true_type {};

template <class _Tp>
inline constexpr bool is_abi_tag_v = is_abi_tag<_Tp>::value;
Expand Down
12 changes: 6 additions & 6 deletions sycl/include/sycl/detail/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ class Builder {
#ifdef __SYCL_DEVICE_ONLY__

template <int N>
using is_valid_dimensions = std::integral_constant<bool, (N > 0) && (N < 4)>;
static inline constexpr bool is_valid_dimensions = (N > 0) && (N < 4);

template <int Dims> static const id<Dims> getElement(id<Dims> *) {
static_assert(is_valid_dimensions<Dims>::value, "invalid dimensions");
static_assert(is_valid_dimensions<Dims>, "invalid dimensions");
return __spirv::initGlobalInvocationId<Dims, id<Dims>>();
}

template <int Dims> static const group<Dims> getElement(group<Dims> *) {
static_assert(is_valid_dimensions<Dims>::value, "invalid dimensions");
static_assert(is_valid_dimensions<Dims>, "invalid dimensions");
range<Dims> GlobalSize{__spirv::initGlobalSize<Dims, range<Dims>>()};
range<Dims> LocalSize{__spirv::initWorkgroupSize<Dims, range<Dims>>()};
range<Dims> GroupRange{__spirv::initNumWorkgroups<Dims, range<Dims>>()};
Expand All @@ -145,7 +145,7 @@ class Builder {

template <int Dims, bool WithOffset>
static std::enable_if_t<WithOffset, const item<Dims, WithOffset>> getItem() {
static_assert(is_valid_dimensions<Dims>::value, "invalid dimensions");
static_assert(is_valid_dimensions<Dims>, "invalid dimensions");
id<Dims> GlobalId{__spirv::initGlobalInvocationId<Dims, id<Dims>>()};
range<Dims> GlobalSize{__spirv::initGlobalSize<Dims, range<Dims>>()};
id<Dims> GlobalOffset{__spirv::initGlobalOffset<Dims, id<Dims>>()};
Expand All @@ -154,14 +154,14 @@ class Builder {

template <int Dims, bool WithOffset>
static std::enable_if_t<!WithOffset, const item<Dims, WithOffset>> getItem() {
static_assert(is_valid_dimensions<Dims>::value, "invalid dimensions");
static_assert(is_valid_dimensions<Dims>, "invalid dimensions");
id<Dims> GlobalId{__spirv::initGlobalInvocationId<Dims, id<Dims>>()};
range<Dims> GlobalSize{__spirv::initGlobalSize<Dims, range<Dims>>()};
return createItem<Dims, false>(GlobalSize, GlobalId);
}

template <int Dims> static const nd_item<Dims> getElement(nd_item<Dims> *) {
static_assert(is_valid_dimensions<Dims>::value, "invalid dimensions");
static_assert(is_valid_dimensions<Dims>, "invalid dimensions");
range<Dims> GlobalSize{__spirv::initGlobalSize<Dims, range<Dims>>()};
range<Dims> LocalSize{__spirv::initWorkgroupSize<Dims, range<Dims>>()};
range<Dims> GroupRange{__spirv::initNumWorkgroups<Dims, range<Dims>>()};
Expand Down
3 changes: 1 addition & 2 deletions sycl/include/sycl/detail/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ template <> struct is_sub_group<sycl::sub_group> : std::true_type {};

template <typename T>
struct is_generic_group
: std::integral_constant<bool,
is_group<T>::value || is_sub_group<T>::value> {};
: std::bool_constant<is_group<T>::value || is_sub_group<T>::value> {};
template <typename T>
inline constexpr bool is_generic_group_v = is_generic_group<T>::value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ class complex<_Tp, typename std::enable_if_t<is_genfloat<_Tp>::value>>;
////////////////////////////////////////////////////////////////////////////////

template <class _Tp>
struct is_genfloat
: std::integral_constant<bool, std::is_same_v<_Tp, double> ||
std::is_same_v<_Tp, float> ||
std::is_same_v<_Tp, sycl::half>> {};
struct is_genfloat : std::bool_constant<std::is_same_v<_Tp, double> ||
std::is_same_v<_Tp, float> ||
std::is_same_v<_Tp, sycl::half>> {};

template <class _Tp>
struct is_gencomplex
: std::integral_constant<bool,
std::is_same_v<_Tp, complex<double>> ||
std::is_same_v<_Tp, complex<float>> ||
std::is_same_v<_Tp, complex<sycl::half>>> {};
: std::bool_constant<std::is_same_v<_Tp, complex<double>> ||
std::is_same_v<_Tp, complex<float>> ||
std::is_same_v<_Tp, complex<sycl::half>>> {};

////////////////////////////////////////////////////////////////////////////////
/// DEFINES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ namespace experimental {

namespace cplx::detail {

template <bool _Val> using _BoolConstant = std::integral_constant<bool, _Val>;

template <class _Tp, class _Up>
using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;

template <class _Tp> struct __numeric_type {
static void __test(...);
static sycl::half __test(sycl::half);
Expand All @@ -46,7 +41,7 @@ template <class _Tp> struct __numeric_type {
static double __test(double);

typedef decltype(__test(std::declval<_Tp>())) type;
static const bool value = _IsNotSame<type, void>::value;
static const bool value = !std::is_same_v<type, void>;
};

template <> struct __numeric_type<void> {
Expand Down
5 changes: 2 additions & 3 deletions sycl/include/sycl/ext/oneapi/experimental/group_sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ struct is_sorter_impl {
std::declval<G>(), std::declval<Val>()))>;

template <typename G = Group>
static decltype(std::integral_constant<bool,
is_expected_return_type<G>::value &&
sycl::is_group_v<G>>{})
static decltype(std::bool_constant<is_expected_return_type<G>::value &&
sycl::is_group_v<G>>{})
test(int);

template <typename = Group> static std::false_type test(...);
Expand Down
4 changes: 2 additions & 2 deletions sycl/include/sycl/group_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ struct is_complex : public std::false_type {};
// ---- is_arithmetic_or_complex
template <typename T>
using is_arithmetic_or_complex =
std::integral_constant<bool, sycl::detail::is_complex<T>::value ||
sycl::detail::is_arithmetic<T>::value>;
std::bool_constant<sycl::detail::is_complex<T>::value ||
sycl::detail::is_arithmetic<T>::value>;

template <typename T>
struct is_vector_arithmetic_or_complex
Expand Down

0 comments on commit 0f64638

Please sign in to comment.