/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/docs-6.4.3/include/ck/utility/type.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/docs-6.4.3/include/ck/utility/type.hpp Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/docs-6.4.3/include/ck/utility/type.hpp Source File
type.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
2 // Copyright (c) 2018-2025, Advanced Micro Devices, Inc. All rights reserved.
3 
4 #pragma once
5 
6 #include "ck/ck.hpp"
9 
10 namespace ck {
11 #ifdef CK_CODE_GEN_RTC
12 // NOLINTNEXTLINE
13 #define CK_BUILTIN_TYPE_TRAIT1(name) \
14  template <class T> \
15  struct name : bool_constant<__##name(T)> \
16  { \
17  }
18 
19 // NOLINTNEXTLINE
20 #define CK_BUILTIN_TYPE_TRAIT2(name) \
21  template <class T, class U> \
22  struct name : bool_constant<__##name(T, U)> \
23  { \
24  }
25 
26 // NOLINTNEXTLINE
27 #define CK_BUILTIN_TYPE_TRAITN(name) \
28  template <class... Ts> \
29  struct name : bool_constant<__##name(Ts...)> \
30  { \
31  }
32 
33 CK_BUILTIN_TYPE_TRAIT1(is_class);
34 CK_BUILTIN_TYPE_TRAIT1(is_pointer);
35 CK_BUILTIN_TYPE_TRAIT1(is_reference);
36 CK_BUILTIN_TYPE_TRAIT1(is_trivially_copyable);
37 CK_BUILTIN_TYPE_TRAIT1(is_unsigned);
38 CK_BUILTIN_TYPE_TRAIT2(is_base_of);
39 
40 template <class T>
41 struct remove_cv
42 {
43  using type = T;
44 };
45 
46 template <class T>
47 struct remove_cv<const T> : remove_cv<T>
48 {
49 };
50 
51 template <class T>
52 struct remove_cv<volatile T> : remove_cv<T>
53 {
54 };
55 
56 template <class T>
57 struct remove_reference
58 {
59  typedef T type;
60 };
61 template <class T>
62 struct remove_reference<T&>
63 {
64  typedef T type;
65 };
66 template <class T>
67 struct remove_reference<T&&>
68 {
69  typedef T type;
70 };
71 template <class T>
72 struct remove_pointer
73 {
74  typedef T type;
75 };
76 template <class T>
77 struct remove_pointer<T*>
78 {
79  typedef T type;
80 };
81 template <class T>
82 struct remove_pointer<T* const>
83 {
84  typedef T type;
85 };
86 template <class T>
87 struct remove_pointer<T* volatile>
88 {
89  typedef T type;
90 };
91 template <class T>
92 struct remove_pointer<T* const volatile>
93 {
94  typedef T type;
95 };
96 
97 template <typename T>
98 constexpr T&& forward(typename remove_reference<T>::type& t_) noexcept
99 {
100  return static_cast<T&&>(t_);
101 }
102 template <typename T>
103 constexpr T&& forward(typename remove_reference<T>::type&& t_) noexcept
104 {
105  return static_cast<T&&>(t_);
106 }
107 
108 template <class T>
109 struct is_const : public integral_constant<bool, false>
110 {
111 };
112 template <class T>
113 struct is_const<const T> : public integral_constant<bool, true>
114 {
115 };
116 template <class T>
117 inline constexpr bool is_const_v = is_const<T>::value;
118 
119 template <typename T>
120 inline constexpr bool is_reference_v = is_reference<T>::value;
121 
122 template <class T>
123 struct remove_const
124 {
125  typedef T type;
126 };
127 template <class T>
128 struct remove_const<const T>
129 {
130  typedef T type;
131 };
132 template <class T>
133 using remove_const_t = typename remove_const<T>::type;
134 template <class T>
135 inline constexpr bool is_class_v = is_class<T>::value;
136 
137 template <class T>
138 inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value;
139 // template <typename T>
140 // T&& declval() noexcept;
141 
142 template <class T, class U = T&&>
143 U private_declval(int);
144 
145 template <class T>
146 T private_declval(long);
147 
148 template <class T>
149 auto declval() noexcept -> decltype(private_declval<T>(0));
150 
151 template <class...>
152 using void_t = void;
153 #else
154 #include <utility>
155 #include <type_traits>
156 using std::declval;
157 using std::forward;
158 using std::is_base_of;
159 using std::is_class;
160 using std::is_class_v;
161 using std::is_const_v;
162 using std::is_pointer;
163 using std::is_reference;
164 using std::is_reference_v;
165 using std::is_trivially_copyable;
166 using std::is_trivially_copyable_v;
167 using std::is_unsigned;
168 using std::remove_const_t;
169 using std::remove_cv;
170 using std::remove_pointer;
171 using std::remove_reference;
172 using std::void_t;
173 #endif
174 
175 template <typename X, typename Y>
176 struct is_same : public integral_constant<bool, false>
177 {
178 };
179 
180 template <typename X>
181 struct is_same<X, X> : public integral_constant<bool, true>
182 {
183 };
184 
185 template <typename X>
186 struct is_floating_point : public integral_constant<bool, false>
187 {
188 };
189 
190 template <>
191 struct is_floating_point<float> : public integral_constant<bool, true>
192 {
193 };
194 
195 template <>
196 struct is_floating_point<double> : public integral_constant<bool, true>
197 {
198 };
199 template <>
200 struct is_floating_point<long double> : public integral_constant<bool, true>
201 {
202 };
203 
204 template <typename X>
205 struct is_integral : public integral_constant<bool, false>
206 {
207 };
208 
209 template <>
210 struct is_integral<int> : public integral_constant<bool, true>
211 {
212 };
213 
214 template <>
215 struct is_integral<unsigned int> : public integral_constant<bool, true>
216 {
217 };
218 
219 template <>
220 struct is_integral<long> : public integral_constant<bool, true>
221 {
222 };
223 
224 template <>
225 struct is_integral<unsigned long> : public integral_constant<bool, true>
226 {
227 };
228 
229 template <>
230 struct is_integral<short> : public integral_constant<bool, true>
231 {
232 };
233 template <>
234 struct is_integral<unsigned short> : public integral_constant<bool, true>
235 {
236 };
237 
238 template <>
239 struct is_integral<long long> : public integral_constant<bool, true>
240 {
241 };
242 
243 template <>
244 struct is_integral<unsigned long long> : public integral_constant<bool, true>
245 {
246 };
247 
248 template <>
249 struct is_integral<char> : public integral_constant<bool, true>
250 {
251 };
252 
253 template <>
254 struct is_integral<signed char> : public integral_constant<bool, true>
255 {
256 };
257 
258 template <>
259 struct is_integral<unsigned char> : public integral_constant<bool, true>
260 {
261 };
262 
263 template <>
264 struct is_integral<wchar_t> : public integral_constant<bool, true>
265 {
266 };
267 template <>
268 struct is_integral<char16_t> : public integral_constant<bool, true>
269 {
270 };
271 
272 template <>
273 struct is_integral<char32_t> : public integral_constant<bool, true>
274 {
275 };
276 
277 template <>
278 struct is_integral<bool> : public integral_constant<bool, true>
279 {
280 };
281 
282 template <typename X, typename Y>
283 inline constexpr bool is_same_v = is_same<X, Y>::value;
284 
285 template <typename X, typename Y>
286 inline constexpr bool is_base_of_v = is_base_of<X, Y>::value;
287 
288 template <typename T>
289 inline constexpr bool is_unsigned_v = is_unsigned<T>::value;
290 
291 template <typename T>
292 using remove_reference_t = typename remove_reference<T>::type;
293 
294 template <typename T>
295 using remove_reference_t = typename remove_reference<T>::type;
296 
297 template <typename T>
298 using remove_cv_t = typename remove_cv<T>::type;
299 template <typename T>
301 
302 template <typename T>
303 using remove_pointer_t = typename remove_pointer<T>::type;
304 
305 template <typename T>
306 inline constexpr bool is_pointer_v = is_pointer<T>::value;
307 
308 template <typename Y, typename X, typename enable_if<sizeof(X) == sizeof(Y), bool>::type = false>
309 __host__ __device__ constexpr Y bit_cast(const X& x)
310 {
311  static_assert(__has_builtin(__builtin_bit_cast), "");
312  static_assert(sizeof(X) == sizeof(Y), "Do not support cast between different size of type");
313 
314  return __builtin_bit_cast(Y, x);
315 }
316 } // namespace ck
Definition: ck.hpp:264
typename remove_reference< T >::type remove_reference_t
Definition: type.hpp:292
__host__ constexpr __device__ Y bit_cast(const X &x)
Definition: type.hpp:309
typename remove_pointer< T >::type remove_pointer_t
Definition: type.hpp:303
constexpr bool is_pointer_v
Definition: type.hpp:306
constexpr bool is_base_of_v
Definition: type.hpp:286
constexpr bool is_unsigned_v
Definition: type.hpp:289
constexpr bool is_same_v
Definition: type.hpp:283
remove_cv_t< remove_reference_t< T > > remove_cvref_t
Definition: type.hpp:300
typename remove_cv< T >::type remove_cv_t
Definition: type.hpp:298
Definition: integral_constant.hpp:10
Definition: type.hpp:187
Definition: type.hpp:206
Definition: type.hpp:177