-
Notifications
You must be signed in to change notification settings - Fork 163
/
is_trivially_relocatable.h
297 lines (260 loc) · 10.9 KB
/
is_trivially_relocatable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
* Copyright 2008-2021 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*! \file
* \brief <a href="https://wg21.link/P1144">P1144</a>'s proposed
* \c std::is_trivially_relocatable, an extensible type trait indicating
* whether a type can be bitwise copied with a facility like
* <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>.
*/
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/static_assert.h>
#include <thrust/detail/type_traits.h>
#include <thrust/type_traits/is_contiguous_iterator.h>
#include <type_traits>
THRUST_NAMESPACE_BEGIN
/*! \addtogroup utility
* \{
*/
/*! \addtogroup type_traits Type Traits
* \{
*/
/*! \cond
*/
namespace detail
{
template <typename T>
struct is_trivially_relocatable_impl;
} // namespace detail
/*! \endcond
*/
/*! \brief <a href="https://en.cppreference.com/w/cpp/named_req/UnaryTypeTrait"><i>UnaryTypeTrait</i></a>
* that returns \c true_type if \c T is
* <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
* aka can be bitwise copied with a facility like
* <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
* and \c false_type otherwise.
*
* \see is_trivially_relocatable_v
* \see is_trivially_relocatable_to
* \see is_indirectly_trivially_relocatable_to
* \see proclaim_trivially_relocatable
* \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
*/
template <typename T>
using is_trivially_relocatable = detail::is_trivially_relocatable_impl<T>;
#if _CCCL_STD_VER >= 2014
/*! \brief <tt>constexpr bool</tt> that is \c true if \c T is
* <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
* aka can be bitwise copied with a facility like
* <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
* and \c false otherwise.
*
* \see is_trivially_relocatable
* \see is_trivially_relocatable_to
* \see is_indirectly_trivially_relocatable_to
* \see proclaim_trivially_relocatable
* \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
*/
template <typename T>
constexpr bool is_trivially_relocatable_v = is_trivially_relocatable<T>::value;
#endif
/*! \brief <a href="https://en.cppreference.com/w/cpp/named_req/BinaryTypeTrait"><i>BinaryTypeTrait</i></a>
* that returns \c true_type if \c From is
* <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
* to \c To, aka can be bitwise copied with a facility like
* <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
* and \c false_type otherwise.
*
* \see is_trivially_relocatable_to_v
* \see is_trivially_relocatable
* \see is_indirectly_trivially_relocatable_to
* \see proclaim_trivially_relocatable
* \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
*/
template <typename From, typename To>
using is_trivially_relocatable_to =
integral_constant<bool, ::cuda::std::is_same<From, To>::value && is_trivially_relocatable<To>::value>;
#if _CCCL_STD_VER >= 2014
/*! \brief <tt>constexpr bool</tt> that is \c true if \c From is
* <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
* to \c To, aka can be bitwise copied with a facility like
* <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
* and \c false otherwise.
*
* \see is_trivially_relocatable_to
* \see is_trivially_relocatable
* \see is_indirectly_trivially_relocatable_to
* \see proclaim_trivially_relocatable
* \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
*/
template <typename From, typename To>
constexpr bool is_trivially_relocatable_to_v = is_trivially_relocatable_to<From, To>::value;
#endif
/*! \brief <a href="https://en.cppreference.com/w/cpp/named_req/BinaryTypeTrait"><i>BinaryTypeTrait</i></a>
* that returns \c true_type if the element type of \c FromIterator is
* <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
* to the element type of \c ToIterator, aka can be bitwise copied with a
* facility like
* <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
* and \c false_type otherwise.
*
* \see is_indirectly_trivially_relocatable_to_v
* \see is_trivially_relocatable
* \see is_trivially_relocatable_to
* \see proclaim_trivially_relocatable
* \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
*/
template <typename FromIterator, typename ToIterator>
using is_indirectly_trivially_relocatable_to =
integral_constant<bool,
is_contiguous_iterator<FromIterator>::value && is_contiguous_iterator<ToIterator>::value
&& is_trivially_relocatable_to<typename thrust::iterator_traits<FromIterator>::value_type,
typename thrust::iterator_traits<ToIterator>::value_type>::value>;
#if _CCCL_STD_VER >= 2014
/*! \brief <tt>constexpr bool</tt> that is \c true if the element type of
* \c FromIterator is
* <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
* to the element type of \c ToIterator, aka can be bitwise copied with a
* facility like
* <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
* and \c false otherwise.
*
* \see is_indirectly_trivially_relocatable_to
* \see is_trivially_relocatable
* \see is_trivially_relocatable_to
* \see proclaim_trivially_relocatable
* \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
*/
template <typename FromIterator, typename ToIterator>
constexpr bool is_indirectly_trivially_relocate_to_v =
is_indirectly_trivially_relocatable_to<FromIterator, ToIterator>::value;
#endif
/*! \brief <a href="http://eel.is/c++draft/namespace.std#def:customization_point"><i>customization point</i></a>
* that can be specialized customized to indicate that a type \c T is
* <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
* aka it can be bitwise copied with a facility like
* <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>.
*
* \see is_indirectly_trivially_relocatable_to
* \see is_trivially_relocatable
* \see is_trivially_relocatable_to
* \see THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE
*/
template <typename T>
struct proclaim_trivially_relocatable : false_type
{};
/*! \brief Declares that the type \c T is
* <a href="https://wg21.link/P1144"><i>TriviallyRelocatable</i></a>,
* aka it can be bitwise copied with a facility like
* <a href="https://en.cppreference.com/w/cpp/string/byte/memcpy"><tt>std::memcpy</tt></a>,
* by specializing \c proclaim_trivially_relocatable.
*
* \see is_indirectly_trivially_relocatable_to
* \see is_trivially_relocatable
* \see is_trivially_relocatable_to
* \see proclaim_trivially_relocatable
*/
#define THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(T) \
THRUST_NAMESPACE_BEGIN \
template <> \
struct proclaim_trivially_relocatable<T> : THRUST_NS_QUALIFIER::true_type \
{}; \
THRUST_NAMESPACE_END \
/**/
///////////////////////////////////////////////////////////////////////////////
/*! \cond
*/
namespace detail
{
// https://wg21.link/P1144R0#wording-inheritance
template <typename T>
struct is_trivially_relocatable_impl
: integral_constant<bool, ::cuda::std::is_trivially_copyable<T>::value || proclaim_trivially_relocatable<T>::value>
{};
template <typename T, std::size_t N>
struct is_trivially_relocatable_impl<T[N]> : is_trivially_relocatable_impl<T>
{};
} // namespace detail
THRUST_NAMESPACE_END
#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(char1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(char2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(char3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(char4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uchar1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uchar2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uchar3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uchar4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(short1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(short2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(short3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(short4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ushort1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ushort2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ushort3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ushort4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(int1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(int2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(int3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(int4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uint1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uint2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uint3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(uint4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(long1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(long2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(long3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(long4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulong1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulong2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulong3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulong4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(longlong1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(longlong2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(longlong3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(longlong4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulonglong1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulonglong2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulonglong3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(ulonglong4)
struct __half;
struct __half2;
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(__half)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(__half2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(float1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(float2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(float3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(float4)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double1)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double2)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double3)
THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double4)
#endif
/*! \endcond
*/
///////////////////////////////////////////////////////////////////////////////
/*! \} // type traits
*/
/*! \} // utility
*/