DPC++ Runtime
Runtime libraries for oneAPI DPC++
type_list.hpp
Go to the documentation of this file.
1 //==----------- type_list.hpp - SYCL list of types utils -------------------==//
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 
9 #pragma once
10 
13 
15 namespace sycl {
16 namespace detail {
17 
18 template <typename T> using head_t = typename T::head;
19 
20 template <typename T> using tail_t = typename T::tail;
21 
22 // type_list
23 template <typename... T> struct type_list;
24 
26 
27 template <typename T>
29  : conditional_t<std::is_same<T, empty_type_list>::value, std::true_type,
30  std::false_type> {};
31 
32 template <> struct type_list<> {};
33 
34 template <typename H, typename... T> struct type_list<H, T...> {
35  using head = H;
36  using tail = type_list<T...>;
37 };
38 
39 template <typename H, typename... T, typename... T2>
40 struct type_list<type_list<H, T...>, T2...> {
41 private:
42  using remainder = tail_t<type_list<H>>;
43  static constexpr bool has_remainder = !is_empty_type_list<remainder>::value;
44  using without_remainder = type_list<T..., T2...>;
45  using with_remainder = type_list<remainder, T..., T2...>;
46 
47 public:
50 };
51 
52 // is_contained
53 template <typename T, typename L>
55  : conditional_t<std::is_same<remove_cv_t<T>, head_t<L>>::value,
56  std::true_type, is_contained<T, tail_t<L>>> {};
57 
58 template <typename T>
59 struct is_contained<T, empty_type_list> : std::false_type {};
60 
61 // value_list
62 template <typename T, T... V> struct value_list;
63 
64 template <typename T, T H, T... V> struct value_list<T, H, V...> {
65  static constexpr T head = H;
66  using tail = value_list<T, V...>;
67 };
68 
69 template <typename T> struct value_list<T> {};
70 
71 // is_contained_value
72 template <typename T, T V, typename TL>
74  : conditional_t<V == TL::head, std::true_type,
75  is_contained_value<T, V, tail_t<TL>>> {};
76 
77 template <typename T, T V>
78 struct is_contained_value<T, V, value_list<T>> : std::false_type {};
79 
80 // address_space_list
81 template <access::address_space... V>
83 
84 template <access::address_space AS, typename VL>
86 
87 // size type predicates
88 template <typename T1, typename T2>
89 struct is_type_size_equal : bool_constant<(sizeof(T1) == sizeof(T2))> {};
90 
91 template <typename T1, typename T2>
92 struct is_type_size_greater : bool_constant<(sizeof(T1) > sizeof(T2))> {};
93 
94 template <typename T1, typename T2>
96  : bool_constant<(sizeof(T1) == (sizeof(T2) * 2))> {};
97 
98 template <typename T1, typename T2>
99 struct is_type_size_less : bool_constant<(sizeof(T1) < sizeof(T2))> {};
100 
101 template <typename T1, typename T2>
102 struct is_type_size_half_of : bool_constant<(sizeof(T1) == (sizeof(T2) / 2))> {
103 };
104 
105 // find required type
106 template <typename TL, template <typename, typename> class C, typename T>
107 struct find_type {
108  using head = head_t<TL>;
109  using tail = typename find_type<tail_t<TL>, C, T>::type;
110  using type = conditional_t<C<head, T>::value, head, tail>;
111 };
112 
113 template <template <typename, typename> class C, typename T>
114 struct find_type<empty_type_list, C, T> {
115  using type = void;
116 };
117 
118 template <typename TL, template <typename, typename> class C, typename T>
119 using find_type_t = typename find_type<TL, C, T>::type;
120 
121 template <typename TL, typename T>
122 using find_same_size_type_t = find_type_t<TL, is_type_size_equal, T>;
123 
124 template <typename TL, typename T>
125 using find_smaller_type_t = find_type_t<TL, is_type_size_less, T>;
126 
127 template <typename TL, typename T>
128 using find_larger_type_t = find_type_t<TL, is_type_size_greater, T>;
129 
130 template <typename TL, typename T>
131 using find_twice_as_small_type_t = find_type_t<TL, is_type_size_half_of, T>;
132 
133 template <typename TL, typename T>
134 using find_twice_as_large_type_t = find_type_t<TL, is_type_size_double_of, T>;
135 
136 } // namespace detail
137 } // namespace sycl
138 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::is_type_size_less
Definition: type_list.hpp:99
cl::sycl::detail::is_empty_type_list
Definition: type_list.hpp:28
cl::sycl::detail::head_t
typename T::head head_t
Definition: type_list.hpp:18
cl::sycl::detail::type_list< type_list< H, T... >, T2... >::tail
conditional_t< has_remainder, with_remainder, without_remainder > tail
Definition: type_list.hpp:49
cl::sycl::detail::type_list
Definition: type_list.hpp:23
cl::sycl::detail::is_contained
Definition: type_list.hpp:54
sycl
Definition: invoke_simd.hpp:68
bool_constant
access.hpp
stl_type_traits.hpp
cl::sycl::detail::type_list< H, T... >::head
H head
Definition: type_list.hpp:35
cl::sycl::detail::conditional_t
typename std::conditional< B, T, F >::type conditional_t
Definition: stl_type_traits.hpp:27
cl::sycl::detail::type_list<>
Definition: type_list.hpp:32
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::is_type_size_equal
Definition: type_list.hpp:89
cl::sycl::detail::value_list
Definition: type_list.hpp:62
cl::sycl::detail::is_type_size_greater
Definition: type_list.hpp:92
cl::sycl::detail::is_type_size_double_of
Definition: type_list.hpp:95
cl::sycl::detail::is_contained_value
Definition: type_list.hpp:73
cl::sycl::access::address_space
address_space
Definition: access.hpp:45
cl::sycl::detail::type_list< type_list< H, T... >, T2... >::head
head_t< type_list< H > > head
Definition: type_list.hpp:48
cl::sycl::remainder
detail::enable_if_t< detail::is_genfloat< T >::value, T > remainder(T x, T y) __NOEXC
Definition: builtins.hpp:399
cl::sycl::detail::tail_t
typename T::tail tail_t
Definition: type_list.hpp:20
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12