paredeyes commited on
Commit
7e2a408
·
verified ·
1 Parent(s): c920e97

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. miniCUDA124/bin/npps64_12.dll +3 -0
  3. miniCUDA124/include/thrust/detail/allocator/allocator_traits.h +450 -0
  4. miniCUDA124/include/thrust/detail/allocator/allocator_traits.inl +473 -0
  5. miniCUDA124/include/thrust/detail/allocator/copy_construct_range.h +54 -0
  6. miniCUDA124/include/thrust/detail/allocator/copy_construct_range.inl +318 -0
  7. miniCUDA124/include/thrust/detail/allocator/default_construct_range.h +44 -0
  8. miniCUDA124/include/thrust/detail/allocator/default_construct_range.inl +120 -0
  9. miniCUDA124/include/thrust/detail/allocator/destroy_range.h +41 -0
  10. miniCUDA124/include/thrust/detail/allocator/destroy_range.inl +175 -0
  11. miniCUDA124/include/thrust/detail/complex/c99math.h +205 -0
  12. miniCUDA124/include/thrust/detail/complex/catrig.h +794 -0
  13. miniCUDA124/include/thrust/detail/complex/catrigf.h +509 -0
  14. miniCUDA124/include/thrust/detail/complex/ccosh.h +223 -0
  15. miniCUDA124/include/thrust/detail/complex/ccoshf.h +151 -0
  16. miniCUDA124/include/thrust/detail/complex/cexp.h +193 -0
  17. miniCUDA124/include/thrust/detail/complex/cexpf.h +171 -0
  18. miniCUDA124/include/thrust/detail/complex/clog.h +222 -0
  19. miniCUDA124/include/thrust/detail/transform_scan.inl +125 -0
  20. miniCUDA124/include/thrust/detail/trivial_sequence.h +104 -0
  21. miniCUDA124/include/thrust/detail/tuple_algorithms.h +118 -0
  22. miniCUDA124/include/thrust/detail/tuple_meta_transform.h +66 -0
  23. miniCUDA124/include/thrust/detail/tuple_transform.h +92 -0
  24. miniCUDA124/include/thrust/detail/type_deduction.h +98 -0
  25. miniCUDA124/include/thrust/detail/type_traits.h +701 -0
  26. miniCUDA124/include/thrust/detail/uninitialized_copy.inl +103 -0
  27. miniCUDA124/include/thrust/detail/uninitialized_fill.inl +98 -0
  28. miniCUDA124/include/thrust/detail/unique.inl +401 -0
  29. miniCUDA124/include/thrust/iterator/constant_iterator.h +258 -0
  30. miniCUDA124/include/thrust/iterator/counting_iterator.h +254 -0
  31. miniCUDA124/include/thrust/iterator/discard_iterator.h +182 -0
  32. miniCUDA124/include/thrust/iterator/iterator_adaptor.h +249 -0
  33. miniCUDA124/include/thrust/iterator/iterator_categories.h +231 -0
  34. miniCUDA124/include/thrust/iterator/iterator_facade.h +550 -0
  35. miniCUDA124/include/thrust/iterator/iterator_traits.h +73 -0
  36. miniCUDA124/include/thrust/iterator/permutation_iterator.h +222 -0
  37. miniCUDA124/include/thrust/iterator/retag.h +77 -0
  38. miniCUDA124/include/thrust/iterator/reverse_iterator.h +245 -0
  39. miniCUDA124/include/thrust/iterator/transform_input_output_iterator.h +172 -0
  40. miniCUDA124/include/thrust/iterator/transform_iterator.h +362 -0
  41. miniCUDA124/include/thrust/iterator/transform_output_iterator.h +172 -0
  42. miniCUDA124/include/thrust/iterator/zip_iterator.h +266 -0
  43. miniCUDA124/include/thrust/mr/allocator.h +262 -0
  44. miniCUDA124/include/thrust/mr/device_memory_resource.h +46 -0
  45. miniCUDA124/include/thrust/mr/disjoint_pool.h +499 -0
  46. miniCUDA124/include/thrust/mr/disjoint_sync_pool.h +125 -0
  47. miniCUDA124/include/thrust/mr/disjoint_tls_pool.h +77 -0
  48. miniCUDA124/include/thrust/mr/fancy_pointer_resource.h +69 -0
  49. miniCUDA124/include/thrust/mr/host_memory_resource.h +40 -0
  50. miniCUDA124/include/thrust/mr/memory_resource.h +226 -0
.gitattributes CHANGED
@@ -92,3 +92,4 @@ miniCUDA124/bin/nppist64_12.dll filter=lfs diff=lfs merge=lfs -text
92
  miniCUDA124/bin/nppig64_12.dll filter=lfs diff=lfs merge=lfs -text
93
  miniCUDA124/bin/ptxas.exe filter=lfs diff=lfs merge=lfs -text
94
  miniCUDA124/bin/nvprof.exe filter=lfs diff=lfs merge=lfs -text
 
 
92
  miniCUDA124/bin/nppig64_12.dll filter=lfs diff=lfs merge=lfs -text
93
  miniCUDA124/bin/ptxas.exe filter=lfs diff=lfs merge=lfs -text
94
  miniCUDA124/bin/nvprof.exe filter=lfs diff=lfs merge=lfs -text
95
+ miniCUDA124/bin/npps64_12.dll filter=lfs diff=lfs merge=lfs -text
miniCUDA124/bin/npps64_12.dll ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:adca8a91eb74badd854caa136d4dc9d8a6da486ec251c9f6c698132722aa3a18
3
+ size 12743168
miniCUDA124/include/thrust/detail/allocator/allocator_traits.h ADDED
@@ -0,0 +1,450 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2018 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // allocator_traits::rebind_alloc and allocator::rebind_traits are from libc++,
18
+ // dual licensed under the MIT and the University of Illinois Open Source
19
+ // Licenses.
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+ #include <thrust/detail/type_traits/pointer_traits.h>
33
+ #include <thrust/detail/type_traits/has_nested_type.h>
34
+ #include <thrust/detail/type_traits/has_member_function.h>
35
+ #include <thrust/detail/type_traits.h>
36
+
37
+ #include <thrust/detail/memory_wrapper.h>
38
+
39
+ THRUST_NAMESPACE_BEGIN
40
+ namespace detail
41
+ {
42
+
43
+
44
+ // forward declaration for has_member_system
45
+ template<typename Alloc> struct allocator_system;
46
+
47
+
48
+ namespace allocator_traits_detail
49
+ {
50
+
51
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_value_type, value_type)
52
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_pointer, pointer)
53
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_const_pointer, const_pointer)
54
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_reference, reference)
55
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_const_reference, const_reference)
56
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_void_pointer, void_pointer)
57
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_const_void_pointer, const_void_pointer)
58
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_difference_type, difference_type)
59
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_size_type, size_type)
60
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_propagate_on_container_copy_assignment, propagate_on_container_copy_assignment)
61
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_propagate_on_container_move_assignment, propagate_on_container_move_assignment)
62
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_propagate_on_container_swap, propagate_on_container_swap)
63
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_system_type, system_type)
64
+ __THRUST_DEFINE_HAS_NESTED_TYPE(has_is_always_equal, is_always_equal)
65
+ __THRUST_DEFINE_HAS_MEMBER_FUNCTION(has_member_system_impl, system)
66
+
67
+ template<typename Alloc, typename U>
68
+ struct has_rebind
69
+ {
70
+ typedef char yes_type;
71
+ typedef int no_type;
72
+
73
+ template<typename S>
74
+ static yes_type test(typename S::template rebind<U>::other*);
75
+ template<typename S>
76
+ static no_type test(...);
77
+
78
+ static bool const value = sizeof(test<U>(0)) == sizeof(yes_type);
79
+
80
+ typedef thrust::detail::integral_constant<bool, value> type;
81
+ };
82
+
83
+ // The following fields of std::allocator have been deprecated (since C++17).
84
+ // There's no way to detect it other than explicit specialization.
85
+ #if THRUST_CPP_DIALECT >= 2017
86
+ #define THRUST_SPECIALIZE_DEPRECATED(trait_name) \
87
+ template <typename T> \
88
+ struct trait_name<std::allocator<T>> : false_type {};
89
+
90
+ THRUST_SPECIALIZE_DEPRECATED(has_is_always_equal)
91
+ THRUST_SPECIALIZE_DEPRECATED(has_pointer)
92
+ THRUST_SPECIALIZE_DEPRECATED(has_const_pointer)
93
+ THRUST_SPECIALIZE_DEPRECATED(has_reference)
94
+ THRUST_SPECIALIZE_DEPRECATED(has_const_reference)
95
+
96
+ #undef THRUST_SPECIALIZE_DEPRECATED
97
+
98
+ template<typename T, typename U>
99
+ struct has_rebind<std::allocator<T>, U> : false_type {};
100
+ #endif
101
+
102
+ template<typename T>
103
+ struct nested_pointer
104
+ {
105
+ typedef typename T::pointer type;
106
+ };
107
+
108
+ template<typename T>
109
+ struct nested_const_pointer
110
+ {
111
+ typedef typename T::const_pointer type;
112
+ };
113
+
114
+ template<typename T>
115
+ struct nested_reference
116
+ {
117
+ typedef typename T::reference type;
118
+ };
119
+
120
+ template<typename T>
121
+ struct nested_const_reference
122
+ {
123
+ typedef typename T::const_reference type;
124
+ };
125
+
126
+ template<typename T>
127
+ struct nested_void_pointer
128
+ {
129
+ typedef typename T::void_pointer type;
130
+ };
131
+
132
+ template<typename T>
133
+ struct nested_const_void_pointer
134
+ {
135
+ typedef typename T::const_void_pointer type;
136
+ };
137
+
138
+ template<typename T>
139
+ struct nested_difference_type
140
+ {
141
+ typedef typename T::difference_type type;
142
+ };
143
+
144
+ template<typename T>
145
+ struct nested_size_type
146
+ {
147
+ typedef typename T::size_type type;
148
+ };
149
+
150
+ template<typename T>
151
+ struct nested_propagate_on_container_copy_assignment
152
+ {
153
+ typedef typename T::propagate_on_container_copy_assignment type;
154
+ };
155
+
156
+ template<typename T>
157
+ struct nested_propagate_on_container_move_assignment
158
+ {
159
+ typedef typename T::propagate_on_container_move_assignment type;
160
+ };
161
+
162
+ template<typename T>
163
+ struct nested_propagate_on_container_swap
164
+ {
165
+ typedef typename T::propagate_on_container_swap type;
166
+ };
167
+
168
+ template<typename T>
169
+ struct nested_is_always_equal
170
+ {
171
+ typedef typename T::is_always_equal type;
172
+ };
173
+
174
+ template<typename T>
175
+ struct nested_system_type
176
+ {
177
+ typedef typename T::system_type type;
178
+ };
179
+
180
+ template<typename Alloc>
181
+ struct has_member_system
182
+ {
183
+ typedef typename allocator_system<Alloc>::type system_type;
184
+
185
+ typedef typename has_member_system_impl<Alloc, system_type&(void)>::type type;
186
+ static const bool value = type::value;
187
+ };
188
+
189
+ template<class Alloc, class U, bool = has_rebind<Alloc, U>::value>
190
+ struct rebind_alloc
191
+ {
192
+ typedef typename Alloc::template rebind<U>::other type;
193
+ };
194
+
195
+ #if THRUST_CPP_DIALECT >= 2011
196
+ template<template<typename, typename...> class Alloc,
197
+ typename T, typename... Args, typename U>
198
+ struct rebind_alloc<Alloc<T, Args...>, U, true>
199
+ {
200
+ typedef typename Alloc<T, Args...>::template rebind<U>::other type;
201
+ };
202
+
203
+ template<template<typename, typename...> class Alloc,
204
+ typename T, typename... Args, typename U>
205
+ struct rebind_alloc<Alloc<T, Args...>, U, false>
206
+ {
207
+ typedef Alloc<U, Args...> type;
208
+ };
209
+ #else // C++03
210
+ template <template <typename> class Alloc, typename T, typename U>
211
+ struct rebind_alloc<Alloc<T>, U, true>
212
+ {
213
+ typedef typename Alloc<T>::template rebind<U>::other type;
214
+ };
215
+
216
+ template <template <typename> class Alloc, typename T, typename U>
217
+ struct rebind_alloc<Alloc<T>, U, false>
218
+ {
219
+ typedef Alloc<U> type;
220
+ };
221
+
222
+ template<template<typename, typename> class Alloc,
223
+ typename T, typename A0, typename U>
224
+ struct rebind_alloc<Alloc<T, A0>, U, true>
225
+ {
226
+ typedef typename Alloc<T, A0>::template rebind<U>::other type;
227
+ };
228
+
229
+ template<template<typename, typename> class Alloc,
230
+ typename T, typename A0, typename U>
231
+ struct rebind_alloc<Alloc<T, A0>, U, false>
232
+ {
233
+ typedef Alloc<U, A0> type;
234
+ };
235
+
236
+ template<template<typename, typename, typename> class Alloc,
237
+ typename T, typename A0, typename A1, typename U>
238
+ struct rebind_alloc<Alloc<T, A0, A1>, U, true>
239
+ {
240
+ typedef typename Alloc<T, A0, A1>::template rebind<U>::other type;
241
+ };
242
+
243
+ template<template<typename, typename, typename> class Alloc,
244
+ typename T, typename A0, typename A1, typename U>
245
+ struct rebind_alloc<Alloc<T, A0, A1>, U, false>
246
+ {
247
+ typedef Alloc<U, A0, A1> type;
248
+ };
249
+
250
+ template<template<typename, typename, typename, typename> class Alloc,
251
+ typename T, typename A0, typename A1, typename A2, typename U>
252
+ struct rebind_alloc<Alloc<T, A0, A1, A2>, U, true>
253
+ {
254
+ typedef typename Alloc<T, A0, A1, A2>::template rebind<U>::other type;
255
+ };
256
+
257
+ template<template<typename, typename, typename, typename> class Alloc,
258
+ typename T, typename A0, typename A1, typename A2, typename U>
259
+ struct rebind_alloc<Alloc<T, A0, A1, A2>, U, false>
260
+ {
261
+ typedef Alloc<U, A0, A1, A2> type;
262
+ };
263
+ #endif
264
+
265
+ } // end allocator_traits_detail
266
+
267
+
268
+ template<typename Alloc>
269
+ struct allocator_traits
270
+ {
271
+ typedef Alloc allocator_type;
272
+
273
+ typedef typename allocator_type::value_type value_type;
274
+
275
+ typedef typename eval_if<
276
+ allocator_traits_detail::has_pointer<allocator_type>::value,
277
+ allocator_traits_detail::nested_pointer<allocator_type>,
278
+ identity_<value_type*>
279
+ >::type pointer;
280
+
281
+ private:
282
+ template<typename T>
283
+ struct rebind_pointer
284
+ {
285
+ typedef typename pointer_traits<pointer>::template rebind<T>::other type;
286
+ };
287
+
288
+ public:
289
+
290
+ typedef typename eval_if<
291
+ allocator_traits_detail::has_const_pointer<allocator_type>::value,
292
+ allocator_traits_detail::nested_const_pointer<allocator_type>,
293
+ rebind_pointer<const value_type>
294
+ >::type const_pointer;
295
+
296
+ typedef typename eval_if<
297
+ allocator_traits_detail::has_void_pointer<allocator_type>::value,
298
+ allocator_traits_detail::nested_void_pointer<allocator_type>,
299
+ rebind_pointer<void>
300
+ >::type void_pointer;
301
+
302
+ typedef typename eval_if<
303
+ allocator_traits_detail::has_const_void_pointer<allocator_type>::value,
304
+ allocator_traits_detail::nested_const_void_pointer<allocator_type>,
305
+ rebind_pointer<const void>
306
+ >::type const_void_pointer;
307
+
308
+ typedef typename eval_if<
309
+ allocator_traits_detail::has_difference_type<allocator_type>::value,
310
+ allocator_traits_detail::nested_difference_type<allocator_type>,
311
+ pointer_difference<pointer>
312
+ >::type difference_type;
313
+
314
+ typedef typename eval_if<
315
+ allocator_traits_detail::has_size_type<allocator_type>::value,
316
+ allocator_traits_detail::nested_size_type<allocator_type>,
317
+ make_unsigned<difference_type>
318
+ >::type size_type;
319
+
320
+ typedef typename eval_if<
321
+ allocator_traits_detail::has_propagate_on_container_copy_assignment<allocator_type>::value,
322
+ allocator_traits_detail::nested_propagate_on_container_copy_assignment<allocator_type>,
323
+ identity_<false_type>
324
+ >::type propagate_on_container_copy_assignment;
325
+
326
+ typedef typename eval_if<
327
+ allocator_traits_detail::has_propagate_on_container_move_assignment<allocator_type>::value,
328
+ allocator_traits_detail::nested_propagate_on_container_move_assignment<allocator_type>,
329
+ identity_<false_type>
330
+ >::type propagate_on_container_move_assignment;
331
+
332
+ typedef typename eval_if<
333
+ allocator_traits_detail::has_propagate_on_container_swap<allocator_type>::value,
334
+ allocator_traits_detail::nested_propagate_on_container_swap<allocator_type>,
335
+ identity_<false_type>
336
+ >::type propagate_on_container_swap;
337
+
338
+ typedef typename eval_if<
339
+ allocator_traits_detail::has_is_always_equal<allocator_type>::value,
340
+ allocator_traits_detail::nested_is_always_equal<allocator_type>,
341
+ is_empty<allocator_type>
342
+ >::type is_always_equal;
343
+
344
+ typedef typename eval_if<
345
+ allocator_traits_detail::has_system_type<allocator_type>::value,
346
+ allocator_traits_detail::nested_system_type<allocator_type>,
347
+ thrust::iterator_system<pointer>
348
+ >::type system_type;
349
+
350
+ // XXX rebind and rebind_traits are alias templates
351
+ // and so are omitted while c++11 is unavailable
352
+
353
+ #if THRUST_CPP_DIALECT >= 2011
354
+ template <typename U>
355
+ using rebind_alloc =
356
+ typename allocator_traits_detail::rebind_alloc<allocator_type, U>::type;
357
+
358
+ template <typename U>
359
+ using rebind_traits = allocator_traits<rebind_alloc<U>>;
360
+
361
+ // We define this nested type alias for compatibility with the C++03-style
362
+ // rebind_* mechanisms.
363
+ using other = allocator_traits;
364
+ #else
365
+ template <typename U>
366
+ struct rebind_alloc
367
+ {
368
+ typedef typename
369
+ allocator_traits_detail::rebind_alloc<allocator_type, U>::type other;
370
+ };
371
+ template <typename U>
372
+ struct rebind_traits
373
+ {
374
+ typedef allocator_traits<typename rebind_alloc<U>::other> other;
375
+ };
376
+ #endif
377
+
378
+ // Deprecated std::allocator typedefs that we need:
379
+ typedef typename thrust::detail::pointer_traits<pointer>::reference reference;
380
+ typedef typename thrust::detail::pointer_traits<const_pointer>::reference const_reference;
381
+
382
+ inline __host__ __device__
383
+ static pointer allocate(allocator_type &a, size_type n);
384
+
385
+ inline __host__ __device__
386
+ static pointer allocate(allocator_type &a, size_type n, const_void_pointer hint);
387
+
388
+ inline __host__ __device__
389
+ static void deallocate(allocator_type &a, pointer p, size_type n);
390
+
391
+ // XXX should probably change T* to pointer below and then relax later
392
+
393
+ template<typename T>
394
+ inline __host__ __device__ static void construct(allocator_type &a, T *p);
395
+
396
+ template<typename T, typename Arg1>
397
+ inline __host__ __device__ static void construct(allocator_type &a, T *p, const Arg1 &arg1);
398
+
399
+ #if THRUST_CPP_DIALECT >= 2011
400
+ template<typename T, typename... Args>
401
+ inline __host__ __device__ static void construct(allocator_type &a, T *p, Args&&... args);
402
+ #endif
403
+
404
+ template<typename T>
405
+ inline __host__ __device__ static void destroy(allocator_type &a, T *p);
406
+
407
+ inline __host__ __device__
408
+ static size_type max_size(const allocator_type &a);
409
+ }; // end allocator_traits
410
+
411
+
412
+ // we consider a type an allocator if T::value_type exists
413
+ // it doesn't make much sense (containers, which are not allocators, will fulfill this requirement),
414
+ // but allocator_traits is specified to work for any type with that nested typedef
415
+ template<typename T>
416
+ struct is_allocator
417
+ : allocator_traits_detail::has_value_type<T>
418
+ {};
419
+
420
+
421
+ // XXX consider moving this non-standard functionality inside allocator_traits
422
+ template<typename Alloc>
423
+ struct allocator_system
424
+ {
425
+ // the type of the allocator's system
426
+ typedef typename eval_if<
427
+ allocator_traits_detail::has_system_type<Alloc>::value,
428
+ allocator_traits_detail::nested_system_type<Alloc>,
429
+ thrust::iterator_system<
430
+ typename allocator_traits<Alloc>::pointer
431
+ >
432
+ >::type type;
433
+
434
+ // the type that get returns
435
+ typedef typename eval_if<
436
+ allocator_traits_detail::has_member_system<Alloc>::value, // if Alloc.system() exists
437
+ add_reference<type>, // then get() needs to return a reference
438
+ identity_<type> // else get() needs to return a value
439
+ >::type get_result_type;
440
+
441
+ __host__ __device__
442
+ inline static get_result_type get(Alloc &a);
443
+ };
444
+
445
+
446
+ } // end detail
447
+ THRUST_NAMESPACE_END
448
+
449
+ #include <thrust/detail/allocator/allocator_traits.inl>
450
+
miniCUDA124/include/thrust/detail/allocator/allocator_traits.inl ADDED
@@ -0,0 +1,473 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2018 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+ #include <thrust/detail/allocator/allocator_traits.h>
29
+ #include <thrust/detail/type_traits/is_call_possible.h>
30
+ #include <thrust/detail/integer_traits.h>
31
+
32
+ #if THRUST_CPP_DIALECT >= 2011
33
+ #include <thrust/detail/type_deduction.h>
34
+ #endif
35
+
36
+ #include <thrust/detail/memory_wrapper.h>
37
+ #include <new>
38
+
39
+ THRUST_NAMESPACE_BEGIN
40
+ namespace detail
41
+ {
42
+
43
+ #if THRUST_CPP_DIALECT >= 2011
44
+
45
+ // std::allocator's member functions are deprecated in C++17 and removed in
46
+ // C++20, so we can't just use the generic implementation for allocator_traits
47
+ // that calls the allocator's member functions.
48
+ // Instead, specialize allocator_traits for std::allocator and defer to
49
+ // std::allocator_traits<std::allocator> and let the STL do whatever it needs
50
+ // to for the current c++ version. Manually forward the calls to suppress
51
+ // host/device warnings.
52
+ template <typename T>
53
+ struct allocator_traits<std::allocator<T>>
54
+ : public std::allocator_traits<std::allocator<T>>
55
+ {
56
+ private:
57
+ using superclass = std::allocator_traits<std::allocator<T>>;
58
+
59
+ public:
60
+ using allocator_type = typename superclass::allocator_type;
61
+ using value_type = typename superclass::value_type;
62
+ using pointer = typename superclass::pointer;
63
+ using const_pointer = typename superclass::const_pointer;
64
+ using void_pointer = typename superclass::void_pointer;
65
+ using const_void_pointer = typename superclass::const_void_pointer;
66
+ using difference_type = typename superclass::difference_type;
67
+ using size_type = typename superclass::size_type;
68
+ using propagate_on_container_swap = typename superclass::propagate_on_container_swap;
69
+ using propagate_on_container_copy_assignment =
70
+ typename superclass::propagate_on_container_copy_assignment;
71
+ using propagate_on_container_move_assignment =
72
+ typename superclass::propagate_on_container_move_assignment;
73
+
74
+ // std::allocator_traits added this in C++17, but thrust::allocator_traits defines
75
+ // it unconditionally.
76
+ using is_always_equal = typename eval_if<
77
+ allocator_traits_detail::has_is_always_equal<allocator_type>::value,
78
+ allocator_traits_detail::nested_is_always_equal<allocator_type>,
79
+ is_empty<allocator_type>
80
+ >::type;
81
+
82
+ // std::allocator_traits doesn't provide these, but
83
+ // thrust::detail::allocator_traits does. These used to be part of the
84
+ // std::allocator API but were deprecated in C++17.
85
+ using reference = typename thrust::detail::pointer_traits<pointer>::reference;
86
+ using const_reference = typename thrust::detail::pointer_traits<const_pointer>::reference;
87
+
88
+ template <typename U>
89
+ using rebind_alloc = std::allocator<U>;
90
+ template <typename U>
91
+ using rebind_traits = allocator_traits<std::allocator<U>>;
92
+
93
+ __thrust_exec_check_disable__
94
+ __host__ __device__
95
+ static pointer allocate(allocator_type &a, size_type n)
96
+ {
97
+ return superclass::allocate(a, n);
98
+ }
99
+
100
+ __thrust_exec_check_disable__
101
+ __host__ __device__
102
+ static pointer allocate(allocator_type &a, size_type n, const_void_pointer hint)
103
+ {
104
+ return superclass::allocate(a, n, hint);
105
+ }
106
+
107
+ __thrust_exec_check_disable__
108
+ __host__ __device__
109
+ static void deallocate(allocator_type &a, pointer p, size_type n)
110
+ {
111
+ superclass::deallocate(a, p, n);
112
+ }
113
+
114
+ __thrust_exec_check_disable__
115
+ template <typename U, typename ...Args>
116
+ __host__ __device__
117
+ static void construct(allocator_type &a, U *p, Args&&... args)
118
+ {
119
+ superclass::construct(a, p, THRUST_FWD(args)...);
120
+ }
121
+
122
+ __thrust_exec_check_disable__
123
+ template <typename U>
124
+ __host__ __device__
125
+ static void destroy(allocator_type &a, U *p)
126
+ {
127
+ superclass::destroy(a, p);
128
+ }
129
+
130
+ __thrust_exec_check_disable__
131
+ __host__ __device__
132
+ static size_type max_size(const allocator_type &a)
133
+ {
134
+ return superclass::max_size(a);
135
+ }
136
+ };
137
+
138
+ #endif // C++11
139
+
140
+ namespace allocator_traits_detail
141
+ {
142
+
143
+ __THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_allocate_with_hint_impl, allocate)
144
+
145
+ template<typename Alloc>
146
+ class has_member_allocate_with_hint
147
+ {
148
+ typedef typename allocator_traits<Alloc>::pointer pointer;
149
+ typedef typename allocator_traits<Alloc>::size_type size_type;
150
+ typedef typename allocator_traits<Alloc>::const_void_pointer const_void_pointer;
151
+
152
+ public:
153
+ typedef typename has_member_allocate_with_hint_impl<Alloc, pointer(size_type,const_void_pointer)>::type type;
154
+ static const bool value = type::value;
155
+ };
156
+
157
+ template<typename Alloc>
158
+ __host__ __device__
159
+ typename enable_if<
160
+ has_member_allocate_with_hint<Alloc>::value,
161
+ typename allocator_traits<Alloc>::pointer
162
+ >::type
163
+ allocate(Alloc &a, typename allocator_traits<Alloc>::size_type n, typename allocator_traits<Alloc>::const_void_pointer hint)
164
+ {
165
+ return a.allocate(n,hint);
166
+ }
167
+
168
+ template<typename Alloc>
169
+ __host__ __device__
170
+ typename disable_if<
171
+ has_member_allocate_with_hint<Alloc>::value,
172
+ typename allocator_traits<Alloc>::pointer
173
+ >::type
174
+ allocate(Alloc &a, typename allocator_traits<Alloc>::size_type n, typename allocator_traits<Alloc>::const_void_pointer)
175
+ {
176
+ return a.allocate(n);
177
+ }
178
+
179
+
180
+ __THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_construct1_impl, construct)
181
+
182
+ template<typename Alloc, typename T>
183
+ struct has_member_construct1
184
+ : has_member_construct1_impl<Alloc, void(T*)>
185
+ {};
186
+
187
+ __thrust_exec_check_disable__
188
+ template<typename Alloc, typename T>
189
+ inline __host__ __device__
190
+ typename enable_if<
191
+ has_member_construct1<Alloc,T>::value
192
+ >::type
193
+ construct(Alloc &a, T *p)
194
+ {
195
+ a.construct(p);
196
+ }
197
+
198
+ __thrust_exec_check_disable__
199
+ template<typename Alloc, typename T>
200
+ inline __host__ __device__
201
+ typename disable_if<
202
+ has_member_construct1<Alloc,T>::value
203
+ >::type
204
+ construct(Alloc &, T *p)
205
+ {
206
+ ::new(static_cast<void*>(p)) T();
207
+ }
208
+
209
+
210
+ __THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_construct2_impl, construct)
211
+
212
+ template<typename Alloc, typename T, typename Arg1>
213
+ struct has_member_construct2
214
+ : has_member_construct2_impl<Alloc, void(T*,const Arg1 &)>
215
+ {};
216
+
217
+ __thrust_exec_check_disable__
218
+ template<typename Alloc, typename T, typename Arg1>
219
+ inline __host__ __device__
220
+ typename enable_if<
221
+ has_member_construct2<Alloc,T,Arg1>::value
222
+ >::type
223
+ construct(Alloc &a, T *p, const Arg1 &arg1)
224
+ {
225
+ a.construct(p,arg1);
226
+ }
227
+
228
+ __thrust_exec_check_disable__
229
+ template<typename Alloc, typename T, typename Arg1>
230
+ inline __host__ __device__
231
+ typename disable_if<
232
+ has_member_construct2<Alloc,T,Arg1>::value
233
+ >::type
234
+ construct(Alloc &, T *p, const Arg1 &arg1)
235
+ {
236
+ ::new(static_cast<void*>(p)) T(arg1);
237
+ }
238
+
239
+ #if THRUST_CPP_DIALECT >= 2011
240
+
241
+ __THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_constructN_impl, construct)
242
+
243
+ template<typename Alloc, typename T, typename... Args>
244
+ struct has_member_constructN
245
+ : has_member_constructN_impl<Alloc, void(T*, Args...)>
246
+ {};
247
+
248
+ __thrust_exec_check_disable__
249
+ template<typename Alloc, typename T, typename... Args>
250
+ inline __host__ __device__
251
+ typename enable_if<
252
+ has_member_constructN<Alloc, T, Args...>::value
253
+ >::type
254
+ construct(Alloc &a, T* p, Args&&... args)
255
+ {
256
+ a.construct(p, THRUST_FWD(args)...);
257
+ }
258
+
259
+ __thrust_exec_check_disable__
260
+ template<typename Alloc, typename T, typename... Args>
261
+ inline __host__ __device__
262
+ typename disable_if<
263
+ has_member_constructN<Alloc, T, Args...>::value
264
+ >::type
265
+ construct(Alloc &, T* p, Args&&... args)
266
+ {
267
+ ::new(static_cast<void*>(p)) T(THRUST_FWD(args)...);
268
+ }
269
+
270
+ #endif
271
+
272
+ __THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_destroy_impl, destroy)
273
+
274
+ template<typename Alloc, typename T>
275
+ struct has_member_destroy
276
+ : has_member_destroy_impl<Alloc, void(T*)>
277
+ {};
278
+
279
+ __thrust_exec_check_disable__
280
+ template<typename Alloc, typename T>
281
+ inline __host__ __device__
282
+ typename enable_if<
283
+ has_member_destroy<Alloc,T>::value
284
+ >::type
285
+ destroy(Alloc &a, T *p)
286
+ {
287
+ a.destroy(p);
288
+ }
289
+
290
+ __thrust_exec_check_disable__
291
+ template<typename Alloc, typename T>
292
+ inline __host__ __device__
293
+ typename disable_if<
294
+ has_member_destroy<Alloc,T>::value
295
+ >::type
296
+ destroy(Alloc &, T *p)
297
+ {
298
+ p->~T();
299
+ }
300
+
301
+
302
+ __THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_max_size_impl, max_size)
303
+
304
+ template<typename Alloc>
305
+ class has_member_max_size
306
+ {
307
+ typedef typename allocator_traits<Alloc>::size_type size_type;
308
+
309
+ public:
310
+ typedef typename has_member_max_size_impl<Alloc, size_type(void)>::type type;
311
+ static const bool value = type::value;
312
+ };
313
+
314
+ template<typename Alloc>
315
+ __host__ __device__
316
+ typename enable_if<
317
+ has_member_max_size<Alloc>::value,
318
+ typename allocator_traits<Alloc>::size_type
319
+ >::type
320
+ max_size(const Alloc &a)
321
+ {
322
+ return a.max_size();
323
+ }
324
+
325
+ template<typename Alloc>
326
+ __host__ __device__
327
+ typename disable_if<
328
+ has_member_max_size<Alloc>::value,
329
+ typename allocator_traits<Alloc>::size_type
330
+ >::type
331
+ max_size(const Alloc &)
332
+ {
333
+ typedef typename allocator_traits<Alloc>::size_type size_type;
334
+ return thrust::detail::integer_traits<size_type>::const_max;
335
+ }
336
+
337
+ template<typename Alloc>
338
+ __host__ __device__
339
+ typename enable_if<
340
+ has_member_system<Alloc>::value,
341
+ typename allocator_system<Alloc>::type &
342
+ >::type
343
+ system(Alloc &a)
344
+ {
345
+ // return the allocator's system
346
+ return a.system();
347
+ }
348
+
349
+ template<typename Alloc>
350
+ __host__ __device__
351
+ typename disable_if<
352
+ has_member_system<Alloc>::value,
353
+ typename allocator_system<Alloc>::type
354
+ >::type
355
+ system(Alloc &)
356
+ {
357
+ // return a copy of a value-initialized system
358
+ return typename allocator_system<Alloc>::type();
359
+ }
360
+
361
+
362
+ } // end allocator_traits_detail
363
+
364
+
365
+ template<typename Alloc>
366
+ __host__ __device__
367
+ typename allocator_traits<Alloc>::pointer
368
+ allocator_traits<Alloc>
369
+ ::allocate(Alloc &a, typename allocator_traits<Alloc>::size_type n)
370
+ {
371
+ struct workaround_warnings
372
+ {
373
+ __thrust_exec_check_disable__
374
+ static __host__ __device__
375
+ typename allocator_traits<Alloc>::pointer
376
+ allocate(Alloc &a, typename allocator_traits<Alloc>::size_type n)
377
+ {
378
+ return a.allocate(n);
379
+ }
380
+ };
381
+
382
+ return workaround_warnings::allocate(a, n);
383
+ }
384
+
385
+ template<typename Alloc>
386
+ __host__ __device__
387
+ typename allocator_traits<Alloc>::pointer
388
+ allocator_traits<Alloc>
389
+ ::allocate(Alloc &a, typename allocator_traits<Alloc>::size_type n, typename allocator_traits<Alloc>::const_void_pointer hint)
390
+ {
391
+ return allocator_traits_detail::allocate(a, n, hint);
392
+ }
393
+
394
+ template<typename Alloc>
395
+ __host__ __device__
396
+ void allocator_traits<Alloc>
397
+ ::deallocate(Alloc &a, typename allocator_traits<Alloc>::pointer p, typename allocator_traits<Alloc>::size_type n)
398
+ {
399
+ struct workaround_warnings
400
+ {
401
+ __thrust_exec_check_disable__
402
+ static __host__ __device__
403
+ void deallocate(Alloc &a, typename allocator_traits<Alloc>::pointer p, typename allocator_traits<Alloc>::size_type n)
404
+ {
405
+ return a.deallocate(p,n);
406
+ }
407
+ };
408
+
409
+ return workaround_warnings::deallocate(a,p,n);
410
+ }
411
+
412
+ template<typename Alloc>
413
+ template<typename T>
414
+ __host__ __device__
415
+ void allocator_traits<Alloc>
416
+ ::construct(allocator_type &a, T *p)
417
+ {
418
+ return allocator_traits_detail::construct(a,p);
419
+ }
420
+
421
+ template<typename Alloc>
422
+ template<typename T, typename Arg1>
423
+ __host__ __device__
424
+ void allocator_traits<Alloc>
425
+ ::construct(allocator_type &a, T *p, const Arg1 &arg1)
426
+ {
427
+ return allocator_traits_detail::construct(a,p,arg1);
428
+ }
429
+
430
+ #if THRUST_CPP_DIALECT >= 2011
431
+
432
+ template<typename Alloc>
433
+ template<typename T, typename... Args>
434
+ __host__ __device__
435
+ void allocator_traits<Alloc>
436
+ ::construct(allocator_type &a, T *p, Args&&... args)
437
+ {
438
+ return allocator_traits_detail::construct(a, p, THRUST_FWD(args)...);
439
+ }
440
+
441
+ #endif
442
+
443
+ template<typename Alloc>
444
+ template<typename T>
445
+ __host__ __device__
446
+ void allocator_traits<Alloc>
447
+ ::destroy(allocator_type &a, T *p)
448
+ {
449
+ return allocator_traits_detail::destroy(a,p);
450
+ }
451
+
452
+ template<typename Alloc>
453
+ __host__ __device__
454
+ typename allocator_traits<Alloc>::size_type
455
+ allocator_traits<Alloc>
456
+ ::max_size(const allocator_type &a)
457
+ {
458
+ return allocator_traits_detail::max_size(a);
459
+ }
460
+
461
+ template<typename Alloc>
462
+ __host__ __device__
463
+ typename allocator_system<Alloc>::get_result_type
464
+ allocator_system<Alloc>
465
+ ::get(Alloc &a)
466
+ {
467
+ return allocator_traits_detail::system(a);
468
+ }
469
+
470
+
471
+ } // end detail
472
+ THRUST_NAMESPACE_END
473
+
miniCUDA124/include/thrust/detail/allocator/copy_construct_range.h ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+ #include <thrust/detail/execution_policy.h>
29
+
30
+ THRUST_NAMESPACE_BEGIN
31
+ namespace detail
32
+ {
33
+
34
+ template<typename System, typename Allocator, typename InputIterator, typename Pointer>
35
+ __host__ __device__
36
+ Pointer copy_construct_range(thrust::execution_policy<System> &from_system,
37
+ Allocator &a,
38
+ InputIterator first,
39
+ InputIterator last,
40
+ Pointer result);
41
+
42
+ template<typename System, typename Allocator, typename InputIterator, typename Size, typename Pointer>
43
+ __host__ __device__
44
+ Pointer copy_construct_range_n(thrust::execution_policy<System> &from_system,
45
+ Allocator &a,
46
+ InputIterator first,
47
+ Size n,
48
+ Pointer result);
49
+
50
+ } // end detail
51
+ THRUST_NAMESPACE_END
52
+
53
+ #include <thrust/detail/allocator/copy_construct_range.inl>
54
+
miniCUDA124/include/thrust/detail/allocator/copy_construct_range.inl ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+ #include <thrust/detail/allocator/allocator_traits.h>
29
+ #include <thrust/detail/type_traits/pointer_traits.h>
30
+ #include <thrust/iterator/iterator_traits.h>
31
+ #include <thrust/detail/copy.h>
32
+ #include <thrust/tuple.h>
33
+ #include <thrust/advance.h>
34
+ #include <thrust/distance.h>
35
+ #include <thrust/iterator/zip_iterator.h>
36
+ #include <thrust/for_each.h>
37
+ #include <thrust/detail/memory_wrapper.h>
38
+
39
+ THRUST_NAMESPACE_BEGIN
40
+ namespace detail
41
+ {
42
+ namespace allocator_traits_detail
43
+ {
44
+
45
+
46
+ template<typename Allocator, typename InputType, typename OutputType>
47
+ struct copy_construct_with_allocator
48
+ {
49
+ Allocator &a;
50
+
51
+ __host__ __device__
52
+ copy_construct_with_allocator(Allocator &a)
53
+ : a(a)
54
+ {}
55
+
56
+ template<typename Tuple>
57
+ inline __host__ __device__
58
+ void operator()(Tuple t)
59
+ {
60
+ const InputType &in = thrust::get<0>(t);
61
+ OutputType &out = thrust::get<1>(t);
62
+
63
+ allocator_traits<Allocator>::construct(a, &out, in);
64
+ }
65
+ };
66
+
67
+
68
+ // we need to use allocator_traits<Allocator>::construct() to
69
+ // copy construct a T if either:
70
+ // 1. Allocator has a 2-argument construct() member or
71
+ // 2. T has a non-trivial copy constructor
72
+ template<typename Allocator, typename T>
73
+ struct needs_copy_construct_via_allocator
74
+ : integral_constant<
75
+ bool,
76
+ (has_member_construct2<Allocator,T,T>::value || !has_trivial_copy_constructor<T>::value)
77
+ >
78
+ {};
79
+
80
+
81
+ // we know that std::allocator::construct's only effect is to call T's
82
+ // copy constructor, so we needn't consider or use its construct() member for copy construction
83
+ template<typename U, typename T>
84
+ struct needs_copy_construct_via_allocator<std::allocator<U>, T>
85
+ : integral_constant<
86
+ bool,
87
+ !has_trivial_copy_constructor<T>::value
88
+ >
89
+ {};
90
+
91
+
92
+ // XXX it's regrettable that this implementation is copied almost
93
+ // exactly from system::detail::generic::uninitialized_copy
94
+ // perhaps generic::uninitialized_copy could call this routine
95
+ // with a default allocator
96
+ template<typename Allocator, typename FromSystem, typename ToSystem, typename InputIterator, typename Pointer>
97
+ __host__ __device__
98
+ typename enable_if_convertible<
99
+ FromSystem,
100
+ ToSystem,
101
+ Pointer
102
+ >::type
103
+ uninitialized_copy_with_allocator(Allocator &a,
104
+ const thrust::execution_policy<FromSystem> &,
105
+ const thrust::execution_policy<ToSystem> &to_system,
106
+ InputIterator first,
107
+ InputIterator last,
108
+ Pointer result)
109
+ {
110
+ // zip up the iterators
111
+ typedef thrust::tuple<InputIterator,Pointer> IteratorTuple;
112
+ typedef thrust::zip_iterator<IteratorTuple> ZipIterator;
113
+
114
+ ZipIterator begin = thrust::make_zip_iterator(thrust::make_tuple(first,result));
115
+ ZipIterator end = begin;
116
+
117
+ // get a zip_iterator pointing to the end
118
+ const typename thrust::iterator_difference<InputIterator>::type n = thrust::distance(first,last);
119
+ thrust::advance(end,n);
120
+
121
+ // create a functor
122
+ typedef typename iterator_traits<InputIterator>::value_type InputType;
123
+ typedef typename iterator_traits<Pointer>::value_type OutputType;
124
+
125
+ // do the for_each
126
+ // note we use to_system to dispatch the for_each
127
+ thrust::for_each(to_system, begin, end, copy_construct_with_allocator<Allocator,InputType,OutputType>(a));
128
+
129
+ // return the end of the output range
130
+ return thrust::get<1>(end.get_iterator_tuple());
131
+ }
132
+
133
+
134
+ // XXX it's regrettable that this implementation is copied almost
135
+ // exactly from system::detail::generic::uninitialized_copy_n
136
+ // perhaps generic::uninitialized_copy_n could call this routine
137
+ // with a default allocator
138
+ template<typename Allocator, typename FromSystem, typename ToSystem, typename InputIterator, typename Size, typename Pointer>
139
+ __host__ __device__
140
+ typename enable_if_convertible<
141
+ FromSystem,
142
+ ToSystem,
143
+ Pointer
144
+ >::type
145
+ uninitialized_copy_with_allocator_n(Allocator &a,
146
+ const thrust::execution_policy<FromSystem> &,
147
+ const thrust::execution_policy<ToSystem> &to_system,
148
+ InputIterator first,
149
+ Size n,
150
+ Pointer result)
151
+ {
152
+ // zip up the iterators
153
+ typedef thrust::tuple<InputIterator,Pointer> IteratorTuple;
154
+ typedef thrust::zip_iterator<IteratorTuple> ZipIterator;
155
+
156
+ ZipIterator begin = thrust::make_zip_iterator(thrust::make_tuple(first,result));
157
+
158
+ // create a functor
159
+ typedef typename iterator_traits<InputIterator>::value_type InputType;
160
+ typedef typename iterator_traits<Pointer>::value_type OutputType;
161
+
162
+ // do the for_each_n
163
+ // note we use to_system to dispatch the for_each_n
164
+ ZipIterator end = thrust::for_each_n(to_system, begin, n, copy_construct_with_allocator<Allocator,InputType,OutputType>(a));
165
+
166
+ // return the end of the output range
167
+ return thrust::get<1>(end.get_iterator_tuple());
168
+ }
169
+
170
+
171
+ template<typename Allocator, typename FromSystem, typename ToSystem, typename InputIterator, typename Pointer>
172
+ __host__ __device__
173
+ typename disable_if_convertible<
174
+ FromSystem,
175
+ ToSystem,
176
+ Pointer
177
+ >::type
178
+ uninitialized_copy_with_allocator(Allocator &,
179
+ const thrust::execution_policy<FromSystem> &from_system,
180
+ const thrust::execution_policy<ToSystem> &to_system,
181
+ InputIterator first,
182
+ InputIterator last,
183
+ Pointer result)
184
+ {
185
+ // the systems aren't trivially interoperable
186
+ // just call two_system_copy and hope for the best
187
+ return thrust::detail::two_system_copy(from_system, to_system, first, last, result);
188
+ } // end uninitialized_copy_with_allocator()
189
+
190
+
191
+ template<typename Allocator, typename FromSystem, typename ToSystem, typename InputIterator, typename Size, typename Pointer>
192
+ __host__ __device__
193
+ typename disable_if_convertible<
194
+ FromSystem,
195
+ ToSystem,
196
+ Pointer
197
+ >::type
198
+ uninitialized_copy_with_allocator_n(Allocator &,
199
+ const thrust::execution_policy<FromSystem> &from_system,
200
+ const thrust::execution_policy<ToSystem> &to_system,
201
+ InputIterator first,
202
+ Size n,
203
+ Pointer result)
204
+ {
205
+ // the systems aren't trivially interoperable
206
+ // just call two_system_copy_n and hope for the best
207
+ return thrust::detail::two_system_copy_n(from_system, to_system, first, n, result);
208
+ } // end uninitialized_copy_with_allocator_n()
209
+
210
+
211
+ template<typename FromSystem, typename Allocator, typename InputIterator, typename Pointer>
212
+ __host__ __device__
213
+ typename disable_if<
214
+ needs_copy_construct_via_allocator<
215
+ Allocator,
216
+ typename pointer_element<Pointer>::type
217
+ >::value,
218
+ Pointer
219
+ >::type
220
+ copy_construct_range(thrust::execution_policy<FromSystem> &from_system,
221
+ Allocator &a,
222
+ InputIterator first,
223
+ InputIterator last,
224
+ Pointer result)
225
+ {
226
+ // just call two_system_copy
227
+ return thrust::detail::two_system_copy(from_system, allocator_system<Allocator>::get(a), first, last, result);
228
+ }
229
+
230
+
231
+ template<typename FromSystem, typename Allocator, typename InputIterator, typename Size, typename Pointer>
232
+ __host__ __device__
233
+ typename disable_if<
234
+ needs_copy_construct_via_allocator<
235
+ Allocator,
236
+ typename pointer_element<Pointer>::type
237
+ >::value,
238
+ Pointer
239
+ >::type
240
+ copy_construct_range_n(thrust::execution_policy<FromSystem> &from_system,
241
+ Allocator &a,
242
+ InputIterator first,
243
+ Size n,
244
+ Pointer result)
245
+ {
246
+ // just call two_system_copy_n
247
+ return thrust::detail::two_system_copy_n(from_system, allocator_system<Allocator>::get(a), first, n, result);
248
+ }
249
+
250
+
251
+ template<typename FromSystem, typename Allocator, typename InputIterator, typename Pointer>
252
+ __host__ __device__
253
+ typename enable_if<
254
+ needs_copy_construct_via_allocator<
255
+ Allocator,
256
+ typename pointer_element<Pointer>::type
257
+ >::value,
258
+ Pointer
259
+ >::type
260
+ copy_construct_range(thrust::execution_policy<FromSystem> &from_system,
261
+ Allocator &a,
262
+ InputIterator first,
263
+ InputIterator last,
264
+ Pointer result)
265
+ {
266
+ return uninitialized_copy_with_allocator(a, from_system, allocator_system<Allocator>::get(a), first, last, result);
267
+ }
268
+
269
+
270
+ template<typename FromSystem, typename Allocator, typename InputIterator, typename Size, typename Pointer>
271
+ __host__ __device__
272
+ typename enable_if<
273
+ needs_copy_construct_via_allocator<
274
+ Allocator,
275
+ typename pointer_element<Pointer>::type
276
+ >::value,
277
+ Pointer
278
+ >::type
279
+ copy_construct_range_n(thrust::execution_policy<FromSystem> &from_system,
280
+ Allocator &a,
281
+ InputIterator first,
282
+ Size n,
283
+ Pointer result)
284
+ {
285
+ return uninitialized_copy_with_allocator_n(a, from_system, allocator_system<Allocator>::get(a), first, n, result);
286
+ }
287
+
288
+
289
+ } // end allocator_traits_detail
290
+
291
+
292
+ template<typename System, typename Allocator, typename InputIterator, typename Pointer>
293
+ __host__ __device__
294
+ Pointer copy_construct_range(thrust::execution_policy<System> &from_system,
295
+ Allocator &a,
296
+ InputIterator first,
297
+ InputIterator last,
298
+ Pointer result)
299
+ {
300
+ return allocator_traits_detail::copy_construct_range(from_system, a, first, last, result);
301
+ }
302
+
303
+
304
+ template<typename System, typename Allocator, typename InputIterator, typename Size, typename Pointer>
305
+ __host__ __device__
306
+ Pointer copy_construct_range_n(thrust::execution_policy<System> &from_system,
307
+ Allocator &a,
308
+ InputIterator first,
309
+ Size n,
310
+ Pointer result)
311
+ {
312
+ return allocator_traits_detail::copy_construct_range_n(from_system, a, first, n, result);
313
+ }
314
+
315
+
316
+ } // end detail
317
+ THRUST_NAMESPACE_END
318
+
miniCUDA124/include/thrust/detail/allocator/default_construct_range.h ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ THRUST_NAMESPACE_BEGIN
30
+ namespace detail
31
+ {
32
+
33
+
34
+ template<typename Allocator, typename Pointer, typename Size>
35
+ __host__ __device__
36
+ inline void default_construct_range(Allocator &a, Pointer p, Size n);
37
+
38
+
39
+ } // end detail
40
+ THRUST_NAMESPACE_END
41
+
42
+ #include <thrust/detail/allocator/default_construct_range.inl>
43
+
44
+
miniCUDA124/include/thrust/detail/allocator/default_construct_range.inl ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+ #include <thrust/detail/allocator/allocator_traits.h>
29
+ #include <thrust/detail/type_traits.h>
30
+ #include <thrust/detail/type_traits/pointer_traits.h>
31
+ #include <thrust/for_each.h>
32
+ #include <thrust/uninitialized_fill.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+ namespace detail
36
+ {
37
+ namespace allocator_traits_detail
38
+ {
39
+
40
+
41
+ template<typename Allocator>
42
+ struct construct1_via_allocator
43
+ {
44
+ Allocator &a;
45
+
46
+ __host__ __device__
47
+ construct1_via_allocator(Allocator &a)
48
+ : a(a)
49
+ {}
50
+
51
+ template<typename T>
52
+ inline __host__ __device__
53
+ void operator()(T &x)
54
+ {
55
+ allocator_traits<Allocator>::construct(a, &x);
56
+ }
57
+ };
58
+
59
+
60
+ // we need to construct T via the allocator if...
61
+ template<typename Allocator, typename T>
62
+ struct needs_default_construct_via_allocator
63
+ : thrust::detail::or_<
64
+ has_member_construct1<Allocator,T>, // if the Allocator does something interesting
65
+ thrust::detail::not_<has_trivial_constructor<T> > // or if T's default constructor does something interesting
66
+ >
67
+ {};
68
+
69
+
70
+ // we know that std::allocator::construct's only effect is to call T's
71
+ // default constructor, so we needn't use it for default construction
72
+ // unless T's constructor does something interesting
73
+ template<typename U, typename T>
74
+ struct needs_default_construct_via_allocator<std::allocator<U>, T>
75
+ : thrust::detail::not_<has_trivial_constructor<T> >
76
+ {};
77
+
78
+
79
+ template<typename Allocator, typename Pointer, typename Size>
80
+ __host__ __device__
81
+ typename enable_if<
82
+ needs_default_construct_via_allocator<
83
+ Allocator,
84
+ typename pointer_element<Pointer>::type
85
+ >::value
86
+ >::type
87
+ default_construct_range(Allocator &a, Pointer p, Size n)
88
+ {
89
+ thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, construct1_via_allocator<Allocator>(a));
90
+ }
91
+
92
+
93
+ template<typename Allocator, typename Pointer, typename Size>
94
+ __host__ __device__
95
+ typename disable_if<
96
+ needs_default_construct_via_allocator<
97
+ Allocator,
98
+ typename pointer_element<Pointer>::type
99
+ >::value
100
+ >::type
101
+ default_construct_range(Allocator &a, Pointer p, Size n)
102
+ {
103
+ thrust::uninitialized_fill_n(allocator_system<Allocator>::get(a), p, n, typename pointer_element<Pointer>::type());
104
+ }
105
+
106
+
107
+ } // end allocator_traits_detail
108
+
109
+
110
+ template<typename Allocator, typename Pointer, typename Size>
111
+ __host__ __device__
112
+ void default_construct_range(Allocator &a, Pointer p, Size n)
113
+ {
114
+ return allocator_traits_detail::default_construct_range(a,p,n);
115
+ }
116
+
117
+
118
+ } // end detail
119
+ THRUST_NAMESPACE_END
120
+
miniCUDA124/include/thrust/detail/allocator/destroy_range.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ THRUST_NAMESPACE_BEGIN
30
+ namespace detail
31
+ {
32
+
33
+ template<typename Allocator, typename Pointer, typename Size>
34
+ __host__ __device__
35
+ inline void destroy_range(Allocator &a, Pointer p, Size n);
36
+
37
+ } // end detail
38
+ THRUST_NAMESPACE_END
39
+
40
+ #include <thrust/detail/allocator/destroy_range.inl>
41
+
miniCUDA124/include/thrust/detail/allocator/destroy_range.inl ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/detail/allocator/destroy_range.h>
30
+ #include <thrust/detail/allocator/allocator_traits.h>
31
+ #include <thrust/detail/type_traits/pointer_traits.h>
32
+ #include <thrust/for_each.h>
33
+ #include <thrust/detail/memory_wrapper.h>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+ namespace detail
37
+ {
38
+ namespace allocator_traits_detail
39
+ {
40
+
41
+
42
+ // destroy_range has three cases:
43
+ // if Allocator has an effectful member function destroy:
44
+ // 1. destroy via the allocator
45
+ // else
46
+ // 2. if T has a non-trivial destructor, destroy the range without using the allocator
47
+ // 3. if T has a trivial destructor, do a no-op
48
+
49
+ template<typename Allocator, typename T>
50
+ struct has_effectful_member_destroy
51
+ : has_member_destroy<Allocator,T>
52
+ {};
53
+
54
+ // std::allocator::destroy's only effect is to invoke its argument's destructor
55
+ template<typename U, typename T>
56
+ struct has_effectful_member_destroy<std::allocator<U>, T>
57
+ : thrust::detail::false_type
58
+ {};
59
+
60
+ // case 1: Allocator has an effectful 1-argument member function "destroy"
61
+ template<typename Allocator, typename Pointer>
62
+ struct enable_if_destroy_range_case1
63
+ : thrust::detail::enable_if<
64
+ has_effectful_member_destroy<
65
+ Allocator,
66
+ typename pointer_element<Pointer>::type
67
+ >::value
68
+ >
69
+ {};
70
+
71
+ // case 2: Allocator has no member function "destroy", but T has a non-trivial destructor
72
+ template<typename Allocator, typename Pointer>
73
+ struct enable_if_destroy_range_case2
74
+ : thrust::detail::enable_if<
75
+ !has_effectful_member_destroy<
76
+ Allocator,
77
+ typename pointer_element<Pointer>::type
78
+ >::value &&
79
+ !has_trivial_destructor<
80
+ typename pointer_element<Pointer>::type
81
+ >::value
82
+ >
83
+ {};
84
+
85
+ // case 3: Allocator has no member function "destroy", and T has a trivial destructor
86
+ template<typename Allocator, typename Pointer>
87
+ struct enable_if_destroy_range_case3
88
+ : thrust::detail::enable_if<
89
+ !has_effectful_member_destroy<
90
+ Allocator,
91
+ typename pointer_element<Pointer>::type
92
+ >::value &&
93
+ has_trivial_destructor<
94
+ typename pointer_element<Pointer>::type
95
+ >::value
96
+ >
97
+ {};
98
+
99
+
100
+
101
+ template<typename Allocator>
102
+ struct destroy_via_allocator
103
+ {
104
+ Allocator &a;
105
+
106
+ __host__ __device__
107
+ destroy_via_allocator(Allocator &a)
108
+ : a(a)
109
+ {}
110
+
111
+ template<typename T>
112
+ inline __host__ __device__
113
+ void operator()(T &x)
114
+ {
115
+ allocator_traits<Allocator>::destroy(a, &x);
116
+ }
117
+ };
118
+
119
+
120
+ // destroy_range case 1: destroy via allocator
121
+ template<typename Allocator, typename Pointer, typename Size>
122
+ __host__ __device__
123
+ typename enable_if_destroy_range_case1<Allocator,Pointer>::type
124
+ destroy_range(Allocator &a, Pointer p, Size n)
125
+ {
126
+ thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, destroy_via_allocator<Allocator>(a));
127
+ }
128
+
129
+
130
+ // we must prepare for His coming
131
+ struct gozer
132
+ {
133
+ __thrust_exec_check_disable__
134
+ template<typename T>
135
+ inline __host__ __device__
136
+ void operator()(T &x)
137
+ {
138
+ x.~T();
139
+ }
140
+ };
141
+
142
+ // destroy_range case 2: destroy without the allocator
143
+ template<typename Allocator, typename Pointer, typename Size>
144
+ __host__ __device__
145
+ typename enable_if_destroy_range_case2<Allocator,Pointer>::type
146
+ destroy_range(Allocator &a, Pointer p, Size n)
147
+ {
148
+ thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, gozer());
149
+ }
150
+
151
+
152
+ // destroy_range case 3: no-op
153
+ template<typename Allocator, typename Pointer, typename Size>
154
+ __host__ __device__
155
+ typename enable_if_destroy_range_case3<Allocator,Pointer>::type
156
+ destroy_range(Allocator &, Pointer, Size)
157
+ {
158
+ // no op
159
+ }
160
+
161
+
162
+ } // end allocator_traits_detail
163
+
164
+
165
+ template<typename Allocator, typename Pointer, typename Size>
166
+ __host__ __device__
167
+ void destroy_range(Allocator &a, Pointer p, Size n)
168
+ {
169
+ return allocator_traits_detail::destroy_range(a,p,n);
170
+ }
171
+
172
+
173
+ } // end detail
174
+ THRUST_NAMESPACE_END
175
+
miniCUDA124/include/thrust/detail/complex/c99math.h ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <math.h>
30
+ #include <cmath>
31
+ #include <thrust/detail/complex/math_private.h>
32
+
33
+ THRUST_NAMESPACE_BEGIN
34
+ namespace detail
35
+ {
36
+ namespace complex
37
+ {
38
+
39
+ // Define basic arithmetic functions so we can use them without explicit scope
40
+ // keeping the code as close as possible to FreeBSDs for ease of maintenance.
41
+ // It also provides an easy way to support compilers with missing C99 functions.
42
+ // When possible, just use the names in the global scope.
43
+ // Some platforms define these as macros, others as free functions.
44
+ // Avoid using the std:: form of these as nvcc may treat std::foo() as __host__ functions.
45
+
46
+ using ::log;
47
+ using ::acos;
48
+ using ::asin;
49
+ using ::sqrt;
50
+ using ::sinh;
51
+ using ::tan;
52
+ using ::cos;
53
+ using ::sin;
54
+ using ::exp;
55
+ using ::cosh;
56
+ using ::atan;
57
+
58
+ template <typename T>
59
+ inline __host__ __device__ T infinity();
60
+
61
+ template <>
62
+ inline __host__ __device__ float infinity<float>()
63
+ {
64
+ float res;
65
+ set_float_word(res, 0x7f800000);
66
+ return res;
67
+ }
68
+
69
+
70
+ template <>
71
+ inline __host__ __device__ double infinity<double>()
72
+ {
73
+ double res;
74
+ insert_words(res, 0x7ff00000,0);
75
+ return res;
76
+ }
77
+
78
+ #if defined _MSC_VER
79
+ __host__ __device__ inline int isinf(float x){
80
+ return std::abs(x) == infinity<float>();
81
+ }
82
+
83
+ __host__ __device__ inline int isinf(double x){
84
+ return std::abs(x) == infinity<double>();
85
+ }
86
+
87
+ __host__ __device__ inline int isnan(float x){
88
+ return x != x;
89
+ }
90
+
91
+ __host__ __device__ inline int isnan(double x){
92
+ return x != x;
93
+ }
94
+
95
+ __host__ __device__ inline int signbit(float x){
96
+ return ((*((uint32_t *)&x)) & 0x80000000) != 0 ? 1 : 0;
97
+ }
98
+
99
+ __host__ __device__ inline int signbit(double x){
100
+ return ((*((uint64_t *)&x)) & 0x8000000000000000) != 0ull ? 1 : 0;
101
+ }
102
+
103
+ __host__ __device__ inline int isfinite(float x){
104
+ return !isnan(x) && !isinf(x);
105
+ }
106
+
107
+ __host__ __device__ inline int isfinite(double x){
108
+ return !isnan(x) && !isinf(x);
109
+ }
110
+
111
+ #else
112
+
113
+ # if defined(__CUDACC__) && !(defined(__CUDA__) && defined(__clang__)) && !defined(_NVHPC_CUDA)
114
+ // NVCC implements at least some signature of these as functions not macros.
115
+ using ::isinf;
116
+ using ::isnan;
117
+ using ::signbit;
118
+ using ::isfinite;
119
+ # else
120
+ // Some compilers do not provide these in the global scope, because they are
121
+ // supposed to be macros. The versions in `std` are supposed to be functions.
122
+ // Since we're not compiling with nvcc, it's safe to use the functions in std::
123
+ using std::isinf;
124
+ using std::isnan;
125
+ using std::signbit;
126
+ using std::isfinite;
127
+ # endif // __CUDACC__
128
+ #endif // _MSC_VER
129
+
130
+ using ::atanh;
131
+
132
+ #if defined _MSC_VER
133
+
134
+ __host__ __device__ inline double copysign(double x, double y){
135
+ uint32_t hx,hy;
136
+ get_high_word(hx,x);
137
+ get_high_word(hy,y);
138
+ set_high_word(x,(hx&0x7fffffff)|(hy&0x80000000));
139
+ return x;
140
+ }
141
+
142
+ __host__ __device__ inline float copysignf(float x, float y){
143
+ uint32_t ix,iy;
144
+ get_float_word(ix,x);
145
+ get_float_word(iy,y);
146
+ set_float_word(x,(ix&0x7fffffff)|(iy&0x80000000));
147
+ return x;
148
+ }
149
+
150
+
151
+
152
+ #if !defined(__CUDACC__) && !defined(_NVHPC_CUDA)
153
+
154
+ // Simple approximation to log1p as Visual Studio is lacking one
155
+ inline double log1p(double x){
156
+ double u = 1.0+x;
157
+ if(u == 1.0){
158
+ return x;
159
+ }else{
160
+ if(u > 2.0){
161
+ // Use normal log for large arguments
162
+ return log(u);
163
+ }else{
164
+ return log(u)*(x/(u-1.0));
165
+ }
166
+ }
167
+ }
168
+
169
+ inline float log1pf(float x){
170
+ float u = 1.0f+x;
171
+ if(u == 1.0f){
172
+ return x;
173
+ }else{
174
+ if(u > 2.0f){
175
+ // Use normal log for large arguments
176
+ return logf(u);
177
+ }else{
178
+ return logf(u)*(x/(u-1.0f));
179
+ }
180
+ }
181
+ }
182
+
183
+ #if _MSV_VER <= 1500
184
+ #include <complex>
185
+
186
+ inline float hypotf(float x, float y){
187
+ return abs(std::complex<float>(x,y));
188
+ }
189
+
190
+ inline double hypot(double x, double y){
191
+ return _hypot(x,y);
192
+ }
193
+
194
+ #endif // _MSC_VER <= 1500
195
+
196
+ #endif // __CUDACC__
197
+
198
+ #endif // _MSC_VER
199
+
200
+ } // namespace complex
201
+
202
+ } // namespace detail
203
+
204
+ THRUST_NAMESPACE_END
205
+
miniCUDA124/include/thrust/detail/complex/catrig.h ADDED
@@ -0,0 +1,794 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /*
45
+ * Adapted from FreeBSD by Filipe Maia <filipe.c.maia@gmail.com>:
46
+ * freebsd/lib/msun/src/catrig.c
47
+ */
48
+
49
+ #pragma once
50
+
51
+ #include <thrust/detail/config.h>
52
+
53
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
54
+ # pragma GCC system_header
55
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
56
+ # pragma clang system_header
57
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
58
+ # pragma system_header
59
+ #endif // no system header
60
+
61
+ #include <thrust/complex.h>
62
+ #include <thrust/detail/complex/math_private.h>
63
+ #include <cfloat>
64
+ #include <cmath>
65
+
66
+ THRUST_NAMESPACE_BEGIN
67
+ namespace detail{
68
+ namespace complex{
69
+
70
+ using thrust::complex;
71
+
72
+ __host__ __device__
73
+ inline void raise_inexact(){
74
+ const volatile float tiny = 7.888609052210118054117286e-31; /* 0x1p-100; */
75
+ // needs the volatile to prevent compiler from ignoring it
76
+ volatile float junk = 1 + tiny;
77
+ (void)junk;
78
+ }
79
+
80
+ __host__ __device__ inline complex<double> clog_for_large_values(complex<double> z);
81
+
82
+ /*
83
+ * Testing indicates that all these functions are accurate up to 4 ULP.
84
+ * The functions casin(h) and cacos(h) are about 2.5 times slower than asinh.
85
+ * The functions catan(h) are a little under 2 times slower than atanh.
86
+ *
87
+ * The code for casinh, casin, cacos, and cacosh comes first. The code is
88
+ * rather complicated, and the four functions are highly interdependent.
89
+ *
90
+ * The code for catanh and catan comes at the end. It is much simpler than
91
+ * the other functions, and the code for these can be disconnected from the
92
+ * rest of the code.
93
+ */
94
+
95
+ /*
96
+ * ================================
97
+ * | casinh, casin, cacos, cacosh |
98
+ * ================================
99
+ */
100
+
101
+ /*
102
+ * The algorithm is very close to that in "Implementing the complex arcsine
103
+ * and arccosine functions using exception handling" by T. E. Hull, Thomas F.
104
+ * Fairgrieve, and Ping Tak Peter Tang, published in ACM Transactions on
105
+ * Mathematical Software, Volume 23 Issue 3, 1997, Pages 299-335,
106
+ * http://dl.acm.org/citation.cfm?id=275324.
107
+ *
108
+ * Throughout we use the convention z = x + I*y.
109
+ *
110
+ * casinh(z) = sign(x)*log(A+sqrt(A*A-1)) + I*asin(B)
111
+ * where
112
+ * A = (|z+I| + |z-I|) / 2
113
+ * B = (|z+I| - |z-I|) / 2 = y/A
114
+ *
115
+ * These formulas become numerically unstable:
116
+ * (a) for Re(casinh(z)) when z is close to the line segment [-I, I] (that
117
+ * is, Re(casinh(z)) is close to 0);
118
+ * (b) for Im(casinh(z)) when z is close to either of the intervals
119
+ * [I, I*infinity) or (-I*infinity, -I] (that is, |Im(casinh(z))| is
120
+ * close to PI/2).
121
+ *
122
+ * These numerical problems are overcome by defining
123
+ * f(a, b) = (hypot(a, b) - b) / 2 = a*a / (hypot(a, b) + b) / 2
124
+ * Then if A < A_crossover, we use
125
+ * log(A + sqrt(A*A-1)) = log1p((A-1) + sqrt((A-1)*(A+1)))
126
+ * A-1 = f(x, 1+y) + f(x, 1-y)
127
+ * and if B > B_crossover, we use
128
+ * asin(B) = atan2(y, sqrt(A*A - y*y)) = atan2(y, sqrt((A+y)*(A-y)))
129
+ * A-y = f(x, y+1) + f(x, y-1)
130
+ * where without loss of generality we have assumed that x and y are
131
+ * non-negative.
132
+ *
133
+ * Much of the difficulty comes because the intermediate computations may
134
+ * produce overflows or underflows. This is dealt with in the paper by Hull
135
+ * et al by using exception handling. We do this by detecting when
136
+ * computations risk underflow or overflow. The hardest part is handling the
137
+ * underflows when computing f(a, b).
138
+ *
139
+ * Note that the function f(a, b) does not appear explicitly in the paper by
140
+ * Hull et al, but the idea may be found on pages 308 and 309. Introducing the
141
+ * function f(a, b) allows us to concentrate many of the clever tricks in this
142
+ * paper into one function.
143
+ */
144
+
145
+ /*
146
+ * Function f(a, b, hypot_a_b) = (hypot(a, b) - b) / 2.
147
+ * Pass hypot(a, b) as the third argument.
148
+ */
149
+ __host__ __device__
150
+ inline double
151
+ f(double a, double b, double hypot_a_b)
152
+ {
153
+ if (b < 0)
154
+ return ((hypot_a_b - b) / 2);
155
+ if (b == 0)
156
+ return (a / 2);
157
+ return (a * a / (hypot_a_b + b) / 2);
158
+ }
159
+
160
+ /*
161
+ * All the hard work is contained in this function.
162
+ * x and y are assumed positive or zero, and less than RECIP_EPSILON.
163
+ * Upon return:
164
+ * rx = Re(casinh(z)) = -Im(cacos(y + I*x)).
165
+ * B_is_usable is set to 1 if the value of B is usable.
166
+ * If B_is_usable is set to 0, sqrt_A2my2 = sqrt(A*A - y*y), and new_y = y.
167
+ * If returning sqrt_A2my2 has potential to result in an underflow, it is
168
+ * rescaled, and new_y is similarly rescaled.
169
+ */
170
+ __host__ __device__
171
+ inline void
172
+ do_hard_work(double x, double y, double *rx, int *B_is_usable, double *B,
173
+ double *sqrt_A2my2, double *new_y)
174
+ {
175
+ double R, S, A; /* A, B, R, and S are as in Hull et al. */
176
+ double Am1, Amy; /* A-1, A-y. */
177
+ const double A_crossover = 10; /* Hull et al suggest 1.5, but 10 works better */
178
+ const double FOUR_SQRT_MIN = 5.966672584960165394632772e-154; /* =0x1p-509; >= 4 * sqrt(DBL_MIN) */
179
+ const double B_crossover = 0.6417; /* suggested by Hull et al */
180
+
181
+ R = hypot(x, y + 1); /* |z+I| */
182
+ S = hypot(x, y - 1); /* |z-I| */
183
+
184
+ /* A = (|z+I| + |z-I|) / 2 */
185
+ A = (R + S) / 2;
186
+ /*
187
+ * Mathematically A >= 1. There is a small chance that this will not
188
+ * be so because of rounding errors. So we will make certain it is
189
+ * so.
190
+ */
191
+ if (A < 1)
192
+ A = 1;
193
+
194
+ if (A < A_crossover) {
195
+ /*
196
+ * Am1 = fp + fm, where fp = f(x, 1+y), and fm = f(x, 1-y).
197
+ * rx = log1p(Am1 + sqrt(Am1*(A+1)))
198
+ */
199
+ if (y == 1 && x < DBL_EPSILON * DBL_EPSILON / 128) {
200
+ /*
201
+ * fp is of order x^2, and fm = x/2.
202
+ * A = 1 (inexactly).
203
+ */
204
+ *rx = sqrt(x);
205
+ } else if (x >= DBL_EPSILON * fabs(y - 1)) {
206
+ /*
207
+ * Underflow will not occur because
208
+ * x >= DBL_EPSILON^2/128 >= FOUR_SQRT_MIN
209
+ */
210
+ Am1 = f(x, 1 + y, R) + f(x, 1 - y, S);
211
+ *rx = log1p(Am1 + sqrt(Am1 * (A + 1)));
212
+ } else if (y < 1) {
213
+ /*
214
+ * fp = x*x/(1+y)/4, fm = x*x/(1-y)/4, and
215
+ * A = 1 (inexactly).
216
+ */
217
+ *rx = x / sqrt((1 - y) * (1 + y));
218
+ } else { /* if (y > 1) */
219
+ /*
220
+ * A-1 = y-1 (inexactly).
221
+ */
222
+ *rx = log1p((y - 1) + sqrt((y - 1) * (y + 1)));
223
+ }
224
+ } else {
225
+ *rx = log(A + sqrt(A * A - 1));
226
+ }
227
+
228
+ *new_y = y;
229
+
230
+ if (y < FOUR_SQRT_MIN) {
231
+ /*
232
+ * Avoid a possible underflow caused by y/A. For casinh this
233
+ * would be legitimate, but will be picked up by invoking atan2
234
+ * later on. For cacos this would not be legitimate.
235
+ */
236
+ *B_is_usable = 0;
237
+ *sqrt_A2my2 = A * (2 / DBL_EPSILON);
238
+ *new_y = y * (2 / DBL_EPSILON);
239
+ return;
240
+ }
241
+
242
+ /* B = (|z+I| - |z-I|) / 2 = y/A */
243
+ *B = y / A;
244
+ *B_is_usable = 1;
245
+
246
+ if (*B > B_crossover) {
247
+ *B_is_usable = 0;
248
+ /*
249
+ * Amy = fp + fm, where fp = f(x, y+1), and fm = f(x, y-1).
250
+ * sqrt_A2my2 = sqrt(Amy*(A+y))
251
+ */
252
+ if (y == 1 && x < DBL_EPSILON / 128) {
253
+ /*
254
+ * fp is of order x^2, and fm = x/2.
255
+ * A = 1 (inexactly).
256
+ */
257
+ *sqrt_A2my2 = sqrt(x) * sqrt((A + y) / 2);
258
+ } else if (x >= DBL_EPSILON * fabs(y - 1)) {
259
+ /*
260
+ * Underflow will not occur because
261
+ * x >= DBL_EPSILON/128 >= FOUR_SQRT_MIN
262
+ * and
263
+ * x >= DBL_EPSILON^2 >= FOUR_SQRT_MIN
264
+ */
265
+ Amy = f(x, y + 1, R) + f(x, y - 1, S);
266
+ *sqrt_A2my2 = sqrt(Amy * (A + y));
267
+ } else if (y > 1) {
268
+ /*
269
+ * fp = x*x/(y+1)/4, fm = x*x/(y-1)/4, and
270
+ * A = y (inexactly).
271
+ *
272
+ * y < RECIP_EPSILON. So the following
273
+ * scaling should avoid any underflow problems.
274
+ */
275
+ *sqrt_A2my2 = x * (4 / DBL_EPSILON / DBL_EPSILON) * y /
276
+ sqrt((y + 1) * (y - 1));
277
+ *new_y = y * (4 / DBL_EPSILON / DBL_EPSILON);
278
+ } else { /* if (y < 1) */
279
+ /*
280
+ * fm = 1-y >= DBL_EPSILON, fp is of order x^2, and
281
+ * A = 1 (inexactly).
282
+ */
283
+ *sqrt_A2my2 = sqrt((1 - y) * (1 + y));
284
+ }
285
+ }
286
+ }
287
+
288
+ /*
289
+ * casinh(z) = z + O(z^3) as z -> 0
290
+ *
291
+ * casinh(z) = sign(x)*clog(sign(x)*z) + O(1/z^2) as z -> infinity
292
+ * The above formula works for the imaginary part as well, because
293
+ * Im(casinh(z)) = sign(x)*atan2(sign(x)*y, fabs(x)) + O(y/z^3)
294
+ * as z -> infinity, uniformly in y
295
+ */
296
+ __host__ __device__ inline
297
+ complex<double> casinh(complex<double> z)
298
+ {
299
+ double x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y;
300
+ int B_is_usable;
301
+ complex<double> w;
302
+ const double RECIP_EPSILON = 1.0 / DBL_EPSILON;
303
+ const double m_ln2 = 6.9314718055994531e-1; /* 0x162e42fefa39ef.0p-53 */
304
+ x = z.real();
305
+ y = z.imag();
306
+ ax = fabs(x);
307
+ ay = fabs(y);
308
+
309
+ if (isnan(x) || isnan(y)) {
310
+ /* casinh(+-Inf + I*NaN) = +-Inf + I*NaN */
311
+ if (isinf(x))
312
+ return (complex<double>(x, y + y));
313
+ /* casinh(NaN + I*+-Inf) = opt(+-)Inf + I*NaN */
314
+ if (isinf(y))
315
+ return (complex<double>(y, x + x));
316
+ /* casinh(NaN + I*0) = NaN + I*0 */
317
+ if (y == 0)
318
+ return (complex<double>(x + x, y));
319
+ /*
320
+ * All other cases involving NaN return NaN + I*NaN.
321
+ * C99 leaves it optional whether to raise invalid if one of
322
+ * the arguments is not NaN, so we opt not to raise it.
323
+ */
324
+ return (complex<double>(x + 0.0 + (y + 0.0), x + 0.0 + (y + 0.0)));
325
+ }
326
+
327
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
328
+ /* clog...() will raise inexact unless x or y is infinite. */
329
+ if (signbit(x) == 0)
330
+ w = clog_for_large_values(z) + m_ln2;
331
+ else
332
+ w = clog_for_large_values(-z) + m_ln2;
333
+ return (complex<double>(copysign(w.real(), x), copysign(w.imag(), y)));
334
+ }
335
+
336
+ /* Avoid spuriously raising inexact for z = 0. */
337
+ if (x == 0 && y == 0)
338
+ return (z);
339
+
340
+ /* All remaining cases are inexact. */
341
+ raise_inexact();
342
+
343
+ const double SQRT_6_EPSILON = 3.6500241499888571e-8; /* 0x13988e1409212e.0p-77 */
344
+ if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
345
+ return (z);
346
+
347
+ do_hard_work(ax, ay, &rx, &B_is_usable, &B, &sqrt_A2my2, &new_y);
348
+ if (B_is_usable)
349
+ ry = asin(B);
350
+ else
351
+ ry = atan2(new_y, sqrt_A2my2);
352
+ return (complex<double>(copysign(rx, x), copysign(ry, y)));
353
+ }
354
+
355
+ /*
356
+ * casin(z) = reverse(casinh(reverse(z)))
357
+ * where reverse(x + I*y) = y + I*x = I*conj(z).
358
+ */
359
+ __host__ __device__ inline
360
+ complex<double> casin(complex<double> z)
361
+ {
362
+ complex<double> w = casinh(complex<double>(z.imag(), z.real()));
363
+
364
+ return (complex<double>(w.imag(), w.real()));
365
+ }
366
+
367
+ /*
368
+ * cacos(z) = PI/2 - casin(z)
369
+ * but do the computation carefully so cacos(z) is accurate when z is
370
+ * close to 1.
371
+ *
372
+ * cacos(z) = PI/2 - z + O(z^3) as z -> 0
373
+ *
374
+ * cacos(z) = -sign(y)*I*clog(z) + O(1/z^2) as z -> infinity
375
+ * The above formula works for the real part as well, because
376
+ * Re(cacos(z)) = atan2(fabs(y), x) + O(y/z^3)
377
+ * as z -> infinity, uniformly in y
378
+ */
379
+ __host__ __device__ inline
380
+ complex<double> cacos(complex<double> z)
381
+ {
382
+ double x, y, ax, ay, rx, ry, B, sqrt_A2mx2, new_x;
383
+ int sx, sy;
384
+ int B_is_usable;
385
+ complex<double> w;
386
+ const double pio2_hi = 1.5707963267948966e0; /* 0x1921fb54442d18.0p-52 */
387
+ const volatile double pio2_lo = 6.1232339957367659e-17; /* 0x11a62633145c07.0p-106 */
388
+ const double m_ln2 = 6.9314718055994531e-1; /* 0x162e42fefa39ef.0p-53 */
389
+
390
+ x = z.real();
391
+ y = z.imag();
392
+ sx = signbit(x);
393
+ sy = signbit(y);
394
+ ax = fabs(x);
395
+ ay = fabs(y);
396
+
397
+ if (isnan(x) || isnan(y)) {
398
+ /* cacos(+-Inf + I*NaN) = NaN + I*opt(-)Inf */
399
+ if (isinf(x))
400
+ return (complex<double>(y + y, -infinity<double>()));
401
+ /* cacos(NaN + I*+-Inf) = NaN + I*-+Inf */
402
+ if (isinf(y))
403
+ return (complex<double>(x + x, -y));
404
+ /* cacos(0 + I*NaN) = PI/2 + I*NaN with inexact */
405
+ if (x == 0)
406
+ return (complex<double>(pio2_hi + pio2_lo, y + y));
407
+ /*
408
+ * All other cases involving NaN return NaN + I*NaN.
409
+ * C99 leaves it optional whether to raise invalid if one of
410
+ * the arguments is not NaN, so we opt not to raise it.
411
+ */
412
+ return (complex<double>(x + 0.0 + (y + 0), x + 0.0 + (y + 0)));
413
+ }
414
+
415
+ const double RECIP_EPSILON = 1.0 / DBL_EPSILON;
416
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
417
+ /* clog...() will raise inexact unless x or y is infinite. */
418
+ w = clog_for_large_values(z);
419
+ rx = fabs(w.imag());
420
+ ry = w.real() + m_ln2;
421
+ if (sy == 0)
422
+ ry = -ry;
423
+ return (complex<double>(rx, ry));
424
+ }
425
+
426
+ /* Avoid spuriously raising inexact for z = 1. */
427
+ if (x == 1.0 && y == 0.0)
428
+ return (complex<double>(0, -y));
429
+
430
+ /* All remaining cases are inexact. */
431
+ raise_inexact();
432
+
433
+ const double SQRT_6_EPSILON = 3.6500241499888571e-8; /* 0x13988e1409212e.0p-77 */
434
+ if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
435
+ return (complex<double>(pio2_hi - (x - pio2_lo), -y));
436
+
437
+ do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x);
438
+ if (B_is_usable) {
439
+ if (sx == 0)
440
+ rx = acos(B);
441
+ else
442
+ rx = acos(-B);
443
+ } else {
444
+ if (sx == 0)
445
+ rx = atan2(sqrt_A2mx2, new_x);
446
+ else
447
+ rx = atan2(sqrt_A2mx2, -new_x);
448
+ }
449
+ if (sy == 0)
450
+ ry = -ry;
451
+ return (complex<double>(rx, ry));
452
+ }
453
+
454
+ /*
455
+ * cacosh(z) = I*cacos(z) or -I*cacos(z)
456
+ * where the sign is chosen so Re(cacosh(z)) >= 0.
457
+ */
458
+ __host__ __device__ inline
459
+ complex<double> cacosh(complex<double> z)
460
+ {
461
+ complex<double> w;
462
+ double rx, ry;
463
+
464
+ w = cacos(z);
465
+ rx = w.real();
466
+ ry = w.imag();
467
+ /* cacosh(NaN + I*NaN) = NaN + I*NaN */
468
+ if (isnan(rx) && isnan(ry))
469
+ return (complex<double>(ry, rx));
470
+ /* cacosh(NaN + I*+-Inf) = +Inf + I*NaN */
471
+ /* cacosh(+-Inf + I*NaN) = +Inf + I*NaN */
472
+ if (isnan(rx))
473
+ return (complex<double>(fabs(ry), rx));
474
+ /* cacosh(0 + I*NaN) = NaN + I*NaN */
475
+ if (isnan(ry))
476
+ return (complex<double>(ry, ry));
477
+ return (complex<double>(fabs(ry), copysign(rx, z.imag())));
478
+ }
479
+
480
+ /*
481
+ * Optimized version of clog() for |z| finite and larger than ~RECIP_EPSILON.
482
+ */
483
+ __host__ __device__ inline
484
+ complex<double> clog_for_large_values(complex<double> z)
485
+ {
486
+ double x, y;
487
+ double ax, ay, t;
488
+ const double m_e = 2.7182818284590452e0; /* 0x15bf0a8b145769.0p-51 */
489
+
490
+ x = z.real();
491
+ y = z.imag();
492
+ ax = fabs(x);
493
+ ay = fabs(y);
494
+ if (ax < ay) {
495
+ t = ax;
496
+ ax = ay;
497
+ ay = t;
498
+ }
499
+
500
+ /*
501
+ * Avoid overflow in hypot() when x and y are both very large.
502
+ * Divide x and y by E, and then add 1 to the logarithm. This depends
503
+ * on E being larger than sqrt(2).
504
+ * Dividing by E causes an insignificant loss of accuracy; however
505
+ * this method is still poor since it is uneccessarily slow.
506
+ */
507
+ if (ax > DBL_MAX / 2)
508
+ return (complex<double>(log(hypot(x / m_e, y / m_e)) + 1, atan2(y, x)));
509
+
510
+ /*
511
+ * Avoid overflow when x or y is large. Avoid underflow when x or
512
+ * y is small.
513
+ */
514
+ const double QUARTER_SQRT_MAX = 5.966672584960165394632772e-154; /* = 0x1p509; <= sqrt(DBL_MAX) / 4 */
515
+ const double SQRT_MIN = 1.491668146240041348658193e-154; /* = 0x1p-511; >= sqrt(DBL_MIN) */
516
+ if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN)
517
+ return (complex<double>(log(hypot(x, y)), atan2(y, x)));
518
+
519
+ return (complex<double>(log(ax * ax + ay * ay) / 2, atan2(y, x)));
520
+ }
521
+
522
+ /*
523
+ * =================
524
+ * | catanh, catan |
525
+ * =================
526
+ */
527
+
528
+ /*
529
+ * sum_squares(x,y) = x*x + y*y (or just x*x if y*y would underflow).
530
+ * Assumes x*x and y*y will not overflow.
531
+ * Assumes x and y are finite.
532
+ * Assumes y is non-negative.
533
+ * Assumes fabs(x) >= DBL_EPSILON.
534
+ */
535
+ __host__ __device__
536
+ inline double sum_squares(double x, double y)
537
+ {
538
+ const double SQRT_MIN = 1.491668146240041348658193e-154; /* = 0x1p-511; >= sqrt(DBL_MIN) */
539
+ /* Avoid underflow when y is small. */
540
+ if (y < SQRT_MIN)
541
+ return (x * x);
542
+
543
+ return (x * x + y * y);
544
+ }
545
+
546
+ /*
547
+ * real_part_reciprocal(x, y) = Re(1/(x+I*y)) = x/(x*x + y*y).
548
+ * Assumes x and y are not NaN, and one of x and y is larger than
549
+ * RECIP_EPSILON. We avoid unwarranted underflow. It is important to not use
550
+ * the code creal(1/z), because the imaginary part may produce an unwanted
551
+ * underflow.
552
+ * This is only called in a context where inexact is always raised before
553
+ * the call, so no effort is made to avoid or force inexact.
554
+ */
555
+ __host__ __device__
556
+ inline double real_part_reciprocal(double x, double y)
557
+ {
558
+ double scale;
559
+ uint32_t hx, hy;
560
+ int32_t ix, iy;
561
+
562
+ /*
563
+ * This code is inspired by the C99 document n1124.pdf, Section G.5.1,
564
+ * example 2.
565
+ */
566
+ get_high_word(hx, x);
567
+ ix = hx & 0x7ff00000;
568
+ get_high_word(hy, y);
569
+ iy = hy & 0x7ff00000;
570
+ //#define BIAS (DBL_MAX_EXP - 1)
571
+ const int BIAS = DBL_MAX_EXP - 1;
572
+ /* XXX more guard digits are useful iff there is extra precision. */
573
+ //#define CUTOFF (DBL_MANT_DIG / 2 + 1) /* just half or 1 guard digit */
574
+ const int CUTOFF = (DBL_MANT_DIG / 2 + 1);
575
+ if (ix - iy >= CUTOFF << 20 || isinf(x))
576
+ return (1 / x); /* +-Inf -> +-0 is special */
577
+ if (iy - ix >= CUTOFF << 20)
578
+ return (x / y / y); /* should avoid double div, but hard */
579
+ if (ix <= (BIAS + DBL_MAX_EXP / 2 - CUTOFF) << 20)
580
+ return (x / (x * x + y * y));
581
+ scale = 1;
582
+ set_high_word(scale, 0x7ff00000 - ix); /* 2**(1-ilogb(x)) */
583
+ x *= scale;
584
+ y *= scale;
585
+ return (x / (x * x + y * y) * scale);
586
+ }
587
+
588
+
589
+ /*
590
+ * catanh(z) = log((1+z)/(1-z)) / 2
591
+ * = log1p(4*x / |z-1|^2) / 4
592
+ * + I * atan2(2*y, (1-x)*(1+x)-y*y) / 2
593
+ *
594
+ * catanh(z) = z + O(z^3) as z -> 0
595
+ *
596
+ * catanh(z) = 1/z + sign(y)*I*PI/2 + O(1/z^3) as z -> infinity
597
+ * The above formula works for the real part as well, because
598
+ * Re(catanh(z)) = x/|z|^2 + O(x/z^4)
599
+ * as z -> infinity, uniformly in x
600
+ */
601
+ #if THRUST_CPP_DIALECT >= 2011 || THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
602
+ __host__ __device__ inline
603
+ complex<double> catanh(complex<double> z)
604
+ {
605
+ double x, y, ax, ay, rx, ry;
606
+ const volatile double pio2_lo = 6.1232339957367659e-17; /* 0x11a62633145c07.0p-106 */
607
+ const double pio2_hi = 1.5707963267948966e0;/* 0x1921fb54442d18.0p-52 */
608
+
609
+
610
+ x = z.real();
611
+ y = z.imag();
612
+ ax = fabs(x);
613
+ ay = fabs(y);
614
+
615
+ /* This helps handle many cases. */
616
+ if (y == 0 && ax <= 1)
617
+ return (complex<double>(atanh(x), y));
618
+
619
+ /* To ensure the same accuracy as atan(), and to filter out z = 0. */
620
+ if (x == 0)
621
+ return (complex<double>(x, atan(y)));
622
+
623
+ if (isnan(x) || isnan(y)) {
624
+ /* catanh(+-Inf + I*NaN) = +-0 + I*NaN */
625
+ if (isinf(x))
626
+ return (complex<double>(copysign(0.0, x), y + y));
627
+ /* catanh(NaN + I*+-Inf) = sign(NaN)0 + I*+-PI/2 */
628
+ if (isinf(y))
629
+ return (complex<double>(copysign(0.0, x),
630
+ copysign(pio2_hi + pio2_lo, y)));
631
+ /*
632
+ * All other cases involving NaN return NaN + I*NaN.
633
+ * C99 leaves it optional whether to raise invalid if one of
634
+ * the arguments is not NaN, so we opt not to raise it.
635
+ */
636
+ return (complex<double>(x + 0.0 + (y + 0), x + 0.0 + (y + 0)));
637
+ }
638
+
639
+ const double RECIP_EPSILON = 1.0 / DBL_EPSILON;
640
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
641
+ return (complex<double>(real_part_reciprocal(x, y),
642
+ copysign(pio2_hi + pio2_lo, y)));
643
+
644
+ const double SQRT_3_EPSILON = 2.5809568279517849e-8; /* 0x1bb67ae8584caa.0p-78 */
645
+ if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) {
646
+ /*
647
+ * z = 0 was filtered out above. All other cases must raise
648
+ * inexact, but this is the only only that needs to do it
649
+ * explicitly.
650
+ */
651
+ raise_inexact();
652
+ return (z);
653
+ }
654
+
655
+ const double m_ln2 = 6.9314718055994531e-1; /* 0x162e42fefa39ef.0p-53 */
656
+ if (ax == 1 && ay < DBL_EPSILON)
657
+ rx = (m_ln2 - log(ay)) / 2;
658
+ else
659
+ rx = log1p(4 * ax / sum_squares(ax - 1, ay)) / 4;
660
+
661
+ if (ax == 1)
662
+ ry = atan2(2.0, -ay) / 2;
663
+ else if (ay < DBL_EPSILON)
664
+ ry = atan2(2 * ay, (1 - ax) * (1 + ax)) / 2;
665
+ else
666
+ ry = atan2(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2;
667
+
668
+ return (complex<double>(copysign(rx, x), copysign(ry, y)));
669
+ }
670
+
671
+ /*
672
+ * catan(z) = reverse(catanh(reverse(z)))
673
+ * where reverse(x + I*y) = y + I*x = I*conj(z).
674
+ */
675
+ __host__ __device__ inline
676
+ complex<double>catan(complex<double> z)
677
+ {
678
+ complex<double> w = catanh(complex<double>(z.imag(), z.real()));
679
+ return (complex<double>(w.imag(), w.real()));
680
+ }
681
+
682
+ #endif
683
+
684
+ } // namespace complex
685
+
686
+ } // namespace detail
687
+
688
+
689
+ template <typename ValueType>
690
+ __host__ __device__
691
+ inline complex<ValueType> acos(const complex<ValueType>& z){
692
+ const complex<ValueType> ret = thrust::asin(z);
693
+ const ValueType pi = ValueType(3.14159265358979323846);
694
+ return complex<ValueType>(pi/2 - ret.real(),-ret.imag());
695
+ }
696
+
697
+
698
+ template <typename ValueType>
699
+ __host__ __device__
700
+ inline complex<ValueType> asin(const complex<ValueType>& z){
701
+ const complex<ValueType> i(0,1);
702
+ return -i*asinh(i*z);
703
+ }
704
+
705
+ template <typename ValueType>
706
+ __host__ __device__
707
+ inline complex<ValueType> atan(const complex<ValueType>& z){
708
+ const complex<ValueType> i(0,1);
709
+ return -i*thrust::atanh(i*z);
710
+ }
711
+
712
+
713
+ template <typename ValueType>
714
+ __host__ __device__
715
+ inline complex<ValueType> acosh(const complex<ValueType>& z){
716
+ thrust::complex<ValueType> ret((z.real() - z.imag()) * (z.real() + z.imag()) - ValueType(1.0),
717
+ ValueType(2.0) * z.real() * z.imag());
718
+ ret = thrust::sqrt(ret);
719
+ if (z.real() < ValueType(0.0)){
720
+ ret = -ret;
721
+ }
722
+ ret += z;
723
+ ret = thrust::log(ret);
724
+ if (ret.real() < ValueType(0.0)){
725
+ ret = -ret;
726
+ }
727
+ return ret;
728
+ }
729
+
730
+ template <typename ValueType>
731
+ __host__ __device__
732
+ inline complex<ValueType> asinh(const complex<ValueType>& z){
733
+ return thrust::log(thrust::sqrt(z*z+ValueType(1))+z);
734
+ }
735
+
736
+ template <typename ValueType>
737
+ __host__ __device__
738
+ inline complex<ValueType> atanh(const complex<ValueType>& z){
739
+ ValueType imag2 = z.imag() * z.imag();
740
+ ValueType n = ValueType(1.0) + z.real();
741
+ n = imag2 + n * n;
742
+
743
+ ValueType d = ValueType(1.0) - z.real();
744
+ d = imag2 + d * d;
745
+ complex<ValueType> ret(ValueType(0.25) * (std::log(n) - std::log(d)),0);
746
+
747
+ d = ValueType(1.0) - z.real() * z.real() - imag2;
748
+
749
+ ret.imag(ValueType(0.5) * std::atan2(ValueType(2.0) * z.imag(), d));
750
+ return ret;
751
+ }
752
+
753
+ template <>
754
+ __host__ __device__
755
+ inline complex<double> acos(const complex<double>& z){
756
+ return detail::complex::cacos(z);
757
+ }
758
+
759
+ template <>
760
+ __host__ __device__
761
+ inline complex<double> asin(const complex<double>& z){
762
+ return detail::complex::casin(z);
763
+ }
764
+
765
+ #if THRUST_CPP_DIALECT >= 2011 || THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
766
+ template <>
767
+ __host__ __device__
768
+ inline complex<double> atan(const complex<double>& z){
769
+ return detail::complex::catan(z);
770
+ }
771
+ #endif
772
+
773
+ template <>
774
+ __host__ __device__
775
+ inline complex<double> acosh(const complex<double>& z){
776
+ return detail::complex::cacosh(z);
777
+ }
778
+
779
+
780
+ template <>
781
+ __host__ __device__
782
+ inline complex<double> asinh(const complex<double>& z){
783
+ return detail::complex::casinh(z);
784
+ }
785
+
786
+ #if THRUST_CPP_DIALECT >= 2011 || THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
787
+ template <>
788
+ __host__ __device__
789
+ inline complex<double> atanh(const complex<double>& z){
790
+ return detail::complex::catanh(z);
791
+ }
792
+ #endif
793
+
794
+ THRUST_NAMESPACE_END
miniCUDA124/include/thrust/detail/complex/catrigf.h ADDED
@@ -0,0 +1,509 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /*
45
+ * Adapted from FreeBSD by Filipe Maia <filipe.c.maia@gmail.com>:
46
+ * freebsd/lib/msun/src/catrig.c
47
+ */
48
+
49
+ #pragma once
50
+
51
+ #include <thrust/detail/config.h>
52
+
53
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
54
+ # pragma GCC system_header
55
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
56
+ # pragma clang system_header
57
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
58
+ # pragma system_header
59
+ #endif // no system header
60
+
61
+ #include <thrust/complex.h>
62
+ #include <thrust/detail/complex/math_private.h>
63
+ #include <cfloat>
64
+ #include <cmath>
65
+
66
+ THRUST_NAMESPACE_BEGIN
67
+ namespace detail{
68
+ namespace complex{
69
+
70
+ using thrust::complex;
71
+
72
+ __host__ __device__ inline
73
+ complex<float> clog_for_large_values(complex<float> z);
74
+
75
+ /*
76
+ * The algorithm is very close to that in "Implementing the complex arcsine
77
+ * and arccosine functions using exception handling" by T. E. Hull, Thomas F.
78
+ * Fairgrieve, and Ping Tak Peter Tang, published in ACM Transactions on
79
+ * Mathematical Software, Volume 23 Issue 3, 1997, Pages 299-335,
80
+ * http://dl.acm.org/citation.cfm?id=275324.
81
+ *
82
+ * See catrig.c for complete comments.
83
+ *
84
+ * XXX comments were removed automatically, and even short ones on the right
85
+ * of statements were removed (all of them), contrary to normal style. Only
86
+ * a few comments on the right of declarations remain.
87
+ */
88
+
89
+ __host__ __device__
90
+ inline float
91
+ f(float a, float b, float hypot_a_b)
92
+ {
93
+ if (b < 0.0f)
94
+ return ((hypot_a_b - b) / 2.0f);
95
+ if (b == 0.0f)
96
+ return (a / 2.0f);
97
+ return (a * a / (hypot_a_b + b) / 2.0f);
98
+ }
99
+
100
+ /*
101
+ * All the hard work is contained in this function.
102
+ * x and y are assumed positive or zero, and less than RECIP_EPSILON.
103
+ * Upon return:
104
+ * rx = Re(casinh(z)) = -Im(cacos(y + I*x)).
105
+ * B_is_usable is set to 1 if the value of B is usable.
106
+ * If B_is_usable is set to 0, sqrt_A2my2 = sqrt(A*A - y*y), and new_y = y.
107
+ * If returning sqrt_A2my2 has potential to result in an underflow, it is
108
+ * rescaled, and new_y is similarly rescaled.
109
+ */
110
+ __host__ __device__
111
+ inline void
112
+ do_hard_work(float x, float y, float *rx, int *B_is_usable, float *B,
113
+ float *sqrt_A2my2, float *new_y)
114
+ {
115
+ float R, S, A; /* A, B, R, and S are as in Hull et al. */
116
+ float Am1, Amy; /* A-1, A-y. */
117
+ const float A_crossover = 10; /* Hull et al suggest 1.5, but 10 works better */
118
+ const float FOUR_SQRT_MIN = 4.336808689942017736029811e-19f;; /* =0x1p-61; >= 4 * sqrt(FLT_MIN) */
119
+ const float B_crossover = 0.6417f; /* suggested by Hull et al */
120
+ R = hypotf(x, y + 1);
121
+ S = hypotf(x, y - 1);
122
+
123
+ A = (R + S) / 2;
124
+ if (A < 1)
125
+ A = 1;
126
+
127
+ if (A < A_crossover) {
128
+ if (y == 1 && x < FLT_EPSILON * FLT_EPSILON / 128) {
129
+ *rx = sqrtf(x);
130
+ } else if (x >= FLT_EPSILON * fabsf(y - 1)) {
131
+ Am1 = f(x, 1 + y, R) + f(x, 1 - y, S);
132
+ *rx = log1pf(Am1 + sqrtf(Am1 * (A + 1)));
133
+ } else if (y < 1) {
134
+ *rx = x / sqrtf((1 - y) * (1 + y));
135
+ } else {
136
+ *rx = log1pf((y - 1) + sqrtf((y - 1) * (y + 1)));
137
+ }
138
+ } else {
139
+ *rx = logf(A + sqrtf(A * A - 1));
140
+ }
141
+
142
+ *new_y = y;
143
+
144
+ if (y < FOUR_SQRT_MIN) {
145
+ *B_is_usable = 0;
146
+ *sqrt_A2my2 = A * (2 / FLT_EPSILON);
147
+ *new_y = y * (2 / FLT_EPSILON);
148
+ return;
149
+ }
150
+
151
+ *B = y / A;
152
+ *B_is_usable = 1;
153
+
154
+ if (*B > B_crossover) {
155
+ *B_is_usable = 0;
156
+ if (y == 1 && x < FLT_EPSILON / 128) {
157
+ *sqrt_A2my2 = sqrtf(x) * sqrtf((A + y) / 2);
158
+ } else if (x >= FLT_EPSILON * fabsf(y - 1)) {
159
+ Amy = f(x, y + 1, R) + f(x, y - 1, S);
160
+ *sqrt_A2my2 = sqrtf(Amy * (A + y));
161
+ } else if (y > 1) {
162
+ *sqrt_A2my2 = x * (4 / FLT_EPSILON / FLT_EPSILON) * y /
163
+ sqrtf((y + 1) * (y - 1));
164
+ *new_y = y * (4 / FLT_EPSILON / FLT_EPSILON);
165
+ } else {
166
+ *sqrt_A2my2 = sqrtf((1 - y) * (1 + y));
167
+ }
168
+ }
169
+
170
+ }
171
+
172
+ __host__ __device__ inline
173
+ complex<float>
174
+ casinhf(complex<float> z)
175
+ {
176
+ float x, y, ax, ay, rx, ry, B, sqrt_A2my2, new_y;
177
+ int B_is_usable;
178
+ complex<float> w;
179
+ const float RECIP_EPSILON = 1.0f / FLT_EPSILON;
180
+ const float m_ln2 = 6.9314718055994531e-1f; /* 0x162e42fefa39ef.0p-53 */
181
+ x = z.real();
182
+ y = z.imag();
183
+ ax = fabsf(x);
184
+ ay = fabsf(y);
185
+
186
+ if (isnan(x) || isnan(y)) {
187
+ if (isinf(x))
188
+ return (complex<float>(x, y + y));
189
+ if (isinf(y))
190
+ return (complex<float>(y, x + x));
191
+ if (y == 0)
192
+ return (complex<float>(x + x, y));
193
+ return (complex<float>(x + 0.0f + (y + 0), x + 0.0f + (y + 0)));
194
+ }
195
+
196
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
197
+ if (signbit(x) == 0)
198
+ w = clog_for_large_values(z) + m_ln2;
199
+ else
200
+ w = clog_for_large_values(-z) + m_ln2;
201
+ return (complex<float>(copysignf(w.real(), x),
202
+ copysignf(w.imag(), y)));
203
+ }
204
+
205
+ if (x == 0 && y == 0)
206
+ return (z);
207
+
208
+ raise_inexact();
209
+
210
+ const float SQRT_6_EPSILON = 8.4572793338e-4f; /* 0xddb3d7.0p-34 */
211
+ if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
212
+ return (z);
213
+
214
+ do_hard_work(ax, ay, &rx, &B_is_usable, &B, &sqrt_A2my2, &new_y);
215
+ if (B_is_usable)
216
+ ry = asinf(B);
217
+ else
218
+ ry = atan2f(new_y, sqrt_A2my2);
219
+ return (complex<float>(copysignf(rx, x), copysignf(ry, y)));
220
+ }
221
+
222
+ __host__ __device__ inline
223
+ complex<float> casinf(complex<float> z)
224
+ {
225
+ complex<float> w = casinhf(complex<float>(z.imag(), z.real()));
226
+
227
+ return (complex<float>(w.imag(), w.real()));
228
+ }
229
+
230
+ __host__ __device__ inline
231
+ complex<float> cacosf(complex<float> z)
232
+ {
233
+ float x, y, ax, ay, rx, ry, B, sqrt_A2mx2, new_x;
234
+ int sx, sy;
235
+ int B_is_usable;
236
+ complex<float> w;
237
+ const float pio2_hi = 1.5707963267948966e0f; /* 0x1921fb54442d18.0p-52 */
238
+ const volatile float pio2_lo = 6.1232339957367659e-17f; /* 0x11a62633145c07.0p-106 */
239
+ const float m_ln2 = 6.9314718055994531e-1f; /* 0x162e42fefa39ef.0p-53 */
240
+
241
+ x = z.real();
242
+ y = z.imag();
243
+ sx = signbit(x);
244
+ sy = signbit(y);
245
+ ax = fabsf(x);
246
+ ay = fabsf(y);
247
+
248
+ if (isnan(x) || isnan(y)) {
249
+ if (isinf(x))
250
+ return (complex<float>(y + y, -infinity<float>()));
251
+ if (isinf(y))
252
+ return (complex<float>(x + x, -y));
253
+ if (x == 0)
254
+ return (complex<float>(pio2_hi + pio2_lo, y + y));
255
+ return (complex<float>(x + 0.0f + (y + 0), x + 0.0f + (y + 0)));
256
+ }
257
+
258
+ const float RECIP_EPSILON = 1.0f / FLT_EPSILON;
259
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON) {
260
+ w = clog_for_large_values(z);
261
+ rx = fabsf(w.imag());
262
+ ry = w.real() + m_ln2;
263
+ if (sy == 0)
264
+ ry = -ry;
265
+ return (complex<float>(rx, ry));
266
+ }
267
+
268
+ if (x == 1 && y == 0)
269
+ return (complex<float>(0, -y));
270
+
271
+ raise_inexact();
272
+
273
+ const float SQRT_6_EPSILON = 8.4572793338e-4f; /* 0xddb3d7.0p-34 */
274
+ if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
275
+ return (complex<float>(pio2_hi - (x - pio2_lo), -y));
276
+
277
+ do_hard_work(ay, ax, &ry, &B_is_usable, &B, &sqrt_A2mx2, &new_x);
278
+ if (B_is_usable) {
279
+ if (sx == 0)
280
+ rx = acosf(B);
281
+ else
282
+ rx = acosf(-B);
283
+ } else {
284
+ if (sx == 0)
285
+ rx = atan2f(sqrt_A2mx2, new_x);
286
+ else
287
+ rx = atan2f(sqrt_A2mx2, -new_x);
288
+ }
289
+ if (sy == 0)
290
+ ry = -ry;
291
+ return (complex<float>(rx, ry));
292
+ }
293
+
294
+ __host__ __device__ inline
295
+ complex<float> cacoshf(complex<float> z)
296
+ {
297
+ complex<float> w;
298
+ float rx, ry;
299
+
300
+ w = cacosf(z);
301
+ rx = w.real();
302
+ ry = w.imag();
303
+ /* cacosh(NaN + I*NaN) = NaN + I*NaN */
304
+ if (isnan(rx) && isnan(ry))
305
+ return (complex<float>(ry, rx));
306
+ /* cacosh(NaN + I*+-Inf) = +Inf + I*NaN */
307
+ /* cacosh(+-Inf + I*NaN) = +Inf + I*NaN */
308
+ if (isnan(rx))
309
+ return (complex<float>(fabsf(ry), rx));
310
+ /* cacosh(0 + I*NaN) = NaN + I*NaN */
311
+ if (isnan(ry))
312
+ return (complex<float>(ry, ry));
313
+ return (complex<float>(fabsf(ry), copysignf(rx, z.imag())));
314
+ }
315
+
316
+ /*
317
+ * Optimized version of clog() for |z| finite and larger than ~RECIP_EPSILON.
318
+ */
319
+ __host__ __device__ inline
320
+ complex<float> clog_for_large_values(complex<float> z)
321
+ {
322
+ float x, y;
323
+ float ax, ay, t;
324
+ const float m_e = 2.7182818284590452e0f; /* 0x15bf0a8b145769.0p-51 */
325
+
326
+ x = z.real();
327
+ y = z.imag();
328
+ ax = fabsf(x);
329
+ ay = fabsf(y);
330
+ if (ax < ay) {
331
+ t = ax;
332
+ ax = ay;
333
+ ay = t;
334
+ }
335
+
336
+ if (ax > FLT_MAX / 2)
337
+ return (complex<float>(logf(hypotf(x / m_e, y / m_e)) + 1,
338
+ atan2f(y, x)));
339
+
340
+ const float QUARTER_SQRT_MAX = 2.3058430092136939520000000e+18f; /* = 0x1p61; <= sqrt(FLT_MAX) / 4 */
341
+ const float SQRT_MIN = 1.084202172485504434007453e-19f; /* 0x1p-63; >= sqrt(FLT_MIN) */
342
+ if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN)
343
+ return (complex<float>(logf(hypotf(x, y)), atan2f(y, x)));
344
+
345
+ return (complex<float>(logf(ax * ax + ay * ay) / 2, atan2f(y, x)));
346
+ }
347
+
348
+ /*
349
+ * =================
350
+ * | catanh, catan |
351
+ * =================
352
+ */
353
+
354
+ /*
355
+ * sum_squares(x,y) = x*x + y*y (or just x*x if y*y would underflow).
356
+ * Assumes x*x and y*y will not overflow.
357
+ * Assumes x and y are finite.
358
+ * Assumes y is non-negative.
359
+ * Assumes fabsf(x) >= FLT_EPSILON.
360
+ */
361
+ __host__ __device__
362
+ inline float sum_squares(float x, float y)
363
+ {
364
+ const float SQRT_MIN = 1.084202172485504434007453e-19f; /* 0x1p-63; >= sqrt(FLT_MIN) */
365
+ /* Avoid underflow when y is small. */
366
+ if (y < SQRT_MIN)
367
+ return (x * x);
368
+
369
+ return (x * x + y * y);
370
+ }
371
+
372
+ __host__ __device__
373
+ inline float real_part_reciprocal(float x, float y)
374
+ {
375
+ float scale;
376
+ uint32_t hx, hy;
377
+ int32_t ix, iy;
378
+
379
+ get_float_word(hx, x);
380
+ ix = hx & 0x7f800000;
381
+ get_float_word(hy, y);
382
+ iy = hy & 0x7f800000;
383
+ //#define BIAS (FLT_MAX_EXP - 1)
384
+ const int BIAS = FLT_MAX_EXP - 1;
385
+ //#define CUTOFF (FLT_MANT_DIG / 2 + 1)
386
+ const int CUTOFF = (FLT_MANT_DIG / 2 + 1);
387
+ if (ix - iy >= CUTOFF << 23 || isinf(x))
388
+ return (1 / x);
389
+ if (iy - ix >= CUTOFF << 23)
390
+ return (x / y / y);
391
+ if (ix <= (BIAS + FLT_MAX_EXP / 2 - CUTOFF) << 23)
392
+ return (x / (x * x + y * y));
393
+ set_float_word(scale, 0x7f800000 - ix);
394
+ x *= scale;
395
+ y *= scale;
396
+ return (x / (x * x + y * y) * scale);
397
+ }
398
+
399
+ #if THRUST_CPP_DIALECT >= 2011 || THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
400
+ __host__ __device__ inline
401
+ complex<float> catanhf(complex<float> z)
402
+ {
403
+ float x, y, ax, ay, rx, ry;
404
+ const volatile float pio2_lo = 6.1232339957367659e-17f; /* 0x11a62633145c07.0p-106 */
405
+ const float pio2_hi = 1.5707963267948966e0f;/* 0x1921fb54442d18.0p-52 */
406
+
407
+
408
+ x = z.real();
409
+ y = z.imag();
410
+ ax = fabsf(x);
411
+ ay = fabsf(y);
412
+
413
+
414
+ if (y == 0 && ax <= 1)
415
+ return (complex<float>(atanhf(x), y));
416
+
417
+ if (x == 0)
418
+ return (complex<float>(x, atanf(y)));
419
+
420
+ if (isnan(x) || isnan(y)) {
421
+ if (isinf(x))
422
+ return (complex<float>(copysignf(0, x), y + y));
423
+ if (isinf(y))
424
+ return (complex<float>(copysignf(0, x),
425
+ copysignf(pio2_hi + pio2_lo, y)));
426
+ return (complex<float>(x + 0.0f + (y + 0.0f), x + 0.0f + (y + 0.0f)));
427
+ }
428
+
429
+ const float RECIP_EPSILON = 1.0f / FLT_EPSILON;
430
+ if (ax > RECIP_EPSILON || ay > RECIP_EPSILON)
431
+ return (complex<float>(real_part_reciprocal(x, y),
432
+ copysignf(pio2_hi + pio2_lo, y)));
433
+
434
+ const float SQRT_3_EPSILON = 5.9801995673e-4f; /* 0x9cc471.0p-34 */
435
+ if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) {
436
+ raise_inexact();
437
+ return (z);
438
+ }
439
+
440
+ const float m_ln2 = 6.9314718056e-1f; /* 0xb17218.0p-24 */
441
+ if (ax == 1 && ay < FLT_EPSILON)
442
+ rx = (m_ln2 - logf(ay)) / 2;
443
+ else
444
+ rx = log1pf(4 * ax / sum_squares(ax - 1, ay)) / 4;
445
+
446
+ if (ax == 1)
447
+ ry = atan2f(2, -ay) / 2;
448
+ else if (ay < FLT_EPSILON)
449
+ ry = atan2f(2 * ay, (1 - ax) * (1 + ax)) / 2;
450
+ else
451
+ ry = atan2f(2 * ay, (1 - ax) * (1 + ax) - ay * ay) / 2;
452
+
453
+ return (complex<float>(copysignf(rx, x), copysignf(ry, y)));
454
+ }
455
+
456
+ __host__ __device__ inline
457
+ complex<float>catanf(complex<float> z){
458
+ complex<float> w = catanhf(complex<float>(z.imag(), z.real()));
459
+ return (complex<float>(w.imag(), w.real()));
460
+ }
461
+ #endif
462
+
463
+ } // namespace complex
464
+
465
+ } // namespace detail
466
+
467
+
468
+ template <>
469
+ __host__ __device__
470
+ inline complex<float> acos(const complex<float>& z){
471
+ return detail::complex::cacosf(z);
472
+ }
473
+
474
+ template <>
475
+ __host__ __device__
476
+ inline complex<float> asin(const complex<float>& z){
477
+ return detail::complex::casinf(z);
478
+ }
479
+
480
+ #if THRUST_CPP_DIALECT >= 2011 || THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
481
+ template <>
482
+ __host__ __device__
483
+ inline complex<float> atan(const complex<float>& z){
484
+ return detail::complex::catanf(z);
485
+ }
486
+ #endif
487
+
488
+ template <>
489
+ __host__ __device__
490
+ inline complex<float> acosh(const complex<float>& z){
491
+ return detail::complex::cacoshf(z);
492
+ }
493
+
494
+
495
+ template <>
496
+ __host__ __device__
497
+ inline complex<float> asinh(const complex<float>& z){
498
+ return detail::complex::casinhf(z);
499
+ }
500
+
501
+ #if THRUST_CPP_DIALECT >= 2011 || THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
502
+ template <>
503
+ __host__ __device__
504
+ inline complex<float> atanh(const complex<float>& z){
505
+ return detail::complex::catanhf(z);
506
+ }
507
+ #endif
508
+
509
+ THRUST_NAMESPACE_END
miniCUDA124/include/thrust/detail/complex/ccosh.h ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice unmodified, this list of conditions, and the following
27
+ * disclaimer.
28
+ * 2. Redistributions in binary form must reproduce the above copyright
29
+ * notice, this list of conditions and the following disclaimer in the
30
+ * documentation and/or other materials provided with the distribution.
31
+ *
32
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSD:
45
+ * lib/msun/src/s_ccosh.c
46
+ */
47
+
48
+ #pragma once
49
+
50
+ #include <thrust/detail/config.h>
51
+
52
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
53
+ # pragma GCC system_header
54
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
55
+ # pragma clang system_header
56
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
57
+ # pragma system_header
58
+ #endif // no system header
59
+
60
+ #include <thrust/complex.h>
61
+ #include <thrust/detail/complex/math_private.h>
62
+
63
+ THRUST_NAMESPACE_BEGIN
64
+ namespace detail{
65
+ namespace complex{
66
+
67
+ /*
68
+ * Hyperbolic cosine of a complex argument z = x + i y.
69
+ *
70
+ * cosh(z) = cosh(x+iy)
71
+ * = cosh(x) cos(y) + i sinh(x) sin(y).
72
+ *
73
+ * Exceptional values are noted in the comments within the source code.
74
+ * These values and the return value were taken from n1124.pdf.
75
+ */
76
+
77
+ __host__ __device__ inline
78
+ thrust::complex<double> ccosh(const thrust::complex<double>& z){
79
+
80
+
81
+ const double huge = 8.98846567431157953864652595395e+307; // 0x1p1023
82
+ double x, y, h;
83
+ uint32_t hx, hy, ix, iy, lx, ly;
84
+
85
+ x = z.real();
86
+ y = z.imag();
87
+
88
+ extract_words(hx, lx, x);
89
+ extract_words(hy, ly, y);
90
+
91
+ ix = 0x7fffffff & hx;
92
+ iy = 0x7fffffff & hy;
93
+
94
+ /* Handle the nearly-non-exceptional cases where x and y are finite. */
95
+ if (ix < 0x7ff00000 && iy < 0x7ff00000) {
96
+ if ((iy | ly) == 0)
97
+ return (thrust::complex<double>(::cosh(x), x * y));
98
+ if (ix < 0x40360000) /* small x: normal case */
99
+ return (thrust::complex<double>(::cosh(x) * ::cos(y), ::sinh(x) * ::sin(y)));
100
+
101
+ /* |x| >= 22, so cosh(x) ~= exp(|x|) */
102
+ if (ix < 0x40862e42) {
103
+ /* x < 710: exp(|x|) won't overflow */
104
+ h = ::exp(::fabs(x)) * 0.5;
105
+ return (thrust::complex<double>(h * cos(y), copysign(h, x) * sin(y)));
106
+ } else if (ix < 0x4096bbaa) {
107
+ /* x < 1455: scale to avoid overflow */
108
+ thrust::complex<double> z_;
109
+ z_ = ldexp_cexp(thrust::complex<double>(fabs(x), y), -1);
110
+ return (thrust::complex<double>(z_.real(), z_.imag() * copysign(1.0, x)));
111
+ } else {
112
+ /* x >= 1455: the result always overflows */
113
+ h = huge * x;
114
+ return (thrust::complex<double>(h * h * cos(y), h * sin(y)));
115
+ }
116
+ }
117
+
118
+ /*
119
+ * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0.
120
+ * The sign of 0 in the result is unspecified. Choice = normally
121
+ * the same as dNaN. Raise the invalid floating-point exception.
122
+ *
123
+ * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0.
124
+ * The sign of 0 in the result is unspecified. Choice = normally
125
+ * the same as d(NaN).
126
+ */
127
+ if ((ix | lx) == 0 && iy >= 0x7ff00000)
128
+ return (thrust::complex<double>(y - y, copysign(0.0, x * (y - y))));
129
+
130
+ /*
131
+ * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0.
132
+ *
133
+ * cosh(NaN +- I 0) = d(NaN) + I sign(d(NaN, +-0))0.
134
+ * The sign of 0 in the result is unspecified.
135
+ */
136
+ if ((iy | ly) == 0 && ix >= 0x7ff00000) {
137
+ if (((hx & 0xfffff) | lx) == 0)
138
+ return (thrust::complex<double>(x * x, copysign(0.0, x) * y));
139
+ return (thrust::complex<double>(x * x, copysign(0.0, (x + x) * y)));
140
+ }
141
+
142
+ /*
143
+ * cosh(x +- I Inf) = dNaN + I dNaN.
144
+ * Raise the invalid floating-point exception for finite nonzero x.
145
+ *
146
+ * cosh(x + I NaN) = d(NaN) + I d(NaN).
147
+ * Optionally raises the invalid floating-point exception for finite
148
+ * nonzero x. Choice = don't raise (except for signaling NaNs).
149
+ */
150
+ if (ix < 0x7ff00000 && iy >= 0x7ff00000)
151
+ return (thrust::complex<double>(y - y, x * (y - y)));
152
+
153
+ /*
154
+ * cosh(+-Inf + I NaN) = +Inf + I d(NaN).
155
+ *
156
+ * cosh(+-Inf +- I Inf) = +Inf + I dNaN.
157
+ * The sign of Inf in the result is unspecified. Choice = always +.
158
+ * Raise the invalid floating-point exception.
159
+ *
160
+ * cosh(+-Inf + I y) = +Inf cos(y) +- I Inf sin(y)
161
+ */
162
+ if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) {
163
+ if (iy >= 0x7ff00000)
164
+ return (thrust::complex<double>(x * x, x * (y - y)));
165
+ return (thrust::complex<double>((x * x) * cos(y), x * sin(y)));
166
+ }
167
+
168
+ /*
169
+ * cosh(NaN + I NaN) = d(NaN) + I d(NaN).
170
+ *
171
+ * cosh(NaN +- I Inf) = d(NaN) + I d(NaN).
172
+ * Optionally raises the invalid floating-point exception.
173
+ * Choice = raise.
174
+ *
175
+ * cosh(NaN + I y) = d(NaN) + I d(NaN).
176
+ * Optionally raises the invalid floating-point exception for finite
177
+ * nonzero y. Choice = don't raise (except for signaling NaNs).
178
+ */
179
+ return (thrust::complex<double>((x * x) * (y - y), (x + x) * (y - y)));
180
+ }
181
+
182
+
183
+ __host__ __device__ inline
184
+ thrust::complex<double> ccos(const thrust::complex<double>& z){
185
+ /* ccos(z) = ccosh(I * z) */
186
+ return (ccosh(thrust::complex<double>(-z.imag(), z.real())));
187
+ }
188
+
189
+ } // namespace complex
190
+
191
+ } // namespace detail
192
+
193
+ template <typename ValueType>
194
+ __host__ __device__
195
+ inline complex<ValueType> cos(const complex<ValueType>& z){
196
+ const ValueType re = z.real();
197
+ const ValueType im = z.imag();
198
+ return complex<ValueType>(std::cos(re) * std::cosh(im),
199
+ -std::sin(re) * std::sinh(im));
200
+ }
201
+
202
+ template <typename ValueType>
203
+ __host__ __device__
204
+ inline complex<ValueType> cosh(const complex<ValueType>& z){
205
+ const ValueType re = z.real();
206
+ const ValueType im = z.imag();
207
+ return complex<ValueType>(std::cosh(re) * std::cos(im),
208
+ std::sinh(re) * std::sin(im));
209
+ }
210
+
211
+ template <>
212
+ __host__ __device__
213
+ inline thrust::complex<double> cos(const thrust::complex<double>& z){
214
+ return detail::complex::ccos(z);
215
+ }
216
+
217
+ template <>
218
+ __host__ __device__
219
+ inline thrust::complex<double> cosh(const thrust::complex<double>& z){
220
+ return detail::complex::ccosh(z);
221
+ }
222
+
223
+ THRUST_NAMESPACE_END
miniCUDA124/include/thrust/detail/complex/ccoshf.h ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice unmodified, this list of conditions, and the following
27
+ * disclaimer.
28
+ * 2. Redistributions in binary form must reproduce the above copyright
29
+ * notice, this list of conditions and the following disclaimer in the
30
+ * documentation and/or other materials provided with the distribution.
31
+ *
32
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSD:
45
+ * lib/msun/src/s_ccoshf.c
46
+ */
47
+
48
+
49
+ #pragma once
50
+
51
+ #include <thrust/detail/config.h>
52
+
53
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
54
+ # pragma GCC system_header
55
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
56
+ # pragma clang system_header
57
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
58
+ # pragma system_header
59
+ #endif // no system header
60
+
61
+ #include <thrust/complex.h>
62
+ #include <thrust/detail/complex/math_private.h>
63
+
64
+ THRUST_NAMESPACE_BEGIN
65
+ namespace detail{
66
+ namespace complex{
67
+
68
+ using thrust::complex;
69
+
70
+ __host__ __device__ inline
71
+ complex<float> ccoshf(const complex<float>& z){
72
+ float x, y, h;
73
+ uint32_t hx, hy, ix, iy;
74
+ const float huge = 1.70141183460469231731687303716e+38; //0x1p127;
75
+
76
+
77
+ x = z.real();
78
+ y = z.imag();
79
+
80
+ get_float_word(hx, x);
81
+ get_float_word(hy, y);
82
+
83
+ ix = 0x7fffffff & hx;
84
+ iy = 0x7fffffff & hy;
85
+ if (ix < 0x7f800000 && iy < 0x7f800000) {
86
+ if (iy == 0){
87
+ return (complex<float>(coshf(x), x * y));
88
+ }
89
+ if (ix < 0x41100000){ /* small x: normal case */
90
+ return (complex<float>(coshf(x) * cosf(y), sinhf(x) * sinf(y)));
91
+ }
92
+ /* |x| >= 9, so cosh(x) ~= exp(|x|) */
93
+ if (ix < 0x42b17218) {
94
+ /* x < 88.7: expf(|x|) won't overflow */
95
+ h = expf(fabsf(x)) * 0.5f;
96
+ return (complex<float>(h * cosf(y), copysignf(h, x) * sinf(y)));
97
+ } else if (ix < 0x4340b1e7) {
98
+ /* x < 192.7: scale to avoid overflow */
99
+ thrust::complex<float> z_;
100
+ z_ = ldexp_cexpf(complex<float>(fabsf(x), y), -1);
101
+ return (complex<float>(z_.real(), z_.imag() * copysignf(1.0f, x)));
102
+ } else {
103
+ /* x >= 192.7: the result always overflows */
104
+ h = huge * x;
105
+ return (complex<float>(h * h * cosf(y), h * sinf(y)));
106
+ }
107
+ }
108
+
109
+ if (ix == 0 && iy >= 0x7f800000){
110
+ return (complex<float>(y - y, copysignf(0.0f, x * (y - y))));
111
+ }
112
+ if (iy == 0 && ix >= 0x7f800000) {
113
+ if ((hx & 0x7fffff) == 0)
114
+ return (complex<float>(x * x, copysignf(0.0f, x) * y));
115
+ return (complex<float>(x * x, copysignf(0.0f, (x + x) * y)));
116
+ }
117
+
118
+ if (ix < 0x7f800000 && iy >= 0x7f800000){
119
+ return (complex<float>(y - y, x * (y - y)));
120
+ }
121
+
122
+ if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
123
+ if (iy >= 0x7f800000)
124
+ return (complex<float>(x * x, x * (y - y)));
125
+ return (complex<float>((x * x) * cosf(y), x * sinf(y)));
126
+ }
127
+ return (complex<float>((x * x) * (y - y), (x + x) * (y - y)));
128
+ }
129
+
130
+ __host__ __device__ inline
131
+ complex<float> ccosf(const complex<float>& z){
132
+ return (ccoshf(complex<float>(-z.imag(), z.real())));
133
+ }
134
+
135
+ } // namespace complex
136
+
137
+ } // namespace detail
138
+
139
+ template <>
140
+ __host__ __device__
141
+ inline complex<float> cos(const complex<float>& z){
142
+ return detail::complex::ccosf(z);
143
+ }
144
+
145
+ template <>
146
+ __host__ __device__
147
+ inline complex<float> cosh(const complex<float>& z){
148
+ return detail::complex::ccoshf(z);
149
+ }
150
+
151
+ THRUST_NAMESPACE_END
miniCUDA124/include/thrust/detail/complex/cexp.h ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSD:
45
+ * lib/msun/src/s_cexp.c
46
+ * lib/msun/src/k_exp.c
47
+ *
48
+ */
49
+
50
+ #pragma once
51
+
52
+ #include <thrust/detail/config.h>
53
+
54
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
55
+ # pragma GCC system_header
56
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
57
+ # pragma clang system_header
58
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
59
+ # pragma system_header
60
+ #endif // no system header
61
+
62
+ #include <thrust/complex.h>
63
+ #include <thrust/detail/complex/math_private.h>
64
+
65
+ THRUST_NAMESPACE_BEGIN
66
+ namespace detail{
67
+ namespace complex{
68
+ /*
69
+ * Compute exp(x), scaled to avoid spurious overflow. An exponent is
70
+ * returned separately in 'expt'.
71
+ *
72
+ * Input: ln(DBL_MAX) <= x < ln(2 * DBL_MAX / DBL_MIN_DENORM) ~= 1454.91
73
+ * Output: 2**1023 <= y < 2**1024
74
+ */
75
+ __host__ __device__ inline
76
+ double frexp_exp(double x, int *expt){
77
+ const uint32_t k = 1799; /* constant for reduction */
78
+ const double kln2 = 1246.97177782734161156; /* k * ln2 */
79
+
80
+ double exp_x;
81
+ uint32_t hx;
82
+
83
+ /*
84
+ * We use exp(x) = exp(x - kln2) * 2**k, carefully chosen to
85
+ * minimize |exp(kln2) - 2**k|. We also scale the exponent of
86
+ * exp_x to MAX_EXP so that the result can be multiplied by
87
+ * a tiny number without losing accuracy due to denormalization.
88
+ */
89
+ exp_x = exp(x - kln2);
90
+ get_high_word(hx, exp_x);
91
+ *expt = (hx >> 20) - (0x3ff + 1023) + k;
92
+ set_high_word(exp_x, (hx & 0xfffff) | ((0x3ff + 1023) << 20));
93
+ return (exp_x);
94
+ }
95
+
96
+
97
+ __host__ __device__ inline
98
+ complex<double> ldexp_cexp(complex<double> z, int expt){
99
+ double x, y, exp_x, scale1, scale2;
100
+ int ex_expt, half_expt;
101
+
102
+ x = z.real();
103
+ y = z.imag();
104
+ exp_x = frexp_exp(x, &ex_expt);
105
+ expt += ex_expt;
106
+
107
+ /*
108
+ * Arrange so that scale1 * scale2 == 2**expt. We use this to
109
+ * compensate for scalbn being horrendously slow.
110
+ */
111
+ half_expt = expt / 2;
112
+ insert_words(scale1, (0x3ff + half_expt) << 20, 0);
113
+ half_expt = expt - half_expt;
114
+ insert_words(scale2, (0x3ff + half_expt) << 20, 0);
115
+
116
+ return (complex<double>(cos(y) * exp_x * scale1 * scale2,
117
+ sin(y) * exp_x * scale1 * scale2));
118
+ }
119
+
120
+
121
+ __host__ __device__ inline
122
+ complex<double> cexp(const complex<double>& z){
123
+ double x, y, exp_x;
124
+ uint32_t hx, hy, lx, ly;
125
+
126
+ const uint32_t
127
+ exp_ovfl = 0x40862e42, /* high bits of MAX_EXP * ln2 ~= 710 */
128
+ cexp_ovfl = 0x4096b8e4; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */
129
+
130
+
131
+ x = z.real();
132
+ y = z.imag();
133
+
134
+ extract_words(hy, ly, y);
135
+ hy &= 0x7fffffff;
136
+
137
+ /* cexp(x + I 0) = exp(x) + I 0 */
138
+ if ((hy | ly) == 0)
139
+ return (complex<double>(exp(x), y));
140
+ extract_words(hx, lx, x);
141
+ /* cexp(0 + I y) = cos(y) + I sin(y) */
142
+ if (((hx & 0x7fffffff) | lx) == 0)
143
+ return (complex<double>(cos(y), sin(y)));
144
+
145
+ if (hy >= 0x7ff00000) {
146
+ if (lx != 0 || (hx & 0x7fffffff) != 0x7ff00000) {
147
+ /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
148
+ return (complex<double>(y - y, y - y));
149
+ } else if (hx & 0x80000000) {
150
+ /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */
151
+ return (complex<double>(0.0, 0.0));
152
+ } else {
153
+ /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */
154
+ return (complex<double>(x, y - y));
155
+ }
156
+ }
157
+
158
+ if (hx >= exp_ovfl && hx <= cexp_ovfl) {
159
+ /*
160
+ * x is between 709.7 and 1454.3, so we must scale to avoid
161
+ * overflow in exp(x).
162
+ */
163
+ return (ldexp_cexp(z, 0));
164
+ } else {
165
+ /*
166
+ * Cases covered here:
167
+ * - x < exp_ovfl and exp(x) won't overflow (common case)
168
+ * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0
169
+ * - x = +-Inf (generated by exp())
170
+ * - x = NaN (spurious inexact exception from y)
171
+ */
172
+ exp_x = std::exp(x);
173
+ return (complex<double>(exp_x * cos(y), exp_x * sin(y)));
174
+ }
175
+ }
176
+
177
+ } // namespace complex
178
+
179
+ } // namespace detail
180
+
181
+ template <typename ValueType>
182
+ __host__ __device__
183
+ inline complex<ValueType> exp(const complex<ValueType>& z){
184
+ return polar(std::exp(z.real()),z.imag());
185
+ }
186
+
187
+ template <>
188
+ __host__ __device__
189
+ inline complex<double> exp(const complex<double>& z){
190
+ return detail::complex::cexp(z);
191
+ }
192
+
193
+ THRUST_NAMESPACE_END
miniCUDA124/include/thrust/detail/complex/cexpf.h ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSD:
45
+ * lib/msun/src/s_cexpf.c
46
+ * lib/msun/src/k_exp.c
47
+ *
48
+ */
49
+
50
+ #pragma once
51
+
52
+ #include <thrust/detail/config.h>
53
+
54
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
55
+ # pragma GCC system_header
56
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
57
+ # pragma clang system_header
58
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
59
+ # pragma system_header
60
+ #endif // no system header
61
+
62
+ #include <thrust/complex.h>
63
+ #include <thrust/detail/complex/math_private.h>
64
+
65
+ THRUST_NAMESPACE_BEGIN
66
+ namespace detail{
67
+ namespace complex{
68
+
69
+ __host__ __device__ inline
70
+ float frexp_expf(float x, int *expt){
71
+ const uint32_t k = 235; /* constant for reduction */
72
+ const float kln2 = 162.88958740F; /* k * ln2 */
73
+
74
+ // should this be a double instead?
75
+ float exp_x;
76
+ uint32_t hx;
77
+
78
+ exp_x = expf(x - kln2);
79
+ get_float_word(hx, exp_x);
80
+ *expt = (hx >> 23) - (0x7f + 127) + k;
81
+ set_float_word(exp_x, (hx & 0x7fffff) | ((0x7f + 127) << 23));
82
+ return (exp_x);
83
+ }
84
+
85
+ __host__ __device__ inline
86
+ complex<float>
87
+ ldexp_cexpf(complex<float> z, int expt)
88
+ {
89
+ float x, y, exp_x, scale1, scale2;
90
+ int ex_expt, half_expt;
91
+
92
+ x = z.real();
93
+ y = z.imag();
94
+ exp_x = frexp_expf(x, &ex_expt);
95
+ expt += ex_expt;
96
+
97
+ half_expt = expt / 2;
98
+ set_float_word(scale1, (0x7f + half_expt) << 23);
99
+ half_expt = expt - half_expt;
100
+ set_float_word(scale2, (0x7f + half_expt) << 23);
101
+
102
+ return (complex<float>(std::cos(y) * exp_x * scale1 * scale2,
103
+ std::sin(y) * exp_x * scale1 * scale2));
104
+ }
105
+
106
+ __host__ __device__ inline
107
+ complex<float> cexpf(const complex<float>& z){
108
+ float x, y, exp_x;
109
+ uint32_t hx, hy;
110
+
111
+ const uint32_t
112
+ exp_ovfl = 0x42b17218, /* MAX_EXP * ln2 ~= 88.722839355 */
113
+ cexp_ovfl = 0x43400074; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */
114
+
115
+ x = z.real();
116
+ y = z.imag();
117
+
118
+ get_float_word(hy, y);
119
+ hy &= 0x7fffffff;
120
+
121
+ /* cexp(x + I 0) = exp(x) + I 0 */
122
+ if (hy == 0)
123
+ return (complex<float>(std::exp(x), y));
124
+ get_float_word(hx, x);
125
+ /* cexp(0 + I y) = cos(y) + I sin(y) */
126
+ if ((hx & 0x7fffffff) == 0){
127
+ return (complex<float>(std::cos(y), std::sin(y)));
128
+ }
129
+ if (hy >= 0x7f800000) {
130
+ if ((hx & 0x7fffffff) != 0x7f800000) {
131
+ /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
132
+ return (complex<float>(y - y, y - y));
133
+ } else if (hx & 0x80000000) {
134
+ /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */
135
+ return (complex<float>(0.0, 0.0));
136
+ } else {
137
+ /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */
138
+ return (complex<float>(x, y - y));
139
+ }
140
+ }
141
+
142
+ if (hx >= exp_ovfl && hx <= cexp_ovfl) {
143
+ /*
144
+ * x is between 88.7 and 192, so we must scale to avoid
145
+ * overflow in expf(x).
146
+ */
147
+ return (ldexp_cexpf(z, 0));
148
+ } else {
149
+ /*
150
+ * Cases covered here:
151
+ * - x < exp_ovfl and exp(x) won't overflow (common case)
152
+ * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0
153
+ * - x = +-Inf (generated by exp())
154
+ * - x = NaN (spurious inexact exception from y)
155
+ */
156
+ exp_x = std::exp(x);
157
+ return (complex<float>(exp_x * std::cos(y), exp_x * std::sin(y)));
158
+ }
159
+ }
160
+
161
+ } // namespace complex
162
+
163
+ } // namespace detail
164
+
165
+ template <>
166
+ __host__ __device__
167
+ inline complex<float> exp(const complex<float>& z){
168
+ return detail::complex::cexpf(z);
169
+ }
170
+
171
+ THRUST_NAMESPACE_END
miniCUDA124/include/thrust/detail/complex/clog.h ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2021 NVIDIA Corporation
3
+ * Copyright 2013 Filipe RNC Maia
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /*-
19
+ * Copyright (c) 2012 Stephen Montgomery-Smith <stephen@FreeBSD.ORG>
20
+ * All rights reserved.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the above copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ *
31
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
32
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
35
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41
+ * SUCH DAMAGE.
42
+ */
43
+
44
+ /* adapted from FreeBSDs msun:*/
45
+
46
+
47
+ #pragma once
48
+
49
+ #include <thrust/detail/config.h>
50
+
51
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
52
+ # pragma GCC system_header
53
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
54
+ # pragma clang system_header
55
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
56
+ # pragma system_header
57
+ #endif // no system header
58
+
59
+ #include <thrust/complex.h>
60
+ #include <thrust/detail/complex/math_private.h>
61
+
62
+ THRUST_NAMESPACE_BEGIN
63
+ namespace detail{
64
+ namespace complex{
65
+
66
+ using thrust::complex;
67
+
68
+ /* round down to 18 = 54/3 bits */
69
+ __host__ __device__ inline
70
+ double trim(double x){
71
+ uint32_t hi;
72
+ get_high_word(hi, x);
73
+ insert_words(x, hi &0xfffffff8, 0);
74
+ return x;
75
+ }
76
+
77
+
78
+ __host__ __device__ inline
79
+ complex<double> clog(const complex<double>& z){
80
+
81
+ // Adapted from FreeBSDs msun
82
+ double x, y;
83
+ double ax, ay;
84
+ double x0, y0, x1, y1, x2, y2, t, hm1;
85
+ double val[12];
86
+ int i, sorted;
87
+ const double e = 2.7182818284590452354;
88
+
89
+ x = z.real();
90
+ y = z.imag();
91
+
92
+ /* Handle NaNs using the general formula to mix them right. */
93
+ if (x != x || y != y){
94
+ return (complex<double>(std::log(norm(z)), std::atan2(y, x)));
95
+ }
96
+
97
+ ax = std::abs(x);
98
+ ay = std::abs(y);
99
+ if (ax < ay) {
100
+ t = ax;
101
+ ax = ay;
102
+ ay = t;
103
+ }
104
+
105
+ /*
106
+ * To avoid unnecessary overflow, if x and y are very large, divide x
107
+ * and y by M_E, and then add 1 to the logarithm. This depends on
108
+ * M_E being larger than sqrt(2).
109
+ * There is a potential loss of accuracy caused by dividing by M_E,
110
+ * but this case should happen extremely rarely.
111
+ */
112
+ // if (ay > 5e307){
113
+ // For high values of ay -> hypotf(DBL_MAX,ay) = inf
114
+ // We expect that for values at or below ay = 5e307 this should not happen
115
+ if (ay > 5e307){
116
+ return (complex<double>(std::log(hypot(x / e, y / e)) + 1.0, std::atan2(y, x)));
117
+ }
118
+ if (ax == 1.) {
119
+ if (ay < 1e-150){
120
+ return (complex<double>((ay * 0.5) * ay, std::atan2(y, x)));
121
+ }
122
+ return (complex<double>(log1p(ay * ay) * 0.5, std::atan2(y, x)));
123
+ }
124
+
125
+ /*
126
+ * Because atan2 and hypot conform to C99, this also covers all the
127
+ * edge cases when x or y are 0 or infinite.
128
+ */
129
+ if (ax < 1e-50 || ay < 1e-50 || ax > 1e50 || ay > 1e50){
130
+ return (complex<double>(std::log(hypot(x, y)), std::atan2(y, x)));
131
+ }
132
+
133
+ /*
134
+ * From this point on, we don't need to worry about underflow or
135
+ * overflow in calculating ax*ax or ay*ay.
136
+ */
137
+
138
+ /* Some easy cases. */
139
+
140
+ if (ax >= 1.0){
141
+ return (complex<double>(log1p((ax-1)*(ax+1) + ay*ay) * 0.5, atan2(y, x)));
142
+ }
143
+
144
+ if (ax*ax + ay*ay <= 0.7){
145
+ return (complex<double>(std::log(ax*ax + ay*ay) * 0.5, std::atan2(y, x)));
146
+ }
147
+
148
+ /*
149
+ * Take extra care so that ULP of real part is small if hypot(x,y) is
150
+ * moderately close to 1.
151
+ */
152
+
153
+
154
+ x0 = trim(ax);
155
+ ax = ax-x0;
156
+ x1 = trim(ax);
157
+ x2 = ax-x1;
158
+ y0 = trim(ay);
159
+ ay = ay-y0;
160
+ y1 = trim(ay);
161
+ y2 = ay-y1;
162
+
163
+ val[0] = x0*x0;
164
+ val[1] = y0*y0;
165
+ val[2] = 2*x0*x1;
166
+ val[3] = 2*y0*y1;
167
+ val[4] = x1*x1;
168
+ val[5] = y1*y1;
169
+ val[6] = 2*x0*x2;
170
+ val[7] = 2*y0*y2;
171
+ val[8] = 2*x1*x2;
172
+ val[9] = 2*y1*y2;
173
+ val[10] = x2*x2;
174
+ val[11] = y2*y2;
175
+
176
+ /* Bubble sort. */
177
+
178
+ do {
179
+ sorted = 1;
180
+ for (i=0;i<11;i++) {
181
+ if (val[i] < val[i+1]) {
182
+ sorted = 0;
183
+ t = val[i];
184
+ val[i] = val[i+1];
185
+ val[i+1] = t;
186
+ }
187
+ }
188
+ } while (!sorted);
189
+
190
+ hm1 = -1;
191
+ for (i=0;i<12;i++){
192
+ hm1 += val[i];
193
+ }
194
+ return (complex<double>(0.5 * log1p(hm1), atan2(y, x)));
195
+ }
196
+
197
+ } // namespace complex
198
+
199
+ } // namespace detail
200
+
201
+ template <typename ValueType>
202
+ __host__ __device__
203
+ inline complex<ValueType> log(const complex<ValueType>& z){
204
+ return complex<ValueType>(std::log(thrust::abs(z)),thrust::arg(z));
205
+ }
206
+
207
+ template <>
208
+ __host__ __device__
209
+ inline complex<double> log(const complex<double>& z){
210
+ return detail::complex::clog(z);
211
+ }
212
+
213
+ template <typename ValueType>
214
+ __host__ __device__
215
+ inline complex<ValueType> log10(const complex<ValueType>& z){
216
+ // Using the explicit literal prevents compile time warnings in
217
+ // devices that don't support doubles
218
+ return thrust::log(z)/ValueType(2.30258509299404568402);
219
+ }
220
+
221
+ THRUST_NAMESPACE_END
222
+
miniCUDA124/include/thrust/detail/transform_scan.inl ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/scan.h>
30
+ #include <thrust/iterator/iterator_traits.h>
31
+ #include <thrust/system/detail/generic/select_system.h>
32
+ #include <thrust/system/detail/generic/transform_scan.h>
33
+ #include <thrust/system/detail/adl/transform_scan.h>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+
38
+ __thrust_exec_check_disable__
39
+ template<typename DerivedPolicy,
40
+ typename InputIterator,
41
+ typename OutputIterator,
42
+ typename UnaryFunction,
43
+ typename AssociativeOperator>
44
+ __host__ __device__
45
+ OutputIterator transform_inclusive_scan(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
46
+ InputIterator first,
47
+ InputIterator last,
48
+ OutputIterator result,
49
+ UnaryFunction unary_op,
50
+ AssociativeOperator binary_op)
51
+ {
52
+ using thrust::system::detail::generic::transform_inclusive_scan;
53
+ return transform_inclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, unary_op, binary_op);
54
+ } // end transform_inclusive_scan()
55
+
56
+
57
+ __thrust_exec_check_disable__
58
+ template<typename DerivedPolicy,
59
+ typename InputIterator,
60
+ typename OutputIterator,
61
+ typename UnaryFunction,
62
+ typename T,
63
+ typename AssociativeOperator>
64
+ __host__ __device__
65
+ OutputIterator transform_exclusive_scan(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
66
+ InputIterator first,
67
+ InputIterator last,
68
+ OutputIterator result,
69
+ UnaryFunction unary_op,
70
+ T init,
71
+ AssociativeOperator binary_op)
72
+ {
73
+ using thrust::system::detail::generic::transform_exclusive_scan;
74
+ return transform_exclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, unary_op, init, binary_op);
75
+ } // end transform_exclusive_scan()
76
+
77
+
78
+ template<typename InputIterator,
79
+ typename OutputIterator,
80
+ typename UnaryFunction,
81
+ typename BinaryFunction>
82
+ OutputIterator transform_inclusive_scan(InputIterator first,
83
+ InputIterator last,
84
+ OutputIterator result,
85
+ UnaryFunction unary_op,
86
+ BinaryFunction binary_op)
87
+ {
88
+ using thrust::system::detail::generic::select_system;
89
+
90
+ typedef typename thrust::iterator_system<InputIterator>::type System1;
91
+ typedef typename thrust::iterator_system<OutputIterator>::type System2;
92
+
93
+ System1 system1;
94
+ System2 system2;
95
+
96
+ return thrust::transform_inclusive_scan(select_system(system1,system2), first, last, result, unary_op, binary_op);
97
+ } // end transform_inclusive_scan()
98
+
99
+
100
+ template<typename InputIterator,
101
+ typename OutputIterator,
102
+ typename UnaryFunction,
103
+ typename T,
104
+ typename AssociativeOperator>
105
+ OutputIterator transform_exclusive_scan(InputIterator first,
106
+ InputIterator last,
107
+ OutputIterator result,
108
+ UnaryFunction unary_op,
109
+ T init,
110
+ AssociativeOperator binary_op)
111
+ {
112
+ using thrust::system::detail::generic::select_system;
113
+
114
+ typedef typename thrust::iterator_system<InputIterator>::type System1;
115
+ typedef typename thrust::iterator_system<OutputIterator>::type System2;
116
+
117
+ System1 system1;
118
+ System2 system2;
119
+
120
+ return thrust::transform_exclusive_scan(select_system(system1,system2), first, last, result, unary_op, init, binary_op);
121
+ } // end transform_exclusive_scan()
122
+
123
+
124
+ THRUST_NAMESPACE_END
125
+
miniCUDA124/include/thrust/detail/trivial_sequence.h ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file trivial_sequence.h
18
+ * \brief Container-like class for wrapping sequences. The wrapped
19
+ * sequence always has trivial iterators, even when the input
20
+ * sequence does not.
21
+ */
22
+
23
+
24
+ #pragma once
25
+
26
+ #include <thrust/detail/config.h>
27
+
28
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
29
+ # pragma GCC system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
31
+ # pragma clang system_header
32
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
33
+ # pragma system_header
34
+ #endif // no system header
35
+
36
+ #include <thrust/iterator/iterator_traits.h>
37
+ #include <thrust/detail/type_traits.h>
38
+ #include <thrust/detail/execution_policy.h>
39
+ #include <thrust/detail/temporary_array.h>
40
+ #include <thrust/type_traits/is_contiguous_iterator.h>
41
+
42
+ THRUST_NAMESPACE_BEGIN
43
+
44
+ namespace detail
45
+ {
46
+
47
+ // never instantiated
48
+ template<typename Iterator, typename DerivedPolicy, typename is_trivial> struct _trivial_sequence { };
49
+
50
+ // trivial case
51
+ template<typename Iterator, typename DerivedPolicy>
52
+ struct _trivial_sequence<Iterator, DerivedPolicy, thrust::detail::true_type>
53
+ {
54
+ typedef Iterator iterator_type;
55
+ Iterator first, last;
56
+
57
+ __host__ __device__
58
+ _trivial_sequence(thrust::execution_policy<DerivedPolicy> &, Iterator _first, Iterator _last) : first(_first), last(_last)
59
+ {
60
+ }
61
+
62
+ __host__ __device__
63
+ iterator_type begin() { return first; }
64
+
65
+ __host__ __device__
66
+ iterator_type end() { return last; }
67
+ };
68
+
69
+ // non-trivial case
70
+ template<typename Iterator, typename DerivedPolicy>
71
+ struct _trivial_sequence<Iterator, DerivedPolicy, thrust::detail::false_type>
72
+ {
73
+ typedef typename thrust::iterator_value<Iterator>::type iterator_value;
74
+ typedef typename thrust::detail::temporary_array<iterator_value, DerivedPolicy>::iterator iterator_type;
75
+
76
+ thrust::detail::temporary_array<iterator_value, DerivedPolicy> buffer;
77
+
78
+ __host__ __device__
79
+ _trivial_sequence(thrust::execution_policy<DerivedPolicy> &exec, Iterator first, Iterator last)
80
+ : buffer(exec, first, last)
81
+ {
82
+ }
83
+
84
+ __host__ __device__
85
+ iterator_type begin() { return buffer.begin(); }
86
+
87
+ __host__ __device__
88
+ iterator_type end() { return buffer.end(); }
89
+ };
90
+
91
+ template <typename Iterator, typename DerivedPolicy>
92
+ struct trivial_sequence
93
+ : detail::_trivial_sequence<Iterator, DerivedPolicy, typename thrust::is_contiguous_iterator<Iterator>::type>
94
+ {
95
+ typedef _trivial_sequence<Iterator, DerivedPolicy, typename thrust::is_contiguous_iterator<Iterator>::type> super_t;
96
+
97
+ __host__ __device__
98
+ trivial_sequence(thrust::execution_policy<DerivedPolicy> &exec, Iterator first, Iterator last) : super_t(exec, first, last) { }
99
+ };
100
+
101
+ } // end namespace detail
102
+
103
+ THRUST_NAMESPACE_END
104
+
miniCUDA124/include/thrust/detail/tuple_algorithms.h ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+ #include <thrust/detail/cpp11_required.h>
29
+
30
+ #if THRUST_CPP_DIALECT >= 2011
31
+
32
+ #include <thrust/detail/type_deduction.h>
33
+ #include <thrust/type_traits/integer_sequence.h>
34
+
35
+ #include <tuple>
36
+
37
+ THRUST_NAMESPACE_BEGIN
38
+
39
+ template <typename Tuple, std::size_t... Is>
40
+ auto tuple_subset(Tuple&& t, index_sequence<Is...>)
41
+ THRUST_DECLTYPE_RETURNS(std::make_tuple(std::get<Is>(THRUST_FWD(t))...));
42
+
43
+ namespace detail
44
+ {
45
+
46
+ template <typename Tuple, typename F, std::size_t... Is>
47
+ void tuple_for_each_impl(Tuple&& t, F&& f, index_sequence<Is...>)
48
+ {
49
+ auto l = { (f(std::get<Is>(t)), 0)... };
50
+ THRUST_UNUSED_VAR(l);
51
+ }
52
+
53
+ template <typename Tuple, typename F, std::size_t... Is>
54
+ auto tuple_transform_impl(Tuple&& t, F&& f, index_sequence<Is...>)
55
+ THRUST_DECLTYPE_RETURNS(std::make_tuple(f(std::get<Is>(t))...));
56
+
57
+ } // namespace detail
58
+
59
+ template <typename... Ts, typename F>
60
+ auto tuple_for_each(std::tuple<Ts...>& t, F&& f)
61
+ THRUST_DECLTYPE_RETURNS(
62
+ detail::tuple_for_each_impl(
63
+ t
64
+ , THRUST_FWD(f)
65
+ , make_index_sequence<sizeof...(Ts)>{}
66
+ )
67
+ );
68
+ template <typename... Ts, typename F>
69
+ auto tuple_for_each(std::tuple<Ts...> const& t, F&& f)
70
+ THRUST_DECLTYPE_RETURNS(
71
+ detail::tuple_for_each_impl(
72
+ t
73
+ , THRUST_FWD(f)
74
+ , make_index_sequence<sizeof...(Ts)>{}
75
+ )
76
+ );
77
+ template <typename... Ts, typename F>
78
+ auto tuple_for_each(std::tuple<Ts...>&& t, F&& f)
79
+ THRUST_DECLTYPE_RETURNS(
80
+ detail::tuple_for_each_impl(
81
+ std::move(t)
82
+ , THRUST_FWD(f)
83
+ , make_index_sequence<sizeof...(Ts)>{}
84
+ )
85
+ );
86
+
87
+ template <typename... Ts, typename F>
88
+ auto tuple_transform(std::tuple<Ts...>& t, F&& f)
89
+ THRUST_DECLTYPE_RETURNS(
90
+ detail::tuple_transform_impl(
91
+ t
92
+ , THRUST_FWD(f)
93
+ , make_index_sequence<sizeof...(Ts)>{}
94
+ )
95
+ );
96
+ template <typename... Ts, typename F>
97
+ auto tuple_transform(std::tuple<Ts...> const& t, F&& f)
98
+ THRUST_DECLTYPE_RETURNS(
99
+ detail::tuple_transform_impl(
100
+ t
101
+ , THRUST_FWD(f)
102
+ , make_index_sequence<sizeof...(Ts)>{}
103
+ )
104
+ );
105
+ template <typename... Ts, typename F>
106
+ auto tuple_transform(std::tuple<Ts...>&& t, F&& f)
107
+ THRUST_DECLTYPE_RETURNS(
108
+ detail::tuple_transform_impl(
109
+ std::move(t)
110
+ , THRUST_FWD(f)
111
+ , make_index_sequence<sizeof...(Ts)>{}
112
+ )
113
+ );
114
+
115
+ THRUST_NAMESPACE_END
116
+
117
+ #endif // THRUST_CPP_DIALECT >= 2011
118
+
miniCUDA124/include/thrust/detail/tuple_meta_transform.h ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/tuple.h>
30
+ #include <thrust/type_traits/integer_sequence.h>
31
+
32
+ THRUST_NAMESPACE_BEGIN
33
+
34
+ namespace detail
35
+ {
36
+
37
+ // introduce an intermediate type tuple_meta_transform_WAR_NVCC
38
+ // rather than directly specializing tuple_meta_transform with
39
+ // default argument IndexSequence = thrust::make_index_sequence<thrust::tuple_size<Tuple>::value>
40
+ // to workaround nvcc 11.0 compiler bug
41
+ template<typename Tuple,
42
+ template<typename> class UnaryMetaFunction,
43
+ typename IndexSequence>
44
+ struct tuple_meta_transform_WAR_NVCC;
45
+
46
+ template<typename Tuple,
47
+ template<typename> class UnaryMetaFunction,
48
+ size_t... Is>
49
+ struct tuple_meta_transform_WAR_NVCC<Tuple, UnaryMetaFunction, thrust::index_sequence<Is...>>
50
+ {
51
+ typedef thrust::tuple<
52
+ typename UnaryMetaFunction<typename thrust::tuple_element<Is,Tuple>::type>::type...
53
+ > type;
54
+ };
55
+
56
+ template<typename Tuple,
57
+ template<typename> class UnaryMetaFunction>
58
+ struct tuple_meta_transform
59
+ {
60
+ typedef typename tuple_meta_transform_WAR_NVCC<Tuple, UnaryMetaFunction, thrust::make_index_sequence<thrust::tuple_size<Tuple>::value>>::type type;
61
+ };
62
+
63
+ } // end detail
64
+
65
+ THRUST_NAMESPACE_END
66
+
miniCUDA124/include/thrust/detail/tuple_transform.h ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/tuple.h>
30
+ #include <thrust/detail/tuple_meta_transform.h>
31
+
32
+ THRUST_NAMESPACE_BEGIN
33
+
34
+ namespace detail
35
+ {
36
+
37
+ template<typename Tuple,
38
+ template<typename> class UnaryMetaFunction,
39
+ typename UnaryFunction,
40
+ typename IndexSequence = thrust::make_index_sequence<thrust::tuple_size<Tuple>::value>>
41
+ struct tuple_transform_functor;
42
+
43
+
44
+ template<typename Tuple,
45
+ template<typename> class UnaryMetaFunction,
46
+ typename UnaryFunction,
47
+ size_t... Is>
48
+ struct tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction,thrust::index_sequence<Is...>>
49
+ {
50
+ static __host__
51
+ typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
52
+ do_it_on_the_host(const Tuple &t, UnaryFunction f)
53
+ {
54
+ typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;
55
+
56
+ return XfrmTuple(f(thrust::get<Is>(t))...);
57
+ }
58
+
59
+ static __host__ __device__
60
+ typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
61
+ do_it_on_the_host_or_device(const Tuple &t, UnaryFunction f)
62
+ {
63
+ typedef typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type XfrmTuple;
64
+
65
+ return XfrmTuple(f(thrust::get<Is>(t))...);
66
+ }
67
+ };
68
+
69
+
70
+ template<template<typename> class UnaryMetaFunction,
71
+ typename Tuple,
72
+ typename UnaryFunction>
73
+ typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
74
+ tuple_host_transform(const Tuple &t, UnaryFunction f)
75
+ {
76
+ return tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction>::do_it_on_the_host(t,f);
77
+ }
78
+
79
+ template<template<typename> class UnaryMetaFunction,
80
+ typename Tuple,
81
+ typename UnaryFunction>
82
+ typename tuple_meta_transform<Tuple,UnaryMetaFunction>::type
83
+ __host__ __device__
84
+ tuple_host_device_transform(const Tuple &t, UnaryFunction f)
85
+ {
86
+ return tuple_transform_functor<Tuple,UnaryMetaFunction,UnaryFunction>::do_it_on_the_host_or_device(t,f);
87
+ }
88
+
89
+ } // end detail
90
+
91
+ THRUST_NAMESPACE_END
92
+
miniCUDA124/include/thrust/detail/type_deduction.h ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2018 NVIDIA Corporation
2
+ // (Bryce Adelstein Lelbach <brycelelbach@gmail.com>)
3
+ // Copyright (c) 2013-2018 Eric Niebler (`THRUST_RETURNS`, etc)
4
+ // Copyright (c) 2016-2018 Casey Carter (`THRUST_RETURNS`, etc)
5
+ //
6
+ // Distributed under the Boost Software License v1.0 (boost.org/LICENSE_1_0.txt)
7
+
8
+ #pragma once
9
+
10
+ #include <thrust/detail/config.h>
11
+
12
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
13
+ # pragma GCC system_header
14
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
15
+ # pragma clang system_header
16
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
17
+ # pragma system_header
18
+ #endif // no system header
19
+ #include <thrust/detail/cpp11_required.h>
20
+
21
+ #if THRUST_CPP_DIALECT >= 2011
22
+
23
+ #include <thrust/detail/preprocessor.h>
24
+
25
+ #include <utility>
26
+ #include <type_traits>
27
+
28
+ ///////////////////////////////////////////////////////////////////////////////
29
+
30
+ /// \def THRUST_FWD(x)
31
+ /// \brief Performs universal forwarding of a universal reference.
32
+ ///
33
+ #define THRUST_FWD(x) ::std::forward<decltype(x)>(x)
34
+
35
+ /// \def THRUST_MVCAP(x)
36
+ /// \brief Capture `x` into a lambda by moving.
37
+ ///
38
+ #define THRUST_MVCAP(x) x = ::std::move(x)
39
+
40
+ /// \def THRUST_RETOF(invocable, ...)
41
+ /// \brief Expands to the type returned by invoking an instance of the invocable
42
+ /// type \a invocable with parameters of type \c __VA_ARGS__. Must
43
+ /// be called with 1 or fewer parameters to the invocable.
44
+ ///
45
+ #define THRUST_RETOF(...) THRUST_PP_DISPATCH(THRUST_RETOF, __VA_ARGS__)
46
+ #define THRUST_RETOF1(C) decltype(::std::declval<C>()())
47
+ #define THRUST_RETOF2(C, V) decltype(::std::declval<C>()(::std::declval<V>()))
48
+
49
+ /// \def THRUST_RETURNS(...)
50
+ /// \brief Expands to a function definition that returns the expression
51
+ /// \c __VA_ARGS__.
52
+ ///
53
+ #define THRUST_RETURNS(...) \
54
+ noexcept(noexcept(__VA_ARGS__)) \
55
+ { return (__VA_ARGS__); } \
56
+ /**/
57
+
58
+ /// \def THRUST_DECLTYPE_RETURNS(...)
59
+ /// \brief Expands to a function definition, including a trailing returning
60
+ /// type, that returns the expression \c __VA_ARGS__.
61
+ ///
62
+ // Trailing return types seem to confuse Doxygen, and cause it to interpret
63
+ // parts of the function's body as new function signatures.
64
+ #if defined(THRUST_DOXYGEN)
65
+ #define THRUST_DECLTYPE_RETURNS(...) \
66
+ { return (__VA_ARGS__); } \
67
+ /**/
68
+ #else
69
+ #define THRUST_DECLTYPE_RETURNS(...) \
70
+ noexcept(noexcept(__VA_ARGS__)) \
71
+ -> decltype(__VA_ARGS__) \
72
+ { return (__VA_ARGS__); } \
73
+ /**/
74
+ #endif
75
+
76
+ /// \def THRUST_DECLTYPE_RETURNS_WITH_SFINAE_CONDITION(condition, ...)
77
+ /// \brief Expands to a function definition, including a trailing returning
78
+ /// type, that returns the expression \c __VA_ARGS__. It shall only
79
+ /// participate in overload resolution if \c condition is \c true.
80
+ ///
81
+ // Trailing return types seem to confuse Doxygen, and cause it to interpret
82
+ // parts of the function's body as new function signatures.
83
+ #if defined(THRUST_DOXYGEN)
84
+ #define THRUST_DECLTYPE_RETURNS(...) \
85
+ { return (__VA_ARGS__); } \
86
+ /**/
87
+ #else
88
+ #define THRUST_DECLTYPE_RETURNS_WITH_SFINAE_CONDITION(condition, ...) \
89
+ noexcept(noexcept(__VA_ARGS__)) \
90
+ -> typename std::enable_if<condition, decltype(__VA_ARGS__)>::type \
91
+ { return (__VA_ARGS__); } \
92
+ /**/
93
+ #endif
94
+
95
+ ///////////////////////////////////////////////////////////////////////////////
96
+
97
+ #endif // THRUST_CPP_DIALECT >= 2011
98
+
miniCUDA124/include/thrust/detail/type_traits.h ADDED
@@ -0,0 +1,701 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2022 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file type_traits.h
19
+ * \brief Temporarily define some type traits
20
+ * until nvcc can compile tr1::type_traits.
21
+ */
22
+
23
+ #pragma once
24
+
25
+ #include <thrust/detail/config.h>
26
+
27
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
28
+ # pragma GCC system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
30
+ # pragma clang system_header
31
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
32
+ # pragma system_header
33
+ #endif // no system header
34
+
35
+ #include <cuda/std/type_traits>
36
+
37
+ #include <type_traits>
38
+
39
+ THRUST_NAMESPACE_BEGIN
40
+
41
+ // forward declaration of device_reference
42
+ template<typename T> class device_reference;
43
+
44
+ namespace detail
45
+ {
46
+ /// helper classes [4.3].
47
+ template<typename T, T v>
48
+ using integral_constant = ::cuda::std::integral_constant<T, v>;
49
+ using true_type = ::cuda::std::true_type;
50
+ using false_type = ::cuda::std::false_type;
51
+
52
+ //template<typename T> struct is_integral : public std::tr1::is_integral<T> {};
53
+ template<typename T> struct is_integral : public false_type {};
54
+ template<> struct is_integral<bool> : public true_type {};
55
+ template<> struct is_integral<char> : public true_type {};
56
+ template<> struct is_integral<signed char> : public true_type {};
57
+ template<> struct is_integral<unsigned char> : public true_type {};
58
+ template<> struct is_integral<short> : public true_type {};
59
+ template<> struct is_integral<unsigned short> : public true_type {};
60
+ template<> struct is_integral<int> : public true_type {};
61
+ template<> struct is_integral<unsigned int> : public true_type {};
62
+ template<> struct is_integral<long> : public true_type {};
63
+ template<> struct is_integral<unsigned long> : public true_type {};
64
+ template<> struct is_integral<long long> : public true_type {};
65
+ template<> struct is_integral<unsigned long long> : public true_type {};
66
+ template<> struct is_integral<const bool> : public true_type {};
67
+ template<> struct is_integral<const char> : public true_type {};
68
+ template<> struct is_integral<const unsigned char> : public true_type {};
69
+ template<> struct is_integral<const short> : public true_type {};
70
+ template<> struct is_integral<const unsigned short> : public true_type {};
71
+ template<> struct is_integral<const int> : public true_type {};
72
+ template<> struct is_integral<const unsigned int> : public true_type {};
73
+ template<> struct is_integral<const long> : public true_type {};
74
+ template<> struct is_integral<const unsigned long> : public true_type {};
75
+ template<> struct is_integral<const long long> : public true_type {};
76
+ template<> struct is_integral<const unsigned long long> : public true_type {};
77
+
78
+ template<typename T> struct is_floating_point : public false_type {};
79
+ template<> struct is_floating_point<float> : public true_type {};
80
+ template<> struct is_floating_point<double> : public true_type {};
81
+ template<> struct is_floating_point<long double> : public true_type {};
82
+
83
+ template<typename T> struct is_arithmetic : public is_integral<T> {};
84
+ template<> struct is_arithmetic<float> : public true_type {};
85
+ template<> struct is_arithmetic<double> : public true_type {};
86
+ template<> struct is_arithmetic<const float> : public true_type {};
87
+ template<> struct is_arithmetic<const double> : public true_type {};
88
+
89
+ template<typename T> struct is_pointer : public false_type {};
90
+ template<typename T> struct is_pointer<T *> : public true_type {};
91
+
92
+ template<typename T> struct is_device_ptr : public false_type {};
93
+
94
+ template<typename T> struct is_void : public false_type {};
95
+ template<> struct is_void<void> : public true_type {};
96
+ template<> struct is_void<const void> : public true_type {};
97
+
98
+ template<typename T> struct is_non_bool_integral : public is_integral<T> {};
99
+ template<> struct is_non_bool_integral<bool> : public false_type {};
100
+
101
+ template<typename T> struct is_non_bool_arithmetic : public is_arithmetic<T> {};
102
+ template<> struct is_non_bool_arithmetic<bool> : public false_type {};
103
+
104
+ template<typename T> struct is_pod
105
+ : public integral_constant<
106
+ bool,
107
+ is_void<T>::value || is_pointer<T>::value || is_arithmetic<T>::value
108
+ #if THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC || \
109
+ THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_CLANG
110
+ // use intrinsic type traits
111
+ || __is_pod(T)
112
+ #elif THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC
113
+ // only use the intrinsic for >= 4.3
114
+ #if (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)
115
+ || __is_pod(T)
116
+ #endif // GCC VERSION
117
+ #endif // THRUST_HOST_COMPILER
118
+ >
119
+ {};
120
+
121
+
122
+ template <typename T>
123
+ struct has_trivial_constructor
124
+ : public integral_constant<bool, is_pod<T>::value || ::cuda::std::is_trivially_constructible<T>::value>
125
+ {};
126
+
127
+ template<typename T>
128
+ struct has_trivial_copy_constructor
129
+ : public integral_constant<bool, is_pod<T>::value || ::cuda::std::is_trivially_copyable<T>::value>
130
+ {};
131
+
132
+ template<typename T> struct has_trivial_destructor : public is_pod<T> {};
133
+
134
+ template<typename T> struct is_const : public false_type {};
135
+ template<typename T> struct is_const<const T> : public true_type {};
136
+
137
+ template<typename T> struct is_volatile : public false_type {};
138
+ template<typename T> struct is_volatile<volatile T> : public true_type {};
139
+
140
+ template<typename T>
141
+ struct add_const
142
+ {
143
+ typedef T const type;
144
+ }; // end add_const
145
+
146
+ template<typename T>
147
+ struct remove_const
148
+ {
149
+ typedef T type;
150
+ }; // end remove_const
151
+
152
+ template<typename T>
153
+ struct remove_const<const T>
154
+ {
155
+ typedef T type;
156
+ }; // end remove_const
157
+
158
+ template<typename T>
159
+ struct add_volatile
160
+ {
161
+ typedef volatile T type;
162
+ }; // end add_volatile
163
+
164
+ template<typename T>
165
+ struct remove_volatile
166
+ {
167
+ typedef T type;
168
+ }; // end remove_volatile
169
+
170
+ template<typename T>
171
+ struct remove_volatile<volatile T>
172
+ {
173
+ typedef T type;
174
+ }; // end remove_volatile
175
+
176
+ template<typename T>
177
+ struct add_cv
178
+ {
179
+ typedef const volatile T type;
180
+ }; // end add_cv
181
+
182
+ template<typename T>
183
+ struct remove_cv
184
+ {
185
+ typedef typename remove_const<typename remove_volatile<T>::type>::type type;
186
+ }; // end remove_cv
187
+
188
+
189
+ template<typename T> struct is_reference : public false_type {};
190
+ template<typename T> struct is_reference<T&> : public true_type {};
191
+
192
+ template<typename T> struct is_proxy_reference : public false_type {};
193
+
194
+ template<typename T> struct is_device_reference : public false_type {};
195
+ template<typename T> struct is_device_reference< thrust::device_reference<T> > : public true_type {};
196
+
197
+
198
+ // NB: Careful with reference to void.
199
+ template<typename _Tp, bool = (is_void<_Tp>::value || is_reference<_Tp>::value)>
200
+ struct __add_reference_helper
201
+ { typedef _Tp& type; };
202
+
203
+ template<typename _Tp>
204
+ struct __add_reference_helper<_Tp, true>
205
+ { typedef _Tp type; };
206
+
207
+ template<typename _Tp>
208
+ struct add_reference
209
+ : public __add_reference_helper<_Tp>{};
210
+
211
+ template<typename T>
212
+ struct remove_reference
213
+ {
214
+ typedef T type;
215
+ }; // end remove_reference
216
+
217
+ template<typename T>
218
+ struct remove_reference<T&>
219
+ {
220
+ typedef T type;
221
+ }; // end remove_reference
222
+
223
+ template<typename T1, typename T2>
224
+ struct is_same
225
+ : public false_type
226
+ {
227
+ }; // end is_same
228
+
229
+ template<typename T>
230
+ struct is_same<T,T>
231
+ : public true_type
232
+ {
233
+ }; // end is_same
234
+
235
+ template<typename T1, typename T2>
236
+ struct lazy_is_same
237
+ : is_same<typename T1::type, typename T2::type>
238
+ {
239
+ }; // end lazy_is_same
240
+
241
+ template<typename T1, typename T2>
242
+ struct is_different
243
+ : public true_type
244
+ {
245
+ }; // end is_different
246
+
247
+ template<typename T>
248
+ struct is_different<T,T>
249
+ : public false_type
250
+ {
251
+ }; // end is_different
252
+
253
+ template<typename T1, typename T2>
254
+ struct lazy_is_different
255
+ : is_different<typename T1::type, typename T2::type>
256
+ {
257
+ }; // end lazy_is_different
258
+
259
+ #if THRUST_CPP_DIALECT >= 2011
260
+
261
+ template<class From, class To>
262
+ using is_convertible = ::cuda::std::is_convertible<From, To>;
263
+
264
+ #else
265
+
266
+ namespace tt_detail
267
+ {
268
+
269
+ template<typename T>
270
+ struct is_int_or_cref
271
+ {
272
+ typedef typename remove_reference<T>::type type_sans_ref;
273
+ static const bool value = (is_integral<T>::value
274
+ || (is_integral<type_sans_ref>::value
275
+ && is_const<type_sans_ref>::value
276
+ && !is_volatile<type_sans_ref>::value));
277
+ }; // end is_int_or_cref
278
+
279
+
280
+ THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN
281
+ THRUST_DISABLE_MSVC_FORCING_VALUE_TO_BOOL_WARNING_BEGIN
282
+
283
+ template<typename From, typename To>
284
+ struct is_convertible_sfinae
285
+ {
286
+ private:
287
+ typedef char yes;
288
+ typedef struct { char two_chars[2]; } no;
289
+
290
+ static inline yes test(To) { return yes(); }
291
+ static inline no test(...) { return no(); }
292
+ static inline typename remove_reference<From>::type& from() { typename remove_reference<From>::type* ptr = 0; return *ptr; }
293
+
294
+ public:
295
+ static const bool value = sizeof(test(from())) == sizeof(yes);
296
+ }; // end is_convertible_sfinae
297
+
298
+
299
+ THRUST_DISABLE_MSVC_FORCING_VALUE_TO_BOOL_WARNING_END
300
+ THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END
301
+
302
+
303
+ template<typename From, typename To>
304
+ struct is_convertible_needs_simple_test
305
+ {
306
+ static const bool from_is_void = is_void<From>::value;
307
+ static const bool to_is_void = is_void<To>::value;
308
+ static const bool from_is_float = is_floating_point<typename remove_reference<From>::type>::value;
309
+ static const bool to_is_int_or_cref = is_int_or_cref<To>::value;
310
+
311
+ static const bool value = (from_is_void || to_is_void || (from_is_float && to_is_int_or_cref));
312
+ }; // end is_convertible_needs_simple_test
313
+
314
+
315
+ template<typename From, typename To,
316
+ bool = is_convertible_needs_simple_test<From,To>::value>
317
+ struct is_convertible
318
+ {
319
+ static const bool value = (is_void<To>::value
320
+ || (is_int_or_cref<To>::value
321
+ && !is_void<From>::value));
322
+ }; // end is_convertible
323
+
324
+
325
+ template<typename From, typename To>
326
+ struct is_convertible<From, To, false>
327
+ {
328
+ static const bool value = (is_convertible_sfinae<typename
329
+ add_reference<From>::type, To>::value);
330
+ }; // end is_convertible
331
+
332
+
333
+ } // end tt_detail
334
+
335
+ template<typename From, typename To>
336
+ struct is_convertible
337
+ : public integral_constant<bool, tt_detail::is_convertible<From, To>::value>
338
+ {
339
+ }; // end is_convertible
340
+
341
+ #endif
342
+
343
+ template<typename T1, typename T2>
344
+ struct is_one_convertible_to_the_other
345
+ : public integral_constant<
346
+ bool,
347
+ is_convertible<T1,T2>::value || is_convertible<T2,T1>::value
348
+ >
349
+ {};
350
+
351
+
352
+ // mpl stuff
353
+ template<typename... Conditions>
354
+ struct or_;
355
+
356
+ template <>
357
+ struct or_<>
358
+ : public integral_constant<
359
+ bool,
360
+ false_type::value // identity for or_
361
+ >
362
+ {
363
+ }; // end or_
364
+
365
+ template <typename Condition, typename... Conditions>
366
+ struct or_<Condition, Conditions...>
367
+ : public integral_constant<
368
+ bool,
369
+ Condition::value || or_<Conditions...>::value
370
+ >
371
+ {
372
+ }; // end or_
373
+
374
+ template <typename... Conditions>
375
+ struct and_;
376
+
377
+ template<>
378
+ struct and_<>
379
+ : public integral_constant<
380
+ bool,
381
+ true_type::value // identity for and_
382
+ >
383
+ {
384
+ }; // end and_
385
+
386
+ template <typename Condition, typename... Conditions>
387
+ struct and_<Condition, Conditions...>
388
+ : public integral_constant<
389
+ bool,
390
+ Condition::value && and_<Conditions...>::value>
391
+ {
392
+ }; // end and_
393
+
394
+ template <typename Boolean>
395
+ struct not_
396
+ : public integral_constant<bool, !Boolean::value>
397
+ {
398
+ }; // end not_
399
+
400
+ template<bool B, class T, class F>
401
+ struct conditional { typedef T type; };
402
+
403
+ template<class T, class F>
404
+ struct conditional<false, T, F> { typedef F type; };
405
+
406
+ template <bool, typename Then, typename Else>
407
+ struct eval_if
408
+ {
409
+ }; // end eval_if
410
+
411
+ template<typename Then, typename Else>
412
+ struct eval_if<true, Then, Else>
413
+ {
414
+ typedef typename Then::type type;
415
+ }; // end eval_if
416
+
417
+ template<typename Then, typename Else>
418
+ struct eval_if<false, Then, Else>
419
+ {
420
+ typedef typename Else::type type;
421
+ }; // end eval_if
422
+
423
+ template<typename T>
424
+ // struct identity
425
+ // XXX WAR nvcc's confusion with thrust::identity
426
+ struct identity_
427
+ {
428
+ typedef T type;
429
+ }; // end identity
430
+
431
+ template<bool, typename T = void> struct enable_if {};
432
+ template<typename T> struct enable_if<true, T> {typedef T type;};
433
+
434
+ template<bool, typename T> struct lazy_enable_if {};
435
+ template<typename T> struct lazy_enable_if<true, T> {typedef typename T::type type;};
436
+
437
+ template<bool condition, typename T = void> struct disable_if : enable_if<!condition, T> {};
438
+ template<bool condition, typename T> struct lazy_disable_if : lazy_enable_if<!condition, T> {};
439
+
440
+
441
+ template<typename T1, typename T2, typename T = void>
442
+ struct enable_if_convertible
443
+ : enable_if< is_convertible<T1,T2>::value, T >
444
+ {};
445
+
446
+
447
+ template<typename T1, typename T2, typename T = void>
448
+ struct disable_if_convertible
449
+ : disable_if< is_convertible<T1,T2>::value, T >
450
+ {};
451
+
452
+
453
+ template<typename T1, typename T2, typename Result = void>
454
+ struct enable_if_different
455
+ : enable_if<is_different<T1,T2>::value, Result>
456
+ {};
457
+
458
+
459
+ template<typename T>
460
+ struct is_numeric
461
+ : and_<
462
+ is_convertible<int,T>,
463
+ is_convertible<T,int>
464
+ >
465
+ {
466
+ }; // end is_numeric
467
+
468
+
469
+ template<typename> struct is_reference_to_const : false_type {};
470
+ template<typename T> struct is_reference_to_const<const T&> : true_type {};
471
+
472
+
473
+ // make_unsigned follows
474
+
475
+ namespace tt_detail
476
+ {
477
+
478
+ template<typename T> struct make_unsigned_simple;
479
+
480
+ template<> struct make_unsigned_simple<char> { typedef unsigned char type; };
481
+ template<> struct make_unsigned_simple<signed char> { typedef unsigned char type; };
482
+ template<> struct make_unsigned_simple<unsigned char> { typedef unsigned char type; };
483
+ template<> struct make_unsigned_simple<short> { typedef unsigned short type; };
484
+ template<> struct make_unsigned_simple<unsigned short> { typedef unsigned short type; };
485
+ template<> struct make_unsigned_simple<int> { typedef unsigned int type; };
486
+ template<> struct make_unsigned_simple<unsigned int> { typedef unsigned int type; };
487
+ template<> struct make_unsigned_simple<long int> { typedef unsigned long int type; };
488
+ template<> struct make_unsigned_simple<unsigned long int> { typedef unsigned long int type; };
489
+ template<> struct make_unsigned_simple<long long int> { typedef unsigned long long int type; };
490
+ template<> struct make_unsigned_simple<unsigned long long int> { typedef unsigned long long int type; };
491
+
492
+ template<typename T>
493
+ struct make_unsigned_base
494
+ {
495
+ // remove cv
496
+ typedef typename remove_cv<T>::type remove_cv_t;
497
+
498
+ // get the simple unsigned type
499
+ typedef typename make_unsigned_simple<remove_cv_t>::type unsigned_remove_cv_t;
500
+
501
+ // add back const, volatile, both, or neither to the simple result
502
+ typedef typename eval_if<
503
+ is_const<T>::value && is_volatile<T>::value,
504
+ // add cv back
505
+ add_cv<unsigned_remove_cv_t>,
506
+ // check const & volatile individually
507
+ eval_if<
508
+ is_const<T>::value,
509
+ // add c back
510
+ add_const<unsigned_remove_cv_t>,
511
+ eval_if<
512
+ is_volatile<T>::value,
513
+ // add v back
514
+ add_volatile<unsigned_remove_cv_t>,
515
+ // original type was neither cv, return the simple unsigned result
516
+ identity_<unsigned_remove_cv_t>
517
+ >
518
+ >
519
+ >::type type;
520
+ };
521
+
522
+ } // end tt_detail
523
+
524
+ template<typename T>
525
+ struct make_unsigned
526
+ : tt_detail::make_unsigned_base<T>
527
+ {};
528
+
529
+ struct largest_available_float
530
+ {
531
+ typedef double type;
532
+ };
533
+
534
+ // T1 wins if they are both the same size
535
+ template<typename T1, typename T2>
536
+ struct larger_type
537
+ : thrust::detail::eval_if<
538
+ (sizeof(T2) > sizeof(T1)),
539
+ thrust::detail::identity_<T2>,
540
+ thrust::detail::identity_<T1>
541
+ >
542
+ {};
543
+
544
+ #if THRUST_CPP_DIALECT >= 2011
545
+
546
+ template<class Base, class Derived>
547
+ using is_base_of = ::cuda::std::is_base_of<Base, Derived>;
548
+
549
+ #else
550
+
551
+ namespace is_base_of_ns
552
+ {
553
+
554
+ typedef char yes;
555
+ typedef struct { char two_chars[2]; } no;
556
+
557
+ template<typename Base, typename Derived>
558
+ struct host
559
+ {
560
+ operator Base*() const;
561
+ operator Derived*();
562
+ }; // end host
563
+
564
+ template<typename Base, typename Derived>
565
+ struct impl
566
+ {
567
+ template<typename T> static yes check(Derived *, T);
568
+ static no check(Base*, int);
569
+
570
+ static const bool value = sizeof(check(host<Base,Derived>(), int())) == sizeof(yes);
571
+ }; // end impl
572
+
573
+ } // end is_base_of_ns
574
+
575
+
576
+ template<typename Base, typename Derived>
577
+ struct is_base_of
578
+ : integral_constant<
579
+ bool,
580
+ is_base_of_ns::impl<Base,Derived>::value
581
+ >
582
+ {};
583
+
584
+ #endif
585
+
586
+ template<typename Base, typename Derived, typename Result = void>
587
+ struct enable_if_base_of
588
+ : enable_if<
589
+ is_base_of<Base,Derived>::value,
590
+ Result
591
+ >
592
+ {};
593
+
594
+
595
+ namespace is_assignable_ns
596
+ {
597
+
598
+ template<typename T1, typename T2>
599
+ class is_assignable
600
+ {
601
+ typedef char yes_type;
602
+ typedef struct { char array[2]; } no_type;
603
+
604
+ template<typename T> static typename add_reference<T>::type declval();
605
+
606
+ template<size_t> struct helper { typedef void * type; };
607
+
608
+ template<typename U1, typename U2> static yes_type test(typename helper<sizeof(declval<U1>() = declval<U2>())>::type);
609
+
610
+ template<typename,typename> static no_type test(...);
611
+
612
+ public:
613
+ static const bool value = sizeof(test<T1,T2>(0)) == 1;
614
+ }; // end is_assignable
615
+
616
+ } // end is_assignable_ns
617
+
618
+
619
+ template<typename T1, typename T2>
620
+ struct is_assignable
621
+ : integral_constant<
622
+ bool,
623
+ is_assignable_ns::is_assignable<T1,T2>::value
624
+ >
625
+ {};
626
+
627
+
628
+ template<typename T>
629
+ struct is_copy_assignable
630
+ : is_assignable<
631
+ typename add_reference<T>::type,
632
+ typename add_reference<typename add_const<T>::type>::type
633
+ >
634
+ {};
635
+
636
+
637
+ template<typename T1, typename T2, typename Enable = void> struct promoted_numerical_type;
638
+
639
+ template<typename T1, typename T2>
640
+ struct promoted_numerical_type<T1,T2,typename enable_if<and_
641
+ <typename is_floating_point<T1>::type, typename is_floating_point<T2>::type>
642
+ ::value>::type>
643
+ {
644
+ typedef typename larger_type<T1,T2>::type type;
645
+ };
646
+
647
+ template<typename T1, typename T2>
648
+ struct promoted_numerical_type<T1,T2,typename enable_if<and_
649
+ <typename is_integral<T1>::type, typename is_floating_point<T2>::type>
650
+ ::value>::type>
651
+ {
652
+ typedef T2 type;
653
+ };
654
+
655
+ template<typename T1, typename T2>
656
+ struct promoted_numerical_type<T1,T2,typename enable_if<and_
657
+ <typename is_floating_point<T1>::type, typename is_integral<T2>::type>
658
+ ::value>::type>
659
+ {
660
+ typedef T1 type;
661
+ };
662
+
663
+ template<typename T>
664
+ struct is_empty_helper : public T
665
+ {
666
+ };
667
+
668
+ struct is_empty_helper_base
669
+ {
670
+ };
671
+
672
+ template<typename T>
673
+ struct is_empty : integral_constant<bool,
674
+ sizeof(is_empty_helper_base) == sizeof(is_empty_helper<T>)
675
+ >
676
+ {
677
+ };
678
+
679
+ template <typename Invokable, typename... Args>
680
+ using invoke_result_t =
681
+ #if THRUST_CPP_DIALECT < 2017
682
+ typename ::cuda::std::result_of<Invokable(Args...)>::type;
683
+ #else // 2017+
684
+ ::cuda::std::invoke_result_t<Invokable, Args...>;
685
+ #endif
686
+
687
+ template <class F, class... Us>
688
+ struct invoke_result
689
+ {
690
+ using type = invoke_result_t<F, Us...>;
691
+ };
692
+
693
+ } // end detail
694
+
695
+ using detail::integral_constant;
696
+ using detail::true_type;
697
+ using detail::false_type;
698
+
699
+ THRUST_NAMESPACE_END
700
+
701
+ #include <thrust/detail/type_traits/has_trivial_assign.h>
miniCUDA124/include/thrust/detail/uninitialized_copy.inl ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/uninitialized_copy.h>
30
+ #include <thrust/iterator/iterator_traits.h>
31
+ #include <thrust/system/detail/generic/select_system.h>
32
+ #include <thrust/system/detail/generic/uninitialized_copy.h>
33
+ #include <thrust/system/detail/adl/uninitialized_copy.h>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+
38
+ __thrust_exec_check_disable__
39
+ template<typename DerivedPolicy, typename InputIterator, typename ForwardIterator>
40
+ __host__ __device__
41
+ ForwardIterator uninitialized_copy(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
42
+ InputIterator first,
43
+ InputIterator last,
44
+ ForwardIterator result)
45
+ {
46
+ using thrust::system::detail::generic::uninitialized_copy;
47
+ return uninitialized_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result);
48
+ } // end uninitialized_copy()
49
+
50
+
51
+ __thrust_exec_check_disable__
52
+ template<typename DerivedPolicy, typename InputIterator, typename Size, typename ForwardIterator>
53
+ __host__ __device__
54
+ ForwardIterator uninitialized_copy_n(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
55
+ InputIterator first,
56
+ Size n,
57
+ ForwardIterator result)
58
+ {
59
+ using thrust::system::detail::generic::uninitialized_copy_n;
60
+ return uninitialized_copy_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, result);
61
+ } // end uninitialized_copy_n()
62
+
63
+
64
+ template<typename InputIterator,
65
+ typename ForwardIterator>
66
+ ForwardIterator uninitialized_copy(InputIterator first,
67
+ InputIterator last,
68
+ ForwardIterator result)
69
+ {
70
+ using thrust::system::detail::generic::select_system;
71
+
72
+ typedef typename thrust::iterator_system<InputIterator>::type System1;
73
+ typedef typename thrust::iterator_system<ForwardIterator>::type System2;
74
+
75
+ System1 system1;
76
+ System2 system2;
77
+
78
+ return thrust::uninitialized_copy(select_system(system1,system2), first, last, result);
79
+ } // end uninitialized_copy()
80
+
81
+
82
+ template<typename InputIterator,
83
+ typename Size,
84
+ typename ForwardIterator>
85
+ ForwardIterator uninitialized_copy_n(InputIterator first,
86
+ Size n,
87
+ ForwardIterator result)
88
+ {
89
+ using thrust::system::detail::generic::select_system;
90
+
91
+ typedef typename thrust::iterator_system<InputIterator>::type System1;
92
+ typedef typename thrust::iterator_system<ForwardIterator>::type System2;
93
+
94
+ System1 system1;
95
+ System2 system2;
96
+
97
+ return thrust::uninitialized_copy_n(select_system(system1,system2), first, n, result);
98
+ } // end uninitialized_copy_n()
99
+
100
+
101
+ THRUST_NAMESPACE_END
102
+
103
+
miniCUDA124/include/thrust/detail/uninitialized_fill.inl ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ #include <thrust/uninitialized_fill.h>
30
+ #include <thrust/iterator/iterator_traits.h>
31
+ #include <thrust/system/detail/generic/select_system.h>
32
+ #include <thrust/system/detail/generic/uninitialized_fill.h>
33
+ #include <thrust/system/detail/adl/uninitialized_fill.h>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+
38
+ __thrust_exec_check_disable__
39
+ template<typename DerivedPolicy, typename ForwardIterator, typename T>
40
+ __host__ __device__
41
+ void uninitialized_fill(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
42
+ ForwardIterator first,
43
+ ForwardIterator last,
44
+ const T &x)
45
+ {
46
+ using thrust::system::detail::generic::uninitialized_fill;
47
+ return uninitialized_fill(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, x);
48
+ } // end uninitialized_fill()
49
+
50
+
51
+ __thrust_exec_check_disable__
52
+ template<typename DerivedPolicy, typename ForwardIterator, typename Size, typename T>
53
+ __host__ __device__
54
+ ForwardIterator uninitialized_fill_n(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
55
+ ForwardIterator first,
56
+ Size n,
57
+ const T &x)
58
+ {
59
+ using thrust::system::detail::generic::uninitialized_fill_n;
60
+ return uninitialized_fill_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, x);
61
+ } // end uninitialized_fill_n()
62
+
63
+
64
+ template<typename ForwardIterator,
65
+ typename T>
66
+ void uninitialized_fill(ForwardIterator first,
67
+ ForwardIterator last,
68
+ const T &x)
69
+ {
70
+ using thrust::system::detail::generic::select_system;
71
+
72
+ typedef typename thrust::iterator_system<ForwardIterator>::type System;
73
+
74
+ System system;
75
+
76
+ thrust::uninitialized_fill(select_system(system), first, last, x);
77
+ } // end uninitialized_fill()
78
+
79
+
80
+ template<typename ForwardIterator,
81
+ typename Size,
82
+ typename T>
83
+ ForwardIterator uninitialized_fill_n(ForwardIterator first,
84
+ Size n,
85
+ const T &x)
86
+ {
87
+ using thrust::system::detail::generic::select_system;
88
+
89
+ typedef typename thrust::iterator_system<ForwardIterator>::type System;
90
+
91
+ System system;
92
+
93
+ return thrust::uninitialized_fill_n(select_system(system), first, n, x);
94
+ } // end uninitialized_fill_n()
95
+
96
+
97
+ THRUST_NAMESPACE_END
98
+
miniCUDA124/include/thrust/detail/unique.inl ADDED
@@ -0,0 +1,401 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+ #include <thrust/unique.h>
29
+ #include <thrust/iterator/iterator_traits.h>
30
+ #include <thrust/system/detail/generic/select_system.h>
31
+ #include <thrust/system/detail/generic/unique.h>
32
+ #include <thrust/system/detail/generic/unique_by_key.h>
33
+ #include <thrust/system/detail/adl/unique.h>
34
+ #include <thrust/system/detail/adl/unique_by_key.h>
35
+
36
+ THRUST_NAMESPACE_BEGIN
37
+
38
+
39
+ __thrust_exec_check_disable__
40
+ template<typename DerivedPolicy,
41
+ typename ForwardIterator>
42
+ __host__ __device__
43
+ ForwardIterator unique(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
44
+ ForwardIterator first,
45
+ ForwardIterator last)
46
+ {
47
+ using thrust::system::detail::generic::unique;
48
+ return unique(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
49
+ } // end unique()
50
+
51
+
52
+ __thrust_exec_check_disable__
53
+ template<typename DerivedPolicy,
54
+ typename ForwardIterator,
55
+ typename BinaryPredicate>
56
+ __host__ __device__
57
+ ForwardIterator unique(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
58
+ ForwardIterator first,
59
+ ForwardIterator last,
60
+ BinaryPredicate binary_pred)
61
+ {
62
+ using thrust::system::detail::generic::unique;
63
+ return unique(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, binary_pred);
64
+ } // end unique()
65
+
66
+
67
+ __thrust_exec_check_disable__
68
+ template<typename DerivedPolicy,
69
+ typename InputIterator,
70
+ typename OutputIterator>
71
+ __host__ __device__
72
+ OutputIterator unique_copy(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
73
+ InputIterator first,
74
+ InputIterator last,
75
+ OutputIterator output)
76
+ {
77
+ using thrust::system::detail::generic::unique_copy;
78
+ return unique_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, output);
79
+ } // end unique_copy()
80
+
81
+
82
+ __thrust_exec_check_disable__
83
+ template<typename DerivedPolicy,
84
+ typename InputIterator,
85
+ typename OutputIterator,
86
+ typename BinaryPredicate>
87
+ __host__ __device__
88
+ OutputIterator unique_copy(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
89
+ InputIterator first,
90
+ InputIterator last,
91
+ OutputIterator output,
92
+ BinaryPredicate binary_pred)
93
+ {
94
+ using thrust::system::detail::generic::unique_copy;
95
+ return unique_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, output, binary_pred);
96
+ } // end unique_copy()
97
+
98
+
99
+ __thrust_exec_check_disable__
100
+ template<typename DerivedPolicy,
101
+ typename ForwardIterator1,
102
+ typename ForwardIterator2>
103
+ __host__ __device__
104
+ thrust::pair<ForwardIterator1,ForwardIterator2>
105
+ unique_by_key(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
106
+ ForwardIterator1 keys_first,
107
+ ForwardIterator1 keys_last,
108
+ ForwardIterator2 values_first)
109
+ {
110
+ using thrust::system::detail::generic::unique_by_key;
111
+ return unique_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first);
112
+ } // end unique_by_key()
113
+
114
+
115
+ __thrust_exec_check_disable__
116
+ template<typename DerivedPolicy,
117
+ typename ForwardIterator1,
118
+ typename ForwardIterator2,
119
+ typename BinaryPredicate>
120
+ __host__ __device__
121
+ thrust::pair<ForwardIterator1,ForwardIterator2>
122
+ unique_by_key(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
123
+ ForwardIterator1 keys_first,
124
+ ForwardIterator1 keys_last,
125
+ ForwardIterator2 values_first,
126
+ BinaryPredicate binary_pred)
127
+ {
128
+ using thrust::system::detail::generic::unique_by_key;
129
+ return unique_by_key(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, binary_pred);
130
+ } // end unique_by_key()
131
+
132
+
133
+ __thrust_exec_check_disable__
134
+ template<typename DerivedPolicy,
135
+ typename InputIterator1,
136
+ typename InputIterator2,
137
+ typename OutputIterator1,
138
+ typename OutputIterator2>
139
+ __host__ __device__
140
+ thrust::pair<OutputIterator1,OutputIterator2>
141
+ unique_by_key_copy(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
142
+ InputIterator1 keys_first,
143
+ InputIterator1 keys_last,
144
+ InputIterator2 values_first,
145
+ OutputIterator1 keys_output,
146
+ OutputIterator2 values_output)
147
+ {
148
+ using thrust::system::detail::generic::unique_by_key_copy;
149
+ return unique_by_key_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, keys_output, values_output);
150
+ } // end unique_by_key_copy()
151
+
152
+
153
+ __thrust_exec_check_disable__
154
+ template<typename DerivedPolicy,
155
+ typename InputIterator1,
156
+ typename InputIterator2,
157
+ typename OutputIterator1,
158
+ typename OutputIterator2,
159
+ typename BinaryPredicate>
160
+ __host__ __device__
161
+ thrust::pair<OutputIterator1,OutputIterator2>
162
+ unique_by_key_copy(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
163
+ InputIterator1 keys_first,
164
+ InputIterator1 keys_last,
165
+ InputIterator2 values_first,
166
+ OutputIterator1 keys_output,
167
+ OutputIterator2 values_output,
168
+ BinaryPredicate binary_pred)
169
+ {
170
+ using thrust::system::detail::generic::unique_by_key_copy;
171
+ return unique_by_key_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, keys_output, values_output, binary_pred);
172
+ } // end unique_by_key_copy()
173
+
174
+
175
+ template<typename ForwardIterator>
176
+ ForwardIterator unique(ForwardIterator first,
177
+ ForwardIterator last)
178
+ {
179
+ using thrust::system::detail::generic::select_system;
180
+
181
+ typedef typename thrust::iterator_system<ForwardIterator>::type System;
182
+
183
+ System system;
184
+
185
+ return thrust::unique(select_system(system), first, last);
186
+ } // end unique()
187
+
188
+
189
+ template<typename ForwardIterator,
190
+ typename BinaryPredicate>
191
+ ForwardIterator unique(ForwardIterator first,
192
+ ForwardIterator last,
193
+ BinaryPredicate binary_pred)
194
+ {
195
+ using thrust::system::detail::generic::select_system;
196
+
197
+ typedef typename thrust::iterator_system<ForwardIterator>::type System;
198
+
199
+ System system;
200
+
201
+ return thrust::unique(select_system(system), first, last, binary_pred);
202
+ } // end unique()
203
+
204
+
205
+ template<typename InputIterator,
206
+ typename OutputIterator>
207
+ OutputIterator unique_copy(InputIterator first,
208
+ InputIterator last,
209
+ OutputIterator output)
210
+ {
211
+ using thrust::system::detail::generic::select_system;
212
+
213
+ typedef typename thrust::iterator_system<InputIterator>::type System1;
214
+ typedef typename thrust::iterator_system<OutputIterator>::type System2;
215
+
216
+ System1 system1;
217
+ System2 system2;
218
+
219
+ return thrust::unique_copy(select_system(system1,system2), first, last, output);
220
+ } // end unique_copy()
221
+
222
+
223
+ template<typename InputIterator,
224
+ typename OutputIterator,
225
+ typename BinaryPredicate>
226
+ OutputIterator unique_copy(InputIterator first,
227
+ InputIterator last,
228
+ OutputIterator output,
229
+ BinaryPredicate binary_pred)
230
+ {
231
+ using thrust::system::detail::generic::select_system;
232
+
233
+ typedef typename thrust::iterator_system<InputIterator>::type System1;
234
+ typedef typename thrust::iterator_system<OutputIterator>::type System2;
235
+
236
+ System1 system1;
237
+ System2 system2;
238
+
239
+ return thrust::unique_copy(select_system(system1,system2), first, last, output, binary_pred);
240
+ } // end unique_copy()
241
+
242
+
243
+ template<typename ForwardIterator1,
244
+ typename ForwardIterator2>
245
+ thrust::pair<ForwardIterator1,ForwardIterator2>
246
+ unique_by_key(ForwardIterator1 keys_first,
247
+ ForwardIterator1 keys_last,
248
+ ForwardIterator2 values_first)
249
+ {
250
+ using thrust::system::detail::generic::select_system;
251
+
252
+ typedef typename thrust::iterator_system<ForwardIterator1>::type System1;
253
+ typedef typename thrust::iterator_system<ForwardIterator2>::type System2;
254
+
255
+ System1 system1;
256
+ System2 system2;
257
+
258
+ return thrust::unique_by_key(select_system(system1,system2), keys_first, keys_last, values_first);
259
+ } // end unique_by_key()
260
+
261
+
262
+ template<typename ForwardIterator1,
263
+ typename ForwardIterator2,
264
+ typename BinaryPredicate>
265
+ thrust::pair<ForwardIterator1,ForwardIterator2>
266
+ unique_by_key(ForwardIterator1 keys_first,
267
+ ForwardIterator1 keys_last,
268
+ ForwardIterator2 values_first,
269
+ BinaryPredicate binary_pred)
270
+ {
271
+ using thrust::system::detail::generic::select_system;
272
+
273
+ typedef typename thrust::iterator_system<ForwardIterator1>::type System1;
274
+ typedef typename thrust::iterator_system<ForwardIterator2>::type System2;
275
+
276
+ System1 system1;
277
+ System2 system2;
278
+
279
+ return thrust::unique_by_key(select_system(system1,system2), keys_first, keys_last, values_first, binary_pred);
280
+ } // end unique_by_key()
281
+
282
+
283
+ template<typename InputIterator1,
284
+ typename InputIterator2,
285
+ typename OutputIterator1,
286
+ typename OutputIterator2>
287
+ thrust::pair<OutputIterator1,OutputIterator2>
288
+ unique_by_key_copy(InputIterator1 keys_first,
289
+ InputIterator1 keys_last,
290
+ InputIterator2 values_first,
291
+ OutputIterator1 keys_output,
292
+ OutputIterator2 values_output)
293
+ {
294
+ using thrust::system::detail::generic::select_system;
295
+
296
+ typedef typename thrust::iterator_system<InputIterator1>::type System1;
297
+ typedef typename thrust::iterator_system<InputIterator2>::type System2;
298
+ typedef typename thrust::iterator_system<OutputIterator1>::type System3;
299
+ typedef typename thrust::iterator_system<OutputIterator2>::type System4;
300
+
301
+ System1 system1;
302
+ System2 system2;
303
+ System3 system3;
304
+ System4 system4;
305
+
306
+ return thrust::unique_by_key_copy(select_system(system1,system2,system3,system4), keys_first, keys_last, values_first, keys_output, values_output);
307
+ } // end unique_by_key_copy()
308
+
309
+
310
+ template<typename InputIterator1,
311
+ typename InputIterator2,
312
+ typename OutputIterator1,
313
+ typename OutputIterator2,
314
+ typename BinaryPredicate>
315
+ thrust::pair<OutputIterator1,OutputIterator2>
316
+ unique_by_key_copy(InputIterator1 keys_first,
317
+ InputIterator1 keys_last,
318
+ InputIterator2 values_first,
319
+ OutputIterator1 keys_output,
320
+ OutputIterator2 values_output,
321
+ BinaryPredicate binary_pred)
322
+ {
323
+ using thrust::system::detail::generic::select_system;
324
+
325
+ typedef typename thrust::iterator_system<InputIterator1>::type System1;
326
+ typedef typename thrust::iterator_system<InputIterator2>::type System2;
327
+ typedef typename thrust::iterator_system<OutputIterator1>::type System3;
328
+ typedef typename thrust::iterator_system<OutputIterator2>::type System4;
329
+
330
+ System1 system1;
331
+ System2 system2;
332
+ System3 system3;
333
+ System4 system4;
334
+
335
+ return thrust::unique_by_key_copy(select_system(system1,system2,system3,system4), keys_first, keys_last, values_first, keys_output, values_output, binary_pred);
336
+ } // end unique_by_key_copy()
337
+
338
+ __thrust_exec_check_disable__
339
+ template <typename DerivedPolicy,
340
+ typename ForwardIterator,
341
+ typename BinaryPredicate>
342
+ __host__ __device__
343
+ typename thrust::iterator_traits<ForwardIterator>::difference_type
344
+ unique_count(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
345
+ ForwardIterator first,
346
+ ForwardIterator last,
347
+ BinaryPredicate binary_pred)
348
+ {
349
+ using thrust::system::detail::generic::unique_count;
350
+ return unique_count(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, binary_pred);
351
+ } // end unique_count()
352
+
353
+ __thrust_exec_check_disable__
354
+ template <typename DerivedPolicy,
355
+ typename ForwardIterator>
356
+ __host__ __device__
357
+ typename thrust::iterator_traits<ForwardIterator>::difference_type
358
+ unique_count(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
359
+ ForwardIterator first,
360
+ ForwardIterator last)
361
+ {
362
+ using thrust::system::detail::generic::unique_count;
363
+ return unique_count(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
364
+ } // end unique_count()
365
+
366
+ __thrust_exec_check_disable__
367
+ template <typename ForwardIterator,
368
+ typename BinaryPredicate>
369
+ __host__ __device__
370
+ typename thrust::iterator_traits<ForwardIterator>::difference_type
371
+ unique_count(ForwardIterator first,
372
+ ForwardIterator last,
373
+ BinaryPredicate binary_pred)
374
+ {
375
+ using thrust::system::detail::generic::select_system;
376
+
377
+ typedef typename thrust::iterator_system<ForwardIterator>::type System;
378
+
379
+ System system;
380
+
381
+ return thrust::unique_count(select_system(system), first, last, binary_pred);
382
+ } // end unique_count()
383
+
384
+ __thrust_exec_check_disable__
385
+ template <typename ForwardIterator>
386
+ __host__ __device__
387
+ typename thrust::iterator_traits<ForwardIterator>::difference_type
388
+ unique_count(ForwardIterator first,
389
+ ForwardIterator last)
390
+ {
391
+ using thrust::system::detail::generic::select_system;
392
+
393
+ typedef typename thrust::iterator_system<ForwardIterator>::type System;
394
+
395
+ System system;
396
+
397
+ return thrust::unique_count(select_system(system), first, last);
398
+ } // end unique_count()
399
+
400
+ THRUST_NAMESPACE_END
401
+
miniCUDA124/include/thrust/iterator/constant_iterator.h ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file thrust/iterator/constant_iterator.h
19
+ * \brief An iterator which returns a constant value when
20
+ * dereferenced
21
+ */
22
+
23
+ #pragma once
24
+
25
+ #include <thrust/detail/config.h>
26
+
27
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
28
+ # pragma GCC system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
30
+ # pragma clang system_header
31
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
32
+ # pragma system_header
33
+ #endif // no system header
34
+ #include <thrust/iterator/detail/constant_iterator_base.h>
35
+ #include <thrust/iterator/iterator_facade.h>
36
+
37
+ THRUST_NAMESPACE_BEGIN
38
+
39
+ /*! \addtogroup iterators
40
+ * \{
41
+ */
42
+
43
+ /*! \addtogroup fancyiterator Fancy Iterators
44
+ * \ingroup iterators
45
+ * \{
46
+ */
47
+
48
+ /*! \p constant_iterator is an iterator which represents a pointer into a range
49
+ * of constant values. This iterator is useful for creating a range filled with the same
50
+ * value without explicitly storing it in memory. Using \p constant_iterator saves both
51
+ * memory capacity and bandwidth.
52
+ *
53
+ * The following code snippet demonstrates how to create a \p constant_iterator whose
54
+ * \c value_type is \c int and whose value is \c 10.
55
+ *
56
+ * \code
57
+ * #include <thrust/iterator/constant_iterator.h>
58
+ *
59
+ * thrust::constant_iterator<int> iter(10);
60
+ *
61
+ * *iter; // returns 10
62
+ * iter[0]; // returns 10
63
+ * iter[1]; // returns 10
64
+ * iter[13]; // returns 10
65
+ *
66
+ * // and so on...
67
+ * \endcode
68
+ *
69
+ * This next example demonstrates how to use a \p constant_iterator with the
70
+ * \p thrust::transform function to increment all elements of a sequence by the
71
+ * same value. We will create a temporary \p constant_iterator with the function
72
+ * \p make_constant_iterator function in order to avoid explicitly specifying
73
+ * its type:
74
+ *
75
+ * \code
76
+ * #include <thrust/iterator/constant_iterator.h>
77
+ * #include <thrust/transform.h>
78
+ * #include <thrust/functional.h>
79
+ * #include <thrust/device_vector.h>
80
+ *
81
+ * int main()
82
+ * {
83
+ * thrust::device_vector<int> data(4);
84
+ * data[0] = 3;
85
+ * data[1] = 7;
86
+ * data[2] = 2;
87
+ * data[3] = 5;
88
+ *
89
+ * // add 10 to all values in data
90
+ * thrust::transform(data.begin(), data.end(),
91
+ * thrust::make_constant_iterator(10),
92
+ * data.begin(),
93
+ * thrust::plus<int>());
94
+ *
95
+ * // data is now [13, 17, 12, 15]
96
+ *
97
+ * return 0;
98
+ * }
99
+ * \endcode
100
+ *
101
+ * \see make_constant_iterator
102
+ */
103
+ template<typename Value,
104
+ typename Incrementable = use_default,
105
+ typename System = use_default>
106
+ class constant_iterator
107
+ : public detail::constant_iterator_base<Value, Incrementable, System>::type
108
+ {
109
+ /*! \cond
110
+ */
111
+ friend class thrust::iterator_core_access;
112
+ typedef typename detail::constant_iterator_base<Value, Incrementable, System>::type super_t;
113
+ typedef typename detail::constant_iterator_base<Value, Incrementable, System>::incrementable incrementable;
114
+ typedef typename detail::constant_iterator_base<Value, Incrementable, System>::base_iterator base_iterator;
115
+
116
+ public:
117
+ typedef typename super_t::reference reference;
118
+ typedef typename super_t::value_type value_type;
119
+
120
+ /*! \endcond
121
+ */
122
+
123
+ /*! Null constructor initializes this \p constant_iterator's constant using its
124
+ * null constructor.
125
+ */
126
+ __host__ __device__
127
+ constant_iterator()
128
+ : super_t(), m_value() {}
129
+
130
+ /*! Copy constructor copies the value of another \p constant_iterator into this
131
+ * \p constant_iterator.
132
+ *
133
+ * \p rhs The constant_iterator to copy.
134
+ */
135
+ __host__ __device__
136
+ constant_iterator(constant_iterator const &rhs)
137
+ : super_t(rhs.base()), m_value(rhs.m_value) {}
138
+
139
+ /*! Copy constructor copies the value of another \p constant_iterator with related
140
+ * System type.
141
+ *
142
+ * \param rhs The \p constant_iterator to copy.
143
+ */
144
+ template<typename OtherSystem>
145
+ __host__ __device__
146
+ constant_iterator(constant_iterator<Value,Incrementable,OtherSystem> const &rhs,
147
+ typename thrust::detail::enable_if_convertible<
148
+ typename thrust::iterator_system<constant_iterator<Value,Incrementable,OtherSystem> >::type,
149
+ typename thrust::iterator_system<super_t>::type
150
+ >::type * = 0)
151
+ : super_t(rhs.base()), m_value(rhs.value()) {}
152
+
153
+ /*! This constructor receives a value to use as the constant value of this
154
+ * \p constant_iterator and an index specifying the location of this
155
+ * \p constant_iterator in a sequence.
156
+ *
157
+ * \p v The value of this \p constant_iterator's constant value.
158
+ * \p i The index of this \p constant_iterator in a sequence. Defaults to the
159
+ * value returned by \c Incrementable's null constructor. For example,
160
+ * when <tt>Incrementable == int</tt>, \c 0.
161
+ */
162
+ __host__ __device__
163
+ constant_iterator(value_type const& v, incrementable const &i = incrementable())
164
+ : super_t(base_iterator(i)), m_value(v) {}
165
+
166
+ /*! This constructor is templated to allow construction from a value type and
167
+ * incrementable type related this this \p constant_iterator's respective types.
168
+ *
169
+ * \p v The value of this \p constant_iterator's constant value.
170
+ * \p i The index of this \p constant_iterator in a sequence. Defaults to the
171
+ * value returned by \c Incrementable's null constructor. For example,
172
+ * when <tt>Incrementable == int</tt>, \c 0.
173
+ */
174
+ template<typename OtherValue, typename OtherIncrementable>
175
+ __host__ __device__
176
+ constant_iterator(OtherValue const& v, OtherIncrementable const& i = incrementable())
177
+ : super_t(base_iterator(i)), m_value(v) {}
178
+
179
+ /*! This method returns the value of this \p constant_iterator's constant value.
180
+ * \return A \c const reference to this \p constant_iterator's constant value.
181
+ */
182
+ __host__ __device__
183
+ Value const& value() const
184
+ { return m_value; }
185
+
186
+ /*! \cond
187
+ */
188
+
189
+ protected:
190
+ __host__ __device__
191
+ Value const& value_reference() const
192
+ { return m_value; }
193
+
194
+ __host__ __device__
195
+ Value & value_reference()
196
+ { return m_value; }
197
+
198
+ private: // Core iterator interface
199
+ __host__ __device__
200
+ reference dereference() const
201
+ {
202
+ return m_value;
203
+ }
204
+
205
+ private:
206
+ Value m_value;
207
+
208
+ /*! \endcond
209
+ */
210
+ }; // end constant_iterator
211
+
212
+
213
+ /*! This version of \p make_constant_iterator creates a \p constant_iterator
214
+ * from values given for both value and index. The type of \p constant_iterator
215
+ * may be inferred by the compiler from the types of its parameters.
216
+ *
217
+ * \param x The value of the returned \p constant_iterator's constant value.
218
+ * \param i The index of the returned \p constant_iterator within a sequence.
219
+ * The type of this parameter defaults to \c int. In the default case,
220
+ * the value of this parameter is \c 0.
221
+ *
222
+ * \return A new \p constant_iterator with constant value & index as given
223
+ * by \p x & \p i.
224
+ *
225
+ * \see constant_iterator
226
+ */
227
+ template<typename ValueT, typename IndexT>
228
+ inline __host__ __device__
229
+ constant_iterator<ValueT, IndexT> make_constant_iterator(ValueT x, IndexT i = int())
230
+ {
231
+ return constant_iterator<ValueT, IndexT>(x, i);
232
+ } // end make_constant_iterator()
233
+
234
+
235
+ /*! This version of \p make_constant_iterator creates a \p constant_iterator
236
+ * using only a parameter for the desired constant value. The value of the
237
+ * returned \p constant_iterator's index is set to \c 0.
238
+ *
239
+ * \param x The value of the returned \p constant_iterator's constant value.
240
+ * \return A new \p constant_iterator with constant value equal to \p x and
241
+ * index equal to \c 0.
242
+ * \see constant_iterator
243
+ */
244
+ template<typename V>
245
+ inline __host__ __device__
246
+ constant_iterator<V> make_constant_iterator(V x)
247
+ {
248
+ return constant_iterator<V>(x, 0);
249
+ } // end make_constant_iterator()
250
+
251
+ /*! \} // end fancyiterators
252
+ */
253
+
254
+ /*! \} // end iterators
255
+ */
256
+
257
+ THRUST_NAMESPACE_END
258
+
miniCUDA124/include/thrust/iterator/counting_iterator.h ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file thrust/iterator/counting_iterator.h
19
+ * \brief An iterator which returns an increasing incrementable value
20
+ * when dereferenced
21
+ */
22
+
23
+ /*
24
+ * Copyright David Abrahams 2003.
25
+ *
26
+ * Distributed under the Boost Software License, Version 1.0.
27
+ * (See accompanying NOTICE file for the complete license)
28
+ *
29
+ * For more information, see http://www.boost.org
30
+ */
31
+
32
+ #pragma once
33
+
34
+ #include <thrust/detail/config.h>
35
+
36
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
37
+ # pragma GCC system_header
38
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
39
+ # pragma clang system_header
40
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
41
+ # pragma system_header
42
+ #endif // no system header
43
+ #include <thrust/iterator/iterator_adaptor.h>
44
+ #include <thrust/iterator/iterator_facade.h>
45
+ #include <thrust/iterator/iterator_categories.h>
46
+
47
+ // #include the details first
48
+ #include <thrust/iterator/detail/counting_iterator.inl>
49
+
50
+ THRUST_NAMESPACE_BEGIN
51
+
52
+ /*! \addtogroup iterators
53
+ * \{
54
+ */
55
+
56
+ /*! \addtogroup fancyiterator Fancy Iterators
57
+ * \ingroup iterators
58
+ * \{
59
+ */
60
+
61
+ /*! \p counting_iterator is an iterator which represents a pointer into a range
62
+ * of sequentially changing values. This iterator is useful for creating a range
63
+ * filled with a sequence without explicitly storing it in memory. Using
64
+ * \p counting_iterator saves memory capacity and bandwidth.
65
+ *
66
+ * The following code snippet demonstrates how to create a \p counting_iterator whose
67
+ * \c value_type is \c int and which sequentially increments by \c 1.
68
+ *
69
+ * \code
70
+ * #include <thrust/iterator/counting_iterator.h>
71
+ * ...
72
+ * // create iterators
73
+ * thrust::counting_iterator<int> first(10);
74
+ * thrust::counting_iterator<int> last = first + 3;
75
+ *
76
+ * first[0] // returns 10
77
+ * first[1] // returns 11
78
+ * first[100] // returns 110
79
+ *
80
+ * // sum of [first, last)
81
+ * thrust::reduce(first, last); // returns 33 (i.e. 10 + 11 + 12)
82
+ *
83
+ * // initialize vector to [0,1,2,..]
84
+ * thrust::counting_iterator<int> iter(0);
85
+ * thrust::device_vector<int> vec(500);
86
+ * thrust::copy(iter, iter + vec.size(), vec.begin());
87
+ * \endcode
88
+ *
89
+ * This next example demonstrates how to use a \p counting_iterator with the
90
+ * \p thrust::copy_if function to compute the indices of the non-zero elements
91
+ * of a \p device_vector. In this example, we use the \p make_counting_iterator
92
+ * function to avoid specifying the type of the \p counting_iterator.
93
+ *
94
+ * \code
95
+ * #include <thrust/iterator/counting_iterator.h>
96
+ * #include <thrust/copy.h>
97
+ * #include <thrust/functional.h>
98
+ * #include <thrust/device_vector.h>
99
+ *
100
+ * int main()
101
+ * {
102
+ * // this example computes indices for all the nonzero values in a sequence
103
+ *
104
+ * // sequence of zero and nonzero values
105
+ * thrust::device_vector<int> stencil(8);
106
+ * stencil[0] = 0;
107
+ * stencil[1] = 1;
108
+ * stencil[2] = 1;
109
+ * stencil[3] = 0;
110
+ * stencil[4] = 0;
111
+ * stencil[5] = 1;
112
+ * stencil[6] = 0;
113
+ * stencil[7] = 1;
114
+ *
115
+ * // storage for the nonzero indices
116
+ * thrust::device_vector<int> indices(8);
117
+ *
118
+ * // compute indices of nonzero elements
119
+ * typedef thrust::device_vector<int>::iterator IndexIterator;
120
+ *
121
+ * // use make_counting_iterator to define the sequence [0, 8)
122
+ * IndexIterator indices_end = thrust::copy_if(thrust::make_counting_iterator(0),
123
+ * thrust::make_counting_iterator(8),
124
+ * stencil.begin(),
125
+ * indices.begin(),
126
+ * thrust::identity<int>());
127
+ * // indices now contains [1,2,5,7]
128
+ *
129
+ * return 0;
130
+ * }
131
+ * \endcode
132
+ *
133
+ * \see make_counting_iterator
134
+ */
135
+ template<typename Incrementable,
136
+ typename System = use_default,
137
+ typename Traversal = use_default,
138
+ typename Difference = use_default>
139
+ class counting_iterator
140
+ : public detail::counting_iterator_base<Incrementable, System, Traversal, Difference>::type
141
+ {
142
+ /*! \cond
143
+ */
144
+ typedef typename detail::counting_iterator_base<Incrementable, System, Traversal, Difference>::type super_t;
145
+
146
+ friend class thrust::iterator_core_access;
147
+
148
+ public:
149
+ typedef typename super_t::reference reference;
150
+ typedef typename super_t::difference_type difference_type;
151
+
152
+ /*! \endcond
153
+ */
154
+
155
+ /*! Default constructor initializes this \p counting_iterator's counter to
156
+ * `Incrementable{}`.
157
+ */
158
+ __host__ __device__
159
+ counting_iterator() : super_t(Incrementable{}) {}
160
+
161
+ /*! Copy constructor copies the value of another \p counting_iterator into a
162
+ * new \p counting_iterator.
163
+ *
164
+ * \p rhs The \p counting_iterator to copy.
165
+ */
166
+ __host__ __device__
167
+ counting_iterator(counting_iterator const &rhs):super_t(rhs.base()){}
168
+
169
+ /*! Copy constructor copies the value of another counting_iterator
170
+ * with related System type.
171
+ *
172
+ * \param rhs The \p counting_iterator to copy.
173
+ */
174
+ template<typename OtherSystem>
175
+ __host__ __device__
176
+ counting_iterator(counting_iterator<Incrementable, OtherSystem, Traversal, Difference> const &rhs,
177
+ typename thrust::detail::enable_if_convertible<
178
+ typename thrust::iterator_system<counting_iterator<Incrementable,OtherSystem,Traversal,Difference> >::type,
179
+ typename thrust::iterator_system<super_t>::type
180
+ >::type * = 0)
181
+ : super_t(rhs.base()){}
182
+
183
+ /*! This \c explicit constructor copies the value of an \c Incrementable
184
+ * into a new \p counting_iterator's \c Incrementable counter.
185
+ *
186
+ * \param x The initial value of the new \p counting_iterator's \c Incrementable
187
+ * counter.
188
+ */
189
+ __host__ __device__
190
+ explicit counting_iterator(Incrementable x):super_t(x){}
191
+
192
+ #if THRUST_CPP_DIALECT >= 2011
193
+ counting_iterator & operator=(const counting_iterator &) = default;
194
+ #endif
195
+
196
+ /*! \cond
197
+ */
198
+ private:
199
+ __host__ __device__
200
+ reference dereference() const
201
+ {
202
+ return this->base_reference();
203
+ }
204
+
205
+ // note that we implement equal specially for floating point counting_iterator
206
+ template <typename OtherIncrementable, typename OtherSystem, typename OtherTraversal, typename OtherDifference>
207
+ __host__ __device__
208
+ bool equal(counting_iterator<OtherIncrementable, OtherSystem, OtherTraversal, OtherDifference> const& y) const
209
+ {
210
+ typedef thrust::detail::counting_iterator_equal<difference_type,Incrementable,OtherIncrementable> e;
211
+ return e::equal(this->base(), y.base());
212
+ }
213
+
214
+ template <class OtherIncrementable>
215
+ __host__ __device__
216
+ difference_type
217
+ distance_to(counting_iterator<OtherIncrementable, System, Traversal, Difference> const& y) const
218
+ {
219
+ typedef typename
220
+ thrust::detail::eval_if<
221
+ thrust::detail::is_numeric<Incrementable>::value,
222
+ thrust::detail::identity_<thrust::detail::number_distance<difference_type, Incrementable, OtherIncrementable> >,
223
+ thrust::detail::identity_<thrust::detail::iterator_distance<difference_type, Incrementable, OtherIncrementable> >
224
+ >::type d;
225
+
226
+ return d::distance(this->base(), y.base());
227
+ }
228
+
229
+ /*! \endcond
230
+ */
231
+ }; // end counting_iterator
232
+
233
+
234
+ /*! \p make_counting_iterator creates a \p counting_iterator
235
+ * using an initial value for its \c Incrementable counter.
236
+ *
237
+ * \param x The initial value of the new \p counting_iterator's counter.
238
+ * \return A new \p counting_iterator whose counter has been initialized to \p x.
239
+ */
240
+ template <typename Incrementable>
241
+ inline __host__ __device__
242
+ counting_iterator<Incrementable> make_counting_iterator(Incrementable x)
243
+ {
244
+ return counting_iterator<Incrementable>(x);
245
+ }
246
+
247
+ /*! \} // end fancyiterators
248
+ */
249
+
250
+ /*! \} // end iterators
251
+ */
252
+
253
+ THRUST_NAMESPACE_END
254
+
miniCUDA124/include/thrust/iterator/discard_iterator.h ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file thrust/iterator/discard_iterator.h
19
+ * \brief An iterator which "discards" (ignores) values assigned to it upon dereference
20
+ */
21
+
22
+ #pragma once
23
+
24
+ #include <thrust/detail/config.h>
25
+
26
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
27
+ # pragma GCC system_header
28
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
29
+ # pragma clang system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
31
+ # pragma system_header
32
+ #endif // no system header
33
+ #include <thrust/iterator/detail/discard_iterator_base.h>
34
+ #include <thrust/iterator/iterator_facade.h>
35
+
36
+ THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN
37
+
38
+ THRUST_NAMESPACE_BEGIN
39
+
40
+ /*! \addtogroup iterators
41
+ * \{
42
+ */
43
+
44
+ /*! \addtogroup fancyiterator Fancy Iterators
45
+ * \ingroup iterators
46
+ * \{
47
+ */
48
+
49
+ /*! \p discard_iterator is an iterator which represents a special kind of pointer that
50
+ * ignores values written to it upon dereference. This iterator is useful for ignoring
51
+ * the output of certain algorithms without wasting memory capacity or bandwidth.
52
+ * \p discard_iterator may also be used to count the size of an algorithm's output which
53
+ * may not be known a priori.
54
+ *
55
+ * The following code snippet demonstrates how to use \p discard_iterator to ignore
56
+ * ignore one of the output ranges of reduce_by_key
57
+ *
58
+ * \code
59
+ * #include <thrust/iterator/discard_iterator.h>
60
+ * #include <thrust/reduce.h>
61
+ * #include <thrust/device_vector.h>
62
+ *
63
+ * int main()
64
+ * {
65
+ * thrust::device_vector<int> keys(7), values(7);
66
+ *
67
+ * keys[0] = 1;
68
+ * keys[1] = 3;
69
+ * keys[2] = 3;
70
+ * keys[3] = 3;
71
+ * keys[4] = 2;
72
+ * keys[5] = 2;
73
+ * keys[6] = 1;
74
+ *
75
+ * values[0] = 9;
76
+ * values[1] = 8;
77
+ * values[2] = 7;
78
+ * values[3] = 6;
79
+ * values[4] = 5;
80
+ * values[5] = 4;
81
+ * values[6] = 3;
82
+ *
83
+ * thrust::device_vector<int> result(4);
84
+ *
85
+ * // we are only interested in the reduced values
86
+ * // use discard_iterator to ignore the output keys
87
+ * thrust::reduce_by_key(keys.begin(), keys.end(),
88
+ * values.begin(),
89
+ * thrust::make_discard_iterator(),
90
+ * result.begin());
91
+ *
92
+ * // result is now [9, 21, 9, 3]
93
+ *
94
+ * return 0;
95
+ * }
96
+ * \endcode
97
+ *
98
+ * \see make_discard_iterator
99
+ */
100
+ template<typename System = use_default>
101
+ class discard_iterator
102
+ : public detail::discard_iterator_base<System>::type
103
+ {
104
+ /*! \cond
105
+ */
106
+ friend class thrust::iterator_core_access;
107
+ typedef typename detail::discard_iterator_base<System>::type super_t;
108
+ typedef typename detail::discard_iterator_base<System>::incrementable incrementable;
109
+ typedef typename detail::discard_iterator_base<System>::base_iterator base_iterator;
110
+
111
+ public:
112
+ typedef typename super_t::reference reference;
113
+ typedef typename super_t::value_type value_type;
114
+
115
+ /*! \endcond
116
+ */
117
+
118
+ /*! Copy constructor copies from a source discard_iterator.
119
+ *
120
+ * \p rhs The discard_iterator to copy.
121
+ */
122
+ __host__ __device__
123
+ discard_iterator(discard_iterator const &rhs)
124
+ : super_t(rhs.base()) {}
125
+
126
+ #if THRUST_CPP_DIALECT >= 2011
127
+ discard_iterator & operator=(const discard_iterator &) = default;
128
+ #endif
129
+
130
+ /*! This constructor receives an optional index specifying the position of this
131
+ * \p discard_iterator in a range.
132
+ *
133
+ * \p i The index of this \p discard_iterator in a range. Defaults to the
134
+ * value returned by \c Incrementable's null constructor. For example,
135
+ * when <tt>Incrementable == int</tt>, \c 0.
136
+ */
137
+ __host__ __device__
138
+ discard_iterator(incrementable const &i = incrementable())
139
+ : super_t(base_iterator(i)) {}
140
+
141
+ /*! \cond
142
+ */
143
+
144
+ private: // Core iterator interface
145
+ __host__ __device__
146
+ reference dereference() const
147
+ {
148
+ return m_element;
149
+ }
150
+
151
+ mutable value_type m_element;
152
+
153
+ /*! \endcond
154
+ */
155
+ }; // end constant_iterator
156
+
157
+
158
+ /*! \p make_discard_iterator creates a \p discard_iterator from an optional index parameter.
159
+ *
160
+ * \param i The index of the returned \p discard_iterator within a range.
161
+ * In the default case, the value of this parameter is \c 0.
162
+ *
163
+ * \return A new \p discard_iterator with index as given by \p i.
164
+ *
165
+ * \see constant_iterator
166
+ */
167
+ inline __host__ __device__
168
+ discard_iterator<> make_discard_iterator(discard_iterator<>::difference_type i = discard_iterator<>::difference_type(0))
169
+ {
170
+ return discard_iterator<>(i);
171
+ } // end make_discard_iterator()
172
+
173
+ /*! \} // end fancyiterators
174
+ */
175
+
176
+ /*! \} // end iterators
177
+ */
178
+
179
+ THRUST_NAMESPACE_END
180
+
181
+ THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END
182
+
miniCUDA124/include/thrust/iterator/iterator_adaptor.h ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file thrust/iterator/iterator_adaptor.h
19
+ * \brief An iterator which adapts a base iterator
20
+ */
21
+
22
+ /*
23
+ * (C) Copyright David Abrahams 2002.
24
+ * (C) Copyright Jeremy Siek 2002.
25
+ * (C) Copyright Thomas Witt 2002.
26
+ *
27
+ * Distributed under the Boost Software License, Version 1.0.
28
+ * (See accompanying NOTICE file for the complete license)
29
+ *
30
+ * For more information, see http://www.boost.org
31
+ */
32
+
33
+ #pragma once
34
+
35
+ #include <thrust/detail/config.h>
36
+
37
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
38
+ # pragma GCC system_header
39
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
40
+ # pragma clang system_header
41
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
42
+ # pragma system_header
43
+ #endif // no system header
44
+ #include <thrust/iterator/iterator_facade.h>
45
+ #include <thrust/detail/use_default.h>
46
+ #include <thrust/iterator/detail/iterator_adaptor_base.h>
47
+
48
+ THRUST_NAMESPACE_BEGIN
49
+
50
+ /*! \addtogroup iterators
51
+ * \{
52
+ */
53
+
54
+ /*! \addtogroup fancyiterator Fancy Iterators
55
+ * \ingroup iterators
56
+ * \{
57
+ */
58
+
59
+ /*! \p iterator_adaptor is an iterator which adapts an existing type of iterator to create a new type of
60
+ * iterator. Most of Thrust's fancy iterators are defined via inheritance from \p iterator_adaptor.
61
+ * While composition of these existing Thrust iterators is often sufficient for expressing the desired
62
+ * functionality, it is occasionally more straightforward to derive from \p iterator_adaptor directly.
63
+ *
64
+ * To see how to use \p iterator_adaptor to create a novel iterator type, let's examine how to use it to
65
+ * define \p repeat_iterator, a fancy iterator which repeats elements from another range a given number of time:
66
+ *
67
+ * \code
68
+ * #include <thrust/iterator/iterator_adaptor.h>
69
+ *
70
+ * // derive repeat_iterator from iterator_adaptor
71
+ * template<typename Iterator>
72
+ * class repeat_iterator
73
+ * : public thrust::iterator_adaptor<
74
+ * repeat_iterator<Iterator>, // the first template parameter is the name of the iterator we're creating
75
+ * Iterator // the second template parameter is the name of the iterator we're adapting
76
+ * // we can use the default for the additional template parameters
77
+ * >
78
+ * {
79
+ * public:
80
+ * // shorthand for the name of the iterator_adaptor we're deriving from
81
+ * typedef thrust::iterator_adaptor<
82
+ * repeat_iterator<Iterator>,
83
+ * Iterator
84
+ * > super_t;
85
+ *
86
+ * __host__ __device__
87
+ * repeat_iterator(const Iterator &x, int n) : super_t(x), begin(x), n(n) {}
88
+ *
89
+ * // befriend thrust::iterator_core_access to allow it access to the private interface below
90
+ * friend class thrust::iterator_core_access;
91
+ *
92
+ * private:
93
+ * // repeat each element of the adapted range n times
94
+ * unsigned int n;
95
+ *
96
+ * // used to keep track of where we began
97
+ * const Iterator begin;
98
+ *
99
+ * // it is private because only thrust::iterator_core_access needs access to it
100
+ * __host__ __device__
101
+ * typename super_t::reference dereference() const
102
+ * {
103
+ * return *(begin + (this->base() - begin) / n);
104
+ * }
105
+ * };
106
+ * \endcode
107
+ *
108
+ * Except for the first two, \p iterator_adaptor's template parameters are optional. When omitted, or when the
109
+ * user specifies \p thrust::use_default in its place, \p iterator_adaptor will use a default type inferred from \p Base.
110
+ *
111
+ * \p iterator_adaptor's functionality is derived from and generally equivalent to \p boost::iterator_adaptor.
112
+ * The exception is Thrust's addition of the template parameter \p System, which is necessary to allow Thrust
113
+ * to dispatch an algorithm to one of several parallel backend systems.
114
+ *
115
+ * \p iterator_adaptor is a powerful tool for creating custom iterators directly. However, the large set of iterator semantics which must be satisfied
116
+ * for algorithm compatibility can make \p iterator_adaptor difficult to use correctly. Unless you require the full expressivity of \p iterator_adaptor,
117
+ * consider building a custom iterator through composition of existing higher-level fancy iterators instead.
118
+ *
119
+ * Interested users may refer to <tt>boost::iterator_adaptor</tt>'s documentation for further usage examples.
120
+ */
121
+ template<typename Derived,
122
+ typename Base,
123
+ typename Value = use_default,
124
+ typename System = use_default,
125
+ typename Traversal = use_default,
126
+ typename Reference = use_default,
127
+ typename Difference = use_default>
128
+ class iterator_adaptor:
129
+ public detail::iterator_adaptor_base<
130
+ Derived, Base, Value, System, Traversal, Reference, Difference
131
+ >::type
132
+ {
133
+ /*! \cond
134
+ */
135
+
136
+ friend class thrust::iterator_core_access;
137
+
138
+ protected:
139
+ typedef typename detail::iterator_adaptor_base<
140
+ Derived, Base, Value, System, Traversal, Reference, Difference
141
+ >::type super_t;
142
+
143
+ /*! \endcond
144
+ */
145
+
146
+ public:
147
+ /*! \p iterator_adaptor's default constructor does nothing.
148
+ */
149
+ iterator_adaptor() = default;
150
+
151
+ /*! This constructor copies from a given instance of the \p Base iterator.
152
+ */
153
+ __thrust_exec_check_disable__
154
+ __host__ __device__
155
+ explicit iterator_adaptor(Base const& iter)
156
+ : m_iterator(iter)
157
+ {}
158
+
159
+ /*! The type of iterator this \p iterator_adaptor's \p adapts.
160
+ */
161
+ typedef Base base_type;
162
+
163
+ /*! \cond
164
+ */
165
+ typedef typename super_t::reference reference;
166
+
167
+ typedef typename super_t::difference_type difference_type;
168
+ /*! \endcond
169
+ */
170
+
171
+ /*! \return A \p const reference to the \p Base iterator this \p iterator_adaptor adapts.
172
+ */
173
+ __host__ __device__
174
+ Base const& base() const
175
+ { return m_iterator; }
176
+
177
+ protected:
178
+ /*! \return A \p const reference to the \p Base iterator this \p iterator_adaptor adapts.
179
+ */
180
+ __host__ __device__
181
+ Base const& base_reference() const
182
+ { return m_iterator; }
183
+
184
+ /*! \return A mutable reference to the \p Base iterator this \p iterator_adaptor adapts.
185
+ */
186
+ __host__ __device__
187
+ Base& base_reference()
188
+ { return m_iterator; }
189
+
190
+ /*! \cond
191
+ */
192
+ private: // Core iterator interface for iterator_facade
193
+
194
+ __thrust_exec_check_disable__
195
+ __host__ __device__
196
+ typename iterator_adaptor::reference dereference() const
197
+ { return *m_iterator; }
198
+
199
+ __thrust_exec_check_disable__
200
+ template<typename OtherDerived, typename OtherIterator, typename V, typename S, typename T, typename R, typename D>
201
+ __host__ __device__
202
+ bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, S, T, R, D> const& x) const
203
+ { return m_iterator == x.base(); }
204
+
205
+ __thrust_exec_check_disable__
206
+ __host__ __device__
207
+ void advance(typename iterator_adaptor::difference_type n)
208
+ {
209
+ // XXX statically assert on random_access_traversal_tag
210
+
211
+ // counting_iterator will pick eg. diff_t=int64 when base=int32.
212
+ // Explicitly cast to avoid static conversion warnings.
213
+ m_iterator = static_cast<base_type>(m_iterator + n);
214
+ }
215
+
216
+ __thrust_exec_check_disable__
217
+ __host__ __device__
218
+ void increment()
219
+ { ++m_iterator; }
220
+
221
+ __thrust_exec_check_disable__
222
+ __host__ __device__
223
+ void decrement()
224
+ {
225
+ // XXX statically assert on bidirectional_traversal_tag
226
+ --m_iterator;
227
+ }
228
+
229
+ __thrust_exec_check_disable__
230
+ template<typename OtherDerived, typename OtherIterator, typename V, typename S, typename T, typename R, typename D>
231
+ __host__ __device__
232
+ typename iterator_adaptor::difference_type distance_to(iterator_adaptor<OtherDerived, OtherIterator, V, S, T, R, D> const& y) const
233
+ { return y.base() - m_iterator; }
234
+
235
+ private:
236
+ Base m_iterator;
237
+
238
+ /*! \endcond
239
+ */
240
+ }; // end iterator_adaptor
241
+
242
+ /*! \} // end fancyiterators
243
+ */
244
+
245
+ /*! \} // end iterators
246
+ */
247
+
248
+ THRUST_NAMESPACE_END
249
+
miniCUDA124/include/thrust/iterator/iterator_categories.h ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file thrust/iterator/iterator_categories.h
19
+ * \brief Types for reasoning about the categories of iterators
20
+ */
21
+
22
+ /*
23
+ * (C) Copyright Jeremy Siek 2002.
24
+ *
25
+ * Distributed under the Boost Software License, Version 1.0.
26
+ * (See accompanying NOTICE file for the complete license)
27
+ *
28
+ * For more information, see http://www.boost.org
29
+ */
30
+
31
+
32
+ #pragma once
33
+
34
+ #include <thrust/detail/config.h>
35
+
36
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
37
+ # pragma GCC system_header
38
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
39
+ # pragma clang system_header
40
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
41
+ # pragma system_header
42
+ #endif // no system header
43
+ #include <thrust/iterator/detail/iterator_category_with_system_and_traversal.h>
44
+ #include <thrust/iterator/detail/iterator_traversal_tags.h>
45
+ #include <thrust/iterator/detail/device_system_tag.h>
46
+
47
+ // #include this for stl's iterator tags
48
+ #include <iterator>
49
+
50
+ THRUST_NAMESPACE_BEGIN
51
+
52
+ /*! \addtogroup iterators
53
+ * \addtogroup iterator_tags Iterator Tags
54
+ * \ingroup iterators
55
+ * \addtogroup iterator_tag_classes Iterator Tag Classes
56
+ * \ingroup iterator_tags
57
+ * \{
58
+ */
59
+
60
+ /*! \p input_device_iterator_tag is an empty class: it has no member functions,
61
+ * member variables, or nested types. It is used solely as a "tag": a
62
+ * representation of the Input Device Iterator concept within the C++ type
63
+ * system.
64
+ *
65
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags iterator_traits,
66
+ * output_device_iterator_tag, forward_device_iterator_tag,
67
+ * bidirectional_device_iterator_tag, random_access_device_iterator_tag,
68
+ * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag,
69
+ * bidirectional_host_iterator_tag, random_access_host_iterator_tag
70
+ */
71
+ struct input_device_iterator_tag
72
+ : thrust::detail::iterator_category_with_system_and_traversal<
73
+ std::input_iterator_tag,
74
+ thrust::device_system_tag,
75
+ thrust::single_pass_traversal_tag
76
+ >
77
+ {};
78
+
79
+ /*! \p output_device_iterator_tag is an empty class: it has no member functions,
80
+ * member variables, or nested types. It is used solely as a "tag": a
81
+ * representation of the Output Device Iterator concept within the C++ type
82
+ * system.
83
+ *
84
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags iterator_traits,
85
+ * input_device_iterator_tag, forward_device_iterator_tag,
86
+ * bidirectional_device_iterator_tag, random_access_device_iterator_tag,
87
+ * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag,
88
+ * bidirectional_host_iterator_tag, random_access_host_iterator_tag
89
+ */
90
+ struct output_device_iterator_tag
91
+ : thrust::detail::iterator_category_with_system_and_traversal<
92
+ std::output_iterator_tag,
93
+ thrust::device_system_tag,
94
+ thrust::single_pass_traversal_tag
95
+ >
96
+ {};
97
+
98
+ /*! \p forward_device_iterator_tag is an empty class: it has no member functions,
99
+ * member variables, or nested types. It is used solely as a "tag": a
100
+ * representation of the Forward Device Iterator concept within the C++ type
101
+ * system.
102
+ *
103
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags iterator_traits,
104
+ * input_device_iterator_tag, output_device_iterator_tag,
105
+ * bidirectional_device_iterator_tag, random_access_device_iterator_tag,
106
+ * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag,
107
+ * bidirectional_host_iterator_tag, random_access_host_iterator_tag
108
+ */
109
+ struct forward_device_iterator_tag
110
+ : thrust::detail::iterator_category_with_system_and_traversal<
111
+ std::forward_iterator_tag,
112
+ thrust::device_system_tag,
113
+ thrust::forward_traversal_tag
114
+ >
115
+ {};
116
+
117
+ /*! \p bidirectional_device_iterator_tag is an empty class: it has no member
118
+ * functions, member variables, or nested types. It is used solely as a "tag": a
119
+ * representation of the Bidirectional Device Iterator concept within the C++
120
+ * type system.
121
+ *
122
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags
123
+ * iterator_traits, input_device_iterator_tag, output_device_iterator_tag,
124
+ * forward_device_iterator_tag, random_access_device_iterator_tag,
125
+ * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag,
126
+ * bidirectional_host_iterator_tag, random_access_host_iterator_tag
127
+ */
128
+ struct bidirectional_device_iterator_tag
129
+ : thrust::detail::iterator_category_with_system_and_traversal<
130
+ std::bidirectional_iterator_tag,
131
+ thrust::device_system_tag,
132
+ thrust::bidirectional_traversal_tag
133
+ >
134
+ {};
135
+
136
+ /*! \p random_access_device_iterator_tag is an empty class: it has no member
137
+ * functions, member variables, or nested types. It is used solely as a "tag": a
138
+ * representation of the Random Access Device Iterator concept within the C++
139
+ * type system.
140
+ *
141
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags
142
+ * iterator_traits, input_device_iterator_tag, output_device_iterator_tag,
143
+ * forward_device_iterator_tag, bidirectional_device_iterator_tag,
144
+ * input_host_iterator_tag, output_host_iterator_tag, forward_host_iterator_tag,
145
+ * bidirectional_host_iterator_tag, random_access_host_iterator_tag
146
+ */
147
+ struct random_access_device_iterator_tag
148
+ : thrust::detail::iterator_category_with_system_and_traversal<
149
+ std::random_access_iterator_tag,
150
+ thrust::device_system_tag,
151
+ thrust::random_access_traversal_tag
152
+ >
153
+ {};
154
+
155
+ /*! \p input_host_iterator_tag is an empty class: it has no member
156
+ * functions, member variables, or nested types. It is used solely as a "tag": a
157
+ * representation of the Input Host Iterator concept within the C++
158
+ * type system.
159
+ *
160
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags
161
+ * iterator_traits, input_device_iterator_tag, output_device_iterator_tag,
162
+ * forward_device_iterator_tag, bidirectional_device_iterator_tag,
163
+ * random_access_device_iterator_tag,
164
+ * output_host_iterator_tag, forward_host_iterator_tag,
165
+ * bidirectional_host_iterator_tag, random_access_host_iterator_tag
166
+ */
167
+ typedef std::input_iterator_tag input_host_iterator_tag;
168
+
169
+ /*! \p output_host_iterator_tag is an empty class: it has no member
170
+ * functions, member variables, or nested types. It is used solely as a "tag": a
171
+ * representation of the Output Host Iterator concept within the C++
172
+ * type system.
173
+ *
174
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags
175
+ * iterator_traits, input_device_iterator_tag, output_device_iterator_tag,
176
+ * forward_device_iterator_tag, bidirectional_device_iterator_tag,
177
+ * random_access_device_iterator_tag,
178
+ * input_host_iterator_tag, forward_host_iterator_tag,
179
+ * bidirectional_host_iterator_tag, random_access_host_iterator_tag
180
+ */
181
+ typedef std::output_iterator_tag output_host_iterator_tag;
182
+
183
+ /*! \p forward_host_iterator_tag is an empty class: it has no member
184
+ * functions, member variables, or nested types. It is used solely as a "tag": a
185
+ * representation of the Forward Host Iterator concept within the C++
186
+ * type system.
187
+ *
188
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags
189
+ * iterator_traits, input_device_iterator_tag, output_device_iterator_tag,
190
+ * forward_device_iterator_tag, bidirectional_device_iterator_tag,
191
+ * random_access_device_iterator_tag,
192
+ * input_host_iterator_tag, output_host_iterator_tag,
193
+ * bidirectional_host_iterator_tag, random_access_host_iterator_tag
194
+ */
195
+ typedef std::forward_iterator_tag forward_host_iterator_tag;
196
+
197
+ /*! \p bidirectional_host_iterator_tag is an empty class: it has no member
198
+ * functions, member variables, or nested types. It is used solely as a "tag": a
199
+ * representation of the Forward Host Iterator concept within the C++
200
+ * type system.
201
+ *
202
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags
203
+ * iterator_traits, input_device_iterator_tag, output_device_iterator_tag,
204
+ * forward_device_iterator_tag, bidirectional_device_iterator_tag,
205
+ * random_access_device_iterator_tag,
206
+ * input_host_iterator_tag, output_host_iterator_tag,
207
+ * forward_host_iterator_tag, random_access_host_iterator_tag
208
+ */
209
+ typedef std::bidirectional_iterator_tag bidirectional_host_iterator_tag;
210
+
211
+ /*! \p random_access_host_iterator_tag is an empty class: it has no member
212
+ * functions, member variables, or nested types. It is used solely as a "tag": a
213
+ * representation of the Forward Host Iterator concept within the C++
214
+ * type system.
215
+ *
216
+ * \see https://en.cppreference.com/w/cpp/iterator/iterator_tags
217
+ * iterator_traits, input_device_iterator_tag, output_device_iterator_tag,
218
+ * forward_device_iterator_tag, bidirectional_device_iterator_tag,
219
+ * random_access_device_iterator_tag,
220
+ * input_host_iterator_tag, output_host_iterator_tag,
221
+ * forward_host_iterator_tag, bidirectional_host_iterator_tag
222
+ */
223
+ typedef std::random_access_iterator_tag random_access_host_iterator_tag;
224
+
225
+ /*! \} // end iterator_tag_classes
226
+ */
227
+
228
+ THRUST_NAMESPACE_END
229
+
230
+ #include <thrust/iterator/detail/universal_categories.h>
231
+
miniCUDA124/include/thrust/iterator/iterator_facade.h ADDED
@@ -0,0 +1,550 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file thrust/iterator/iterator_facade.h
18
+ * \brief A class which exposes a public interface for iterators
19
+ */
20
+
21
+ /*
22
+ * (C) Copyright David Abrahams 2002.
23
+ * (C) Copyright Jeremy Siek 2002.
24
+ * (C) Copyright Thomas Witt 2002.
25
+ *
26
+ * Distributed under the Boost Software License, Version 1.0.
27
+ * (See accompanying NOTICE file for the complete license)
28
+ *
29
+ * For more information, see http://www.boost.org
30
+ */
31
+
32
+
33
+ #pragma once
34
+
35
+ #include <thrust/detail/config.h>
36
+
37
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
38
+ # pragma GCC system_header
39
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
40
+ # pragma clang system_header
41
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
42
+ # pragma system_header
43
+ #endif // no system header
44
+ #include <thrust/detail/type_traits.h>
45
+ #include <thrust/iterator/detail/iterator_facade_category.h>
46
+ #include <thrust/iterator/detail/distance_from_result.h>
47
+
48
+ THRUST_NAMESPACE_BEGIN
49
+
50
+ /*! \addtogroup iterators
51
+ * \{
52
+ */
53
+
54
+ /*! \addtogroup fancyiterator Fancy Iterators
55
+ * \ingroup iterators
56
+ * \{
57
+ */
58
+
59
+
60
+ // This forward declaration is required for the friend declaration
61
+ // in iterator_core_access
62
+ template<typename Derived, typename Value, typename System, typename Traversal, typename Reference, typename Difference> class iterator_facade;
63
+
64
+
65
+ /*! \p iterator_core_access is the class which user iterator types derived from \p thrust::iterator_adaptor
66
+ * or \p thrust::iterator_facade must befriend to allow it to access their private interface.
67
+ */
68
+ class iterator_core_access
69
+ {
70
+ /*! \cond
71
+ */
72
+
73
+ // declare our friends
74
+ template<typename Derived, typename Value, typename System, typename Traversal, typename Reference, typename Difference> friend class iterator_facade;
75
+
76
+ // iterator comparisons are our friends
77
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
78
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
79
+ inline __host__ __device__
80
+ friend bool
81
+ operator ==(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
82
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs);
83
+
84
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
85
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
86
+ inline __host__ __device__
87
+ friend bool
88
+ operator !=(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
89
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs);
90
+
91
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
92
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
93
+ inline __host__ __device__
94
+ friend bool
95
+ operator <(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
96
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs);
97
+
98
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
99
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
100
+ inline __host__ __device__
101
+ friend bool
102
+ operator >(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
103
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs);
104
+
105
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
106
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
107
+ inline __host__ __device__
108
+ friend bool
109
+ operator <=(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
110
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs);
111
+
112
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
113
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
114
+ inline __host__ __device__
115
+ friend bool
116
+ operator >=(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
117
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs);
118
+
119
+ // iterator difference is our friend
120
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
121
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
122
+ inline __host__ __device__
123
+ friend
124
+ typename thrust::detail::distance_from_result<
125
+ iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1>,
126
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2>
127
+ >::type
128
+ operator-(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
129
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs);
130
+
131
+ template<typename Facade>
132
+ __host__ __device__
133
+ static typename Facade::reference dereference(Facade const& f)
134
+ {
135
+ return f.dereference();
136
+ }
137
+
138
+ template<typename Facade>
139
+ __host__ __device__
140
+ static void increment(Facade& f)
141
+ {
142
+ f.increment();
143
+ }
144
+
145
+ template<typename Facade>
146
+ __host__ __device__
147
+ static void decrement(Facade& f)
148
+ {
149
+ f.decrement();
150
+ }
151
+
152
+ template <class Facade1, class Facade2>
153
+ __host__ __device__
154
+ static bool equal(Facade1 const& f1, Facade2 const& f2)
155
+ {
156
+ return f1.equal(f2);
157
+ }
158
+
159
+ // XXX TODO: Investigate whether we need both of these cases
160
+ //template <class Facade1, class Facade2>
161
+ //__host__ __device__
162
+ //static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::true_)
163
+ //{
164
+ // return f1.equal(f2);
165
+ //}
166
+
167
+ //template <class Facade1, class Facade2>
168
+ //__host__ __device__
169
+ //static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::false_)
170
+ //{
171
+ // return f2.equal(f1);
172
+ //}
173
+
174
+ template <class Facade>
175
+ __host__ __device__
176
+ static void advance(Facade& f, typename Facade::difference_type n)
177
+ {
178
+ f.advance(n);
179
+ }
180
+
181
+ // Facade2 is convertible to Facade1,
182
+ // so return Facade1's difference_type
183
+ template <class Facade1, class Facade2>
184
+ __host__ __device__
185
+ static typename Facade1::difference_type
186
+ distance_from(Facade1 const& f1, Facade2 const& f2, thrust::detail::true_type)
187
+ {
188
+ return -f1.distance_to(f2);
189
+ }
190
+
191
+ // Facade2 is not convertible to Facade1,
192
+ // so return Facade2's difference_type
193
+ template <class Facade1, class Facade2>
194
+ __host__ __device__
195
+ static typename Facade2::difference_type
196
+ distance_from(Facade1 const& f1, Facade2 const& f2, thrust::detail::false_type)
197
+ {
198
+ return f2.distance_to(f1);
199
+ }
200
+
201
+ template <class Facade1, class Facade2>
202
+ __host__ __device__
203
+ static typename thrust::detail::distance_from_result<Facade1,Facade2>::type
204
+ distance_from(Facade1 const& f1, Facade2 const& f2)
205
+ {
206
+ // dispatch the implementation of this method upon whether or not
207
+ // Facade2 is convertible to Facade1
208
+ return distance_from(f1, f2,
209
+ typename thrust::detail::is_convertible<Facade2,Facade1>::type());
210
+ }
211
+
212
+ //
213
+ // Curiously Recurring Template interface.
214
+ //
215
+ template <typename Derived, typename Value, typename System, typename Traversal, typename Reference, typename Difference>
216
+ __host__ __device__
217
+ static Derived& derived(iterator_facade<Derived,Value,System,Traversal,Reference,Difference>& facade)
218
+ {
219
+ return *static_cast<Derived*>(&facade);
220
+ }
221
+
222
+ template <typename Derived, typename Value, typename System, typename Traversal, typename Reference, typename Difference>
223
+ __host__ __device__
224
+ static Derived const& derived(iterator_facade<Derived,Value,System,Traversal,Reference,Difference> const& facade)
225
+ {
226
+ return *static_cast<Derived const*>(&facade);
227
+ }
228
+
229
+ /*! \endcond
230
+ */
231
+ }; // end iterator_core_access
232
+
233
+
234
+ /*! \p iterator_facade is a template which allows the programmer to define a novel iterator with a standards-conforming interface
235
+ * which Thrust can use to reason about algorithm acceleration opportunities.
236
+ *
237
+ * Because most of a standard iterator's interface is defined in terms of a small set of core primitives, \p iterator_facade
238
+ * defines the non-primitive portion mechanically. In principle a novel iterator could explicitly provide the entire interface in
239
+ * an ad hoc fashion but doing so might be tedious and prone to subtle errors.
240
+ *
241
+ * Often \p iterator_facade is too primitive a tool to use for defining novel iterators. In these cases, \p iterator_adaptor
242
+ * or a specific fancy iterator should be used instead.
243
+ *
244
+ * \p iterator_facade's functionality is derived from and generally equivalent to \p boost::iterator_facade.
245
+ * The exception is Thrust's addition of the template parameter \p System, which is necessary to allow Thrust
246
+ * to dispatch an algorithm to one of several parallel backend systems. An additional exception is Thrust's omission
247
+ * of the \c operator-> member function.
248
+ *
249
+ * Interested users may refer to <tt>boost::iterator_facade</tt>'s documentation for usage examples.
250
+ *
251
+ * \note \p iterator_facade's arithmetic operator free functions exist with the usual meanings but are omitted here for brevity.
252
+ */
253
+ template<typename Derived,
254
+ typename Value,
255
+ typename System,
256
+ typename Traversal,
257
+ typename Reference,
258
+ typename Difference = std::ptrdiff_t>
259
+ class iterator_facade
260
+ {
261
+ private:
262
+ /*! \cond
263
+ */
264
+
265
+ //
266
+ // Curiously Recurring Template interface.
267
+ //
268
+ __host__ __device__
269
+ Derived& derived()
270
+ {
271
+ return *static_cast<Derived*>(this);
272
+ }
273
+
274
+ __host__ __device__
275
+ Derived const& derived() const
276
+ {
277
+ return *static_cast<Derived const*>(this);
278
+ }
279
+ /*! \endcond
280
+ */
281
+
282
+ public:
283
+ /*! The type of element pointed to by \p iterator_facade.
284
+ */
285
+ typedef typename thrust::detail::remove_const<Value>::type value_type;
286
+
287
+ /*! The return type of \p iterator_facade::operator*().
288
+ */
289
+ typedef Reference reference;
290
+
291
+ /*! The return type of \p iterator_facade's non-existent \c operator->()
292
+ * member function. Unlike \c boost::iterator_facade, \p iterator_facade
293
+ * disallows access to the \p value_type's members through expressions of the
294
+ * form <tt>iter->member</tt>. \p pointer is defined to \c void to indicate
295
+ * that these expressions are not allowed. This limitation may be relaxed in a
296
+ * future version of Thrust.
297
+ */
298
+ typedef void pointer;
299
+
300
+ /*! The type of expressions of the form <tt>x - y</tt> where <tt>x</tt> and <tt>y</tt>
301
+ * are of type \p iterator_facade.
302
+ */
303
+ typedef Difference difference_type;
304
+
305
+ /*! The type of iterator category of \p iterator_facade.
306
+ */
307
+ typedef typename thrust::detail::iterator_facade_category<
308
+ System, Traversal, Value, Reference
309
+ >::type iterator_category;
310
+
311
+ /*! \p operator*() dereferences this \p iterator_facade.
312
+ * \return A reference to the element pointed to by this \p iterator_facade.
313
+ */
314
+ __host__ __device__
315
+ reference operator*() const
316
+ {
317
+ return iterator_core_access::dereference(this->derived());
318
+ }
319
+
320
+ // XXX unimplemented for now, consider implementing it later
321
+ //pointer operator->() const
322
+ //{
323
+ // return;
324
+ //}
325
+
326
+ // XXX investigate whether or not we need to go to the lengths
327
+ // boost does to determine the return type
328
+
329
+ /*! \p operator[] performs indexed dereference.
330
+ * \return A reference to the element \p n distance away from this \p iterator_facade.
331
+ */
332
+ __host__ __device__
333
+ reference operator[](difference_type n) const
334
+ {
335
+ return *(this->derived() + n);
336
+ }
337
+
338
+ /*! \p operator++ pre-increments this \p iterator_facade to refer to the element in the next position.
339
+ * \return <tt>*this</tt>
340
+ */
341
+ __host__ __device__
342
+ Derived& operator++()
343
+ {
344
+ iterator_core_access::increment(this->derived());
345
+ return this->derived();
346
+ }
347
+
348
+ /*! \p operator++ post-increments this \p iterator_facade and returns a new \p iterator_facade referring to the element in the next position.
349
+ * \return A copy of <tt>*this</tt> before increment.
350
+ */
351
+ __host__ __device__
352
+ Derived operator++(int)
353
+ {
354
+ Derived tmp(this->derived());
355
+ ++*this;
356
+ return tmp;
357
+ }
358
+
359
+ /*! \p operator-- pre-decrements this \p iterator_facade to refer to the element in the previous position.
360
+ * \return <tt>*this</tt>
361
+ */
362
+ __host__ __device__
363
+ Derived& operator--()
364
+ {
365
+ iterator_core_access::decrement(this->derived());
366
+ return this->derived();
367
+ }
368
+
369
+ /*! \p operator-- post-decrements this \p iterator_facade and returns a new \p iterator_facade referring to the element in the previous position.
370
+ * \return A copy of <tt>*this</tt> before decrement.
371
+ */
372
+ __host__ __device__
373
+ Derived operator--(int)
374
+ {
375
+ Derived tmp(this->derived());
376
+ --*this;
377
+ return tmp;
378
+ }
379
+
380
+ /*! \p operator+= increments this \p iterator_facade to refer to an element a given distance after its current position.
381
+ * \param n The quantity to increment.
382
+ * \return <tt>*this</tt>
383
+ */
384
+ __host__ __device__
385
+ Derived& operator+=(difference_type n)
386
+ {
387
+ iterator_core_access::advance(this->derived(), n);
388
+ return this->derived();
389
+ }
390
+
391
+ /*! \p operator-= decrements this \p iterator_facade to refer to an element a given distance before its current postition.
392
+ * \param n The quantity to decrement.
393
+ * \return <tt>*this</tt>
394
+ */
395
+ __host__ __device__
396
+ Derived& operator-=(difference_type n)
397
+ {
398
+ iterator_core_access::advance(this->derived(), -n);
399
+ return this->derived();
400
+ }
401
+
402
+ /*! \p operator- subtracts a given quantity from this \p iterator_facade and returns a new \p iterator_facade referring to the element at the given position before this \p iterator_facade.
403
+ * \param n The quantity to decrement
404
+ * \return An \p iterator_facade pointing \p n elements before this \p iterator_facade.
405
+ */
406
+ __host__ __device__
407
+ Derived operator-(difference_type n) const
408
+ {
409
+ Derived result(this->derived());
410
+ return result -= n;
411
+ }
412
+ }; // end iterator_facade
413
+
414
+ /*! \cond
415
+ */
416
+
417
+ // Comparison operators
418
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
419
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
420
+ inline __host__ __device__
421
+ // XXX it might be nice to implement this at some point
422
+ //typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
423
+ bool
424
+ operator ==(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
425
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs)
426
+ {
427
+ return iterator_core_access
428
+ ::equal(*static_cast<Derived1 const*>(&lhs),
429
+ *static_cast<Derived2 const*>(&rhs));
430
+ }
431
+
432
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
433
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
434
+ inline __host__ __device__
435
+ // XXX it might be nice to implement this at some point
436
+ //typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
437
+ bool
438
+ operator !=(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
439
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs)
440
+ {
441
+ return !iterator_core_access
442
+ ::equal(*static_cast<Derived1 const*>(&lhs),
443
+ *static_cast<Derived2 const*>(&rhs));
444
+ }
445
+
446
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
447
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
448
+ inline __host__ __device__
449
+ // XXX it might be nice to implement this at some point
450
+ //typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
451
+ bool
452
+ operator <(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
453
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs)
454
+ {
455
+ return 0 > iterator_core_access
456
+ ::distance_from(*static_cast<Derived1 const*>(&lhs),
457
+ *static_cast<Derived2 const*>(&rhs));
458
+ }
459
+
460
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
461
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
462
+ inline __host__ __device__
463
+ // XXX it might be nice to implement this at some point
464
+ //typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
465
+ bool
466
+ operator >(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
467
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs)
468
+ {
469
+ return 0 < iterator_core_access
470
+ ::distance_from(*static_cast<Derived1 const*>(&lhs),
471
+ *static_cast<Derived2 const*>(&rhs));
472
+ }
473
+
474
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
475
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
476
+ inline __host__ __device__
477
+ // XXX it might be nice to implement this at some point
478
+ //typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
479
+ bool
480
+ operator <=(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
481
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs)
482
+ {
483
+ return 0 >= iterator_core_access
484
+ ::distance_from(*static_cast<Derived1 const*>(&lhs),
485
+ *static_cast<Derived2 const*>(&rhs));
486
+ }
487
+
488
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
489
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
490
+ inline __host__ __device__
491
+ // XXX it might be nice to implement this at some point
492
+ //typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
493
+ bool
494
+ operator >=(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
495
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs)
496
+ {
497
+ return 0 <= iterator_core_access
498
+ ::distance_from(*static_cast<Derived1 const*>(&lhs),
499
+ *static_cast<Derived2 const*>(&rhs));
500
+ }
501
+
502
+ // Iterator difference
503
+ template <typename Derived1, typename Value1, typename System1, typename Traversal1, typename Reference1, typename Difference1,
504
+ typename Derived2, typename Value2, typename System2, typename Traversal2, typename Reference2, typename Difference2>
505
+ inline __host__ __device__
506
+
507
+ // divine the type this operator returns
508
+ typename thrust::detail::distance_from_result<
509
+ iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1>,
510
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2>
511
+ >::type
512
+
513
+ operator-(iterator_facade<Derived1,Value1,System1,Traversal1,Reference1,Difference1> const& lhs,
514
+ iterator_facade<Derived2,Value2,System2,Traversal2,Reference2,Difference2> const& rhs)
515
+ {
516
+ return iterator_core_access
517
+ ::distance_from(*static_cast<Derived1 const*>(&lhs),
518
+ *static_cast<Derived2 const*>(&rhs));
519
+ }
520
+
521
+ // Iterator addition
522
+ template <typename Derived, typename Value, typename System, typename Traversal, typename Reference, typename Difference>
523
+ inline __host__ __device__
524
+ Derived operator+ (iterator_facade<Derived,Value,System,Traversal,Reference,Difference> const& i,
525
+ typename Derived::difference_type n)
526
+ {
527
+ Derived tmp(static_cast<Derived const&>(i));
528
+ return tmp += n;
529
+ }
530
+
531
+ template <typename Derived, typename Value, typename System, typename Traversal, typename Reference, typename Difference>
532
+ inline __host__ __device__
533
+ Derived operator+ (typename Derived::difference_type n,
534
+ iterator_facade<Derived,Value,System,Traversal,Reference,Difference> const& i)
535
+ {
536
+ Derived tmp(static_cast<Derived const&>(i));
537
+ return tmp += n;
538
+ }
539
+
540
+ /*! \endcond
541
+ */
542
+
543
+ /*! \} // end fancyiterators
544
+ */
545
+
546
+ /*! \} // end iterators
547
+ */
548
+
549
+ THRUST_NAMESPACE_END
550
+
miniCUDA124/include/thrust/iterator/iterator_traits.h ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file thrust/iterator/iterator_traits.h
19
+ * \brief Traits and metafunctions for reasoning about the traits of iterators
20
+ */
21
+
22
+ /*
23
+ * (C) Copyright David Abrahams 2003.
24
+ *
25
+ * Distributed under the Boost Software License, Version 1.0.
26
+ * (See accompanying NOTICE file for the complete license)
27
+ *
28
+ * For more information, see http://www.boost.org
29
+ */
30
+
31
+ #pragma once
32
+
33
+ #include <thrust/detail/config.h>
34
+
35
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
36
+ # pragma GCC system_header
37
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
38
+ # pragma clang system_header
39
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
40
+ # pragma system_header
41
+ #endif // no system header
42
+ #include <thrust/type_traits/void_t.h>
43
+
44
+ #include <iterator>
45
+
46
+ THRUST_NAMESPACE_BEGIN
47
+
48
+ /*! \p iterator_traits is a type trait class that provides a uniform
49
+ * interface for querying the properties of iterators at compile-time.
50
+ */
51
+ template <typename T>
52
+ struct iterator_traits : std::iterator_traits<T> {};
53
+
54
+ template<typename Iterator> struct iterator_value;
55
+
56
+ template<typename Iterator> struct iterator_pointer;
57
+
58
+ template<typename Iterator> struct iterator_reference;
59
+
60
+ template<typename Iterator> struct iterator_difference;
61
+
62
+ template<typename Iterator> struct iterator_traversal;
63
+
64
+ template<typename Iterator> struct iterator_system;
65
+
66
+ THRUST_NAMESPACE_END
67
+
68
+ #include <thrust/iterator/detail/iterator_traversal_tags.h>
69
+ #include <thrust/iterator/detail/host_system_tag.h>
70
+ #include <thrust/iterator/detail/device_system_tag.h>
71
+ #include <thrust/iterator/detail/any_system_tag.h>
72
+ #include <thrust/iterator/detail/iterator_traits.inl>
73
+
miniCUDA124/include/thrust/iterator/permutation_iterator.h ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file thrust/iterator/permutation_iterator.h
18
+ * \brief An iterator which performs a gather or scatter operation when dereferenced
19
+ */
20
+
21
+ /*
22
+ * (C) Copyright Toon Knapen 2001.
23
+ * (C) Copyright David Abrahams 2003.
24
+ * (C) Copyright Roland Richter 2003.
25
+ *
26
+ * Distributed under the Boost Software License, Version 1.0.
27
+ * (See accompanying NOTICE file for the complete license)
28
+ *
29
+ * For more information, see http://www.boost.org
30
+ */
31
+
32
+ #pragma once
33
+
34
+ #include <thrust/detail/config.h>
35
+
36
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
37
+ # pragma GCC system_header
38
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
39
+ # pragma clang system_header
40
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
41
+ # pragma system_header
42
+ #endif // no system header
43
+ #include <thrust/detail/type_traits.h>
44
+ #include <thrust/iterator/detail/permutation_iterator_base.h>
45
+ #include <thrust/iterator/iterator_facade.h>
46
+ #include <thrust/iterator/iterator_traits.h>
47
+
48
+ THRUST_NAMESPACE_BEGIN
49
+
50
+
51
+ /*! \addtogroup iterators
52
+ * \{
53
+ */
54
+
55
+ /*! \addtogroup fancyiterator Fancy Iterators
56
+ * \ingroup iterators
57
+ * \{
58
+ */
59
+
60
+ /*! \p permutation_iterator is an iterator which represents a pointer into a
61
+ * reordered view of a given range. \p permutation_iterator is an imprecise name;
62
+ * the reordered view need not be a strict permutation. This iterator is useful
63
+ * for fusing a scatter or gather operation with other algorithms.
64
+ *
65
+ * This iterator takes two arguments:
66
+ *
67
+ * - an iterator to the range \c V on which the "permutation" will be applied
68
+ * - the reindexing scheme that defines how the elements of \c V will be permuted.
69
+ *
70
+ * Note that \p permutation_iterator is not limited to strict permutations of the
71
+ * given range \c V. The distance between begin and end of the reindexing iterators
72
+ * is allowed to be smaller compared to the size of the range \c V, in which case
73
+ * the \p permutation_iterator only provides a "permutation" of a subrange of \c V.
74
+ * The indices neither need to be unique. In this same context, it must be noted
75
+ * that the past-the-end \p permutation_iterator is completely defined by means of
76
+ * the past-the-end iterator to the indices.
77
+ *
78
+ * The following code snippet demonstrates how to create a \p permutation_iterator
79
+ * which represents a reordering of the contents of a \p device_vector.
80
+ *
81
+ * \code
82
+ * #include <thrust/iterator/permutation_iterator.h>
83
+ * #include <thrust/device_vector.h>
84
+ * ...
85
+ * thrust::device_vector<float> values(8);
86
+ * values[0] = 10.0f;
87
+ * values[1] = 20.0f;
88
+ * values[2] = 30.0f;
89
+ * values[3] = 40.0f;
90
+ * values[4] = 50.0f;
91
+ * values[5] = 60.0f;
92
+ * values[6] = 70.0f;
93
+ * values[7] = 80.0f;
94
+ *
95
+ * thrust::device_vector<int> indices(4);
96
+ * indices[0] = 2;
97
+ * indices[1] = 6;
98
+ * indices[2] = 1;
99
+ * indices[3] = 3;
100
+ *
101
+ * typedef thrust::device_vector<float>::iterator ElementIterator;
102
+ * typedef thrust::device_vector<int>::iterator IndexIterator;
103
+ *
104
+ * thrust::permutation_iterator<ElementIterator,IndexIterator> iter(values.begin(), indices.begin());
105
+ *
106
+ * *iter; // returns 30.0f;
107
+ * iter[0]; // returns 30.0f;
108
+ * iter[1]; // returns 70.0f;
109
+ * iter[2]; // returns 20.0f;
110
+ * iter[3]; // returns 40.0f;
111
+ *
112
+ * // iter[4] is an out-of-bounds error
113
+ *
114
+ * *iter = -1.0f; // sets values[2] to -1.0f;
115
+ * iter[0] = -1.0f; // sets values[2] to -1.0f;
116
+ * iter[1] = -1.0f; // sets values[6] to -1.0f;
117
+ * iter[2] = -1.0f; // sets values[1] to -1.0f;
118
+ * iter[3] = -1.0f; // sets values[3] to -1.0f;
119
+ *
120
+ * // values is now {10, -1, -1, -1, 50, 60, -1, 80}
121
+ * \endcode
122
+ *
123
+ * \see make_permutation_iterator
124
+ */
125
+ template <typename ElementIterator,
126
+ typename IndexIterator>
127
+ class permutation_iterator
128
+ : public thrust::detail::permutation_iterator_base<
129
+ ElementIterator,
130
+ IndexIterator
131
+ >::type
132
+ {
133
+ /*! \cond
134
+ */
135
+ private:
136
+ typedef typename detail::permutation_iterator_base<ElementIterator,IndexIterator>::type super_t;
137
+
138
+ friend class thrust::iterator_core_access;
139
+ /*! \endcond
140
+ */
141
+
142
+ public:
143
+ /*! Null constructor calls the null constructor of this \p permutation_iterator's
144
+ * element iterator.
145
+ */
146
+ permutation_iterator() = default;
147
+
148
+ /*! Constructor accepts an \c ElementIterator into a range of values and an
149
+ * \c IndexIterator into a range of indices defining the indexing scheme on the
150
+ * values.
151
+ *
152
+ * \param x An \c ElementIterator pointing this \p permutation_iterator's range of values.
153
+ * \param y An \c IndexIterator pointing to an indexing scheme to use on \p x.
154
+ */
155
+ __host__ __device__
156
+ explicit permutation_iterator(ElementIterator x, IndexIterator y)
157
+ : super_t(y), m_element_iterator(x) {}
158
+
159
+ /*! Copy constructor accepts a related \p permutation_iterator.
160
+ * \param r A compatible \p permutation_iterator to copy from.
161
+ */
162
+ template<typename OtherElementIterator, typename OtherIndexIterator>
163
+ __host__ __device__
164
+ permutation_iterator(permutation_iterator<OtherElementIterator,OtherIndexIterator> const &r
165
+ // XXX remove these guards when we have static_assert
166
+ , typename detail::enable_if_convertible<OtherElementIterator, ElementIterator>::type* = 0
167
+ , typename detail::enable_if_convertible<OtherIndexIterator, IndexIterator>::type* = 0
168
+ )
169
+ : super_t(r.base()), m_element_iterator(r.m_element_iterator)
170
+ {}
171
+
172
+ /*! \cond
173
+ */
174
+ private:
175
+ // MSVC 2013 and 2015 incorrectly warning about returning a reference to
176
+ // a local/temporary here.
177
+ // See goo.gl/LELTNp
178
+ THRUST_DISABLE_MSVC_WARNING_BEGIN(4172)
179
+
180
+ __thrust_exec_check_disable__
181
+ __host__ __device__
182
+ typename super_t::reference dereference() const
183
+ {
184
+ return *(m_element_iterator + *this->base());
185
+ }
186
+
187
+ THRUST_DISABLE_MSVC_WARNING_END(4172)
188
+
189
+ // make friends for the copy constructor
190
+ template<typename,typename> friend class permutation_iterator;
191
+
192
+ ElementIterator m_element_iterator;
193
+ /*! \endcond
194
+ */
195
+ }; // end permutation_iterator
196
+
197
+
198
+ /*! \p make_permutation_iterator creates a \p permutation_iterator
199
+ * from an \c ElementIterator pointing to a range of elements to "permute"
200
+ * and an \c IndexIterator pointing to a range of indices defining an indexing
201
+ * scheme on the values.
202
+ *
203
+ * \param e An \c ElementIterator pointing to a range of values.
204
+ * \param i An \c IndexIterator pointing to an indexing scheme to use on \p e.
205
+ * \return A new \p permutation_iterator which permutes the range \p e by \p i.
206
+ * \see permutation_iterator
207
+ */
208
+ template<typename ElementIterator, typename IndexIterator>
209
+ __host__ __device__
210
+ permutation_iterator<ElementIterator,IndexIterator> make_permutation_iterator(ElementIterator e, IndexIterator i)
211
+ {
212
+ return permutation_iterator<ElementIterator,IndexIterator>(e,i);
213
+ }
214
+
215
+ /*! \} // end fancyiterators
216
+ */
217
+
218
+ /*! \} // end iterators
219
+ */
220
+
221
+ THRUST_NAMESPACE_END
222
+
miniCUDA124/include/thrust/iterator/retag.h ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file thrust/iterator/retag.h
18
+ * \brief Functionality for altering an iterator's associated system.
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+ #include <thrust/iterator/detail/retag.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+
37
+ /*! \ingroup iterator_tags
38
+ * \{
39
+ */
40
+
41
+ #if 0
42
+ /*! \p reinterpret_tag returns a copy of an iterator and changes the type of the result's system tag.
43
+ * \tparam Tag Any system tag.
44
+ * \tparam Iterator Any iterator type.
45
+ * \param iter The iterator of interest.
46
+ * \return An iterator of unspecified type whose system tag is \p Tag and whose behavior is otherwise
47
+ * equivalent to \p iter.
48
+ * \note Unlike \p retag, \p reinterpret_tag does not enforce that the converted-to system tag be
49
+ * related to the converted-from system tag.
50
+ * \see retag
51
+ */
52
+ template<typename Tag, typename Iterator>
53
+ __host__ __device__
54
+ unspecified_iterator_type reinterpret_tag(Iterator iter);
55
+
56
+ /*! \p retag returns a copy of an iterator and changes the type of the result's system tag.
57
+ * \tparam Tag \p Tag shall be convertible to <tt>thrust::iterator_system<Iterator>::type</tt>,
58
+ * or <tt>thrust::iterator_system<Iterator>::type</tt> is a base type of \p Tag.
59
+ * \tparam Iterator Any iterator type.
60
+ * \param iter The iterator of interest.
61
+ * \return An iterator of unspecified type whose system tag is \p Tag and whose behavior is
62
+ * otherwise equivalent to \p iter.
63
+ * \note Unlike \p reinterpret_tag, \p retag enforces that the converted-to system tag be
64
+ * related to the converted-from system tag.
65
+ * \see reinterpret_tag
66
+ */
67
+ template<typename Tag, typename Iterator>
68
+ __host__ __device__
69
+ unspecified_iterator_type retag(Iterator iter);
70
+ #endif
71
+
72
+ /*! \} // iterator_tags
73
+ */
74
+
75
+
76
+ THRUST_NAMESPACE_END
77
+
miniCUDA124/include/thrust/iterator/reverse_iterator.h ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file thrust/iterator/reverse_iterator.h
19
+ * \brief An iterator adaptor which adapts another iterator to traverse backwards
20
+ */
21
+
22
+ /*
23
+ * (C) Copyright David Abrahams 2002.
24
+ * (C) Copyright Jeremy Siek 2002.
25
+ * (C) Copyright Thomas Witt 2002.
26
+ *
27
+ * Distributed under the Boost Software License, Version 1.0.
28
+ * (See accompanying NOTICE file for the complete license)
29
+ *
30
+ * For more information, see http://www.boost.org
31
+ */
32
+
33
+ #pragma once
34
+
35
+ #include <thrust/detail/config.h>
36
+
37
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
38
+ # pragma GCC system_header
39
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
40
+ # pragma clang system_header
41
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
42
+ # pragma system_header
43
+ #endif // no system header
44
+ #include <thrust/detail/type_traits.h>
45
+ #include <thrust/iterator/detail/reverse_iterator_base.h>
46
+ #include <thrust/iterator/iterator_facade.h>
47
+
48
+ THRUST_NAMESPACE_BEGIN
49
+
50
+ /*! \addtogroup iterators
51
+ * \{
52
+ */
53
+
54
+ /*! \addtogroup fancyiterator Fancy Iterators
55
+ * \ingroup iterators
56
+ * \{
57
+ */
58
+
59
+ /*! \p reverse_iterator is an iterator which represents a pointer into a
60
+ * reversed view of a given range. In this way, \p reverse_iterator allows
61
+ * backwards iteration through a bidirectional input range.
62
+ *
63
+ * It is important to note that although \p reverse_iterator is constructed
64
+ * from a given iterator, it points to the element preceding it. In this way,
65
+ * the past-the-end \p reverse_iterator of a given range points to the element
66
+ * preceding the first element of the input range. By the same token, the first
67
+ * \p reverse_iterator of a given range is constructed from a past-the-end iterator
68
+ * of the original range yet points to the last element of the input.
69
+ *
70
+ * The following code snippet demonstrates how to create a \p reverse_iterator
71
+ * which represents a reversed view of the contents of a \p device_vector.
72
+ *
73
+ * \code
74
+ * #include <thrust/iterator/reverse_iterator.h>
75
+ * #include <thrust/device_vector.h>
76
+ * ...
77
+ * thrust::device_vector<float> v(4);
78
+ * v[0] = 0.0f;
79
+ * v[1] = 1.0f;
80
+ * v[2] = 2.0f;
81
+ * v[3] = 3.0f;
82
+ *
83
+ * typedef thrust::device_vector<float>::iterator Iterator;
84
+ *
85
+ * // note that we point the iterator to the *end* of the device_vector
86
+ * thrust::reverse_iterator<Iterator> iter(values.end());
87
+ *
88
+ * *iter; // returns 3.0f;
89
+ * iter[0]; // returns 3.0f;
90
+ * iter[1]; // returns 2.0f;
91
+ * iter[2]; // returns 1.0f;
92
+ * iter[3]; // returns 0.0f;
93
+ *
94
+ * // iter[4] is an out-of-bounds error
95
+ * \endcode
96
+ *
97
+ * Since reversing a range is a common operation, containers like \p device_vector
98
+ * have nested typedefs for declaration shorthand and methods for constructing
99
+ * reverse_iterators. The following code snippet is equivalent to the previous:
100
+ *
101
+ * \code
102
+ * #include <thrust/device_vector.h>
103
+ * ...
104
+ * thrust::device_vector<float> v(4);
105
+ * v[0] = 0.0f;
106
+ * v[1] = 1.0f;
107
+ * v[2] = 2.0f;
108
+ * v[3] = 3.0f;
109
+ *
110
+ * // we use the nested type reverse_iterator to refer to a reversed view of
111
+ * // a device_vector and the method rbegin() to create a reverse_iterator pointing
112
+ * // to the beginning of the reversed device_vector
113
+ * thrust::device_iterator<float>::reverse_iterator iter = values.rbegin();
114
+ *
115
+ * *iter; // returns 3.0f;
116
+ * iter[0]; // returns 3.0f;
117
+ * iter[1]; // returns 2.0f;
118
+ * iter[2]; // returns 1.0f;
119
+ * iter[3]; // returns 0.0f;
120
+ *
121
+ * // iter[4] is an out-of-bounds error
122
+ *
123
+ * // similarly, rend() points to the end of the reversed sequence:
124
+ * assert(values.rend() == (iter + 4));
125
+ * \endcode
126
+ *
127
+ * Finally, the following code snippet demonstrates how to use reverse_iterator to
128
+ * perform a reversed prefix sum operation on the contents of a device_vector:
129
+ *
130
+ * \code
131
+ * #include <thrust/device_vector.h>
132
+ * #include <thrust/scan.h>
133
+ * ...
134
+ * thrust::device_vector<int> v(5);
135
+ * v[0] = 0;
136
+ * v[1] = 1;
137
+ * v[2] = 2;
138
+ * v[3] = 3;
139
+ * v[4] = 4;
140
+ *
141
+ * thrust::device_vector<int> result(5);
142
+ *
143
+ * // exclusive scan v into result in reverse
144
+ * thrust::exclusive_scan(v.rbegin(), v.rend(), result.begin());
145
+ *
146
+ * // result is now {0, 4, 7, 9, 10}
147
+ * \endcode
148
+ *
149
+ * \see make_reverse_iterator
150
+ */
151
+ template<typename BidirectionalIterator>
152
+ class reverse_iterator
153
+ : public detail::reverse_iterator_base<BidirectionalIterator>::type
154
+ {
155
+ /*! \cond
156
+ */
157
+ private:
158
+ typedef typename thrust::detail::reverse_iterator_base<
159
+ BidirectionalIterator
160
+ >::type super_t;
161
+
162
+ friend class thrust::iterator_core_access;
163
+ /*! \endcond
164
+ */
165
+
166
+ public:
167
+ /*! Default constructor does nothing.
168
+ */
169
+ __host__ __device__
170
+ reverse_iterator() {}
171
+
172
+ /*! \p Constructor accepts a \c BidirectionalIterator pointing to a range
173
+ * for this \p reverse_iterator to reverse.
174
+ *
175
+ * \param x A \c BidirectionalIterator pointing to a range to reverse.
176
+ */
177
+ __host__ __device__
178
+ explicit reverse_iterator(BidirectionalIterator x);
179
+
180
+ /*! \p Copy constructor allows construction from a related compatible
181
+ * \p reverse_iterator.
182
+ *
183
+ * \param r A \p reverse_iterator to copy from.
184
+ */
185
+ template<typename OtherBidirectionalIterator>
186
+ __host__ __device__
187
+ reverse_iterator(reverse_iterator<OtherBidirectionalIterator> const &r
188
+ // XXX msvc screws this up
189
+ // XXX remove these guards when we have static_assert
190
+ #if THRUST_HOST_COMPILER != THRUST_HOST_COMPILER_MSVC
191
+ , typename thrust::detail::enable_if<
192
+ thrust::detail::is_convertible<
193
+ OtherBidirectionalIterator,
194
+ BidirectionalIterator
195
+ >::value
196
+ >::type * = 0
197
+ #endif // MSVC
198
+ );
199
+
200
+ /*! \cond
201
+ */
202
+ private:
203
+ __thrust_exec_check_disable__
204
+ __host__ __device__
205
+ typename super_t::reference dereference() const;
206
+
207
+ __host__ __device__
208
+ void increment();
209
+
210
+ __host__ __device__
211
+ void decrement();
212
+
213
+ __host__ __device__
214
+ void advance(typename super_t::difference_type n);
215
+
216
+ template<typename OtherBidirectionalIterator>
217
+ __host__ __device__
218
+ typename super_t::difference_type
219
+ distance_to(reverse_iterator<OtherBidirectionalIterator> const &y) const;
220
+ /*! \endcond
221
+ */
222
+ }; // end reverse_iterator
223
+
224
+
225
+ /*! \p make_reverse_iterator creates a \p reverse_iterator
226
+ * from a \c BidirectionalIterator pointing to a range of elements to reverse.
227
+ *
228
+ * \param x A \c BidirectionalIterator pointing to a range to reverse.
229
+ * \return A new \p reverse_iterator which reverses the range \p x.
230
+ */
231
+ template<typename BidirectionalIterator>
232
+ __host__ __device__
233
+ reverse_iterator<BidirectionalIterator> make_reverse_iterator(BidirectionalIterator x);
234
+
235
+
236
+ /*! \} // end fancyiterators
237
+ */
238
+
239
+ /*! \} // end iterators
240
+ */
241
+
242
+ THRUST_NAMESPACE_END
243
+
244
+ #include <thrust/iterator/detail/reverse_iterator.inl>
245
+
miniCUDA124/include/thrust/iterator/transform_input_output_iterator.h ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2020 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file thrust/iterator/transform_input_output_iterator.h
18
+ * \brief An iterator which adapts another iterator by applying transform
19
+ * functions when reading and writing dereferenced values.
20
+ */
21
+
22
+ #pragma once
23
+
24
+ #include <thrust/detail/config.h>
25
+
26
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
27
+ # pragma GCC system_header
28
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
29
+ # pragma clang system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
31
+ # pragma system_header
32
+ #endif // no system header
33
+ #include <thrust/iterator/detail/transform_input_output_iterator.inl>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+ /*! \addtogroup iterators
38
+ * \{
39
+ */
40
+
41
+ /*! \addtogroup fancyiterator Fancy Iterators
42
+ * \ingroup iterators
43
+ * \{
44
+ */
45
+
46
+ /*! \p transform_input_output_iterator is a special kind of iterator which applies
47
+ * transform functions when reading from or writing to dereferenced values.
48
+ * This iterator is useful for algorithms that operate on a type that needs to
49
+ * be serialized/deserialized from values in another iterator, avoiding the
50
+ * need to materialize intermediate results in memory. This also enables the
51
+ * transform functions to be fused with the operations that read and write to
52
+ * the `transform_input_output_iterator`.
53
+ *
54
+ * The following code snippet demonstrates how to create a
55
+ * \p transform_input_output_iterator which performs different transformations when
56
+ * reading from and writing to the iterator.
57
+ *
58
+ * \code
59
+ * #include <thrust/iterator/transform_input_output_iterator.h>
60
+ * #include <thrust/device_vector.h>
61
+ *
62
+ * int main()
63
+ * {
64
+ * const size_t size = 4;
65
+ * thrust::device_vector<float> v(size);
66
+ *
67
+ * // Write 1.0f, 2.0f, 3.0f, 4.0f to vector
68
+ * thrust::sequence(v.begin(), v.end(), 1);
69
+ *
70
+ * // Iterator that returns negated values and writes squared values
71
+ * auto iter = thrust::make_transform_input_output_iterator(v.begin(),
72
+ * thrust::negate<float>{}, thrust::square<float>{});
73
+ *
74
+ * // Iterator negates values when reading
75
+ * std::cout << iter[0] << " "; // -1.0f;
76
+ * std::cout << iter[1] << " "; // -2.0f;
77
+ * std::cout << iter[2] << " "; // -3.0f;
78
+ * std::cout << iter[3] << "\n"; // -4.0f;
79
+ *
80
+ * // Write 1.0f, 2.0f, 3.0f, 4.0f to iterator
81
+ * thrust::sequence(iter, iter + size, 1);
82
+ *
83
+ * // Values were squared before writing to vector
84
+ * std::cout << v[0] << " "; // 1.0f;
85
+ * std::cout << v[1] << " "; // 4.0f;
86
+ * std::cout << v[2] << " "; // 9.0f;
87
+ * std::cout << v[3] << "\n"; // 16.0f;
88
+ *
89
+ * }
90
+ * \endcode
91
+ *
92
+ * \see make_transform_input_output_iterator
93
+ */
94
+
95
+ template <typename InputFunction, typename OutputFunction, typename Iterator>
96
+ class transform_input_output_iterator
97
+ : public detail::transform_input_output_iterator_base<InputFunction, OutputFunction, Iterator>::type
98
+ {
99
+
100
+ /*! \cond
101
+ */
102
+
103
+ public:
104
+
105
+ typedef typename
106
+ detail::transform_input_output_iterator_base<InputFunction, OutputFunction, Iterator>::type
107
+ super_t;
108
+
109
+ friend class thrust::iterator_core_access;
110
+ /*! \endcond
111
+ */
112
+
113
+ transform_input_output_iterator() = default;
114
+
115
+ /*! This constructor takes as argument a \c Iterator an \c InputFunction and an
116
+ * \c OutputFunction and copies them to a new \p transform_input_output_iterator
117
+ *
118
+ * \param io An \c Iterator pointing to where the input to \c InputFunction
119
+ * will be read from and the result of \c OutputFunction will be written to
120
+ * \param input_function An \c InputFunction to be executed on values read from the iterator
121
+ * \param output_function An \c OutputFunction to be executed on values written to the iterator
122
+ */
123
+ __host__ __device__
124
+ transform_input_output_iterator(Iterator const& io, InputFunction input_function, OutputFunction output_function)
125
+ : super_t(io), input_function(input_function), output_function(output_function)
126
+ {
127
+ }
128
+
129
+ /*! \cond
130
+ */
131
+ private:
132
+
133
+ __host__ __device__
134
+ typename super_t::reference dereference() const
135
+ {
136
+ return detail::transform_input_output_iterator_proxy<
137
+ InputFunction, OutputFunction, Iterator
138
+ >(this->base_reference(), input_function, output_function);
139
+ }
140
+
141
+ InputFunction input_function;
142
+ OutputFunction output_function;
143
+
144
+ /*! \endcond
145
+ */
146
+ }; // end transform_input_output_iterator
147
+
148
+ /*! \p make_transform_input_output_iterator creates a \p transform_input_output_iterator from
149
+ * an \c Iterator a \c InputFunction and a \c OutputFunction
150
+ *
151
+ * \param io An \c Iterator pointing to where the input to \c InputFunction
152
+ * will be read from and the result of \c OutputFunction will be written to
153
+ * \param input_function An \c InputFunction to be executed on values read from the iterator
154
+ * \param output_function An \c OutputFunction to be executed on values written to the iterator
155
+ * \see transform_input_output_iterator
156
+ */
157
+ template <typename InputFunction, typename OutputFunction, typename Iterator>
158
+ transform_input_output_iterator<InputFunction, OutputFunction, Iterator>
159
+ __host__ __device__
160
+ make_transform_input_output_iterator(Iterator io, InputFunction input_function, OutputFunction output_function)
161
+ {
162
+ return transform_input_output_iterator<InputFunction, OutputFunction, Iterator>(io, input_function, output_function);
163
+ } // end make_transform_input_output_iterator
164
+
165
+ /*! \} // end fancyiterators
166
+ */
167
+
168
+ /*! \} // end iterators
169
+ */
170
+
171
+ THRUST_NAMESPACE_END
172
+
miniCUDA124/include/thrust/iterator/transform_iterator.h ADDED
@@ -0,0 +1,362 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file thrust/iterator/transform_iterator.h
19
+ * \brief An iterator which adapts another iterator by applying a function to the result of its dereference
20
+ */
21
+
22
+ /*
23
+ * (C) Copyright David Abrahams 2002.
24
+ * (C) Copyright Jeremy Siek 2002.
25
+ * (C) Copyright Thomas Witt 2002.
26
+ *
27
+ * Distributed under the Boost Software License, Version 1.0.
28
+ * (See accompanying NOTICE file for the complete license)
29
+ *
30
+ * For more information, see http://www.boost.org
31
+ */
32
+
33
+ #pragma once
34
+
35
+ #include <thrust/detail/config.h>
36
+
37
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
38
+ # pragma GCC system_header
39
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
40
+ # pragma clang system_header
41
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
42
+ # pragma system_header
43
+ #endif // no system header
44
+
45
+ // #include the details first
46
+ #include <thrust/iterator/detail/transform_iterator.inl>
47
+ #include <thrust/iterator/iterator_facade.h>
48
+ #include <thrust/iterator/iterator_traits.h>
49
+ #include <thrust/detail/type_traits.h>
50
+
51
+ THRUST_NAMESPACE_BEGIN
52
+
53
+ /*! \addtogroup iterators
54
+ * \{
55
+ */
56
+
57
+ /*! \addtogroup fancyiterator Fancy Iterators
58
+ * \ingroup iterators
59
+ * \{
60
+ */
61
+
62
+ /*! \p transform_iterator is an iterator which represents a pointer into a range
63
+ * of values after transformation by a function. This iterator is useful for
64
+ * creating a range filled with the result of applying an operation to another range
65
+ * without either explicitly storing it in memory, or explicitly executing the transformation.
66
+ * Using \p transform_iterator facilitates kernel fusion by deferring the execution
67
+ * of a transformation until the value is needed while saving both memory capacity
68
+ * and bandwidth.
69
+ *
70
+ * The following code snippet demonstrates how to create a \p transform_iterator
71
+ * which represents the result of \c sqrtf applied to the contents of a \p device_vector.
72
+ *
73
+ * \code
74
+ * #include <thrust/iterator/transform_iterator.h>
75
+ * #include <thrust/device_vector.h>
76
+ *
77
+ * // note: functor inherits from unary_function
78
+ * struct square_root : public thrust::unary_function<float,float>
79
+ * {
80
+ * __host__ __device__
81
+ * float operator()(float x) const
82
+ * {
83
+ * return sqrtf(x);
84
+ * }
85
+ * };
86
+ *
87
+ * int main()
88
+ * {
89
+ * thrust::device_vector<float> v(4);
90
+ * v[0] = 1.0f;
91
+ * v[1] = 4.0f;
92
+ * v[2] = 9.0f;
93
+ * v[3] = 16.0f;
94
+ *
95
+ * typedef thrust::device_vector<float>::iterator FloatIterator;
96
+ *
97
+ * thrust::transform_iterator<square_root, FloatIterator> iter(v.begin(), square_root());
98
+ *
99
+ * *iter; // returns 1.0f
100
+ * iter[0]; // returns 1.0f;
101
+ * iter[1]; // returns 2.0f;
102
+ * iter[2]; // returns 3.0f;
103
+ * iter[3]; // returns 4.0f;
104
+ *
105
+ * // iter[4] is an out-of-bounds error
106
+ * }
107
+ * \endcode
108
+ *
109
+ * This next example demonstrates how to use a \p transform_iterator with the
110
+ * \p thrust::reduce function to compute the sum of squares of a sequence.
111
+ * We will create temporary \p transform_iterators with the
112
+ * \p make_transform_iterator function in order to avoid explicitly specifying their type:
113
+ *
114
+ * \code
115
+ * #include <thrust/iterator/transform_iterator.h>
116
+ * #include <thrust/device_vector.h>
117
+ * #include <thrust/reduce.h>
118
+ * #include <iostream>
119
+ *
120
+ * // note: functor inherits from unary_function
121
+ * struct square : public thrust::unary_function<float,float>
122
+ * {
123
+ * __host__ __device__
124
+ * float operator()(float x) const
125
+ * {
126
+ * return x * x;
127
+ * }
128
+ * };
129
+ *
130
+ * int main()
131
+ * {
132
+ * // initialize a device array
133
+ * thrust::device_vector<float> v(4);
134
+ * v[0] = 1.0f;
135
+ * v[1] = 2.0f;
136
+ * v[2] = 3.0f;
137
+ * v[3] = 4.0f;
138
+ *
139
+ * float sum_of_squares =
140
+ * thrust::reduce(thrust::make_transform_iterator(v.begin(), square()),
141
+ * thrust::make_transform_iterator(v.end(), square()));
142
+ *
143
+ * std::cout << "sum of squares: " << sum_of_squares << std::endl;
144
+ * return 0;
145
+ * }
146
+ * \endcode
147
+ *
148
+ * Note that in the previous two examples the transform functor (namely \c square_root
149
+ * and \c square) inherits from \c thrust::unary_function. Inheriting from
150
+ * \c thrust::unary_function ensures that a functor is a valid \c AdaptableUnaryFunction
151
+ * and provides all the necessary \c typedef declarations. The \p transform_iterator
152
+ * can also be applied to a \c UnaryFunction that does not inherit from
153
+ * \c thrust::unary_function using an optional template argument. The following example
154
+ * illustrates how to use the third template argument to specify the \c result_type of
155
+ * the function.
156
+ *
157
+ * \code
158
+ * #include <thrust/iterator/transform_iterator.h>
159
+ * #include <thrust/device_vector.h>
160
+ *
161
+ * // note: functor *does not* inherit from unary_function
162
+ * struct square_root
163
+ * {
164
+ * __host__ __device__
165
+ * float operator()(float x) const
166
+ * {
167
+ * return sqrtf(x);
168
+ * }
169
+ * };
170
+ *
171
+ * int main()
172
+ * {
173
+ * thrust::device_vector<float> v(4);
174
+ * v[0] = 1.0f;
175
+ * v[1] = 4.0f;
176
+ * v[2] = 9.0f;
177
+ * v[3] = 16.0f;
178
+ *
179
+ * typedef thrust::device_vector<float>::iterator FloatIterator;
180
+ *
181
+ * // note: float result_type is specified explicitly
182
+ * thrust::transform_iterator<square_root, FloatIterator, float> iter(v.begin(), square_root());
183
+ *
184
+ * *iter; // returns 1.0f
185
+ * iter[0]; // returns 1.0f;
186
+ * iter[1]; // returns 2.0f;
187
+ * iter[2]; // returns 3.0f;
188
+ * iter[3]; // returns 4.0f;
189
+ *
190
+ * // iter[4] is an out-of-bounds error
191
+ * }
192
+ * \endcode
193
+ *
194
+ * \see make_transform_iterator
195
+ */
196
+ template <class AdaptableUnaryFunction, class Iterator, class Reference = use_default, class Value = use_default>
197
+ class transform_iterator
198
+ : public detail::transform_iterator_base<AdaptableUnaryFunction, Iterator, Reference, Value>::type
199
+ {
200
+ /*! \cond
201
+ */
202
+ public:
203
+ typedef typename
204
+ detail::transform_iterator_base<AdaptableUnaryFunction, Iterator, Reference, Value>::type
205
+ super_t;
206
+
207
+ friend class thrust::iterator_core_access;
208
+ /*! \endcond
209
+ */
210
+
211
+ public:
212
+ /*! Null constructor does nothing.
213
+ */
214
+ transform_iterator() = default;
215
+
216
+ #if THRUST_CPP_DIALECT >= 2011
217
+ transform_iterator(transform_iterator const&) = default;
218
+ #endif
219
+
220
+ /*! This constructor takes as arguments an \c Iterator and an \c AdaptableUnaryFunction
221
+ * and copies them to a new \p transform_iterator.
222
+ *
223
+ * \param x An \c Iterator pointing to the input to this \p transform_iterator's \c AdaptableUnaryFunction.
224
+ * \param f An \c AdaptableUnaryFunction used to transform the objects pointed to by \p x.
225
+ */
226
+ __host__ __device__
227
+ transform_iterator(Iterator const& x, AdaptableUnaryFunction f)
228
+ : super_t(x), m_f(f) {
229
+ }
230
+
231
+ /*! This explicit constructor copies the value of a given \c Iterator and creates
232
+ * this \p transform_iterator's \c AdaptableUnaryFunction using its null constructor.
233
+ *
234
+ * \param x An \c Iterator to copy.
235
+ */
236
+ __host__ __device__
237
+ explicit transform_iterator(Iterator const& x)
238
+ : super_t(x) { }
239
+
240
+ /*! This copy constructor creates a new \p transform_iterator from another
241
+ * \p transform_iterator.
242
+ *
243
+ * \param other The \p transform_iterator to copy.
244
+ */
245
+ template<typename OtherAdaptableUnaryFunction,
246
+ typename OtherIterator,
247
+ typename OtherReference,
248
+ typename OtherValue>
249
+ __host__ __device__
250
+ transform_iterator(const transform_iterator<OtherAdaptableUnaryFunction, OtherIterator, OtherReference, OtherValue> &other,
251
+ typename thrust::detail::enable_if_convertible<OtherIterator, Iterator>::type* = 0,
252
+ typename thrust::detail::enable_if_convertible<OtherAdaptableUnaryFunction, AdaptableUnaryFunction>::type* = 0)
253
+ : super_t(other.base()), m_f(other.functor()) {}
254
+
255
+ /*! Copy assignment operator copies from another \p transform_iterator.
256
+ * \p other The other \p transform_iterator to copy
257
+ * \return <tt>*this</tt>
258
+ *
259
+ * \note If the type of this \p transform_iterator's functor is not copy assignable
260
+ * (for example, if it is a lambda) it is not an error to call this function.
261
+ * In this case, however, the functor will not be modified.
262
+ *
263
+ * In any case, this \p transform_iterator's underlying iterator will be copy assigned.
264
+ */
265
+ __host__ __device__
266
+ transform_iterator &operator=(const transform_iterator &other)
267
+ {
268
+ return do_assign(other,
269
+ // XXX gcc 4.2.1 crashes on is_copy_assignable; just assume the functor is assignable as a WAR
270
+ #if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_GCC) && (THRUST_GCC_VERSION <= 40201)
271
+ thrust::detail::true_type()
272
+ #else
273
+ typename thrust::detail::is_copy_assignable<AdaptableUnaryFunction>::type()
274
+ #endif // THRUST_HOST_COMPILER
275
+ );
276
+ }
277
+
278
+ /*! This method returns a copy of this \p transform_iterator's \c AdaptableUnaryFunction.
279
+ * \return A copy of this \p transform_iterator's \c AdaptableUnaryFunction.
280
+ */
281
+ __host__ __device__
282
+ AdaptableUnaryFunction functor() const
283
+ { return m_f; }
284
+
285
+ /*! \cond
286
+ */
287
+ private:
288
+ __host__ __device__
289
+ transform_iterator &do_assign(const transform_iterator &other, thrust::detail::true_type)
290
+ {
291
+ super_t::operator=(other);
292
+
293
+ // do assign to m_f
294
+ m_f = other.functor();
295
+
296
+ return *this;
297
+ }
298
+
299
+ __host__ __device__
300
+ transform_iterator &do_assign(const transform_iterator &other, thrust::detail::false_type)
301
+ {
302
+ super_t::operator=(other);
303
+
304
+ // don't assign to m_f
305
+
306
+ return *this;
307
+ }
308
+
309
+ // MSVC 2013 and 2015 incorrectly warning about returning a reference to
310
+ // a local/temporary here.
311
+ // See goo.gl/LELTNp
312
+ THRUST_DISABLE_MSVC_WARNING_BEGIN(4172)
313
+
314
+ __thrust_exec_check_disable__
315
+ __host__ __device__
316
+ typename super_t::reference dereference() const
317
+ {
318
+ // Create a temporary to allow iterators with wrapped references to
319
+ // convert to their value type before calling m_f. Note that this
320
+ // disallows non-constant operations through m_f.
321
+ typename thrust::iterator_value<Iterator>::type const& x = *this->base();
322
+ return m_f(x);
323
+ }
324
+
325
+ THRUST_DISABLE_MSVC_WARNING_END(4172)
326
+
327
+ // tag this as mutable per Dave Abrahams in this thread:
328
+ // http://lists.boost.org/Archives/boost/2004/05/65332.php
329
+ mutable AdaptableUnaryFunction m_f;
330
+
331
+ /*! \endcond
332
+ */
333
+ }; // end transform_iterator
334
+
335
+
336
+ /*! \p make_transform_iterator creates a \p transform_iterator
337
+ * from an \c Iterator and \c AdaptableUnaryFunction.
338
+ *
339
+ * \param it The \c Iterator pointing to the input range of the
340
+ * newly created \p transform_iterator.
341
+ * \param fun The \c AdaptableUnaryFunction used to transform the range pointed
342
+ * to by \p it in the newly created \p transform_iterator.
343
+ * \return A new \p transform_iterator which transforms the range at
344
+ * \p it by \p fun.
345
+ * \see transform_iterator
346
+ */
347
+ template <class AdaptableUnaryFunction, class Iterator>
348
+ inline __host__ __device__
349
+ transform_iterator<AdaptableUnaryFunction, Iterator>
350
+ make_transform_iterator(Iterator it, AdaptableUnaryFunction fun)
351
+ {
352
+ return transform_iterator<AdaptableUnaryFunction, Iterator>(it, fun);
353
+ } // end make_transform_iterator
354
+
355
+ /*! \} // end fancyiterators
356
+ */
357
+
358
+ /*! \} // end iterators
359
+ */
360
+
361
+ THRUST_NAMESPACE_END
362
+
miniCUDA124/include/thrust/iterator/transform_output_iterator.h ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2018 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file thrust/iterator/transform_output_iterator.h
18
+ * \brief An output iterator which adapts another output iterator by applying a
19
+ * function to the result of its dereference before writing it.
20
+ */
21
+
22
+ #pragma once
23
+
24
+ #include <thrust/detail/config.h>
25
+
26
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
27
+ # pragma GCC system_header
28
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
29
+ # pragma clang system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
31
+ # pragma system_header
32
+ #endif // no system header
33
+ #include <thrust/iterator/detail/transform_output_iterator.inl>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+ /*! \addtogroup iterators
38
+ * \{
39
+ */
40
+
41
+ /*! \addtogroup fancyiterator Fancy Iterators
42
+ * \ingroup iterators
43
+ * \{
44
+ */
45
+
46
+ /*! \p transform_output_iterator is a special kind of output iterator which
47
+ * transforms a value written upon dereference. This iterator is useful
48
+ * for transforming an output from algorithms without explicitly storing the
49
+ * intermediate result in the memory and applying subsequent transformation,
50
+ * thereby avoiding wasting memory capacity and bandwidth.
51
+ * Using \p transform_iterator facilitates kernel fusion by deferring execution
52
+ * of transformation until the value is written while saving both memory
53
+ * capacity and bandwidth.
54
+ *
55
+ * The following code snippet demonstrated how to create a
56
+ * \p transform_output_iterator which applies \c sqrtf to the assigning value.
57
+ *
58
+ * \code
59
+ * #include <thrust/iterator/transform_output_iterator.h>
60
+ * #include <thrust/device_vector.h>
61
+ *
62
+ * // note: functor inherits form unary function
63
+ * // note: functor inherits from unary_function
64
+ * struct square_root : public thrust::unary_function<float,float>
65
+ * {
66
+ * __host__ __device__
67
+ * float operator()(float x) const
68
+ * {
69
+ * return sqrtf(x);
70
+ * }
71
+ * };
72
+ *
73
+ * int main()
74
+ * {
75
+ * thrust::device_vector<float> v(4);
76
+ *
77
+ * typedef thrust::device_vector<float>::iterator FloatIterator;
78
+ * thrust::transform_output_iterator<square_root, FloatIterator> iter(v.begin(), square_root());
79
+ *
80
+ * iter[0] = 1.0f; // stores sqrtf( 1.0f)
81
+ * iter[1] = 4.0f; // stores sqrtf( 4.0f)
82
+ * iter[2] = 9.0f; // stores sqrtf( 9.0f)
83
+ * iter[3] = 16.0f; // stores sqrtf(16.0f)
84
+ * // iter[4] is an out-of-bounds error
85
+ *
86
+ * v[0]; // returns 1.0f;
87
+ * v[1]; // returns 2.0f;
88
+ * v[2]; // returns 3.0f;
89
+ * v[3]; // returns 4.0f;
90
+ *
91
+ * }
92
+ * \endcode
93
+ *
94
+ * \see make_transform_output_iterator
95
+ */
96
+
97
+ template <typename UnaryFunction, typename OutputIterator>
98
+ class transform_output_iterator
99
+ : public detail::transform_output_iterator_base<UnaryFunction, OutputIterator>::type
100
+ {
101
+
102
+ /*! \cond
103
+ */
104
+
105
+ public:
106
+
107
+ typedef typename
108
+ detail::transform_output_iterator_base<UnaryFunction, OutputIterator>::type
109
+ super_t;
110
+
111
+ friend class thrust::iterator_core_access;
112
+ /*! \endcond
113
+ */
114
+
115
+ transform_output_iterator() = default;
116
+
117
+ /*! This constructor takes as argument an \c OutputIterator and an \c
118
+ * UnaryFunction and copies them to a new \p transform_output_iterator
119
+ *
120
+ * \param out An \c OutputIterator pointing to the output range whereto the result of
121
+ * \p transform_output_iterator's \c UnaryFunction will be written.
122
+ * \param fun An \c UnaryFunction used to transform the objects assigned to
123
+ * this \p transform_output_iterator.
124
+ */
125
+ __host__ __device__
126
+ transform_output_iterator(OutputIterator const& out, UnaryFunction fun) : super_t(out), fun(fun)
127
+ {
128
+ }
129
+
130
+ /*! \cond
131
+ */
132
+ private:
133
+
134
+ __host__ __device__
135
+ typename super_t::reference dereference() const
136
+ {
137
+ return detail::transform_output_iterator_proxy<
138
+ UnaryFunction, OutputIterator
139
+ >(this->base_reference(), fun);
140
+ }
141
+
142
+ UnaryFunction fun;
143
+
144
+ /*! \endcond
145
+ */
146
+ }; // end transform_output_iterator
147
+
148
+ /*! \p make_transform_output_iterator creates a \p transform_output_iterator from
149
+ * an \c OutputIterator and \c UnaryFunction.
150
+ *
151
+ * \param out The \c OutputIterator pointing to the output range of the newly
152
+ * created \p transform_output_iterator
153
+ * \param fun The \c UnaryFunction transform the object before assigning it to
154
+ * \c out by the newly created \p transform_output_iterator
155
+ * \see transform_output_iterator
156
+ */
157
+ template <typename UnaryFunction, typename OutputIterator>
158
+ transform_output_iterator<UnaryFunction, OutputIterator>
159
+ __host__ __device__
160
+ make_transform_output_iterator(OutputIterator out, UnaryFunction fun)
161
+ {
162
+ return transform_output_iterator<UnaryFunction, OutputIterator>(out, fun);
163
+ } // end make_transform_output_iterator
164
+
165
+ /*! \} // end fancyiterators
166
+ */
167
+
168
+ /*! \} // end iterators
169
+ */
170
+
171
+ THRUST_NAMESPACE_END
172
+
miniCUDA124/include/thrust/iterator/zip_iterator.h ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2013 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /*! \file thrust/iterator/zip_iterator.h
19
+ * \brief An iterator which returns a tuple of the result of dereferencing
20
+ * a tuple of iterators when dereferenced
21
+ */
22
+
23
+ /*
24
+ * Copyright David Abrahams and Thomas Becker 2000-2006.
25
+ *
26
+ * Distributed under the Boost Software License, Version 1.0.
27
+ * (See accompanying NOTICE file for the complete license)
28
+ *
29
+ * For more information, see http://www.boost.org
30
+ */
31
+
32
+ #pragma once
33
+
34
+ #include <thrust/detail/config.h>
35
+
36
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
37
+ # pragma GCC system_header
38
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
39
+ # pragma clang system_header
40
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
41
+ # pragma system_header
42
+ #endif // no system header
43
+ #include <thrust/iterator/detail/zip_iterator_base.h>
44
+ #include <thrust/iterator/iterator_facade.h>
45
+ #include <thrust/detail/type_traits.h>
46
+
47
+ THRUST_NAMESPACE_BEGIN
48
+
49
+ /*! \addtogroup iterators
50
+ * \{
51
+ */
52
+
53
+ /*! \addtogroup fancyiterator Fancy Iterators
54
+ * \ingroup iterators
55
+ * \{
56
+ */
57
+
58
+ /*! \p zip_iterator is an iterator which represents a pointer into a range
59
+ * of \p tuples whose elements are themselves taken from a \p tuple of input
60
+ * iterators. This iterator is useful for creating a virtual array of structures
61
+ * while achieving the same performance and bandwidth as the structure of arrays
62
+ * idiom. \p zip_iterator also facilitates kernel fusion by providing a convenient
63
+ * means of amortizing the execution of the same operation over multiple ranges.
64
+ *
65
+ * The following code snippet demonstrates how to create a \p zip_iterator
66
+ * which represents the result of "zipping" multiple ranges together.
67
+ *
68
+ * \code
69
+ * #include <thrust/iterator/zip_iterator.h>
70
+ * #include <thrust/tuple.h>
71
+ * #include <thrust/device_vector.h>
72
+ * ...
73
+ * thrust::device_vector<int> int_v(3);
74
+ * int_v[0] = 0; int_v[1] = 1; int_v[2] = 2;
75
+ *
76
+ * thrust::device_vector<float> float_v(3);
77
+ * float_v[0] = 0.0f; float_v[1] = 1.0f; float_v[2] = 2.0f;
78
+ *
79
+ * thrust::device_vector<char> char_v(3);
80
+ * char_v[0] = 'a'; char_v[1] = 'b'; char_v[2] = 'c';
81
+ *
82
+ * // typedef these iterators for shorthand
83
+ * typedef thrust::device_vector<int>::iterator IntIterator;
84
+ * typedef thrust::device_vector<float>::iterator FloatIterator;
85
+ * typedef thrust::device_vector<char>::iterator CharIterator;
86
+ *
87
+ * // typedef a tuple of these iterators
88
+ * typedef thrust::tuple<IntIterator, FloatIterator, CharIterator> IteratorTuple;
89
+ *
90
+ * // typedef the zip_iterator of this tuple
91
+ * typedef thrust::zip_iterator<IteratorTuple> ZipIterator;
92
+ *
93
+ * // finally, create the zip_iterator
94
+ * ZipIterator iter(thrust::make_tuple(int_v.begin(), float_v.begin(), char_v.begin()));
95
+ *
96
+ * *iter; // returns (0, 0.0f, 'a')
97
+ * iter[0]; // returns (0, 0.0f, 'a')
98
+ * iter[1]; // returns (1, 1.0f, 'b')
99
+ * iter[2]; // returns (2, 2.0f, 'c')
100
+ *
101
+ * thrust::get<0>(iter[2]); // returns 2
102
+ * thrust::get<1>(iter[0]); // returns 0.0f
103
+ * thrust::get<2>(iter[1]); // returns 'b'
104
+ *
105
+ * // iter[3] is an out-of-bounds error
106
+ * \endcode
107
+ *
108
+ * Defining the type of a \p zip_iterator can be complex. The next code example demonstrates
109
+ * how to use the \p make_zip_iterator function with the \p make_tuple function to avoid
110
+ * explicitly specifying the type of the \p zip_iterator. This example shows how to use
111
+ * \p zip_iterator to copy multiple ranges with a single call to \p thrust::copy.
112
+ *
113
+ * \code
114
+ * #include <thrust/zip_iterator.h>
115
+ * #include <thrust/tuple.h>
116
+ * #include <thrust/device_vector.h>
117
+ *
118
+ * int main()
119
+ * {
120
+ * thrust::device_vector<int> int_in(3), int_out(3);
121
+ * int_in[0] = 0;
122
+ * int_in[1] = 1;
123
+ * int_in[2] = 2;
124
+ *
125
+ * thrust::device_vector<float> float_in(3), float_out(3);
126
+ * float_in[0] = 0.0f;
127
+ * float_in[1] = 10.0f;
128
+ * float_in[2] = 20.0f;
129
+ *
130
+ * thrust::copy(thrust::make_zip_iterator(thrust::make_tuple(int_in.begin(), float_in.begin())),
131
+ * thrust::make_zip_iterator(thrust::make_tuple(int_in.end(), float_in.end())),
132
+ * thrust::make_zip_iterator(thrust::make_tuple(int_out.begin(),float_out.begin())));
133
+ *
134
+ * // int_out is now [0, 1, 2]
135
+ * // float_out is now [0.0f, 10.0f, 20.0f]
136
+ *
137
+ * return 0;
138
+ * }
139
+ * \endcode
140
+ *
141
+ * \see make_zip_iterator
142
+ * \see make_tuple
143
+ * \see tuple
144
+ * \see get
145
+ */
146
+ template <typename IteratorTuple>
147
+ class zip_iterator
148
+ : public detail::zip_iterator_base<IteratorTuple>::type
149
+ {
150
+ public:
151
+ /*! Null constructor does nothing.
152
+ */
153
+ inline __host__ __device__
154
+ zip_iterator();
155
+
156
+ /*! This constructor creates a new \p zip_iterator from a
157
+ * \p tuple of iterators.
158
+ *
159
+ * \param iterator_tuple The \p tuple of iterators to copy from.
160
+ */
161
+ inline __host__ __device__
162
+ zip_iterator(IteratorTuple iterator_tuple);
163
+
164
+ /*! This copy constructor creates a new \p zip_iterator from another
165
+ * \p zip_iterator.
166
+ *
167
+ * \param other The \p zip_iterator to copy.
168
+ */
169
+ template<typename OtherIteratorTuple>
170
+ inline __host__ __device__
171
+ zip_iterator(const zip_iterator<OtherIteratorTuple> &other,
172
+ typename thrust::detail::enable_if_convertible<
173
+ OtherIteratorTuple,
174
+ IteratorTuple
175
+ >::type * = 0);
176
+
177
+ /*! This method returns a \c const reference to this \p zip_iterator's
178
+ * \p tuple of iterators.
179
+ *
180
+ * \return A \c const reference to this \p zip_iterator's \p tuple
181
+ * of iterators.
182
+ */
183
+ inline __host__ __device__
184
+ const IteratorTuple &get_iterator_tuple() const;
185
+
186
+ /*! \cond
187
+ */
188
+ private:
189
+ typedef typename
190
+ detail::zip_iterator_base<IteratorTuple>::type super_t;
191
+
192
+ friend class thrust::iterator_core_access;
193
+
194
+ // Dereferencing returns a tuple built from the dereferenced
195
+ // iterators in the iterator tuple.
196
+ __host__ __device__
197
+ typename super_t::reference dereference() const;
198
+
199
+ // Two zip_iterators are equal if the two first iterators of the
200
+ // tuple are equal. Note this differs from Boost's implementation, which
201
+ // considers the entire tuple.
202
+ template<typename OtherIteratorTuple>
203
+ inline __host__ __device__
204
+ bool equal(const zip_iterator<OtherIteratorTuple> &other) const;
205
+
206
+ // Advancing a zip_iterator means to advance all iterators in the tuple
207
+ inline __host__ __device__
208
+ void advance(typename super_t::difference_type n);
209
+
210
+ // Incrementing a zip iterator means to increment all iterators in the tuple
211
+ inline __host__ __device__
212
+ void increment();
213
+
214
+ // Decrementing a zip iterator means to decrement all iterators in the tuple
215
+ inline __host__ __device__
216
+ void decrement();
217
+
218
+ // Distance is calculated using the first iterator in the tuple.
219
+ template<typename OtherIteratorTuple>
220
+ inline __host__ __device__
221
+ typename super_t::difference_type
222
+ distance_to(const zip_iterator<OtherIteratorTuple> &other) const;
223
+
224
+ // The iterator tuple.
225
+ IteratorTuple m_iterator_tuple;
226
+
227
+ /*! \endcond
228
+ */
229
+ }; // end zip_iterator
230
+
231
+ /*! \p make_zip_iterator creates a \p zip_iterator from a \p tuple
232
+ * of iterators.
233
+ *
234
+ * \param t The \p tuple of iterators to copy.
235
+ * \return A newly created \p zip_iterator which zips the iterators encapsulated in \p t.
236
+ *
237
+ * \see zip_iterator
238
+ */
239
+ template<typename... Iterators>
240
+ inline __host__ __device__
241
+ zip_iterator<thrust::tuple<Iterators...>> make_zip_iterator(thrust::tuple<Iterators...> t);
242
+
243
+
244
+ /*! \p make_zip_iterator creates a \p zip_iterator from
245
+ * iterators.
246
+ *
247
+ * \param its The iterators to copy.
248
+ * \return A newly created \p zip_iterator which zips the iterators.
249
+ *
250
+ * \see zip_iterator
251
+ */
252
+ template<typename... Iterators>
253
+ inline __host__ __device__
254
+ zip_iterator<thrust::tuple<Iterators...>> make_zip_iterator(Iterators... its);
255
+
256
+
257
+ /*! \} // end fancyiterators
258
+ */
259
+
260
+ /*! \} // end iterators
261
+ */
262
+
263
+ THRUST_NAMESPACE_END
264
+
265
+ #include <thrust/iterator/detail/zip_iterator.inl>
266
+
miniCUDA124/include/thrust/mr/allocator.h ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file
18
+ * \brief Allocator types usable with \ref Memory Resources.
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+
33
+ #include <limits>
34
+
35
+ #include <thrust/detail/config.h>
36
+ #include <thrust/detail/config/memory_resource.h>
37
+ #include <thrust/detail/type_traits/pointer_traits.h>
38
+
39
+ #include <thrust/mr/validator.h>
40
+ #include <thrust/mr/polymorphic_adaptor.h>
41
+
42
+ THRUST_NAMESPACE_BEGIN
43
+ namespace mr
44
+ {
45
+
46
+ /*! \addtogroup allocators Allocators
47
+ * \ingroup memory_management
48
+ * \{
49
+ */
50
+
51
+ /*! An \p mr::allocator is a template that fulfills the C++ requirements for Allocators,
52
+ * allowing to use the NPA-based memory resources where an Allocator is required. Unlike
53
+ * memory resources, but like other allocators, \p mr::allocator is typed and bound to
54
+ * allocate object of a specific type, however it can be freely rebound to other types.
55
+ *
56
+ * \tparam T the type that will be allocated by this allocator.
57
+ * \tparam MR the upstream memory resource to use for memory allocation. Must derive from
58
+ * \p thrust::mr::memory_resource and must be \p final (in C++11 and beyond).
59
+ */
60
+ template<typename T, class MR>
61
+ class allocator : private validator<MR>
62
+ {
63
+ public:
64
+ /*! The pointer to void type of this allocator. */
65
+ typedef typename MR::pointer void_pointer;
66
+
67
+ /*! The value type allocated by this allocator. Equivalent to \p T. */
68
+ typedef T value_type;
69
+ /*! The pointer type allocated by this allocator. Equivaled to the pointer type of \p MR rebound to \p T. */
70
+ typedef typename thrust::detail::pointer_traits<void_pointer>::template rebind<T>::other pointer;
71
+ /*! The pointer to const type. Equivalent to a pointer type of \p MR rebound to <tt>const T</tt>. */
72
+ typedef typename thrust::detail::pointer_traits<void_pointer>::template rebind<const T>::other const_pointer;
73
+ /*! The reference to the type allocated by this allocator. Supports smart references. */
74
+ typedef typename thrust::detail::pointer_traits<pointer>::reference reference;
75
+ /*! The const reference to the type allocated by this allocator. Supports smart references. */
76
+ typedef typename thrust::detail::pointer_traits<const_pointer>::reference const_reference;
77
+ /*! The size type of this allocator. Always \p std::size_t. */
78
+ typedef std::size_t size_type;
79
+ /*! The difference type between pointers allocated by this allocator. */
80
+ typedef typename thrust::detail::pointer_traits<pointer>::difference_type difference_type;
81
+
82
+ /*! Specifies that the allocator shall be propagated on container copy assignment. */
83
+ typedef detail::true_type propagate_on_container_copy_assignment;
84
+ /*! Specifies that the allocator shall be propagated on container move assignment. */
85
+ typedef detail::true_type propagate_on_container_move_assignment;
86
+ /*! Specifies that the allocator shall be propagated on container swap. */
87
+ typedef detail::true_type propagate_on_container_swap;
88
+
89
+ /*! The \p rebind metafunction provides the type of an \p allocator instantiated with another type.
90
+ *
91
+ * \tparam U the other type to use for instantiation.
92
+ */
93
+ template<typename U>
94
+ struct rebind
95
+ {
96
+ /*! The typedef \p other gives the type of the rebound \p allocator.
97
+ */
98
+ typedef allocator<U, MR> other;
99
+ };
100
+
101
+ /*! Calculates the maximum number of elements allocated by this allocator.
102
+ *
103
+ * \return the maximum value of \p std::size_t, divided by the size of \p T.
104
+ */
105
+ __thrust_exec_check_disable__
106
+ __host__ __device__
107
+ size_type max_size() const
108
+ {
109
+ return (std::numeric_limits<size_type>::max)() / sizeof(T);
110
+ }
111
+
112
+ /*! Constructor.
113
+ *
114
+ * \param resource the resource to be used to allocate raw memory.
115
+ */
116
+ __host__ __device__
117
+ allocator(MR * resource) : mem_res(resource)
118
+ {
119
+ }
120
+
121
+ /*! Copy constructor. Copies the resource pointer. */
122
+ template<typename U>
123
+ __host__ __device__
124
+ allocator(const allocator<U, MR> & other) : mem_res(other.resource())
125
+ {
126
+ }
127
+
128
+ /*! Allocates objects of type \p T.
129
+ *
130
+ * \param n number of elements to allocate
131
+ * \return a pointer to the newly allocated storage.
132
+ */
133
+ THRUST_NODISCARD
134
+ __host__
135
+ pointer allocate(size_type n)
136
+ {
137
+ return static_cast<pointer>(mem_res->do_allocate(n * sizeof(T), THRUST_ALIGNOF(T)));
138
+ }
139
+
140
+ /*! Deallocates objects of type \p T.
141
+ *
142
+ * \param p pointer returned by a previous call to \p allocate
143
+ * \param n number of elements, passed as an argument to the \p allocate call that produced \p p
144
+ */
145
+ __host__
146
+ void deallocate(pointer p, size_type n)
147
+ {
148
+ return mem_res->do_deallocate(p, n * sizeof(T), THRUST_ALIGNOF(T));
149
+ }
150
+
151
+ /*! Extracts the memory resource used by this allocator.
152
+ *
153
+ * \return the memory resource used by this allocator.
154
+ */
155
+ __host__ __device__
156
+ MR * resource() const
157
+ {
158
+ return mem_res;
159
+ }
160
+
161
+ private:
162
+ MR * mem_res;
163
+ };
164
+
165
+ /*! Compares the allocators for equality by comparing the underlying memory resources. */
166
+ template<typename T, typename MR>
167
+ __host__ __device__
168
+ bool operator==(const allocator<T, MR> & lhs, const allocator<T, MR> & rhs) noexcept
169
+ {
170
+ return *lhs.resource() == *rhs.resource();
171
+ }
172
+
173
+ /*! Compares the allocators for inequality by comparing the underlying memory resources. */
174
+ template<typename T, typename MR>
175
+ __host__ __device__
176
+ bool operator!=(const allocator<T, MR> & lhs, const allocator<T, MR> & rhs) noexcept
177
+ {
178
+ return !(lhs == rhs);
179
+ }
180
+
181
+ #if THRUST_CPP_DIALECT >= 2011
182
+
183
+ template<typename T, typename Pointer>
184
+ using polymorphic_allocator = allocator<T, polymorphic_adaptor_resource<Pointer> >;
185
+
186
+ #else // C++11
187
+
188
+ template<typename T, typename Pointer>
189
+ class polymorphic_allocator : public allocator<T, polymorphic_adaptor_resource<Pointer> >
190
+ {
191
+ typedef allocator<T, polymorphic_adaptor_resource<Pointer> > base;
192
+
193
+ public:
194
+ /*! Initializes the base class with the parameter \p resource.
195
+ */
196
+ polymorphic_allocator(polymorphic_adaptor_resource<Pointer> * resource) : base(resource)
197
+ {
198
+ }
199
+ };
200
+
201
+ #endif // C++11
202
+
203
+ /*! A helper allocator class that uses global instances of a given upstream memory resource. Requires the memory resource
204
+ * to be default constructible.
205
+ *
206
+ * \tparam T the type that will be allocated by this allocator.
207
+ * \tparam Upstream the upstream memory resource to use for memory allocation. Must derive from
208
+ * \p thrust::mr::memory_resource and must be \p final (in C++11 and beyond).
209
+ */
210
+ template<typename T, typename Upstream>
211
+ class stateless_resource_allocator : public thrust::mr::allocator<T, Upstream>
212
+ {
213
+ typedef thrust::mr::allocator<T, Upstream> base;
214
+
215
+ public:
216
+ /*! The \p rebind metafunction provides the type of an \p stateless_resource_allocator instantiated with another type.
217
+ *
218
+ * \tparam U the other type to use for instantiation.
219
+ */
220
+ template<typename U>
221
+ struct rebind
222
+ {
223
+ /*! The typedef \p other gives the type of the rebound \p stateless_resource_allocator.
224
+ */
225
+ typedef stateless_resource_allocator<U, Upstream> other;
226
+ };
227
+
228
+ /*! Default constructor. Uses \p get_global_resource to get the global instance of \p Upstream and initializes the
229
+ * \p allocator base subobject with that resource.
230
+ */
231
+ __thrust_exec_check_disable__
232
+ __host__ __device__
233
+ stateless_resource_allocator() : base(get_global_resource<Upstream>())
234
+ {
235
+ }
236
+
237
+ /*! Copy constructor. Copies the memory resource pointer. */
238
+ __host__ __device__
239
+ stateless_resource_allocator(const stateless_resource_allocator & other)
240
+ : base(other) {}
241
+
242
+ /*! Conversion constructor from an allocator of a different type. Copies the memory resource pointer. */
243
+ template<typename U>
244
+ __host__ __device__
245
+ stateless_resource_allocator(const stateless_resource_allocator<U, Upstream> & other)
246
+ : base(other) {}
247
+
248
+ #if THRUST_CPP_DIALECT >= 2011
249
+ stateless_resource_allocator & operator=(const stateless_resource_allocator &) = default;
250
+ #endif
251
+
252
+ /*! Destructor. */
253
+ __host__ __device__
254
+ ~stateless_resource_allocator() {}
255
+ };
256
+
257
+ /*! \} // allocators
258
+ */
259
+
260
+ } // end mr
261
+ THRUST_NAMESPACE_END
262
+
miniCUDA124/include/thrust/mr/device_memory_resource.h ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018-2020 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ // #include the device system's memory_resource header
30
+ #define __THRUST_DEVICE_SYSTEM_MEMORY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/memory_resource.h>
31
+ #include __THRUST_DEVICE_SYSTEM_MEMORY_HEADER
32
+ #undef __THRUST_DEVICE_SYSTEM_MEMORY_HEADER
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+
37
+ typedef thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::memory_resource
38
+ device_memory_resource;
39
+ typedef thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::universal_memory_resource
40
+ universal_memory_resource;
41
+ typedef thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::universal_host_pinned_memory_resource
42
+ universal_host_pinned_memory_resource;
43
+
44
+
45
+ THRUST_NAMESPACE_END
46
+
miniCUDA124/include/thrust/mr/disjoint_pool.h ADDED
@@ -0,0 +1,499 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file
18
+ * \brief A caching and pooling memory resource adaptor which uses separate upstream resources for memory allocation
19
+ * and bookkeeping.
20
+ */
21
+
22
+ #pragma once
23
+
24
+ #include <thrust/detail/config.h>
25
+
26
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
27
+ # pragma GCC system_header
28
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
29
+ # pragma clang system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
31
+ # pragma system_header
32
+ #endif // no system header
33
+
34
+ #include <thrust/detail/algorithm_wrapper.h>
35
+ #include <thrust/detail/config.h>
36
+
37
+ #include <thrust/host_vector.h>
38
+ #include <thrust/binary_search.h>
39
+ #include <thrust/detail/seq.h>
40
+
41
+ #include <thrust/mr/memory_resource.h>
42
+ #include <thrust/mr/allocator.h>
43
+ #include <thrust/mr/pool_options.h>
44
+
45
+ #include <cassert>
46
+
47
+ THRUST_NAMESPACE_BEGIN
48
+ namespace mr
49
+ {
50
+
51
+ /** \addtogroup memory_resources Memory Resources
52
+ * \ingroup memory_management
53
+ * \{
54
+ */
55
+
56
+ /*! A memory resource adaptor allowing for pooling and caching allocations from \p Upstream, using \p Bookkeeper for
57
+ * management of that cached and pooled memory, allowing to cache portions of memory inaccessible from the host.
58
+ *
59
+ * On a typical memory resource, calls to \p allocate and \p deallocate actually allocate and deallocate memory. Pooling
60
+ * memory resources only allocate and deallocate memory from an external resource (the upstream memory resource) when
61
+ * there's no suitable memory currently cached; otherwise, they use memory they have acquired beforehand, to make
62
+ * memory allocation faster and more efficient.
63
+ *
64
+ * The disjoint version of the pool resources uses a separate upstream memory resource, \p Bookkeeper, to allocate memory
65
+ * necessary to manage the cached memory. There may be many reasons to do that; the canonical one is that \p Upstream
66
+ * allocates memory that is inaccessible to the code of the pool resource, which means that it cannot embed the necessary
67
+ * information in memory obtained from \p Upstream; for instance, \p Upstream can be a CUDA non-managed memory
68
+ * resource, or a CUDA managed memory resource whose memory we would prefer to not migrate back and forth between
69
+ * host and device when executing bookkeeping code.
70
+ *
71
+ * This is not the only case where it makes sense to use a disjoint pool resource, though. In a multi-core environment
72
+ * it may be beneficial to avoid stealing cache lines from other cores by writing over bookkeeping information
73
+ * embedded in an allocated block of memory. In such a case, one can imagine wanting to use a disjoint pool where
74
+ * both the upstream and the bookkeeper are of the same type, to allocate memory consistently, but separately for
75
+ * those two purposes.
76
+ *
77
+ * \tparam Upstream the type of memory resources that will be used for allocating memory blocks to be handed off to the user
78
+ * \tparam Bookkeeper the type of memory resources that will be used for allocating bookkeeping memory
79
+ */
80
+ template<typename Upstream, typename Bookkeeper>
81
+ class disjoint_unsynchronized_pool_resource final
82
+ : public memory_resource<typename Upstream::pointer>,
83
+ private validator2<Upstream, Bookkeeper>
84
+ {
85
+ public:
86
+ /*! Get the default options for a disjoint pool. These are meant to be a sensible set of values for many use cases,
87
+ * and as such, may be tuned in the future. This function is exposed so that creating a set of options that are
88
+ * just a slight departure from the defaults is easy.
89
+ */
90
+ static pool_options get_default_options()
91
+ {
92
+ pool_options ret;
93
+
94
+ ret.min_blocks_per_chunk = 16;
95
+ ret.min_bytes_per_chunk = 1024;
96
+ ret.max_blocks_per_chunk = static_cast<std::size_t>(1) << 20;
97
+ ret.max_bytes_per_chunk = static_cast<std::size_t>(1) << 30;
98
+
99
+ ret.smallest_block_size = THRUST_MR_DEFAULT_ALIGNMENT;
100
+ ret.largest_block_size = static_cast<std::size_t>(1) << 20;
101
+
102
+ ret.alignment = THRUST_MR_DEFAULT_ALIGNMENT;
103
+
104
+ ret.cache_oversized = true;
105
+
106
+ ret.cached_size_cutoff_factor = 16;
107
+ ret.cached_alignment_cutoff_factor = 16;
108
+
109
+ return ret;
110
+ }
111
+
112
+ /*! Constructor.
113
+ *
114
+ * \param upstream the upstream memory resource for allocations
115
+ * \param bookkeeper the upstream memory resource for bookkeeping
116
+ * \param options pool options to use
117
+ */
118
+ disjoint_unsynchronized_pool_resource(Upstream * upstream, Bookkeeper * bookkeeper,
119
+ pool_options options = get_default_options())
120
+ : m_upstream(upstream),
121
+ m_bookkeeper(bookkeeper),
122
+ m_options(options),
123
+ m_smallest_block_log2(detail::log2_ri(m_options.smallest_block_size)),
124
+ m_pools(m_bookkeeper),
125
+ m_allocated(m_bookkeeper),
126
+ m_cached_oversized(m_bookkeeper),
127
+ m_oversized(m_bookkeeper)
128
+ {
129
+ assert(m_options.validate());
130
+
131
+ pointer_vector free(m_bookkeeper);
132
+ pool p(free);
133
+ m_pools.resize(detail::log2_ri(m_options.largest_block_size) - m_smallest_block_log2 + 1, p);
134
+ }
135
+
136
+ // TODO: C++11: use delegating constructors
137
+
138
+ /*! Constructor. Upstream and bookkeeping resources are obtained by calling \p get_global_resource for their types.
139
+ *
140
+ * \param options pool options to use
141
+ */
142
+ disjoint_unsynchronized_pool_resource(pool_options options = get_default_options())
143
+ : m_upstream(get_global_resource<Upstream>()),
144
+ m_bookkeeper(get_global_resource<Bookkeeper>()),
145
+ m_options(options),
146
+ m_smallest_block_log2(detail::log2_ri(m_options.smallest_block_size)),
147
+ m_pools(m_bookkeeper),
148
+ m_allocated(m_bookkeeper),
149
+ m_cached_oversized(m_bookkeeper),
150
+ m_oversized(m_bookkeeper)
151
+ {
152
+ assert(m_options.validate());
153
+
154
+ pointer_vector free(m_bookkeeper);
155
+ pool p(free);
156
+ m_pools.resize(detail::log2_ri(m_options.largest_block_size) - m_smallest_block_log2 + 1, p);
157
+ }
158
+
159
+ /*! Destructor. Releases all held memory to upstream.
160
+ */
161
+ ~disjoint_unsynchronized_pool_resource()
162
+ {
163
+ release();
164
+ }
165
+
166
+ private:
167
+ typedef typename Upstream::pointer void_ptr;
168
+ typedef typename thrust::detail::pointer_traits<void_ptr>::template rebind<char>::other char_ptr;
169
+
170
+ struct chunk_descriptor
171
+ {
172
+ std::size_t size;
173
+ void_ptr pointer;
174
+ };
175
+
176
+ typedef thrust::host_vector<
177
+ chunk_descriptor,
178
+ allocator<chunk_descriptor, Bookkeeper>
179
+ > chunk_vector;
180
+
181
+ struct oversized_block_descriptor
182
+ {
183
+ std::size_t size;
184
+ std::size_t alignment;
185
+ void_ptr pointer;
186
+
187
+ __host__ __device__
188
+ bool operator==(const oversized_block_descriptor & other) const
189
+ {
190
+ return size == other.size && alignment == other.alignment && pointer == other.pointer;
191
+ }
192
+
193
+ __host__ __device__
194
+ bool operator<(const oversized_block_descriptor & other) const
195
+ {
196
+ return size < other.size || (size == other.size && alignment < other.alignment);
197
+ }
198
+ };
199
+
200
+ struct equal_pointers
201
+ {
202
+ public:
203
+ __host__ __device__
204
+ equal_pointers(void_ptr p) : p(p)
205
+ {
206
+ }
207
+
208
+ __host__ __device__
209
+ bool operator()(const oversized_block_descriptor & desc) const
210
+ {
211
+ return desc.pointer == p;
212
+ }
213
+
214
+ private:
215
+ void_ptr p;
216
+ };
217
+
218
+ struct matching_alignment
219
+ {
220
+ public:
221
+ __host__ __device__
222
+ matching_alignment(std::size_t requested) : requested(requested)
223
+ {
224
+ }
225
+
226
+ __host__ __device__
227
+ bool operator()(const oversized_block_descriptor & desc) const
228
+ {
229
+ return desc.alignment >= requested;
230
+ }
231
+
232
+ private:
233
+ std::size_t requested;
234
+ };
235
+
236
+ typedef thrust::host_vector<
237
+ oversized_block_descriptor,
238
+ allocator<oversized_block_descriptor, Bookkeeper>
239
+ > oversized_block_vector;
240
+
241
+ typedef thrust::host_vector<
242
+ void_ptr,
243
+ allocator<void_ptr, Bookkeeper>
244
+ > pointer_vector;
245
+
246
+ struct pool
247
+ {
248
+ __host__
249
+ pool(const pointer_vector & free)
250
+ : free_blocks(free),
251
+ previous_allocated_count(0)
252
+ {
253
+ }
254
+
255
+ __host__
256
+ pool(const pool & other)
257
+ : free_blocks(other.free_blocks),
258
+ previous_allocated_count(other.previous_allocated_count)
259
+ {
260
+ }
261
+
262
+ #if THRUST_CPP_DIALECT >= 2011
263
+ pool & operator=(const pool &) = default;
264
+ #endif
265
+
266
+ __host__
267
+ ~pool() {}
268
+
269
+ pointer_vector free_blocks;
270
+ std::size_t previous_allocated_count;
271
+ };
272
+
273
+ typedef thrust::host_vector<
274
+ pool,
275
+ allocator<pool, Bookkeeper>
276
+ > pool_vector;
277
+
278
+ Upstream * m_upstream;
279
+ Bookkeeper * m_bookkeeper;
280
+
281
+ pool_options m_options;
282
+ std::size_t m_smallest_block_log2;
283
+
284
+ // buckets containing free lists for each pooled size
285
+ pool_vector m_pools;
286
+ // list of all allocations from upstream for the above
287
+ chunk_vector m_allocated;
288
+ // list of all cached oversized/overaligned blocks that have been returned to the pool to cache
289
+ oversized_block_vector m_cached_oversized;
290
+ // list of all oversized/overaligned allocations from upstream
291
+ oversized_block_vector m_oversized;
292
+
293
+ public:
294
+ /*! Releases all held memory to upstream.
295
+ */
296
+ void release()
297
+ {
298
+ // reset the buckets
299
+ for (std::size_t i = 0; i < m_pools.size(); ++i)
300
+ {
301
+ m_pools[i].free_blocks.clear();
302
+ m_pools[i].previous_allocated_count = 0;
303
+ }
304
+
305
+ // deallocate memory allocated for the buckets
306
+ for (std::size_t i = 0; i < m_allocated.size(); ++i)
307
+ {
308
+ m_upstream->do_deallocate(
309
+ m_allocated[i].pointer,
310
+ m_allocated[i].size,
311
+ m_options.alignment);
312
+ }
313
+
314
+ // deallocate cached oversized/overaligned memory
315
+ for (std::size_t i = 0; i < m_oversized.size(); ++i)
316
+ {
317
+ m_upstream->do_deallocate(
318
+ m_oversized[i].pointer,
319
+ m_oversized[i].size,
320
+ m_oversized[i].alignment);
321
+ }
322
+
323
+ m_allocated.clear();
324
+ m_oversized.clear();
325
+ m_cached_oversized.clear();
326
+ }
327
+
328
+ THRUST_NODISCARD virtual void_ptr do_allocate(std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) override
329
+ {
330
+ bytes = (std::max)(bytes, m_options.smallest_block_size);
331
+ assert(detail::is_power_of_2(alignment));
332
+
333
+ // an oversized and/or overaligned allocation requested; needs to be allocated separately
334
+ if (bytes > m_options.largest_block_size || alignment > m_options.alignment)
335
+ {
336
+ oversized_block_descriptor oversized;
337
+ oversized.size = bytes;
338
+ oversized.alignment = alignment;
339
+
340
+ if (m_options.cache_oversized && !m_cached_oversized.empty())
341
+ {
342
+ typename oversized_block_vector::iterator it = thrust::lower_bound(
343
+ thrust::seq,
344
+ m_cached_oversized.begin(),
345
+ m_cached_oversized.end(),
346
+ oversized);
347
+
348
+ // if the size is bigger than the requested size by a factor
349
+ // bigger than or equal to the specified cutoff for size,
350
+ // allocate a new block
351
+ if (it != m_cached_oversized.end())
352
+ {
353
+ std::size_t size_factor = (*it).size / bytes;
354
+ if (size_factor >= m_options.cached_size_cutoff_factor)
355
+ {
356
+ it = m_cached_oversized.end();
357
+ }
358
+ }
359
+
360
+ if (it != m_cached_oversized.end() && (*it).alignment < alignment)
361
+ {
362
+ it = find_if(it + 1, m_cached_oversized.end(), matching_alignment(alignment));
363
+ }
364
+
365
+ // if the alignment is bigger than the requested one by a factor
366
+ // bigger than or equal to the specified cutoff for alignment,
367
+ // allocate a new block
368
+ if (it != m_cached_oversized.end())
369
+ {
370
+ std::size_t alignment_factor = (*it).alignment / alignment;
371
+ if (alignment_factor >= m_options.cached_alignment_cutoff_factor)
372
+ {
373
+ it = m_cached_oversized.end();
374
+ }
375
+ }
376
+
377
+ if (it != m_cached_oversized.end())
378
+ {
379
+ oversized.pointer = (*it).pointer;
380
+ m_cached_oversized.erase(it);
381
+ return oversized.pointer;
382
+ }
383
+ }
384
+
385
+ // no fitting cached block found; allocate a new one that's just up to the specs
386
+ oversized.pointer = m_upstream->do_allocate(bytes, alignment);
387
+ m_oversized.push_back(oversized);
388
+
389
+ return oversized.pointer;
390
+ }
391
+
392
+ // the request is NOT for oversized and/or overaligned memory
393
+ // allocate a block from an appropriate bucket
394
+ std::size_t bytes_log2 = thrust::detail::log2_ri(bytes);
395
+ std::size_t bucket_idx = bytes_log2 - m_smallest_block_log2;
396
+ pool & bucket = m_pools[bucket_idx];
397
+
398
+ // if the free list of the bucket has no elements, allocate a new chunk
399
+ // and split it into blocks pushed to the free list
400
+ if (bucket.free_blocks.empty())
401
+ {
402
+ std::size_t bucket_size = static_cast<std::size_t>(1) << bytes_log2;
403
+
404
+ std::size_t n = bucket.previous_allocated_count;
405
+ if (n == 0)
406
+ {
407
+ n = m_options.min_blocks_per_chunk;
408
+ if (n < (m_options.min_bytes_per_chunk >> bytes_log2))
409
+ {
410
+ n = m_options.min_bytes_per_chunk >> bytes_log2;
411
+ }
412
+ }
413
+ else
414
+ {
415
+ n = n * 3 / 2;
416
+ if (n > (m_options.max_bytes_per_chunk >> bytes_log2))
417
+ {
418
+ n = m_options.max_bytes_per_chunk >> bytes_log2;
419
+ }
420
+ if (n > m_options.max_blocks_per_chunk)
421
+ {
422
+ n = m_options.max_blocks_per_chunk;
423
+ }
424
+ }
425
+
426
+ bytes = n << bytes_log2;
427
+
428
+ assert(n >= m_options.min_blocks_per_chunk);
429
+ assert(n <= m_options.max_blocks_per_chunk);
430
+ assert(bytes >= m_options.min_bytes_per_chunk);
431
+ assert(bytes <= m_options.max_bytes_per_chunk);
432
+
433
+ chunk_descriptor allocated;
434
+ allocated.size = bytes;
435
+ allocated.pointer = m_upstream->do_allocate(bytes, m_options.alignment);
436
+ m_allocated.push_back(allocated);
437
+ bucket.previous_allocated_count = n;
438
+
439
+ for (std::size_t i = 0; i < n; ++i)
440
+ {
441
+ bucket.free_blocks.push_back(
442
+ static_cast<void_ptr>(
443
+ static_cast<char_ptr>(allocated.pointer) + i * bucket_size
444
+ )
445
+ );
446
+ }
447
+ }
448
+
449
+ // allocate a block from the front of the bucket's free list
450
+ void_ptr ret = bucket.free_blocks.back();
451
+ bucket.free_blocks.pop_back();
452
+ return ret;
453
+ }
454
+
455
+ virtual void do_deallocate(void_ptr p, std::size_t n, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) override
456
+ {
457
+ n = (std::max)(n, m_options.smallest_block_size);
458
+ assert(detail::is_power_of_2(alignment));
459
+
460
+ // verify that the pointer is at least as aligned as claimed
461
+ assert(reinterpret_cast<detail::intmax_t>(detail::pointer_traits<void_ptr>::get(p)) % alignment == 0);
462
+
463
+ // the deallocated block is oversized and/or overaligned
464
+ if (n > m_options.largest_block_size || alignment > m_options.alignment)
465
+ {
466
+ typename oversized_block_vector::iterator it = find_if(m_oversized.begin(), m_oversized.end(), equal_pointers(p));
467
+ assert(it != m_oversized.end());
468
+
469
+ oversized_block_descriptor oversized = *it;
470
+
471
+ if (m_options.cache_oversized)
472
+ {
473
+ typename oversized_block_vector::iterator position = lower_bound(m_cached_oversized.begin(), m_cached_oversized.end(), oversized);
474
+ m_cached_oversized.insert(position, oversized);
475
+ return;
476
+ }
477
+
478
+ m_oversized.erase(it);
479
+
480
+ m_upstream->do_deallocate(p, oversized.size, oversized.alignment);
481
+
482
+ return;
483
+ }
484
+
485
+ // push the block to the front of the appropriate bucket's free list
486
+ std::size_t n_log2 = thrust::detail::log2_ri(n);
487
+ std::size_t bucket_idx = n_log2 - m_smallest_block_log2;
488
+ pool & bucket = m_pools[bucket_idx];
489
+
490
+ bucket.free_blocks.push_back(p);
491
+ }
492
+ };
493
+
494
+ /*! \} // memory_resource
495
+ */
496
+
497
+ } // end mr
498
+ THRUST_NAMESPACE_END
499
+
miniCUDA124/include/thrust/mr/disjoint_sync_pool.h ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file
18
+ * \brief A mutex-synchronized version of \p disjoint_unsynchronized_pool_resource.
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+ #include <thrust/detail/cpp11_required.h>
33
+
34
+ #if THRUST_CPP_DIALECT >= 2011
35
+
36
+ #include <mutex>
37
+
38
+ #include <thrust/mr/disjoint_pool.h>
39
+
40
+ THRUST_NAMESPACE_BEGIN
41
+ namespace mr
42
+ {
43
+
44
+ /*! \addtogroup memory_resources Memory Resources
45
+ * \ingroup memory_management
46
+ * \{
47
+ */
48
+
49
+ /*! A mutex-synchronized version of \p disjoint_unsynchronized_pool_resource. Uses \p std::mutex, and therefore requires C++11.
50
+ *
51
+ * \tparam Upstream the type of memory resources that will be used for allocating memory blocks to be handed off to the user
52
+ * \tparam Bookkeeper the type of memory resources that will be used for allocating bookkeeping memory
53
+ */
54
+ template<typename Upstream, typename Bookkeeper>
55
+ struct disjoint_synchronized_pool_resource : public memory_resource<typename Upstream::pointer>
56
+ {
57
+ typedef disjoint_unsynchronized_pool_resource<Upstream, Bookkeeper> unsync_pool;
58
+ typedef std::lock_guard<std::mutex> lock_t;
59
+
60
+ typedef typename Upstream::pointer void_ptr;
61
+
62
+ public:
63
+ /*! Get the default options for a disjoint pool. These are meant to be a sensible set of values for many use cases,
64
+ * and as such, may be tuned in the future. This function is exposed so that creating a set of options that are
65
+ * just a slight departure from the defaults is easy.
66
+ */
67
+ static pool_options get_default_options()
68
+ {
69
+ return unsync_pool::get_default_options();
70
+ }
71
+
72
+ /*! Constructor.
73
+ *
74
+ * \param upstream the upstream memory resource for allocations
75
+ * \param bookkeeper the upstream memory resource for bookkeeping
76
+ * \param options pool options to use
77
+ */
78
+ disjoint_synchronized_pool_resource(Upstream * upstream, Bookkeeper * bookkeeper,
79
+ pool_options options = get_default_options())
80
+ : upstream_pool(upstream, bookkeeper, options)
81
+ {
82
+ }
83
+
84
+ /*! Constructor. Upstream and bookkeeping resources are obtained by calling \p get_global_resource for their types.
85
+ *
86
+ * \param options pool options to use
87
+ */
88
+ disjoint_synchronized_pool_resource(pool_options options = get_default_options())
89
+ : upstream_pool(get_global_resource<Upstream>(), get_global_resource<Bookkeeper>(), options)
90
+ {
91
+ }
92
+
93
+ /*! Releases all held memory to upstream.
94
+ */
95
+ void release()
96
+ {
97
+ lock_t lock(mtx);
98
+ upstream_pool.release();
99
+ }
100
+
101
+ THRUST_NODISCARD virtual void_ptr do_allocate(std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) override
102
+ {
103
+ lock_t lock(mtx);
104
+ return upstream_pool.do_allocate(bytes, alignment);
105
+ }
106
+
107
+ virtual void do_deallocate(void_ptr p, std::size_t n, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) override
108
+ {
109
+ lock_t lock(mtx);
110
+ upstream_pool.do_deallocate(p, n, alignment);
111
+ }
112
+
113
+ private:
114
+ std::mutex mtx;
115
+ unsync_pool upstream_pool;
116
+ };
117
+
118
+ /*! \} // memory_resources
119
+ */
120
+
121
+ } // end mr
122
+ THRUST_NAMESPACE_END
123
+
124
+ #endif // THRUST_CPP_DIALECT >= 2011
125
+
miniCUDA124/include/thrust/mr/disjoint_tls_pool.h ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file disjoint_tls_pool.h
18
+ * \brief A function wrapping a thread local instance of a \p disjoint_unsynchronized_pool_resource.
19
+ */
20
+
21
+ #pragma once
22
+
23
+ #include <thrust/detail/config.h>
24
+
25
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
26
+ # pragma GCC system_header
27
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
28
+ # pragma clang system_header
29
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
30
+ # pragma system_header
31
+ #endif // no system header
32
+ #include <thrust/detail/cpp11_required.h>
33
+
34
+ #if THRUST_CPP_DIALECT >= 2011
35
+
36
+ #include <thrust/mr/disjoint_pool.h>
37
+
38
+ THRUST_NAMESPACE_BEGIN
39
+ namespace mr
40
+ {
41
+
42
+ /*! \addtogroup memory_management Memory Management
43
+ * \addtogroup memory_resources Memory Resources
44
+ * \ingroup memory_resources
45
+ * \{
46
+ */
47
+
48
+ /*! Potentially constructs, if not yet created, and then returns the address of a thread-local
49
+ * \p disjoint_unsynchronized_pool_resource,
50
+ *
51
+ * \tparam Upstream the first template argument to the pool template
52
+ * \tparam Bookkeeper the second template argument to the pool template
53
+ * \param upstream the first argument to the constructor, if invoked
54
+ * \param bookkeeper the second argument to the constructor, if invoked
55
+ */
56
+ template<typename Upstream, typename Bookkeeper>
57
+ __host__
58
+ thrust::mr::disjoint_unsynchronized_pool_resource<Upstream, Bookkeeper> & tls_disjoint_pool(
59
+ Upstream * upstream = NULL,
60
+ Bookkeeper * bookkeeper = NULL)
61
+ {
62
+ static thread_local auto adaptor = [&]{
63
+ assert(upstream && bookkeeper);
64
+ return thrust::mr::disjoint_unsynchronized_pool_resource<Upstream, Bookkeeper>(upstream, bookkeeper);
65
+ }();
66
+
67
+ return adaptor;
68
+ }
69
+
70
+ /*! \}
71
+ */
72
+
73
+ } // end mr
74
+ THRUST_NAMESPACE_END
75
+
76
+ #endif // THRUST_CPP_DIALECT >= 2011
77
+
miniCUDA124/include/thrust/mr/fancy_pointer_resource.h ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+ #include <thrust/detail/type_traits/pointer_traits.h>
29
+
30
+ #include <thrust/mr/memory_resource.h>
31
+ #include <thrust/mr/validator.h>
32
+
33
+ THRUST_NAMESPACE_BEGIN
34
+ namespace mr
35
+ {
36
+
37
+ template<typename Upstream, typename Pointer>
38
+ class fancy_pointer_resource final : public memory_resource<Pointer>, private validator<Upstream>
39
+ {
40
+ public:
41
+ fancy_pointer_resource() : m_upstream(get_global_resource<Upstream>())
42
+ {
43
+ }
44
+
45
+ fancy_pointer_resource(Upstream * upstream) : m_upstream(upstream)
46
+ {
47
+ }
48
+
49
+ THRUST_NODISCARD
50
+ virtual Pointer do_allocate(std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT) override
51
+ {
52
+ return static_cast<Pointer>(m_upstream->do_allocate(bytes, alignment));
53
+ }
54
+
55
+ virtual void do_deallocate(Pointer p, std::size_t bytes, std::size_t alignment) override
56
+ {
57
+ return m_upstream->do_deallocate(
58
+ static_cast<typename Upstream::pointer>(
59
+ thrust::detail::pointer_traits<Pointer>::get(p)),
60
+ bytes, alignment);
61
+ }
62
+
63
+ private:
64
+ Upstream * m_upstream;
65
+ };
66
+
67
+ } // end mr
68
+ THRUST_NAMESPACE_END
69
+
miniCUDA124/include/thrust/mr/host_memory_resource.h ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018-2020 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #pragma once
18
+
19
+ #include <thrust/detail/config.h>
20
+
21
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
22
+ # pragma GCC system_header
23
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
24
+ # pragma clang system_header
25
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
26
+ # pragma system_header
27
+ #endif // no system header
28
+
29
+ // #include the host system's memory_resource header
30
+ #define __THRUST_HOST_SYSTEM_MEMORY_HEADER <__THRUST_HOST_SYSTEM_ROOT/memory_resource.h>
31
+ #include __THRUST_HOST_SYSTEM_MEMORY_HEADER
32
+ #undef __THRUST_HOST_SYSTEM_MEMORY_HEADER
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ typedef thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::memory_resource
37
+ host_memory_resource;
38
+
39
+ THRUST_NAMESPACE_END
40
+
miniCUDA124/include/thrust/mr/memory_resource.h ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2018 NVIDIA Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /*! \file
18
+ * \brief A base class for the memory resource system, similar to
19
+ * std::memory_resource, and related utilities.
20
+ */
21
+
22
+ #pragma once
23
+
24
+ #include <thrust/detail/config.h>
25
+
26
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
27
+ # pragma GCC system_header
28
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
29
+ # pragma clang system_header
30
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
31
+ # pragma system_header
32
+ #endif // no system header
33
+
34
+ #include <thrust/detail/config/memory_resource.h>
35
+ #ifdef THRUST_MR_STD_MR_HEADER
36
+ # include THRUST_MR_STD_MR_HEADER
37
+ #endif
38
+
39
+ THRUST_NAMESPACE_BEGIN
40
+ /*! \brief \p thrust::mr is the namespace containing system agnostic types and functions for \p memory_resource related functionalities.
41
+ */
42
+ namespace mr
43
+ {
44
+
45
+ /** \addtogroup memory_resources Memory Resources
46
+ * \ingroup memory_management
47
+ * \{
48
+ */
49
+
50
+ /*! \p memory_resource is the base class for all other memory resources.
51
+ *
52
+ * \tparam Pointer the pointer type that is allocated and deallocated by the memory resource
53
+ * derived from this base class. If this is <tt>void *</tt>, this class derives from
54
+ * <tt>std::pmr::memory_resource</tt>.
55
+ */
56
+ template<typename Pointer = void *>
57
+ class memory_resource
58
+ {
59
+ public:
60
+ /*! Alias for the template parameter.
61
+ */
62
+ typedef Pointer pointer;
63
+
64
+ /*! Virtual destructor, defaulted when possible.
65
+ */
66
+ virtual ~memory_resource() = default;
67
+
68
+ /*! Allocates memory of size at least \p bytes and alignment at least \p alignment.
69
+ *
70
+ * \param bytes size, in bytes, that is requested from this allocation
71
+ * \param alignment alignment that is requested from this allocation
72
+ * \throws thrust::bad_alloc when no memory with requested size and alignment can be allocated.
73
+ * \return A pointer to void to the newly allocated memory.
74
+ */
75
+ THRUST_NODISCARD
76
+ pointer allocate(std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT)
77
+ {
78
+ return do_allocate(bytes, alignment);
79
+ }
80
+
81
+ /*! Deallocates memory pointed to by \p p.
82
+ *
83
+ * \param p pointer to be deallocated
84
+ * \param bytes the size of the allocation. This must be equivalent to the value of \p bytes that
85
+ * was passed to the allocation function that returned \p p.
86
+ * \param alignment the alignment of the allocation. This must be equivalent to the value of \p alignment
87
+ * that was passed to the allocation function that returned \p p.
88
+ */
89
+ void deallocate(pointer p, std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT)
90
+ {
91
+ do_deallocate(p, bytes, alignment);
92
+ }
93
+
94
+ /*! Compares this resource to the other one. The default implementation uses identity comparison,
95
+ * which is often the right thing to do and doesn't require RTTI involvement.
96
+ *
97
+ * \param other the other resource to compare this resource to
98
+ * \return whether the two resources are equivalent.
99
+ */
100
+ __host__ __device__
101
+ bool is_equal(const memory_resource & other) const noexcept
102
+ {
103
+ return do_is_equal(other);
104
+ }
105
+
106
+ /*! Allocates memory of size at least \p bytes and alignment at least \p alignment.
107
+ *
108
+ * \param bytes size, in bytes, that is requested from this allocation
109
+ * \param alignment alignment that is requested from this allocation
110
+ * \throws thrust::bad_alloc when no memory with requested size and alignment can be allocated.
111
+ * \return A pointer to void to the newly allocated memory.
112
+ */
113
+ virtual pointer do_allocate(std::size_t bytes, std::size_t alignment) = 0;
114
+
115
+ /*! Deallocates memory pointed to by \p p.
116
+ *
117
+ * \param p pointer to be deallocated
118
+ * \param bytes the size of the allocation. This must be equivalent to the value of \p bytes that
119
+ * was passed to the allocation function that returned \p p.
120
+ * \param alignment the size of the allocation. This must be equivalent to the value of \p alignment
121
+ * that was passed to the allocation function that returned \p p.
122
+ */
123
+ virtual void do_deallocate(pointer p, std::size_t bytes, std::size_t alignment) = 0;
124
+
125
+ /*! Compares this resource to the other one. The default implementation uses identity comparison,
126
+ * which is often the right thing to do and doesn't require RTTI involvement.
127
+ *
128
+ * \param other the other resource to compare this resource to
129
+ * \return whether the two resources are equivalent.
130
+ */
131
+ __host__ __device__
132
+ virtual bool do_is_equal(const memory_resource & other) const noexcept
133
+ {
134
+ return this == &other;
135
+ }
136
+ };
137
+
138
+ template<>
139
+ class memory_resource<void *>
140
+ #ifdef THRUST_STD_MR_NS
141
+ : THRUST_STD_MR_NS::memory_resource
142
+ #endif
143
+ {
144
+ public:
145
+ typedef void * pointer;
146
+
147
+ virtual ~memory_resource() = default;
148
+
149
+ THRUST_NODISCARD
150
+ pointer allocate(std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT)
151
+ {
152
+ return do_allocate(bytes, alignment);
153
+ }
154
+
155
+ void deallocate(pointer p, std::size_t bytes, std::size_t alignment = THRUST_MR_DEFAULT_ALIGNMENT)
156
+ {
157
+ do_deallocate(p, bytes, alignment);
158
+ }
159
+
160
+ __host__ __device__
161
+ bool is_equal(const memory_resource & other) const noexcept
162
+ {
163
+ return do_is_equal(other);
164
+ }
165
+
166
+ virtual pointer do_allocate(std::size_t bytes, std::size_t alignment) = 0;
167
+ virtual void do_deallocate(pointer p, std::size_t bytes, std::size_t alignment) = 0;
168
+ __host__ __device__
169
+ virtual bool do_is_equal(const memory_resource & other) const noexcept
170
+ {
171
+ return this == &other;
172
+ }
173
+
174
+ #ifdef THRUST_STD_MR_NS
175
+ // the above do_is_equal is a different function than the one from the standard memory resource
176
+ // can't implement this reasonably without RTTI though; it's reasonable to assume false otherwise
177
+
178
+ virtual bool do_is_equal(const THRUST_STD_MR_NS::memory_resource & other) const noexcept override
179
+ {
180
+ # ifdef THRUST_HAS_DYNAMIC_CAST
181
+ auto mr_resource = dynamic_cast<memory_resource<> *>(&other);
182
+ return mr_resource && do_is_equal(*mr_resource);
183
+ # else
184
+ return this == &other;
185
+ # endif
186
+ }
187
+ #endif
188
+ };
189
+
190
+ /*! Compares the memory resources for equality, first by identity, then by \p is_equal.
191
+ */
192
+ template<typename Pointer>
193
+ __host__ __device__
194
+ bool operator==(const memory_resource<Pointer> & lhs, const memory_resource<Pointer> & rhs) noexcept
195
+ {
196
+ return &lhs == &rhs || rhs.is_equal(rhs);
197
+ }
198
+
199
+ /*! Compares the memory resources for inequality, first by identity, then by \p is_equal.
200
+ */
201
+ template<typename Pointer>
202
+ __host__ __device__
203
+ bool operator!=(const memory_resource<Pointer> & lhs, const memory_resource<Pointer> & rhs) noexcept
204
+ {
205
+ return !(lhs == rhs);
206
+ }
207
+
208
+ /*! Returns a global instance of \p MR, created as a function local static variable.
209
+ *
210
+ * \tparam MR type of a memory resource to get an instance from. Must be \p DefaultConstructible.
211
+ * \return a pointer to a global instance of \p MR.
212
+ */
213
+ template<typename MR>
214
+ __host__
215
+ MR * get_global_resource()
216
+ {
217
+ static MR resource;
218
+ return &resource;
219
+ }
220
+
221
+ /*! \} // memory_resource
222
+ */
223
+
224
+ } // end mr
225
+ THRUST_NAMESPACE_END
226
+