ZTWHHH commited on
Commit
df9e5f4
·
verified ·
1 Parent(s): 0ed7984

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. vllm/lib/libcrypto.so +3 -0
  3. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__atomic/atomic.h +141 -0
  4. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__cmath/ceil_div.h +86 -0
  5. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__latch/latch.h +40 -0
  6. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/completion_mechanism.h +43 -0
  7. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_bulk_shared_global.h +56 -0
  8. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_fallback.h +68 -0
  9. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_shared_global.h +102 -0
  10. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/dispatch_memcpy_async.h +157 -0
  11. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/is_local_smem_barrier.h +45 -0
  12. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async.h +166 -0
  13. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_barrier.h +118 -0
  14. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_tx.h +90 -0
  15. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_completion.h +168 -0
  16. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/try_get_barrier_handle.h +55 -0
  17. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource.h +129 -0
  18. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource_ref.h +653 -0
  19. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__type_traits/is_floating_point.h +45 -0
  20. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/std/__memory/temporary_buffer.h +89 -0
  21. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__preprocessor +176 -0
  22. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__target_macros +610 -0
  23. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/target +232 -0
  24. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/adjacent_difference.h +251 -0
  25. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/advance.h +147 -0
  26. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/allocate_unique.h +350 -0
  27. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/binary_search.h +1887 -0
  28. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/complex.h +854 -0
  29. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/count.h +246 -0
  30. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_delete.h +59 -0
  31. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_free.h +72 -0
  32. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_make_unique.h +56 -0
  33. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc.h +108 -0
  34. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc_allocator.h +193 -0
  35. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new.h +91 -0
  36. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new_allocator.h +181 -0
  37. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_reference.h +977 -0
  38. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_vector.h +547 -0
  39. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/equal.h +247 -0
  40. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/event.h +35 -0
  41. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/execution_policy.h +384 -0
  42. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/extrema.h +800 -0
  43. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/fill.h +201 -0
  44. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/for_each.h +266 -0
  45. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/future.h +183 -0
  46. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/generate.h +197 -0
  47. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/inner_product.h +268 -0
  48. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/logical.h +290 -0
  49. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/memory.h +395 -0
  50. vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/merge.h +725 -0
.gitattributes CHANGED
@@ -1768,3 +1768,4 @@ videollama2/lib/python3.10/site-packages/scipy.libs/libscipy_openblas-c128ec02.s
1768
  vllm/lib/python3.10/site-packages/cupy/_core/flags.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1769
  vllm/lib/python3.10/site-packages/cupy/_core/_accelerator.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1770
  vllm/lib/python3.10/site-packages/cupy/_core/_fusion_kernel.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
1768
  vllm/lib/python3.10/site-packages/cupy/_core/flags.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1769
  vllm/lib/python3.10/site-packages/cupy/_core/_accelerator.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1770
  vllm/lib/python3.10/site-packages/cupy/_core/_fusion_kernel.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
1771
+ vllm/lib/libcrypto.so filter=lfs diff=lfs merge=lfs -text
vllm/lib/libcrypto.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a3a22a04cfb89e45ac9fabc0c71c3935ea24c47178c4390c492cb458dca935df
3
+ size 5172040
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__atomic/atomic.h ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef _CUDA___ATOMIC_ATOMIC_H
12
+ #define _CUDA___ATOMIC_ATOMIC_H
13
+
14
+ #include <cuda/std/detail/__config>
15
+
16
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
17
+ # pragma GCC system_header
18
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
19
+ # pragma clang system_header
20
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
21
+ # pragma system_header
22
+ #endif // no system header
23
+
24
+ #include <cuda/std/atomic>
25
+
26
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
27
+
28
+ // atomic<T>
29
+
30
+ template <class _Tp, thread_scope _Sco = thread_scope::thread_scope_system>
31
+ struct atomic : public _CUDA_VSTD::__atomic_impl<_Tp, _Sco>
32
+ {
33
+ using value_type = _Tp;
34
+
35
+ _CCCL_HIDE_FROM_ABI constexpr atomic() noexcept = default;
36
+
37
+ _LIBCUDACXX_HIDE_FROM_ABI constexpr atomic(_Tp __d) noexcept
38
+ : _CUDA_VSTD::__atomic_impl<_Tp, _Sco>(__d)
39
+ {}
40
+
41
+ atomic(const atomic&) = delete;
42
+ atomic& operator=(const atomic&) = delete;
43
+ atomic& operator=(const atomic&) volatile = delete;
44
+
45
+ _LIBCUDACXX_HIDE_FROM_ABI _Tp operator=(_Tp __d) volatile noexcept
46
+ {
47
+ this->store(__d);
48
+ return __d;
49
+ }
50
+ _LIBCUDACXX_HIDE_FROM_ABI _Tp operator=(_Tp __d) noexcept
51
+ {
52
+ this->store(__d);
53
+ return __d;
54
+ }
55
+
56
+ _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_max(const _Tp& __op, memory_order __m = memory_order_seq_cst) noexcept
57
+ {
58
+ return _CUDA_VSTD::__atomic_fetch_max_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{});
59
+ }
60
+ _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_max(const _Tp& __op, memory_order __m = memory_order_seq_cst) volatile noexcept
61
+ {
62
+ return _CUDA_VSTD::__atomic_fetch_max_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{});
63
+ }
64
+
65
+ _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_min(const _Tp& __op, memory_order __m = memory_order_seq_cst) noexcept
66
+ {
67
+ return _CUDA_VSTD::__atomic_fetch_min_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{});
68
+ }
69
+ _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_min(const _Tp& __op, memory_order __m = memory_order_seq_cst) volatile noexcept
70
+ {
71
+ return _CUDA_VSTD::__atomic_fetch_min_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{});
72
+ }
73
+ };
74
+
75
+ // atomic_ref<T>
76
+
77
+ template <class _Tp, thread_scope _Sco = thread_scope::thread_scope_system>
78
+ struct atomic_ref : public _CUDA_VSTD::__atomic_ref_impl<_Tp, _Sco>
79
+ {
80
+ using value_type = _Tp;
81
+
82
+ static constexpr size_t required_alignment = sizeof(_Tp);
83
+
84
+ static constexpr bool is_always_lock_free = sizeof(_Tp) <= 8;
85
+
86
+ _LIBCUDACXX_HIDE_FROM_ABI explicit constexpr atomic_ref(_Tp& __ref)
87
+ : _CUDA_VSTD::__atomic_ref_impl<_Tp, _Sco>(__ref)
88
+ {}
89
+
90
+ _LIBCUDACXX_HIDE_FROM_ABI _Tp operator=(_Tp __v) const noexcept
91
+ {
92
+ this->store(__v);
93
+ return __v;
94
+ }
95
+
96
+ _CCCL_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default;
97
+ atomic_ref& operator=(const atomic_ref&) = delete;
98
+ atomic_ref& operator=(const atomic_ref&) const = delete;
99
+
100
+ _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_max(const _Tp& __op, memory_order __m = memory_order_seq_cst) const noexcept
101
+ {
102
+ return _CUDA_VSTD::__atomic_fetch_max_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{});
103
+ }
104
+
105
+ _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_min(const _Tp& __op, memory_order __m = memory_order_seq_cst) const noexcept
106
+ {
107
+ return _CUDA_VSTD::__atomic_fetch_min_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{});
108
+ }
109
+ };
110
+
111
+ inline _CCCL_HOST_DEVICE void
112
+ atomic_thread_fence(memory_order __m, thread_scope _Scope = thread_scope::thread_scope_system)
113
+ {
114
+ NV_DISPATCH_TARGET(
115
+ NV_IS_DEVICE,
116
+ (switch (_Scope) {
117
+ case thread_scope::thread_scope_system:
118
+ _CUDA_VSTD::__atomic_thread_fence_cuda((int) __m, __thread_scope_system_tag{});
119
+ break;
120
+ case thread_scope::thread_scope_device:
121
+ _CUDA_VSTD::__atomic_thread_fence_cuda((int) __m, __thread_scope_device_tag{});
122
+ break;
123
+ case thread_scope::thread_scope_block:
124
+ _CUDA_VSTD::__atomic_thread_fence_cuda((int) __m, __thread_scope_block_tag{});
125
+ break;
126
+ // Atomics scoped to themselves do not require fencing
127
+ case thread_scope::thread_scope_thread:
128
+ break;
129
+ }),
130
+ NV_IS_HOST,
131
+ ((void) _Scope; _CUDA_VSTD::atomic_thread_fence(__m);))
132
+ }
133
+
134
+ inline _CCCL_HOST_DEVICE void atomic_signal_fence(memory_order __m)
135
+ {
136
+ _CUDA_VSTD::atomic_signal_fence(__m);
137
+ }
138
+
139
+ _LIBCUDACXX_END_NAMESPACE_CUDA
140
+
141
+ #endif // _CUDA___ATOMIC_ATOMIC_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__cmath/ceil_div.h ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef _CUDA___CMATH_CEIL_DIV_H
12
+ #define _CUDA___CMATH_CEIL_DIV_H
13
+
14
+ #include <cuda/std/detail/__config>
15
+
16
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
17
+ # pragma GCC system_header
18
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
19
+ # pragma clang system_header
20
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
21
+ # pragma system_header
22
+ #endif // no system header
23
+
24
+ #include <cuda/std/__type_traits/common_type.h>
25
+ #include <cuda/std/__type_traits/enable_if.h>
26
+ #include <cuda/std/__type_traits/is_enum.h>
27
+ #include <cuda/std/__type_traits/is_integral.h>
28
+ #include <cuda/std/__type_traits/is_signed.h>
29
+ #include <cuda/std/__type_traits/is_unsigned.h>
30
+ #include <cuda/std/__type_traits/make_unsigned.h>
31
+ #include <cuda/std/__type_traits/underlying_type.h>
32
+
33
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
34
+
35
+ //! @brief Divides two numbers \p __a and \p __b, rounding up if there is a remainder
36
+ //! @param __a The dividend
37
+ //! @param __b The divisor
38
+ //! @pre \p __a must be non-negative
39
+ //! @pre \p __b must be positive
40
+ template <class _Tp,
41
+ class _Up,
42
+ _CUDA_VSTD::enable_if_t<_CCCL_TRAIT(_CUDA_VSTD::is_unsigned, _Tp), int> = 0,
43
+ _CUDA_VSTD::enable_if_t<_CCCL_TRAIT(_CUDA_VSTD::is_integral, _Up), int> = 0>
44
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX14 _Tp ceil_div(const _Tp __a, const _Up __b) noexcept
45
+ {
46
+ _CCCL_ASSERT(__b > _Up(0), "cuda::ceil_div: b must be positive");
47
+ using _UCommon = _CUDA_VSTD::make_unsigned_t<_CUDA_VSTD::common_type_t<_Tp, _Up>>;
48
+ const auto __res = static_cast<_UCommon>(__a) / static_cast<_UCommon>(__b);
49
+ return static_cast<_Tp>(__res + (__res * static_cast<_UCommon>(__b) != static_cast<_UCommon>(__a)));
50
+ }
51
+
52
+ //! @brief Divides two numbers \p __a and \p __b, rounding up if there is a remainder
53
+ //! @param __a The dividend
54
+ //! @param __b The divisor
55
+ //! @pre \p __a must be non-negative
56
+ //! @pre \p __b must be positive
57
+ template <class _Tp,
58
+ class _Up,
59
+ _CUDA_VSTD::enable_if_t<_CCCL_TRAIT(_CUDA_VSTD::is_signed, _Tp), int> = 0,
60
+ _CUDA_VSTD::enable_if_t<_CCCL_TRAIT(_CUDA_VSTD::is_integral, _Up), int> = 0>
61
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX14 _Tp ceil_div(const _Tp __a, const _Up __b) noexcept
62
+ {
63
+ _CCCL_ASSERT(__a >= _Tp(0), "cuda::ceil_div: a must be non negative");
64
+ _CCCL_ASSERT(__b > _Up(0), "cuda::ceil_div: b must be positive");
65
+ using _UCommon = _CUDA_VSTD::make_unsigned_t<_CUDA_VSTD::common_type_t<_Tp, _Up>>;
66
+ // Due to the precondition `__a >= 0` we can safely cast to unsigned without danger of overflowing
67
+ return static_cast<_Tp>((static_cast<_UCommon>(__a) + static_cast<_UCommon>(__b) - 1) / static_cast<_UCommon>(__b));
68
+ }
69
+
70
+ //! @brief Divides two numbers \p __a and \p __b, rounding up if there is a remainder, \p __b is an enum
71
+ //! @param __a The dividend
72
+ //! @param __b The divisor
73
+ //! @pre \p __a must be non-negative
74
+ //! @pre \p __b must be positive
75
+ template <class _Tp,
76
+ class _Up,
77
+ _CUDA_VSTD::enable_if_t<_CCCL_TRAIT(_CUDA_VSTD::is_integral, _Tp), int> = 0,
78
+ _CUDA_VSTD::enable_if_t<_CCCL_TRAIT(_CUDA_VSTD::is_enum, _Up), int> = 0>
79
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX14 _Tp ceil_div(const _Tp __a, const _Up __b) noexcept
80
+ {
81
+ return ::cuda::ceil_div(__a, static_cast<_CUDA_VSTD::underlying_type_t<_Up>>(__b));
82
+ }
83
+
84
+ _LIBCUDACXX_END_NAMESPACE_CUDA
85
+
86
+ #endif // _CUDA___CMATH_CEIL_DIV_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__latch/latch.h ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef __CUDA__LATCH_LATCH_H
12
+ #define __CUDA__LATCH_LATCH_H
13
+
14
+ #include <cuda/std/detail/__config>
15
+
16
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
17
+ # pragma GCC system_header
18
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
19
+ # pragma clang system_header
20
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
21
+ # pragma system_header
22
+ #endif // no system header
23
+
24
+ #include <cuda/std/__latch/latch.h>
25
+ #include <cuda/std/cstddef>
26
+
27
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
28
+
29
+ template <thread_scope _Sco>
30
+ class latch : public _CUDA_VSTD::__latch_base<_Sco>
31
+ {
32
+ public:
33
+ _LIBCUDACXX_HIDE_FROM_ABI constexpr latch(_CUDA_VSTD::ptrdiff_t __count)
34
+ : _CUDA_VSTD::__latch_base<_Sco>(__count)
35
+ {}
36
+ };
37
+
38
+ _LIBCUDACXX_END_NAMESPACE_CUDA
39
+
40
+ #endif // __CUDA__LATCH_LATCH_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/completion_mechanism.h ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef _CUDA___BARRIER_COMPLETION_MECHANISM_H
12
+ #define _CUDA___BARRIER_COMPLETION_MECHANISM_H
13
+
14
+ #include <cuda/std/detail/__config>
15
+
16
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
17
+ # pragma GCC system_header
18
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
19
+ # pragma clang system_header
20
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
21
+ # pragma system_header
22
+ #endif // no system header
23
+
24
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
25
+
26
+ //! @brief __completion_mechanism allows memcpy_async to report back what completion
27
+ //! mechanism it used. This is necessary to determine in which way to synchronize
28
+ //! the memcpy_async with a sync object (barrier or pipeline).
29
+ //
30
+ //! In addition, we use this enum to create bit flags so that calling functions
31
+ //! can specify which completion mechanisms can be used (__sync is always
32
+ //! allowed).
33
+ enum class __completion_mechanism
34
+ {
35
+ __sync = 0,
36
+ __mbarrier_complete_tx = 1 << 0, // Use powers of two here to support the
37
+ __async_group = 1 << 1, // bit flag use case
38
+ __async_bulk_group = 1 << 2,
39
+ };
40
+
41
+ _LIBCUDACXX_END_NAMESPACE_CUDA
42
+
43
+ #endif // _CUDA___BARRIER_COMPLETION_MECHANISM_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_bulk_shared_global.h ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of libcu++, the C++ Standard Library for your entire system,
5
+ // under the Apache License v2.0 with LLVM Exceptions.
6
+ // See https://llvm.org/LICENSE.txt for license information.
7
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
9
+ //
10
+ //===----------------------------------------------------------------------===//
11
+
12
+ #ifndef _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_BULK_SHARED_GLOBAL_H_
13
+ #define _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_BULK_SHARED_GLOBAL_H_
14
+
15
+ #include <cuda/std/detail/__config>
16
+
17
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
18
+ # pragma GCC system_header
19
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
20
+ # pragma clang system_header
21
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
22
+ # pragma system_header
23
+ #endif // no system header
24
+
25
+ #if _CCCL_HAS_CUDA_COMPILER
26
+ # if __cccl_ptx_isa >= 800
27
+
28
+ # include <cuda/__ptx/instructions/cp_async_bulk.h>
29
+ # include <cuda/__ptx/ptx_dot_variants.h>
30
+ # include <cuda/__ptx/ptx_helper_functions.h>
31
+ # include <cuda/std/cstdint>
32
+
33
+ # include <nv/target>
34
+
35
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
36
+
37
+ extern "C" _CCCL_DEVICE void __cuda_ptx_cp_async_bulk_shared_global_is_not_supported_before_SM_90__();
38
+ template <typename _Group>
39
+ inline __device__ void __cp_async_bulk_shared_global(
40
+ const _Group& __g, char* __dest, const char* __src, _CUDA_VSTD::size_t __size, _CUDA_VSTD::uint64_t* __bar_handle)
41
+ {
42
+ // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-bulk
43
+ NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90,
44
+ (if (__g.thread_rank() == 0) {
45
+ _CUDA_VPTX::cp_async_bulk(
46
+ _CUDA_VPTX::space_cluster, _CUDA_VPTX::space_global, __dest, __src, __size, __bar_handle);
47
+ }),
48
+ (__cuda_ptx_cp_async_bulk_shared_global_is_not_supported_before_SM_90__();));
49
+ }
50
+
51
+ _LIBCUDACXX_END_NAMESPACE_CUDA
52
+
53
+ # endif // __cccl_ptx_isa >= 800
54
+ #endif // _CCCL_CUDA_COMPILER
55
+
56
+ #endif // _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_BULK_SHARED_GLOBAL_H_
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_fallback.h ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of libcu++, the C++ Standard Library for your entire system,
5
+ // under the Apache License v2.0 with LLVM Exceptions.
6
+ // See https://llvm.org/LICENSE.txt for license information.
7
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
9
+ //
10
+ //===----------------------------------------------------------------------===//
11
+
12
+ #ifndef _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_FALLBACK_H_
13
+ #define _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_FALLBACK_H_
14
+
15
+ #include <cuda/std/detail/__config>
16
+
17
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
18
+ # pragma GCC system_header
19
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
20
+ # pragma clang system_header
21
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
22
+ # pragma system_header
23
+ #endif // no system header
24
+
25
+ #include <cuda/std/cstddef>
26
+
27
+ #include <nv/target>
28
+
29
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
30
+
31
+ template <_CUDA_VSTD::size_t _Copy_size>
32
+ struct __copy_chunk
33
+ {
34
+ _CCCL_ALIGNAS(_Copy_size) char data[_Copy_size];
35
+ };
36
+
37
+ template <_CUDA_VSTD::size_t _Alignment, typename _Group>
38
+ inline _CCCL_HOST_DEVICE void
39
+ __cp_async_fallback_mechanism(_Group __g, char* __dest, const char* __src, _CUDA_VSTD::size_t __size)
40
+ {
41
+ // Maximal copy size is 16 bytes
42
+ constexpr _CUDA_VSTD::size_t __copy_size = (_Alignment > 16) ? 16 : _Alignment;
43
+
44
+ using __chunk_t = __copy_chunk<__copy_size>;
45
+
46
+ // "Group"-strided loop over memory
47
+ const _CUDA_VSTD::size_t __stride = __g.size() * __copy_size;
48
+
49
+ // An unroll factor of 64 ought to be enough for anybody. This unroll pragma
50
+ // is mainly intended to place an upper bound on loop unrolling. The number
51
+ // is more than high enough for the intended use case: an unroll factor of
52
+ // 64 allows moving 4 * 64 * 256 = 64kb in one unrolled loop with 256
53
+ // threads (copying ints). On the other hand, in the unfortunate case that
54
+ // we have to move 1024 bytes / thread with char width, then we prevent
55
+ // fully unrolling the loop to 1024 copy instructions. This prevents the
56
+ // compile times from increasing unreasonably, and also has negligible
57
+ // impact on runtime performance.
58
+ _LIBCUDACXX_PRAGMA_UNROLL(64)
59
+ for (_CUDA_VSTD::size_t __offset = __g.thread_rank() * __copy_size; __offset < __size; __offset += __stride)
60
+ {
61
+ __chunk_t tmp = *reinterpret_cast<const __chunk_t*>(__src + __offset);
62
+ *reinterpret_cast<__chunk_t*>(__dest + __offset) = tmp;
63
+ }
64
+ }
65
+
66
+ _LIBCUDACXX_END_NAMESPACE_CUDA
67
+
68
+ #endif // _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_FALLBACK_H_
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_shared_global.h ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of libcu++, the C++ Standard Library for your entire system,
5
+ // under the Apache License v2.0 with LLVM Exceptions.
6
+ // See https://llvm.org/LICENSE.txt for license information.
7
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
9
+ //
10
+ //===----------------------------------------------------------------------===//
11
+
12
+ #ifndef _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_SHARED_GLOBAL_H_
13
+ #define _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_SHARED_GLOBAL_H_
14
+
15
+ #include <cuda/std/detail/__config>
16
+
17
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
18
+ # pragma GCC system_header
19
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
20
+ # pragma clang system_header
21
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
22
+ # pragma system_header
23
+ #endif // no system header
24
+
25
+ #if _CCCL_HAS_CUDA_COMPILER
26
+
27
+ # include <cuda/__ptx/ptx_dot_variants.h>
28
+ # include <cuda/__ptx/ptx_helper_functions.h>
29
+ # include <cuda/std/cstdint>
30
+
31
+ # include <nv/target>
32
+
33
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
34
+
35
+ extern "C" _CCCL_DEVICE void __cuda_ptx_cp_async_shared_global_is_not_supported_before_SM_80__();
36
+ template <size_t _Copy_size>
37
+ inline __device__ void __cp_async_shared_global(char* __dest, const char* __src)
38
+ {
39
+ // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async
40
+
41
+ // If `if constexpr` is not available, this function gets instantiated even
42
+ // if is not called. Do not static_assert in that case.
43
+ # if _CCCL_STD_VER >= 2017
44
+ static_assert(_Copy_size == 4 || _Copy_size == 8 || _Copy_size == 16,
45
+ "cp.async.shared.global requires a copy size of 4, 8, or 16.");
46
+ # endif // _CCCL_STD_VER >= 2017
47
+
48
+ NV_IF_ELSE_TARGET(
49
+ NV_PROVIDES_SM_80,
50
+ (asm volatile("cp.async.ca.shared.global [%0], [%1], %2, %2;"
51
+ :
52
+ : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__dest))),
53
+ "l"(static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__src))),
54
+ "n"(_Copy_size)
55
+ : "memory");),
56
+ (__cuda_ptx_cp_async_shared_global_is_not_supported_before_SM_80__();));
57
+ }
58
+
59
+ template <>
60
+ inline __device__ void __cp_async_shared_global<16>(char* __dest, const char* __src)
61
+ {
62
+ // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async
63
+ // When copying 16 bytes, it is possible to skip L1 cache (.cg).
64
+ NV_IF_ELSE_TARGET(
65
+ NV_PROVIDES_SM_80,
66
+ (asm volatile("cp.async.cg.shared.global [%0], [%1], %2, %2;"
67
+ :
68
+ : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__dest))),
69
+ "l"(static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__src))),
70
+ "n"(16)
71
+ : "memory");),
72
+ (__cuda_ptx_cp_async_shared_global_is_not_supported_before_SM_80__();));
73
+ }
74
+
75
+ template <size_t _Alignment, typename _Group>
76
+ inline __device__ void
77
+ __cp_async_shared_global_mechanism(_Group __g, char* __dest, const char* __src, _CUDA_VSTD::size_t __size)
78
+ {
79
+ // If `if constexpr` is not available, this function gets instantiated even
80
+ // if is not called. Do not static_assert in that case.
81
+ # if _CCCL_STD_VER >= 2017
82
+ static_assert(4 <= _Alignment, "cp.async requires at least 4-byte alignment");
83
+ # endif // _CCCL_STD_VER >= 2017
84
+
85
+ // Maximal copy size is 16.
86
+ constexpr int __copy_size = (_Alignment > 16) ? 16 : _Alignment;
87
+ // We use an int offset here, because we are copying to shared memory,
88
+ // which is easily addressable using int.
89
+ const int __group_size = __g.size();
90
+ const int __group_rank = __g.thread_rank();
91
+ const int __stride = __group_size * __copy_size;
92
+ for (int __offset = __group_rank * __copy_size; __offset < static_cast<int>(__size); __offset += __stride)
93
+ {
94
+ __cp_async_shared_global<__copy_size>(__dest + __offset, __src + __offset);
95
+ }
96
+ }
97
+
98
+ _LIBCUDACXX_END_NAMESPACE_CUDA
99
+
100
+ #endif // _CCCL_CUDA_COMPILER
101
+
102
+ #endif // _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_SHARED_GLOBAL_H_
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/dispatch_memcpy_async.h ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of libcu++, the C++ Standard Library for your entire system,
5
+ // under the Apache License v2.0 with LLVM Exceptions.
6
+ // See https://llvm.org/LICENSE.txt for license information.
7
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
9
+ //
10
+ //===----------------------------------------------------------------------===//
11
+
12
+ #ifndef _CUDA_PTX__MEMCPY_ASYNC_DISPATCH_MEMCPY_ASYNC_H_
13
+ #define _CUDA_PTX__MEMCPY_ASYNC_DISPATCH_MEMCPY_ASYNC_H_
14
+
15
+ #include <cuda/std/detail/__config>
16
+
17
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
18
+ # pragma GCC system_header
19
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
20
+ # pragma clang system_header
21
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
22
+ # pragma system_header
23
+ #endif // no system header
24
+
25
+ #include <cuda/__memcpy_async/completion_mechanism.h>
26
+ #include <cuda/__memcpy_async/cp_async_bulk_shared_global.h>
27
+ #include <cuda/__memcpy_async/cp_async_fallback.h>
28
+ #include <cuda/__memcpy_async/cp_async_shared_global.h>
29
+ #include <cuda/std/cstddef>
30
+ #include <cuda/std/cstdint>
31
+ #include <cuda/std/detail/libcxx/include/cstring>
32
+
33
+ #include <nv/target>
34
+
35
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
36
+
37
+ /***********************************************************************
38
+ * cuda::memcpy_async dispatch
39
+ *
40
+ * The dispatch mechanism takes all the arguments and dispatches to the
41
+ * fastest asynchronous copy mechanism available.
42
+ *
43
+ * It returns a __completion_mechanism that indicates which completion mechanism
44
+ * was used by the copy mechanism. This value can be used by the sync object to
45
+ * further synchronize if necessary.
46
+ *
47
+ ***********************************************************************/
48
+
49
+ template <_CUDA_VSTD::size_t _Align, typename _Group>
50
+ _CCCL_NODISCARD _CCCL_DEVICE inline __completion_mechanism __dispatch_memcpy_async_any_to_any(
51
+ _Group const& __group,
52
+ char* __dest_char,
53
+ char const* __src_char,
54
+ _CUDA_VSTD::size_t __size,
55
+ _CUDA_VSTD::uint32_t __allowed_completions,
56
+ _CUDA_VSTD::uint64_t* __bar_handle)
57
+ {
58
+ __cp_async_fallback_mechanism<_Align>(__group, __dest_char, __src_char, __size);
59
+ return __completion_mechanism::__sync;
60
+ }
61
+
62
+ template <_CUDA_VSTD::size_t _Align, typename _Group>
63
+ _CCCL_NODISCARD _CCCL_DEVICE inline __completion_mechanism __dispatch_memcpy_async_global_to_shared(
64
+ _Group const& __group,
65
+ char* __dest_char,
66
+ char const* __src_char,
67
+ _CUDA_VSTD::size_t __size,
68
+ _CUDA_VSTD::uint32_t __allowed_completions,
69
+ _CUDA_VSTD::uint64_t* __bar_handle)
70
+ {
71
+ #if __cccl_ptx_isa >= 800
72
+ NV_IF_TARGET(
73
+ NV_PROVIDES_SM_90,
74
+ (const bool __can_use_complete_tx = __allowed_completions & uint32_t(__completion_mechanism::__mbarrier_complete_tx);
75
+ (void) __can_use_complete_tx;
76
+ _CCCL_ASSERT(__can_use_complete_tx == (nullptr != __bar_handle),
77
+ "Pass non-null bar_handle if and only if can_use_complete_tx.");
78
+ _CCCL_IF_CONSTEXPR (_Align >= 16) {
79
+ if (__can_use_complete_tx && __isShared(__bar_handle))
80
+ {
81
+ __cp_async_bulk_shared_global(__group, __dest_char, __src_char, __size, __bar_handle);
82
+ return __completion_mechanism::__mbarrier_complete_tx;
83
+ }
84
+ }
85
+ // Fallthrough to SM 80..
86
+ ));
87
+ #endif // __cccl_ptx_isa >= 800
88
+
89
+ NV_IF_TARGET(
90
+ NV_PROVIDES_SM_80,
91
+ (_CCCL_IF_CONSTEXPR (_Align >= 4) {
92
+ const bool __can_use_async_group = __allowed_completions & uint32_t(__completion_mechanism::__async_group);
93
+ if (__can_use_async_group)
94
+ {
95
+ __cp_async_shared_global_mechanism<_Align>(__group, __dest_char, __src_char, __size);
96
+ return __completion_mechanism::__async_group;
97
+ }
98
+ }
99
+ // Fallthrough..
100
+ ));
101
+
102
+ __cp_async_fallback_mechanism<_Align>(__group, __dest_char, __src_char, __size);
103
+ return __completion_mechanism::__sync;
104
+ }
105
+
106
+ // __dispatch_memcpy_async is the internal entry point for dispatching to the correct memcpy_async implementation.
107
+ template <_CUDA_VSTD::size_t _Align, typename _Group>
108
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI __completion_mechanism __dispatch_memcpy_async(
109
+ _Group const& __group,
110
+ char* __dest_char,
111
+ char const* __src_char,
112
+ _CUDA_VSTD::size_t __size,
113
+ _CUDA_VSTD::uint32_t __allowed_completions,
114
+ _CUDA_VSTD::uint64_t* __bar_handle)
115
+ {
116
+ NV_IF_ELSE_TARGET(
117
+ NV_IS_DEVICE,
118
+ (
119
+ // Dispatch based on direction of the copy: global to shared, shared to
120
+ // global, etc.
121
+
122
+ // CUDA compilers <= 12.2 may not propagate assumptions about the state space
123
+ // of pointers correctly. Therefore, we
124
+ // 1) put the code for each copy direction in a separate function, and
125
+ // 2) make sure none of the code paths can reach each other by "falling through".
126
+ //
127
+ // See nvbug 4074679 and also PR #478.
128
+ if (__isGlobal(__src_char) && __isShared(__dest_char)) {
129
+ return __dispatch_memcpy_async_global_to_shared<_Align>(
130
+ __group, __dest_char, __src_char, __size, __allowed_completions, __bar_handle);
131
+ } else {
132
+ return __dispatch_memcpy_async_any_to_any<_Align>(
133
+ __group, __dest_char, __src_char, __size, __allowed_completions, __bar_handle);
134
+ }),
135
+ (
136
+ // Host code path:
137
+ if (__group.thread_rank() == 0) {
138
+ memcpy(__dest_char, __src_char, __size);
139
+ } return __completion_mechanism::__sync;));
140
+ }
141
+
142
+ template <_CUDA_VSTD::size_t _Align, typename _Group>
143
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI __completion_mechanism __dispatch_memcpy_async(
144
+ _Group const& __group,
145
+ char* __dest_char,
146
+ char const* __src_char,
147
+ _CUDA_VSTD::size_t __size,
148
+ _CUDA_VSTD::uint32_t __allowed_completions)
149
+ {
150
+ _CCCL_ASSERT(!(__allowed_completions & uint32_t(__completion_mechanism::__mbarrier_complete_tx)),
151
+ "Cannot allow mbarrier_complete_tx completion mechanism when not passing a barrier. ");
152
+ return __dispatch_memcpy_async<_Align>(__group, __dest_char, __src_char, __size, __allowed_completions, nullptr);
153
+ }
154
+
155
+ _LIBCUDACXX_END_NAMESPACE_CUDA
156
+
157
+ #endif // _CUDA_PTX__MEMCPY_ASYNC_DISPATCH_MEMCPY_ASYNC_H_
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/is_local_smem_barrier.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef _CUDA___BARRIER_IS_LOCAL_SMEM_BARRIER_H
12
+ #define _CUDA___BARRIER_IS_LOCAL_SMEM_BARRIER_H
13
+
14
+ #include <cuda/std/detail/__config>
15
+
16
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
17
+ # pragma GCC system_header
18
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
19
+ # pragma clang system_header
20
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
21
+ # pragma system_header
22
+ #endif // no system header
23
+
24
+ #include <cuda/__barrier/barrier.h>
25
+ #include <cuda/std/__atomic/scopes.h>
26
+ #include <cuda/std/__barrier/empty_completion.h>
27
+ #include <cuda/std/__type_traits/is_same.h>
28
+
29
+ #include <nv/target>
30
+
31
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
32
+
33
+ //! @brief __is_local_smem_barrier returns true if barrier is (1) block-scoped and (2) located in shared memory.
34
+ template <thread_scope _Sco,
35
+ typename _CompF,
36
+ bool _Is_mbarrier = (_Sco == thread_scope_block)
37
+ && _CCCL_TRAIT(_CUDA_VSTD::is_same, _CompF, _CUDA_VSTD::__empty_completion)>
38
+ _LIBCUDACXX_HIDE_FROM_ABI bool __is_local_smem_barrier(barrier<_Sco, _CompF>& __barrier)
39
+ {
40
+ NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return _Is_mbarrier && __isShared(&__barrier);), (return false;));
41
+ }
42
+
43
+ _LIBCUDACXX_END_NAMESPACE_CUDA
44
+
45
+ #endif // _CUDA___BARRIER_IS_LOCAL_SMEM_BARRIER_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async.h ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of libcu++, the C++ Standard Library for your entire system,
5
+ // under the Apache License v2.0 with LLVM Exceptions.
6
+ // See https://llvm.org/LICENSE.txt for license information.
7
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
9
+ //
10
+ //===----------------------------------------------------------------------===//
11
+
12
+ #ifndef _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_H_
13
+ #define _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_H_
14
+
15
+ #include <cuda/std/detail/__config>
16
+
17
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
18
+ # pragma GCC system_header
19
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
20
+ # pragma clang system_header
21
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
22
+ # pragma system_header
23
+ #endif // no system header
24
+
25
+ #if _CCCL_HAS_CUDA_COMPILER
26
+
27
+ # include <cuda/__barrier/aligned_size.h>
28
+ # include <cuda/__barrier/async_contract_fulfillment.h>
29
+ # include <cuda/__barrier/barrier.h>
30
+ # include <cuda/__barrier/barrier_block_scope.h>
31
+ # include <cuda/__barrier/barrier_thread_scope.h>
32
+ # include <cuda/__memcpy_async/memcpy_async_barrier.h>
33
+ # include <cuda/std/__atomic/scopes.h>
34
+ # include <cuda/std/__type_traits/void_t.h>
35
+ # include <cuda/std/cstddef>
36
+
37
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
38
+
39
+ /***********************************************************************
40
+ * memcpy_async code:
41
+ *
42
+ * A call to cuda::memcpy_async(dest, src, size, barrier) can dispatch to any of
43
+ * these PTX instructions:
44
+ *
45
+ * 1. normal synchronous copy (fallback)
46
+ * 2. cp.async: shared <- global
47
+ * 3. cp.async.bulk: shared <- global
48
+ * 4. TODO: cp.async.bulk: global <- shared
49
+ * 5. TODO: cp.async.bulk: cluster <- shared
50
+ *
51
+ * Which of these options is chosen, depends on:
52
+ *
53
+ * 1. The alignment of dest, src, and size;
54
+ * 2. The direction of the copy
55
+ * 3. The current compute capability
56
+ * 4. The requested completion mechanism
57
+ *
58
+ * PTX has 3 asynchronous completion mechanisms:
59
+ *
60
+ * 1. Async group - local to a thread. Used by cp.async
61
+ * 2. Bulk async group - local to a thread. Used by cp.async.bulk (shared -> global)
62
+ * 3. mbarrier::complete_tx - shared memory barier. Used by cp.async.bulk (other directions)
63
+ *
64
+ * The code is organized as follows:
65
+ *
66
+ * 1. Asynchronous copy mechanisms that wrap the PTX instructions
67
+ *
68
+ * 2. Device memcpy_async implementation per copy direction (global to shared,
69
+ * shared to global, etc). Dispatches to fastest mechanism based on requested
70
+ * completion mechanism(s), pointer alignment, and architecture.
71
+ *
72
+ * 3. Host and device memcpy_async implementations. Host implementation is
73
+ * basically a memcpy wrapper; device implementation dispatches based on the
74
+ * direction of the copy.
75
+ *
76
+ * 4. __memcpy_async_barrier:
77
+ * a) Sets the allowed completion mechanisms based on the barrier location
78
+ * b) Calls the host or device memcpy_async implementation
79
+ * c) If necessary, synchronizes with the barrier based on the returned
80
+ * completion mechanism.
81
+ *
82
+ * 5. The public memcpy_async function overloads. Call into
83
+ * __memcpy_async_barrier.
84
+ *
85
+ ***********************************************************************/
86
+
87
+ /***********************************************************************
88
+ * Asynchronous copy mechanisms:
89
+ *
90
+ * 1. cp.async.bulk: shared <- global
91
+ * 2. TODO: cp.async.bulk: cluster <- shared
92
+ * 3. TODO: cp.async.bulk: global <- shared
93
+ * 4. cp.async: shared <- global
94
+ * 5. normal synchronous copy (fallback)
95
+ ***********************************************************************/
96
+
97
+ template <typename _Group, class _Tp, _CUDA_VSTD::size_t _Alignment, thread_scope _Sco, typename _CompF>
98
+ _LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment memcpy_async(
99
+ _Group const& __group,
100
+ _Tp* __destination,
101
+ _Tp const* __source,
102
+ aligned_size_t<_Alignment> __size,
103
+ barrier<_Sco, _CompF>& __barrier)
104
+ {
105
+ return __memcpy_async_barrier(__group, __destination, __source, __size, __barrier);
106
+ }
107
+
108
+ template <class _Tp, typename _Size, thread_scope _Sco, typename _CompF>
109
+ _LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment
110
+ memcpy_async(_Tp* __destination, _Tp const* __source, _Size __size, barrier<_Sco, _CompF>& __barrier)
111
+ {
112
+ return __memcpy_async_barrier(__single_thread_group{}, __destination, __source, __size, __barrier);
113
+ }
114
+
115
+ template <typename _Group, class _Tp, thread_scope _Sco, typename _CompF>
116
+ _LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment memcpy_async(
117
+ _Group const& __group,
118
+ _Tp* __destination,
119
+ _Tp const* __source,
120
+ _CUDA_VSTD::size_t __size,
121
+ barrier<_Sco, _CompF>& __barrier)
122
+ {
123
+ return __memcpy_async_barrier(__group, __destination, __source, __size, __barrier);
124
+ }
125
+
126
+ template <typename _Group, thread_scope _Sco, typename _CompF>
127
+ _LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment memcpy_async(
128
+ _Group const& __group,
129
+ void* __destination,
130
+ void const* __source,
131
+ _CUDA_VSTD::size_t __size,
132
+ barrier<_Sco, _CompF>& __barrier)
133
+ {
134
+ return __memcpy_async_barrier(
135
+ __group, reinterpret_cast<char*>(__destination), reinterpret_cast<char const*>(__source), __size, __barrier);
136
+ }
137
+
138
+ template <typename _Group, _CUDA_VSTD::size_t _Alignment, thread_scope _Sco, typename _CompF>
139
+ _LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment memcpy_async(
140
+ _Group const& __group,
141
+ void* __destination,
142
+ void const* __source,
143
+ aligned_size_t<_Alignment> __size,
144
+ barrier<_Sco, _CompF>& __barrier)
145
+ {
146
+ return __memcpy_async_barrier(
147
+ __group, reinterpret_cast<char*>(__destination), reinterpret_cast<char const*>(__source), __size, __barrier);
148
+ }
149
+
150
+ template <typename _Size, thread_scope _Sco, typename _CompF>
151
+ _LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment
152
+ memcpy_async(void* __destination, void const* __source, _Size __size, barrier<_Sco, _CompF>& __barrier)
153
+ {
154
+ return __memcpy_async_barrier(
155
+ __single_thread_group{},
156
+ reinterpret_cast<char*>(__destination),
157
+ reinterpret_cast<char const*>(__source),
158
+ __size,
159
+ __barrier);
160
+ }
161
+
162
+ _LIBCUDACXX_END_NAMESPACE_CUDA
163
+
164
+ #endif // _CCCL_CUDA_COMPILER
165
+
166
+ #endif // _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_H_
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_barrier.h ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of libcu++, the C++ Standard Library for your entire system,
5
+ // under the Apache License v2.0 with LLVM Exceptions.
6
+ // See https://llvm.org/LICENSE.txt for license information.
7
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
9
+ //
10
+ //===----------------------------------------------------------------------===//
11
+
12
+ #ifndef _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_BARRIER_H_
13
+ #define _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_BARRIER_H_
14
+
15
+ #include <cuda/std/detail/__config>
16
+
17
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
18
+ # pragma GCC system_header
19
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
20
+ # pragma clang system_header
21
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
22
+ # pragma system_header
23
+ #endif // no system header
24
+
25
+ #include <cuda/__barrier/barrier.h>
26
+ #include <cuda/__barrier/barrier_block_scope.h>
27
+ #include <cuda/__barrier/barrier_thread_scope.h>
28
+ #include <cuda/__memcpy_async/completion_mechanism.h>
29
+ #include <cuda/__memcpy_async/dispatch_memcpy_async.h>
30
+ #include <cuda/__memcpy_async/is_local_smem_barrier.h>
31
+ #include <cuda/__memcpy_async/memcpy_completion.h>
32
+ #include <cuda/__memcpy_async/try_get_barrier_handle.h>
33
+ #include <cuda/std/__atomic/scopes.h>
34
+ #include <cuda/std/__type_traits/is_trivially_copyable.h>
35
+ #include <cuda/std/cstddef>
36
+ #include <cuda/std/cstdint>
37
+
38
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
39
+
40
+ /***********************************************************************
41
+ * cuda::memcpy_async dispatch helper functions
42
+ *
43
+ * - __get_size_align struct to determine the alignment from a size type.
44
+ ***********************************************************************/
45
+
46
+ // The __get_size_align struct provides a way to query the guaranteed
47
+ // "alignment" of a provided size. In this case, an n-byte aligned size means
48
+ // that the size is a multiple of n.
49
+ //
50
+ // Use as follows:
51
+ // static_assert(__get_size_align<size_t>::align == 1)
52
+ // static_assert(__get_size_align<aligned_size_t<n>>::align == n)
53
+
54
+ // Default impl: always returns 1.
55
+ template <typename, typename = void>
56
+ struct __get_size_align
57
+ {
58
+ static constexpr int align = 1;
59
+ };
60
+
61
+ // aligned_size_t<n> overload: return n.
62
+ template <typename T>
63
+ struct __get_size_align<T, _CUDA_VSTD::void_t<decltype(T::align)>>
64
+ {
65
+ static constexpr int align = T::align;
66
+ };
67
+
68
+ ////////////////////////////////////////////////////////////////////////////////
69
+
70
+ struct __single_thread_group
71
+ {
72
+ _LIBCUDACXX_HIDE_FROM_ABI void sync() const {}
73
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _CUDA_VSTD::size_t size() const
74
+ {
75
+ return 1;
76
+ };
77
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _CUDA_VSTD::size_t thread_rank() const
78
+ {
79
+ return 0;
80
+ };
81
+ };
82
+
83
+ template <typename _Group, class _Tp, typename _Size, thread_scope _Sco, typename _CompF>
84
+ _LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment __memcpy_async_barrier(
85
+ _Group const& __group, _Tp* __destination, _Tp const* __source, _Size __size, barrier<_Sco, _CompF>& __barrier)
86
+ {
87
+ static_assert(_CCCL_TRAIT(_CUDA_VSTD::is_trivially_copyable, _Tp), "memcpy_async requires a trivially copyable type");
88
+
89
+ // 1. Determine which completion mechanisms can be used with the current
90
+ // barrier. A local shared memory barrier, i.e., block-scope barrier in local
91
+ // shared memory, supports the mbarrier_complete_tx mechanism in addition to
92
+ // the async group mechanism.
93
+ _CUDA_VSTD::uint32_t __allowed_completions =
94
+ __is_local_smem_barrier(__barrier)
95
+ ? (_CUDA_VSTD::uint32_t(__completion_mechanism::__async_group)
96
+ | _CUDA_VSTD::uint32_t(__completion_mechanism::__mbarrier_complete_tx))
97
+ : _CUDA_VSTD::uint32_t(__completion_mechanism::__async_group);
98
+
99
+ // Alignment: Use the maximum of the alignment of _Tp and that of a possible cuda::aligned_size_t.
100
+ constexpr _CUDA_VSTD::size_t __size_align = __get_size_align<_Size>::align;
101
+ constexpr _CUDA_VSTD::size_t __align = (alignof(_Tp) < __size_align) ? __size_align : alignof(_Tp);
102
+ // Cast to char pointers. We don't need the type for alignment anymore and
103
+ // erasing the types reduces the number of instantiations of down-stream
104
+ // functions.
105
+ char* __dest_char = reinterpret_cast<char*>(__destination);
106
+ char const* __src_char = reinterpret_cast<char const*>(__source);
107
+
108
+ // 2. Issue actual copy instructions.
109
+ auto __bh = __try_get_barrier_handle(__barrier);
110
+ auto __cm = __dispatch_memcpy_async<__align>(__group, __dest_char, __src_char, __size, __allowed_completions, __bh);
111
+
112
+ // 3. Synchronize barrier with copy instructions.
113
+ return __memcpy_completion_impl::__defer(__cm, __group, __size, __barrier);
114
+ }
115
+
116
+ _LIBCUDACXX_END_NAMESPACE_CUDA
117
+
118
+ #endif // _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_BARRIER_H_
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_tx.h ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of libcu++, the C++ Standard Library for your entire system,
5
+ // under the Apache License v2.0 with LLVM Exceptions.
6
+ // See https://llvm.org/LICENSE.txt for license information.
7
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
9
+ //
10
+ //===----------------------------------------------------------------------===//
11
+
12
+ #ifndef _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_TX_H_
13
+ #define _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_TX_H_
14
+
15
+ #include <cuda/std/detail/__config>
16
+
17
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
18
+ # pragma GCC system_header
19
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
20
+ # pragma clang system_header
21
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
22
+ # pragma system_header
23
+ #endif // no system header
24
+
25
+ #if _CCCL_HAS_CUDA_COMPILER
26
+ # if __cccl_ptx_isa >= 800
27
+
28
+ # include <cuda/__barrier/aligned_size.h>
29
+ # include <cuda/__barrier/async_contract_fulfillment.h>
30
+ # include <cuda/__barrier/barrier_block_scope.h>
31
+ # include <cuda/__barrier/barrier_native_handle.h>
32
+ # include <cuda/__ptx/instructions/cp_async_bulk.h>
33
+ # include <cuda/__ptx/ptx_dot_variants.h>
34
+ # include <cuda/__ptx/ptx_helper_functions.h>
35
+ # include <cuda/std/__atomic/scopes.h>
36
+ # include <cuda/std/__type_traits/is_trivially_copyable.h>
37
+ # include <cuda/std/cstdint>
38
+
39
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE
40
+
41
+ extern "C" _CCCL_DEVICE void __cuda_ptx_memcpy_async_tx_is_not_supported_before_SM_90__();
42
+ template <typename _Tp, _CUDA_VSTD::size_t _Alignment>
43
+ _CCCL_DEVICE inline async_contract_fulfillment memcpy_async_tx(
44
+ _Tp* __dest,
45
+ const _Tp* __src,
46
+ ::cuda::aligned_size_t<_Alignment> __size,
47
+ ::cuda::barrier<::cuda::thread_scope_block>& __b)
48
+ {
49
+ // When compiling with NVCC and GCC 4.8, certain user defined types that _are_ trivially copyable are
50
+ // incorrectly classified as not trivially copyable. Remove this assertion to allow for their usage with
51
+ // memcpy_async when compiling with GCC 4.8.
52
+ // FIXME: remove the #if once GCC 4.8 is no longer supported.
53
+ # if !_CCCL_COMPILER(GCC) || _CCCL_COMPILER(GCC, >, 4, 8)
54
+ static_assert(_CUDA_VSTD::is_trivially_copyable<_Tp>::value, "memcpy_async_tx requires a trivially copyable type");
55
+ # endif
56
+ static_assert(16 <= _Alignment, "mempcy_async_tx expects arguments to be at least 16 byte aligned.");
57
+
58
+ _CCCL_ASSERT(__isShared(barrier_native_handle(__b)), "Barrier must be located in local shared memory.");
59
+ _CCCL_ASSERT(__isShared(__dest), "dest must point to shared memory.");
60
+ _CCCL_ASSERT(__isGlobal(__src), "src must point to global memory.");
61
+
62
+ NV_IF_ELSE_TARGET(
63
+ NV_PROVIDES_SM_90,
64
+ (
65
+ if (__isShared(__dest) && __isGlobal(__src)) {
66
+ _CUDA_VPTX::cp_async_bulk(
67
+ _CUDA_VPTX::space_cluster,
68
+ _CUDA_VPTX::space_global,
69
+ __dest,
70
+ __src,
71
+ static_cast<uint32_t>(__size),
72
+ barrier_native_handle(__b));
73
+ } else {
74
+ // memcpy_async_tx only supports copying from global to shared
75
+ // or from shared to remote cluster dsmem. To copy to remote
76
+ // dsmem, we need to arrive on a cluster-scoped barrier, which
77
+ // is not yet implemented. So we trap in this case as well.
78
+ _CCCL_UNREACHABLE();
79
+ }),
80
+ (__cuda_ptx_memcpy_async_tx_is_not_supported_before_SM_90__();));
81
+
82
+ return async_contract_fulfillment::async;
83
+ }
84
+
85
+ _LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE
86
+
87
+ # endif // __cccl_ptx_isa >= 800
88
+ #endif // _CCCL_CUDA_COMPILER
89
+
90
+ #endif // _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_TX_H_
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_completion.h ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef _CUDA___MEMCPY_ASYNC_MEMCPY_COMPLETION_H
12
+ #define _CUDA___MEMCPY_ASYNC_MEMCPY_COMPLETION_H
13
+
14
+ #include <cuda/std/detail/__config>
15
+
16
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
17
+ # pragma GCC system_header
18
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
19
+ # pragma clang system_header
20
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
21
+ # pragma system_header
22
+ #endif // no system header
23
+
24
+ #include <cuda/__barrier/async_contract_fulfillment.h>
25
+ #include <cuda/__barrier/barrier_block_scope.h>
26
+ #include <cuda/__barrier/barrier_expect_tx.h>
27
+ #include <cuda/__fwd/pipeline.h>
28
+ #include <cuda/__memcpy_async/completion_mechanism.h>
29
+ #include <cuda/__memcpy_async/is_local_smem_barrier.h>
30
+ #include <cuda/__memcpy_async/try_get_barrier_handle.h>
31
+ #include <cuda/std/__atomic/scopes.h>
32
+ #include <cuda/std/cstdint>
33
+
34
+ #if _CCCL_HAS_CUDA_COMPILER
35
+ # include <cuda/__ptx/ptx_dot_variants.h>
36
+ # include <cuda/__ptx/ptx_helper_functions.h>
37
+ #endif // _CCCL_CUDA_COMPILER
38
+
39
+ #include <nv/target>
40
+
41
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
42
+
43
+ // This struct contains functions to defer the completion of a barrier phase
44
+ // or pipeline stage until a specific memcpy_async operation *initiated by
45
+ // this thread* has completed.
46
+
47
+ // The user is still responsible for arriving and waiting on (or otherwise
48
+ // synchronizing with) the barrier or pipeline barrier to see the results of
49
+ // copies from other threads participating in the synchronization object.
50
+ struct __memcpy_completion_impl
51
+ {
52
+ template <typename _Group>
53
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI static async_contract_fulfillment
54
+ __defer(__completion_mechanism __cm,
55
+ _Group const& __group,
56
+ _CUDA_VSTD::size_t __size,
57
+ barrier<::cuda::thread_scope_block>& __barrier)
58
+ {
59
+ // In principle, this is the overload for shared memory barriers. However, a
60
+ // block-scope barrier may also be located in global memory. Therefore, we
61
+ // check if the barrier is a non-smem barrier and handle that separately.
62
+ if (!__is_local_smem_barrier(__barrier))
63
+ {
64
+ return __defer_non_smem_barrier(__cm, __group, __size, __barrier);
65
+ }
66
+
67
+ switch (__cm)
68
+ {
69
+ case __completion_mechanism::__async_group:
70
+ // Pre-SM80, the async_group mechanism is not available.
71
+ NV_IF_TARGET(
72
+ NV_PROVIDES_SM_80,
73
+ (
74
+ // Non-Blocking: unbalance barrier by 1, barrier will be
75
+ // rebalanced when all thread-local cp.async instructions
76
+ // have completed writing to shared memory.
77
+ _CUDA_VSTD::uint64_t* __bh = __try_get_barrier_handle(__barrier);
78
+
79
+ asm volatile("cp.async.mbarrier.arrive.shared.b64 [%0];" ::"r"(static_cast<_CUDA_VSTD::uint32_t>(
80
+ __cvta_generic_to_shared(__bh)))
81
+ : "memory");));
82
+ return async_contract_fulfillment::async;
83
+ case __completion_mechanism::__async_bulk_group:
84
+ // This completion mechanism should not be used with a shared
85
+ // memory barrier. Or at least, we do not currently envision
86
+ // bulk group to be used with shared memory barriers.
87
+ _CCCL_UNREACHABLE();
88
+ case __completion_mechanism::__mbarrier_complete_tx:
89
+ #if __cccl_ptx_isa >= 800
90
+ // Pre-sm90, the mbarrier_complete_tx completion mechanism is not available.
91
+ NV_IF_TARGET(NV_PROVIDES_SM_90,
92
+ (
93
+ // Only perform the expect_tx operation with the leader thread
94
+ if (__group.thread_rank() == 0) { ::cuda::device::barrier_expect_tx(__barrier, __size); }));
95
+ #endif // __cccl_ptx_isa >= 800
96
+ return async_contract_fulfillment::async;
97
+ case __completion_mechanism::__sync:
98
+ // sync: In this case, we do not need to do anything. The user will have
99
+ // to issue `bar.arrive_wait();` to see the effect of the transaction.
100
+ return async_contract_fulfillment::none;
101
+ default:
102
+ // Get rid of "control reaches end of non-void function":
103
+ _CCCL_UNREACHABLE();
104
+ }
105
+ }
106
+
107
+ template <typename _Group, thread_scope _Sco, typename _CompF>
108
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI static async_contract_fulfillment __defer(
109
+ __completion_mechanism __cm, _Group const& __group, _CUDA_VSTD::size_t __size, barrier<_Sco, _CompF>& __barrier)
110
+ {
111
+ return __defer_non_smem_barrier(__cm, __group, __size, __barrier);
112
+ }
113
+
114
+ template <typename _Group, thread_scope _Sco, typename _CompF>
115
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI static async_contract_fulfillment __defer_non_smem_barrier(
116
+ __completion_mechanism __cm, _Group const& __group, _CUDA_VSTD::size_t __size, barrier<_Sco, _CompF>& __barrier)
117
+ {
118
+ // Overload for non-smem barriers.
119
+ switch (__cm)
120
+ {
121
+ case __completion_mechanism::__async_group:
122
+ // Pre-SM80, the async_group mechanism is not available.
123
+ NV_IF_TARGET(NV_PROVIDES_SM_80,
124
+ (
125
+ // Blocking: wait for all thread-local cp.async instructions to have
126
+ // completed writing to shared memory.
127
+ asm volatile("cp.async.wait_all;" ::
128
+ : "memory");));
129
+ return async_contract_fulfillment::async;
130
+ case __completion_mechanism::__mbarrier_complete_tx:
131
+ // Non-smem barriers do not have an mbarrier_complete_tx mechanism..
132
+ _CCCL_UNREACHABLE();
133
+ case __completion_mechanism::__async_bulk_group:
134
+ // This completion mechanism is currently not expected to be used with barriers.
135
+ _CCCL_UNREACHABLE();
136
+ case __completion_mechanism::__sync:
137
+ // sync: In this case, we do not need to do anything.
138
+ return async_contract_fulfillment::none;
139
+ default:
140
+ // Get rid of "control reaches end of non-void function":
141
+ _CCCL_UNREACHABLE();
142
+ }
143
+ }
144
+
145
+ template <typename _Group, thread_scope _Sco>
146
+ _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI static async_contract_fulfillment
147
+ __defer(__completion_mechanism __cm, _Group const&, _CUDA_VSTD::size_t, pipeline<_Sco>&)
148
+ {
149
+ switch (__cm)
150
+ {
151
+ case __completion_mechanism::__async_group:
152
+ return async_contract_fulfillment::async;
153
+ case __completion_mechanism::__async_bulk_group:
154
+ return async_contract_fulfillment::async;
155
+ case __completion_mechanism::__mbarrier_complete_tx:
156
+ return async_contract_fulfillment::async;
157
+ case __completion_mechanism::__sync:
158
+ return async_contract_fulfillment::none;
159
+ default:
160
+ // Get rid of "control reaches end of non-void function":
161
+ _CCCL_UNREACHABLE();
162
+ }
163
+ }
164
+ };
165
+
166
+ _LIBCUDACXX_END_NAMESPACE_CUDA
167
+
168
+ #endif // _CUDA___MEMCPY_ASYNC_MEMCPY_COMPLETION_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/try_get_barrier_handle.h ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef _CUDA___BARRIER_TRY_GET_BARRIER_HANDLE_H
12
+ #define _CUDA___BARRIER_TRY_GET_BARRIER_HANDLE_H
13
+
14
+ #include <cuda/std/detail/__config>
15
+
16
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
17
+ # pragma GCC system_header
18
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
19
+ # pragma clang system_header
20
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
21
+ # pragma system_header
22
+ #endif // no system header
23
+
24
+ #include <cuda/__barrier/barrier_block_scope.h>
25
+ #include <cuda/__barrier/barrier_native_handle.h>
26
+ #include <cuda/std/__atomic/scopes.h>
27
+ #include <cuda/std/__barrier/barrier.h>
28
+ #include <cuda/std/__barrier/empty_completion.h>
29
+ #include <cuda/std/__type_traits/is_same.h>
30
+ #include <cuda/std/cstdint>
31
+
32
+ #include <nv/target>
33
+
34
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
35
+
36
+ //! @brief __try_get_barrier_handle returns barrier handle of block-scoped barriers and a nullptr otherwise.
37
+ template <thread_scope _Sco, typename _CompF>
38
+ _LIBCUDACXX_HIDE_FROM_ABI _CUDA_VSTD::uint64_t* __try_get_barrier_handle(barrier<_Sco, _CompF>& __barrier)
39
+ {
40
+ return nullptr;
41
+ }
42
+
43
+ template <>
44
+ _LIBCUDACXX_HIDE_FROM_ABI _CUDA_VSTD::uint64_t*
45
+ __try_get_barrier_handle<::cuda::thread_scope_block, _CUDA_VSTD::__empty_completion>(
46
+ barrier<thread_scope_block>& __barrier)
47
+ {
48
+ (void) __barrier;
49
+ NV_DISPATCH_TARGET(
50
+ NV_IS_DEVICE, (return ::cuda::device::barrier_native_handle(__barrier);), NV_ANY_TARGET, (return nullptr;));
51
+ }
52
+
53
+ _LIBCUDACXX_END_NAMESPACE_CUDA
54
+
55
+ #endif // _CUDA___BARRIER_TRY_GET_BARRIER_HANDLE_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource.h ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef _CUDA__MEMORY_RESOURCE_RESOURCE_H
12
+ #define _CUDA__MEMORY_RESOURCE_RESOURCE_H
13
+
14
+ #include <cuda/std/detail/__config>
15
+
16
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
17
+ # pragma GCC system_header
18
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
19
+ # pragma clang system_header
20
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
21
+ # pragma system_header
22
+ #endif // no system header
23
+
24
+ #if !_CCCL_COMPILER(MSVC2017) && defined(LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE)
25
+
26
+ # include <cuda/__memory_resource/get_property.h>
27
+ # include <cuda/std/__concepts/concept_macros.h>
28
+ # include <cuda/std/__concepts/convertible_to.h>
29
+ # include <cuda/std/__concepts/equality_comparable.h>
30
+ # include <cuda/std/__concepts/same_as.h>
31
+ # include <cuda/std/__tuple_dir/sfinae_helpers.h>
32
+ # include <cuda/std/__type_traits/decay.h>
33
+ # include <cuda/std/__type_traits/fold.h>
34
+ # include <cuda/stream_ref>
35
+
36
+ # if _CCCL_STD_VER >= 2014
37
+
38
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_MR
39
+
40
+ //! @brief The \c resource concept verifies that a type Resource satisfies the basic requirements of a memory
41
+ //! resource
42
+ //! @rst
43
+ //! We require that a resource supports the following interface
44
+ //!
45
+ //! - ``allocate(size_t bytes, size_t alignment)``
46
+ //! - ``deallocate(void* ptr, size_t bytes, size_t alignment)``
47
+ //! - ``T() == T()``
48
+ //! - ``T() != T()``
49
+ //!
50
+ //! @endrst
51
+ //! @tparam _Resource The type that should implement the resource concept
52
+ template <class _Resource>
53
+ _CCCL_CONCEPT resource =
54
+ _CCCL_REQUIRES_EXPR((_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment)(
55
+ _Same_as(void*) __res.allocate(__bytes, __alignment), //
56
+ _Same_as(void) __res.deallocate(__ptr, __bytes, __alignment),
57
+ requires(_CUDA_VSTD::equality_comparable<_Resource>));
58
+
59
+ //! @brief The \c async_resource concept verifies that a type Resource satisfies the basic requirements of a
60
+ //! memory resource and additionally supports stream ordered allocations
61
+ //! @rst
62
+ //! We require that an async resource supports the following interface
63
+ //!
64
+ //! - ``allocate(size_t bytes, size_t alignment)``
65
+ //! - ``deallocate(void* ptr, size_t bytes, size_t alignment)``
66
+ //! - ``T() == T()``
67
+ //! - ``T() != T()``
68
+ //!
69
+ //! - ``allocate_async(size_t bytes, size_t alignment, cuda::stream_ref stream)``
70
+ //! - ``deallocate_async(void* ptr, size_t bytes, size_t alignment, cuda::stream_ref stream)``
71
+ //!
72
+ //! @endrst
73
+ //! @tparam _Resource The type that should implement the async resource concept
74
+ template <class _Resource>
75
+ _CCCL_CONCEPT async_resource = _CCCL_REQUIRES_EXPR(
76
+ (_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)(
77
+ _Same_as(void*) __res.allocate_async(__bytes, __alignment, __stream),
78
+ _Same_as(void) __res.deallocate_async(__ptr, __bytes, __alignment, __stream),
79
+ requires(resource<_Resource>));
80
+
81
+ //! @brief The \c resource_with concept verifies that a type Resource satisfies the `resource` concept and
82
+ //! also satisfies all the provided Properties
83
+ //! @tparam _Resource
84
+ //! @tparam _Properties
85
+ // We cannot use fold expressions here due to a nvcc bug
86
+ template <class _Resource, class... _Properties>
87
+ _CCCL_CONCEPT resource_with = _CCCL_REQUIRES_EXPR((_Resource, variadic _Properties))(
88
+ requires(resource<_Resource>), requires(_CUDA_VSTD::__all<has_property<_Resource, _Properties>...>::value));
89
+
90
+ //! @brief The \c async_resource_with concept verifies that a type Resource satisfies the `async_resource`
91
+ //! concept and also satisfies all the provided Properties
92
+ //! @tparam _Resource
93
+ //! @tparam _Properties
94
+ // We cannot use fold expressions here due to a nvcc bug
95
+ template <class _Resource, class... _Properties>
96
+ _CCCL_CONCEPT async_resource_with = _CCCL_REQUIRES_EXPR((_Resource, variadic _Properties))(
97
+ requires(async_resource<_Resource>), requires(_CUDA_VSTD::__all<has_property<_Resource, _Properties>...>::value));
98
+
99
+ template <bool _Convertible>
100
+ struct __different_resource__
101
+ {
102
+ template <class _OtherResource>
103
+ static constexpr bool __value(_OtherResource*) noexcept
104
+ {
105
+ return resource<_OtherResource>;
106
+ }
107
+ };
108
+
109
+ template <>
110
+ struct __different_resource__<true>
111
+ {
112
+ static constexpr bool __value(void*) noexcept
113
+ {
114
+ return false;
115
+ }
116
+ };
117
+
118
+ template <class _Resource, class _OtherResource>
119
+ _CCCL_CONCEPT __different_resource =
120
+ __different_resource__<_CUDA_VSTD::convertible_to<_OtherResource const&, _Resource const&>>::__value(
121
+ static_cast<_OtherResource*>(nullptr));
122
+
123
+ _LIBCUDACXX_END_NAMESPACE_CUDA_MR
124
+
125
+ # endif // _CCCL_STD_VER >= 2014
126
+
127
+ #endif // !_CCCL_COMPILER(MSVC2017) && LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE
128
+
129
+ #endif //_CUDA__MEMORY_RESOURCE_RESOURCE_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource_ref.h ADDED
@@ -0,0 +1,653 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef _CUDA__MEMORY_RESOURCE_RESOURCE_REF_H
12
+ #define _CUDA__MEMORY_RESOURCE_RESOURCE_REF_H
13
+
14
+ #include <cuda/std/detail/__config>
15
+
16
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
17
+ # pragma GCC system_header
18
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
19
+ # pragma clang system_header
20
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
21
+ # pragma system_header
22
+ #endif // no system header
23
+
24
+ #if !_CCCL_COMPILER(MSVC2017) && defined(LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE)
25
+
26
+ # include <cuda/__memory_resource/get_property.h>
27
+ # include <cuda/__memory_resource/properties.h>
28
+ # include <cuda/__memory_resource/resource.h>
29
+ # include <cuda/std/__concepts/concept_macros.h>
30
+ # include <cuda/std/__memory/addressof.h>
31
+ # include <cuda/std/__type_traits/is_base_of.h>
32
+ # include <cuda/std/__type_traits/is_nothrow_move_constructible.h>
33
+ # include <cuda/std/__type_traits/type_set.h>
34
+ # include <cuda/std/__utility/exchange.h>
35
+ # include <cuda/std/__utility/move.h>
36
+ # include <cuda/std/cstddef>
37
+ # include <cuda/stream_ref>
38
+
39
+ # if _CCCL_STD_VER >= 2014
40
+
41
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA_MR
42
+
43
+ union _AnyResourceStorage
44
+ {
45
+ _LIBCUDACXX_HIDE_FROM_ABI constexpr _AnyResourceStorage(void* __ptr = nullptr) noexcept
46
+ : __ptr_(__ptr)
47
+ {}
48
+
49
+ void* __ptr_;
50
+ char __buf_[3 * sizeof(void*)];
51
+ };
52
+
53
+ template <class _Resource>
54
+ constexpr bool _IsSmall() noexcept
55
+ {
56
+ return (sizeof(_Resource) <= sizeof(_AnyResourceStorage)) //
57
+ && (alignof(_AnyResourceStorage) % alignof(_Resource) == 0)
58
+ && _CCCL_TRAIT(_CUDA_VSTD::is_nothrow_move_constructible, _Resource);
59
+ }
60
+
61
+ template <class _Resource>
62
+ constexpr _Resource* _Any_resource_cast(_AnyResourceStorage* __object) noexcept
63
+ {
64
+ return static_cast<_Resource*>(_IsSmall<_Resource>() ? __object->__buf_ : __object->__ptr_);
65
+ }
66
+
67
+ template <class _Resource>
68
+ constexpr const _Resource* _Any_resource_cast(const _AnyResourceStorage* __object) noexcept
69
+ {
70
+ return static_cast<const _Resource*>(_IsSmall<_Resource>() ? __object->__buf_ : __object->__ptr_);
71
+ }
72
+
73
+ enum class _WrapperType
74
+ {
75
+ _Reference,
76
+ _Owning
77
+ };
78
+
79
+ enum class _AllocType
80
+ {
81
+ _Default,
82
+ _Async,
83
+ };
84
+
85
+ struct _Alloc_vtable
86
+ {
87
+ using _AllocFn = void* (*) (void*, size_t, size_t);
88
+ using _DeallocFn = void (*)(void*, void*, size_t, size_t) _CCCL_FUNCTION_TYPE_NOEXCEPT;
89
+ using _EqualFn = bool (*)(void*, void*);
90
+ using _DestroyFn = void (*)(_AnyResourceStorage*) _CCCL_FUNCTION_TYPE_NOEXCEPT;
91
+ using _MoveFn = void (*)(_AnyResourceStorage*, _AnyResourceStorage*) _CCCL_FUNCTION_TYPE_NOEXCEPT;
92
+ using _CopyFn = void (*)(_AnyResourceStorage*, const _AnyResourceStorage*);
93
+
94
+ bool __is_small;
95
+ _AllocFn __alloc_fn;
96
+ _DeallocFn __dealloc_fn;
97
+ _EqualFn __equal_fn;
98
+ _DestroyFn __destroy_fn;
99
+ _MoveFn __move_fn;
100
+ _CopyFn __copy_fn;
101
+
102
+ constexpr _Alloc_vtable(
103
+ bool __is_small_,
104
+ _AllocFn __alloc_fn_,
105
+ _DeallocFn __dealloc_fn_,
106
+ _EqualFn __equal_fn_,
107
+ _DestroyFn __destroy_fn_,
108
+ _MoveFn __move_fn_,
109
+ _CopyFn __copy_fn_) noexcept
110
+ : __is_small(__is_small_)
111
+ , __alloc_fn(__alloc_fn_)
112
+ , __dealloc_fn(__dealloc_fn_)
113
+ , __equal_fn(__equal_fn_)
114
+ , __destroy_fn(__destroy_fn_)
115
+ , __move_fn(__move_fn_)
116
+ , __copy_fn(__copy_fn_)
117
+ {}
118
+ };
119
+
120
+ struct _Async_alloc_vtable : public _Alloc_vtable
121
+ {
122
+ using _AsyncAllocFn = void* (*) (void*, size_t, size_t, ::cuda::stream_ref);
123
+ using _AsyncDeallocFn = void (*)(void*, void*, size_t, size_t, ::cuda::stream_ref);
124
+
125
+ _AsyncAllocFn __async_alloc_fn;
126
+ _AsyncDeallocFn __async_dealloc_fn;
127
+
128
+ constexpr _Async_alloc_vtable(
129
+ bool __is_small_,
130
+ _Alloc_vtable::_AllocFn __alloc_fn_,
131
+ _Alloc_vtable::_DeallocFn __dealloc_fn_,
132
+ _Alloc_vtable::_EqualFn __equal_fn_,
133
+ _Alloc_vtable::_DestroyFn __destroy_fn_,
134
+ _Alloc_vtable::_MoveFn __move_fn_,
135
+ _Alloc_vtable::_CopyFn __copy_fn_,
136
+ _AsyncAllocFn __async_alloc_fn_,
137
+ _AsyncDeallocFn __async_dealloc_fn_) noexcept
138
+ : _Alloc_vtable(__is_small_, __alloc_fn_, __dealloc_fn_, __equal_fn_, __destroy_fn_, __move_fn_, __copy_fn_)
139
+ , __async_alloc_fn(__async_alloc_fn_)
140
+ , __async_dealloc_fn(__async_dealloc_fn_)
141
+ {}
142
+ };
143
+
144
+ struct _Resource_vtable_builder
145
+ {
146
+ template <_WrapperType _Wrapper_type>
147
+ using __wrapper_type = _CUDA_VSTD::integral_constant<_WrapperType, _Wrapper_type>;
148
+
149
+ template <class _Resource, class _Property>
150
+ static __property_value_t<_Property> _Get_property(const void* __res) noexcept
151
+ {
152
+ return get_property(*static_cast<const _Resource*>(__res), _Property{});
153
+ }
154
+
155
+ template <class _Resource>
156
+ static void* _Alloc(void* __object, size_t __bytes, size_t __alignment)
157
+ {
158
+ return static_cast<_Resource*>(__object)->allocate(__bytes, __alignment);
159
+ }
160
+
161
+ template <class _Resource>
162
+ static void _Dealloc(void* __object, void* __ptr, size_t __bytes, size_t __alignment) noexcept
163
+ {
164
+ // TODO: this breaks RMM because their memory resources do not declare their
165
+ // deallocate functions to be noexcept. Comment out the check for now until
166
+ // we can fix RMM.
167
+ // static_assert(noexcept(static_cast<_Resource*>(__object)->deallocate(__ptr, __bytes, __alignment)));
168
+ return static_cast<_Resource*>(__object)->deallocate(__ptr, __bytes, __alignment);
169
+ }
170
+
171
+ template <class _Resource>
172
+ static void* _Alloc_async(void* __object, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)
173
+ {
174
+ return static_cast<_Resource*>(__object)->allocate_async(__bytes, __alignment, __stream);
175
+ }
176
+
177
+ template <class _Resource>
178
+ static void
179
+ _Dealloc_async(void* __object, void* __ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)
180
+ {
181
+ return static_cast<_Resource*>(__object)->deallocate_async(__ptr, __bytes, __alignment, __stream);
182
+ }
183
+
184
+ template <class _Resource>
185
+ static bool _Equal(void* __left, void* __rhs)
186
+ {
187
+ return *static_cast<_Resource*>(__left) == *static_cast<_Resource*>(__rhs);
188
+ }
189
+
190
+ template <class _Resource>
191
+ static void _Destroy_impl(_AnyResourceStorage* __object_, __wrapper_type<_WrapperType::_Owning>) noexcept
192
+ {
193
+ _Resource* __object = _Any_resource_cast<_Resource>(__object_);
194
+ _CCCL_IF_CONSTEXPR (_IsSmall<_Resource>())
195
+ {
196
+ __object->~_Resource();
197
+ }
198
+ else
199
+ {
200
+ delete __object;
201
+ }
202
+ }
203
+
204
+ template <class _Resource>
205
+ static void _Destroy_impl(_AnyResourceStorage*, __wrapper_type<_WrapperType::_Reference>) noexcept
206
+ {}
207
+
208
+ template <class _Resource, _WrapperType _Wrapper_type>
209
+ static void _Destroy(_AnyResourceStorage* __object) noexcept
210
+ {
211
+ _Destroy_impl<_Resource>(__object, __wrapper_type<_Wrapper_type>{});
212
+ }
213
+
214
+ template <class _Resource>
215
+ static void _Move_impl(
216
+ _AnyResourceStorage* __object, _AnyResourceStorage* __other_, __wrapper_type<_WrapperType::_Owning>) noexcept
217
+ {
218
+ _CCCL_IF_CONSTEXPR (_IsSmall<_Resource>())
219
+ {
220
+ _Resource* __other = _Any_resource_cast<_Resource>(__other_);
221
+ ::new (static_cast<void*>(__object->__buf_)) _Resource(_CUDA_VSTD::move(*__other));
222
+ __other->~_Resource();
223
+ }
224
+ else
225
+ {
226
+ __object->__ptr_ = _CUDA_VSTD::exchange(__other_->__ptr_, nullptr);
227
+ }
228
+ }
229
+
230
+ template <class _Resource>
231
+ static void _Move_impl(_AnyResourceStorage*, _AnyResourceStorage*, __wrapper_type<_WrapperType::_Reference>) noexcept
232
+ {}
233
+
234
+ template <class _Resource, _WrapperType _Wrapper_type>
235
+ static void _Move(_AnyResourceStorage* __object, _AnyResourceStorage* __other) noexcept
236
+ {
237
+ _Move_impl<_Resource>(__object, __other, __wrapper_type<_Wrapper_type>{});
238
+ }
239
+
240
+ template <class _Resource>
241
+ static void _Copy_impl(
242
+ _AnyResourceStorage* __object, const _AnyResourceStorage* __other, __wrapper_type<_WrapperType::_Owning>) noexcept
243
+ {
244
+ _CCCL_IF_CONSTEXPR (_IsSmall<_Resource>())
245
+ {
246
+ ::new (static_cast<void*>(__object->__buf_)) _Resource(*_Any_resource_cast<_Resource>(__other));
247
+ }
248
+ else
249
+ {
250
+ __object->__ptr_ = new _Resource(*_Any_resource_cast<_Resource>(__other));
251
+ }
252
+ }
253
+
254
+ template <class _Resource>
255
+ static void
256
+ _Copy_impl(_AnyResourceStorage*, const _AnyResourceStorage*, __wrapper_type<_WrapperType::_Reference>) noexcept
257
+ {}
258
+
259
+ template <class _Resource, _WrapperType _Wrapper_type>
260
+ static void _Copy(_AnyResourceStorage* __object, const _AnyResourceStorage* __other)
261
+ {
262
+ _Copy_impl<_Resource>(__object, __other, __wrapper_type<_Wrapper_type>{});
263
+ }
264
+
265
+ _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type, _WrapperType _Wrapper_type)
266
+ _CCCL_REQUIRES((_Alloc_type == _AllocType::_Default))
267
+ static constexpr _Alloc_vtable _Create() noexcept
268
+ {
269
+ return {_IsSmall<_Resource>(),
270
+ &_Resource_vtable_builder::_Alloc<_Resource>,
271
+ &_Resource_vtable_builder::_Dealloc<_Resource>,
272
+ &_Resource_vtable_builder::_Equal<_Resource>,
273
+ &_Resource_vtable_builder::_Destroy<_Resource, _Wrapper_type>,
274
+ &_Resource_vtable_builder::_Move<_Resource, _Wrapper_type>,
275
+ &_Resource_vtable_builder::_Copy<_Resource, _Wrapper_type>};
276
+ }
277
+
278
+ _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type, _WrapperType _Wrapper_type)
279
+ _CCCL_REQUIRES((_Alloc_type == _AllocType::_Async))
280
+ static constexpr _Async_alloc_vtable _Create() noexcept
281
+ {
282
+ return {_IsSmall<_Resource>(),
283
+ &_Resource_vtable_builder::_Alloc<_Resource>,
284
+ &_Resource_vtable_builder::_Dealloc<_Resource>,
285
+ &_Resource_vtable_builder::_Equal<_Resource>,
286
+ &_Resource_vtable_builder::_Destroy<_Resource, _Wrapper_type>,
287
+ &_Resource_vtable_builder::_Move<_Resource, _Wrapper_type>,
288
+ &_Resource_vtable_builder::_Copy<_Resource, _Wrapper_type>,
289
+ &_Resource_vtable_builder::_Alloc_async<_Resource>,
290
+ &_Resource_vtable_builder::_Dealloc_async<_Resource>};
291
+ }
292
+ };
293
+
294
+ template <class _Property>
295
+ using __property_fn_t = __property_value_t<_Property> (*)(const void*);
296
+
297
+ template <class _Property>
298
+ struct _Property_vtable
299
+ {
300
+ __property_fn_t<_Property> __property_fn = nullptr;
301
+
302
+ constexpr _Property_vtable(__property_fn_t<_Property> __property_fn_) noexcept
303
+ : __property_fn(__property_fn_)
304
+ {}
305
+ };
306
+
307
+ template <_AllocType _Alloc_type, class... _Properties>
308
+ class basic_resource_ref;
309
+
310
+ template <class... _Properties>
311
+ struct _Resource_vtable : public _Property_vtable<_Properties>...
312
+ {
313
+ constexpr _Resource_vtable(__property_fn_t<_Properties>... __property_fn_) noexcept
314
+ : _Property_vtable<_Properties>(__property_fn_)...
315
+ {}
316
+
317
+ template <class... _OtherProperties>
318
+ constexpr _Resource_vtable(const _Resource_vtable<_OtherProperties...>& __other) noexcept
319
+ : _Property_vtable<_Properties>(__other._Property_vtable<_Properties>::__property_fn)...
320
+ {}
321
+
322
+ template <class _Resource>
323
+ static constexpr _Resource_vtable _Create() noexcept
324
+ {
325
+ return {&_Resource_vtable_builder::_Get_property<_Resource, _Properties>...};
326
+ }
327
+ };
328
+
329
+ template <class... _Properties>
330
+ struct _Filtered;
331
+
332
+ template <bool _IsUniqueProperty>
333
+ struct _Property_filter
334
+ {
335
+ template <class _Property, class... _Properties>
336
+ using _Filtered_properties =
337
+ typename _Filtered<_Properties...>::_Filtered_vtable::template _Append_property<_Property>;
338
+ };
339
+
340
+ template <>
341
+ struct _Property_filter<false>
342
+ {
343
+ template <class _Property, class... _Properties>
344
+ using _Filtered_properties = typename _Filtered<_Properties...>::_Filtered_vtable;
345
+ };
346
+
347
+ template <class _Property, class... _Properties>
348
+ struct _Filtered<_Property, _Properties...>
349
+ {
350
+ using _Filtered_vtable = typename _Property_filter<
351
+ property_with_value<_Property> && !_CUDA_VSTD::__is_included_in_v<_Property, _Properties...>>::
352
+ template _Filtered_properties<_Property, _Properties...>;
353
+
354
+ template <class _OtherPropery>
355
+ using _Append_property = _Filtered<_OtherPropery, _Property, _Properties...>;
356
+
357
+ using _Vtable = _Resource_vtable<_Property, _Properties...>;
358
+ };
359
+
360
+ template <>
361
+ struct _Filtered<>
362
+ {
363
+ using _Filtered_vtable = _Filtered<>;
364
+
365
+ template <class _OtherPropery>
366
+ using _Append_property = _Filtered<_OtherPropery>;
367
+
368
+ using _Vtable = _Resource_vtable<>;
369
+ };
370
+
371
+ template <class... _Properties>
372
+ using _Filtered_vtable = typename _Filtered<_Properties...>::_Filtered_vtable::_Vtable;
373
+
374
+ template <_WrapperType _Wrapper_type>
375
+ using __alloc_object_storage_t = _CUDA_VSTD::_If<_Wrapper_type == _WrapperType::_Reference, void*, _AnyResourceStorage>;
376
+
377
+ struct _Resource_ref_base
378
+ {};
379
+
380
+ template <class _Vtable, _WrapperType _Wrapper_type>
381
+ struct _CCCL_DECLSPEC_EMPTY_BASES _Alloc_base : _Resource_ref_base
382
+ {
383
+ static_assert(_CUDA_VSTD::is_base_of_v<_Alloc_vtable, _Vtable>, "");
384
+
385
+ _Alloc_base(void* __object_, const _Vtable* __static_vtabl_) noexcept
386
+ : __object(__object_)
387
+ , __static_vtable(__static_vtabl_)
388
+ {}
389
+
390
+ _CCCL_NODISCARD void* allocate(size_t __bytes, size_t __alignment = alignof(_CUDA_VSTD::max_align_t))
391
+ {
392
+ return __static_vtable->__alloc_fn(_Get_object(), __bytes, __alignment);
393
+ }
394
+
395
+ void deallocate(void* _Ptr, size_t __bytes, size_t __alignment = alignof(_CUDA_VSTD::max_align_t)) noexcept
396
+ {
397
+ __static_vtable->__dealloc_fn(_Get_object(), _Ptr, __bytes, __alignment);
398
+ }
399
+
400
+ protected:
401
+ static _CCCL_FORCEINLINE void* _Get_object_(bool, void* __object) noexcept
402
+ {
403
+ return __object;
404
+ }
405
+
406
+ static _CCCL_FORCEINLINE void* _Get_object_(const bool __is_small, const _AnyResourceStorage& __object) noexcept
407
+ {
408
+ const void* __pv = __is_small ? __object.__buf_ : __object.__ptr_;
409
+ return const_cast<void*>(__pv);
410
+ }
411
+
412
+ void* _Get_object() const noexcept
413
+ {
414
+ return _Get_object_(__static_vtable->__is_small, this->__object);
415
+ }
416
+
417
+ __alloc_object_storage_t<_Wrapper_type> __object{};
418
+ const _Vtable* __static_vtable = nullptr;
419
+ };
420
+
421
+ template <class _Vtable, _WrapperType _Wrapper_type>
422
+ struct _Async_alloc_base : public _Alloc_base<_Vtable, _Wrapper_type>
423
+ {
424
+ static_assert(_CUDA_VSTD::is_base_of_v<_Async_alloc_vtable, _Vtable>, "");
425
+
426
+ _Async_alloc_base(void* __object_, const _Vtable* __static_vtabl_) noexcept
427
+ : _Alloc_base<_Vtable, _Wrapper_type>(__object_, __static_vtabl_)
428
+ {}
429
+
430
+ _CCCL_NODISCARD void* allocate_async(size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)
431
+ {
432
+ return this->__static_vtable->__async_alloc_fn(this->_Get_object(), __bytes, __alignment, __stream);
433
+ }
434
+
435
+ _CCCL_NODISCARD void* allocate_async(size_t __bytes, ::cuda::stream_ref __stream)
436
+ {
437
+ return this->__static_vtable->__async_alloc_fn(this->_Get_object(), __bytes, alignof(max_align_t), __stream);
438
+ }
439
+
440
+ void deallocate_async(void* _Ptr, size_t __bytes, ::cuda::stream_ref __stream)
441
+ {
442
+ this->__static_vtable->__async_dealloc_fn(this->_Get_object(), _Ptr, __bytes, alignof(max_align_t), __stream);
443
+ }
444
+
445
+ void deallocate_async(void* _Ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)
446
+ {
447
+ this->__static_vtable->__async_dealloc_fn(this->_Get_object(), _Ptr, __bytes, __alignment, __stream);
448
+ }
449
+ };
450
+
451
+ template <class _Resource>
452
+ _CCCL_CONCEPT _Is_resource_ref = _CUDA_VSTD::convertible_to<_Resource&, _Resource_ref_base>;
453
+
454
+ template <_AllocType _Alloc_type, _WrapperType _Wrapper_type>
455
+ using _Resource_base =
456
+ _CUDA_VSTD::_If<_Alloc_type == _AllocType::_Default,
457
+ _Alloc_base<_Alloc_vtable, _Wrapper_type>,
458
+ _Async_alloc_base<_Async_alloc_vtable, _Wrapper_type>>;
459
+
460
+ template <_AllocType _Alloc_type>
461
+ using _Vtable_store = _CUDA_VSTD::_If<_Alloc_type == _AllocType::_Default, _Alloc_vtable, _Async_alloc_vtable>;
462
+
463
+ template <_AllocType _Alloc_type, _WrapperType _Wrapper_type, class _Resource>
464
+ _CCCL_INLINE_VAR constexpr _Vtable_store<_Alloc_type> __alloc_vtable =
465
+ _Resource_vtable_builder::template _Create<_Resource, _Alloc_type, _Wrapper_type>();
466
+
467
+ struct _Resource_ref_helper
468
+ {
469
+ //! This is used from \c basic_any_resource to make it convertible to a \c basic_resource_ref
470
+ template <_AllocType _Alloc_type, class... _Properties>
471
+ static basic_resource_ref<_Alloc_type, _Properties...>
472
+ _Construct(void* __object,
473
+ const _Vtable_store<_Alloc_type>* __static_vtable,
474
+ _Filtered_vtable<_Properties...> __properties) noexcept
475
+ {
476
+ return basic_resource_ref<_Alloc_type, _Properties...>(__object, __static_vtable, __properties);
477
+ }
478
+ };
479
+
480
+ template <_AllocType _Alloc_type, class... _Properties>
481
+ class basic_resource_ref
482
+ : public _Resource_base<_Alloc_type, _WrapperType::_Reference>
483
+ , private _Filtered_vtable<_Properties...>
484
+ {
485
+ private:
486
+ static_assert(__contains_execution_space_property<_Properties...>,
487
+ "The properties of cuda::mr::basic_resource_ref must contain at least one execution space property!");
488
+
489
+ template <_AllocType, class...>
490
+ friend class basic_resource_ref;
491
+
492
+ template <class...>
493
+ friend struct _Resource_vtable;
494
+
495
+ friend struct _Resource_ref_helper;
496
+
497
+ using __vtable = _Filtered_vtable<_Properties...>;
498
+
499
+ //! @brief Checks whether \c _OtherProperties is a true superset of \c _Properties, accounting for host_accessible
500
+ template <class... _OtherProperties>
501
+ static constexpr bool __properties_match =
502
+ _CUDA_VSTD::__type_set_contains_v<_CUDA_VSTD::__make_type_set<_OtherProperties...>, _Properties...>;
503
+
504
+ //! @brief Constructs a \c basic_resource_ref from a void*, a resource vtable ptr, and a vtable
505
+ //! for the properties. This is used to create a \c basic_resource_ref from a \c basic_any_resource.
506
+ explicit basic_resource_ref(
507
+ void* __object_, const _Vtable_store<_Alloc_type>* __static_vtable, __vtable __properties) noexcept
508
+ : _Resource_base<_Alloc_type, _WrapperType::_Reference>(__object_, __static_vtable)
509
+ , __vtable(__properties)
510
+ {}
511
+
512
+ public:
513
+ //! @brief Constructs a \c basic_resource_ref from a type that satisfies the \c resource or \c async_resource concept
514
+ //! as well as all properties
515
+ //! @param __res The resource to be wrapped within the \c basic_resource_ref
516
+ _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type2 = _Alloc_type)
517
+ _CCCL_REQUIRES((!_Is_resource_ref<_Resource>) _CCCL_AND(_Alloc_type2 == _AllocType::_Default)
518
+ _CCCL_AND resource_with<_Resource, _Properties...>)
519
+ basic_resource_ref(_Resource& __res) noexcept
520
+ : _Resource_base<_Alloc_type, _WrapperType::_Reference>(
521
+ _CUDA_VSTD::addressof(__res), &__alloc_vtable<_Alloc_type, _WrapperType::_Reference, _Resource>)
522
+ , __vtable(__vtable::template _Create<_Resource>())
523
+ {}
524
+
525
+ //! @brief Constructs a \c resource_ref from a type that satisfies the \c async_resource concept as well as all
526
+ //! properties. This ignores the async interface of the passed in resource
527
+ //! @param __res The resource to be wrapped within the \c resource_ref
528
+ _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type2 = _Alloc_type)
529
+ _CCCL_REQUIRES((!_Is_resource_ref<_Resource>) _CCCL_AND(_Alloc_type2 == _AllocType::_Async)
530
+ _CCCL_AND async_resource_with<_Resource, _Properties...>)
531
+ basic_resource_ref(_Resource& __res) noexcept
532
+ : _Resource_base<_Alloc_type, _WrapperType::_Reference>(
533
+ _CUDA_VSTD::addressof(__res), &__alloc_vtable<_Alloc_type, _WrapperType::_Reference, _Resource>)
534
+ , __vtable(__vtable::template _Create<_Resource>())
535
+ {}
536
+
537
+ //! @brief Constructs a \c basic_resource_ref from a type that satisfies the \c resource or \c async_resource concept
538
+ //! as well as all properties
539
+ //! @param __res Pointer to a resource to be wrapped within the \c basic_resource_ref
540
+ _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type2 = _Alloc_type)
541
+ _CCCL_REQUIRES((!_Is_resource_ref<_Resource>) _CCCL_AND(_Alloc_type2 == _AllocType::_Default)
542
+ _CCCL_AND resource_with<_Resource, _Properties...>)
543
+ basic_resource_ref(_Resource* __res) noexcept
544
+ : _Resource_base<_Alloc_type, _WrapperType::_Reference>(
545
+ __res, &__alloc_vtable<_Alloc_type, _WrapperType::_Reference, _Resource>)
546
+ , __vtable(__vtable::template _Create<_Resource>())
547
+ {}
548
+
549
+ //! @brief Constructs a \c resource_ref from a type that satisfies the \c async_resource concept as well as all
550
+ //! properties. This ignores the async interface of the passed in resource
551
+ //! @param __res Pointer to a resource to be wrapped within the \c resource_ref
552
+ _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type2 = _Alloc_type)
553
+ _CCCL_REQUIRES((!_Is_resource_ref<_Resource>) _CCCL_AND(_Alloc_type2 == _AllocType::_Async)
554
+ _CCCL_AND async_resource_with<_Resource, _Properties...>)
555
+ basic_resource_ref(_Resource* __res) noexcept
556
+ : _Resource_base<_Alloc_type, _WrapperType::_Reference>(
557
+ __res, &__alloc_vtable<_Alloc_type, _WrapperType::_Reference, _Resource>)
558
+ , __vtable(__vtable::template _Create<_Resource>())
559
+ {}
560
+
561
+ //! @brief Conversion from a \c basic_resource_ref with the same set of properties but in a different order
562
+ //! @param __ref The other \c basic_resource_ref
563
+ _CCCL_TEMPLATE(class... _OtherProperties)
564
+ _CCCL_REQUIRES(__properties_match<_OtherProperties...>)
565
+ basic_resource_ref(basic_resource_ref<_Alloc_type, _OtherProperties...> __ref) noexcept
566
+ : _Resource_base<_Alloc_type, _WrapperType::_Reference>(__ref.__object, __ref.__static_vtable)
567
+ , __vtable(static_cast<const _Filtered_vtable<_OtherProperties...>&>(__ref))
568
+ {}
569
+
570
+ //! @brief Conversion from a \c async_resource_ref with the same set of properties but in a different order to a
571
+ //! \c resource_ref
572
+ //! @param __ref The other \c async_resource_ref
573
+ _CCCL_TEMPLATE(_AllocType _OtherAllocType, class... _OtherProperties)
574
+ _CCCL_REQUIRES((_OtherAllocType == _AllocType::_Async) _CCCL_AND(_OtherAllocType != _Alloc_type)
575
+ _CCCL_AND __properties_match<_OtherProperties...>)
576
+ basic_resource_ref(basic_resource_ref<_OtherAllocType, _OtherProperties...> __ref) noexcept
577
+ : _Resource_base<_Alloc_type, _WrapperType::_Reference>(__ref.__object, __ref.__static_vtable)
578
+ , __vtable(static_cast<const _Filtered_vtable<_OtherProperties...>&>(__ref))
579
+ {}
580
+
581
+ //! @brief Equality comparison between two \c basic_resource_ref
582
+ //! @param __lhs The first \c basic_resource_ref
583
+ //! @param __rhs The second \c basic_resource_ref
584
+ //! @return Checks whether both resources have the same equality function stored in their vtable and if so returns
585
+ //! the result of that equality comparison. Otherwise returns false.
586
+ _CCCL_NODISCARD_FRIEND bool operator==(const basic_resource_ref& __lhs, const basic_resource_ref& __rhs)
587
+ {
588
+ // BUGBUG: comparing function pointers like this can lead to false negatives:
589
+ return (__lhs.__static_vtable->__equal_fn == __rhs.__static_vtable->__equal_fn)
590
+ && __lhs.__static_vtable->__equal_fn(__lhs.__object, __rhs.__object);
591
+ }
592
+
593
+ //! @overload
594
+ _CCCL_TEMPLATE(class... _OtherProperties)
595
+ _CCCL_REQUIRES((sizeof...(_Properties) == sizeof...(_OtherProperties))
596
+ _CCCL_AND __properties_match<_OtherProperties...>)
597
+ _CCCL_NODISCARD bool operator==(const basic_resource_ref<_Alloc_type, _OtherProperties...>& __rhs) const
598
+ {
599
+ // BUGBUG: comparing function pointers like this can lead to false negatives:
600
+ return (this->__static_vtable->__equal_fn == __rhs.__static_vtable->__equal_fn)
601
+ && this->__static_vtable->__equal_fn(this->__object, __rhs.__object);
602
+ }
603
+
604
+ //! @brief Inequality comparison between two \c basic_resource_ref
605
+ //! @param __lhs The first \c basic_resource_ref
606
+ //! @param __rhs The second \c basic_resource_ref
607
+ //! @return Checks whether both resources have the same equality function stored in their vtable and if so returns
608
+ //! the inverse result of that equality comparison. Otherwise returns true.
609
+ _CCCL_NODISCARD_FRIEND bool operator!=(const basic_resource_ref& __lhs, const basic_resource_ref& __rhs)
610
+ {
611
+ return !(__lhs == __rhs);
612
+ }
613
+
614
+ //! @overload
615
+ _CCCL_TEMPLATE(class... _OtherProperties)
616
+ _CCCL_REQUIRES((sizeof...(_Properties) == sizeof...(_OtherProperties))
617
+ _CCCL_AND __properties_match<_OtherProperties...>)
618
+ _CCCL_NODISCARD bool operator!=(const basic_resource_ref<_Alloc_type, _OtherProperties...>& __rhs) const
619
+ {
620
+ return !(*this == __rhs);
621
+ }
622
+
623
+ //! @brief Forwards the stateless properties
624
+ _CCCL_TEMPLATE(class _Property)
625
+ _CCCL_REQUIRES((!property_with_value<_Property>) _CCCL_AND _CUDA_VSTD::__is_included_in_v<_Property, _Properties...>)
626
+ friend void get_property(const basic_resource_ref&, _Property) noexcept {}
627
+
628
+ //! @brief Forwards the stateful properties
629
+ _CCCL_TEMPLATE(class _Property)
630
+ _CCCL_REQUIRES(property_with_value<_Property> _CCCL_AND _CUDA_VSTD::__is_included_in_v<_Property, _Properties...>)
631
+ _CCCL_NODISCARD_FRIEND __property_value_t<_Property> get_property(const basic_resource_ref& __res, _Property) noexcept
632
+ {
633
+ return __res._Property_vtable<_Property>::__property_fn(__res.__object);
634
+ }
635
+ };
636
+
637
+ //! @brief Type erased wrapper around a `resource` that satisfies \tparam _Properties
638
+ //! @tparam _Properties The properties that any resource wrapped within the `resource_ref` needs to satisfy
639
+ template <class... _Properties>
640
+ using resource_ref = basic_resource_ref<_AllocType::_Default, _Properties...>;
641
+
642
+ //! @brief Type erased wrapper around a `async_resource` that satisfies \tparam _Properties
643
+ //! @tparam _Properties The properties that any async resource wrapped within the `async_resource_ref` needs to satisfy
644
+ template <class... _Properties>
645
+ using async_resource_ref = basic_resource_ref<_AllocType::_Async, _Properties...>;
646
+
647
+ _LIBCUDACXX_END_NAMESPACE_CUDA_MR
648
+
649
+ # endif // _CCCL_STD_VER >= 2014
650
+
651
+ #endif // !_CCCL_COMPILER(MSVC2017) && LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE
652
+
653
+ #endif //_CUDA__MEMORY_RESOURCE_RESOURCE_REF_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__type_traits/is_floating_point.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ // SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
7
+ //
8
+ //===----------------------------------------------------------------------===//
9
+
10
+ #ifndef __CUDA__TYPE_TRAITS_IS_FLOATING_POINT_H
11
+ #define __CUDA__TYPE_TRAITS_IS_FLOATING_POINT_H
12
+
13
+ #include <cuda/std/detail/__config>
14
+
15
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
16
+ # pragma GCC system_header
17
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
18
+ # pragma clang system_header
19
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
20
+ # pragma system_header
21
+ #endif // no system header
22
+
23
+ #include <cuda/std/__type_traits/integral_constant.h>
24
+ #include <cuda/std/__type_traits/is_extended_floating_point.h>
25
+ #include <cuda/std/__type_traits/is_floating_point.h>
26
+ #include <cuda/std/__type_traits/remove_cv.h>
27
+
28
+ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
29
+
30
+ template <class _Tp>
31
+ struct _CCCL_TYPE_VISIBILITY_DEFAULT is_floating_point
32
+ : _CUDA_VSTD::bool_constant<_CUDA_VSTD::is_floating_point<_CUDA_VSTD::remove_cv_t<_Tp>>::value
33
+ || _CUDA_VSTD::__is_extended_floating_point<_CUDA_VSTD::remove_cv_t<_Tp>>::value>
34
+ {};
35
+
36
+ #if !defined(_CCCL_NO_VARIABLE_TEMPLATES)
37
+ template <class _Tp>
38
+ _CCCL_INLINE_VAR constexpr bool is_floating_point_v =
39
+ _CUDA_VSTD::is_floating_point_v<_CUDA_VSTD::remove_cv_t<_Tp>>
40
+ || _CUDA_VSTD::__is_extended_floating_point_v<_CUDA_VSTD::remove_cv_t<_Tp>>;
41
+ #endif // !_CCCL_NO_VARIABLE_TEMPLATES
42
+
43
+ _LIBCUDACXX_END_NAMESPACE_CUDA
44
+
45
+ #endif // __CUDA__TYPE_TRAITS_IS_FLOATING_POINT_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/std/__memory/temporary_buffer.h ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // -*- C++ -*-
2
+ //===----------------------------------------------------------------------===//
3
+ //
4
+ // Part of libcu++, the C++ Standard Library for your entire system,
5
+ // under the Apache License v2.0 with LLVM Exceptions.
6
+ // See https://llvm.org/LICENSE.txt for license information.
7
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8
+ // SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
9
+ //
10
+ //===----------------------------------------------------------------------===//
11
+
12
+ #ifndef _LIBCUDACXX___MEMORY_TEMPORARY_BUFFER_H
13
+ #define _LIBCUDACXX___MEMORY_TEMPORARY_BUFFER_H
14
+
15
+ #include <cuda/std/detail/__config>
16
+
17
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
18
+ # pragma GCC system_header
19
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
20
+ # pragma clang system_header
21
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
22
+ # pragma system_header
23
+ #endif // no system header
24
+
25
+ #include <cuda/std/__iterator/iterator.h>
26
+ #include <cuda/std/__iterator/iterator_traits.h>
27
+ #include <cuda/std/__memory/addressof.h>
28
+ #include <cuda/std/__new_>
29
+ #include <cuda/std/__type_traits/alignment_of.h>
30
+ #include <cuda/std/__utility/move.h>
31
+ #include <cuda/std/__utility/pair.h>
32
+ #include <cuda/std/cstddef>
33
+ #include <cuda/std/limits>
34
+
35
+ _LIBCUDACXX_BEGIN_NAMESPACE_STD
36
+
37
+ template <class _Tp>
38
+ _CCCL_NODISCARD _LIBCUDACXX_NO_CFI _LIBCUDACXX_HIDE_FROM_ABI pair<_Tp*, ptrdiff_t>
39
+ get_temporary_buffer(ptrdiff_t __n) noexcept
40
+ {
41
+ pair<_Tp*, ptrdiff_t> __r(0, 0);
42
+ const ptrdiff_t __m =
43
+ (~ptrdiff_t(0) ^ ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) / sizeof(_Tp);
44
+ if (__n > __m)
45
+ {
46
+ __n = __m;
47
+ }
48
+ while (__n > 0)
49
+ {
50
+ #if !defined(_LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION)
51
+ if (__is_overaligned_for_new(_LIBCUDACXX_ALIGNOF(_Tp)))
52
+ {
53
+ _CUDA_VSTD::align_val_t __al = _CUDA_VSTD::align_val_t(_CUDA_VSTD::alignment_of<_Tp>::value);
54
+ __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al));
55
+ }
56
+ else
57
+ {
58
+ __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
59
+ }
60
+ #else // ^^^ !_LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION ^^^ / vvv _LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION vvv
61
+ if (__is_overaligned_for_new(_LIBCUDACXX_ALIGNOF(_Tp)))
62
+ {
63
+ // Since aligned operator new is unavailable, return an empty
64
+ // buffer rather than one with invalid alignment.
65
+ return __r;
66
+ }
67
+
68
+ __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
69
+ #endif // _LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION
70
+
71
+ if (__r.first)
72
+ {
73
+ __r.second = __n;
74
+ break;
75
+ }
76
+ __n /= 2;
77
+ }
78
+ return __r;
79
+ }
80
+
81
+ template <class _Tp>
82
+ _LIBCUDACXX_HIDE_FROM_ABI void return_temporary_buffer(_Tp* __p) noexcept
83
+ {
84
+ _CUDA_VSTD::__cccl_deallocate_unsized((void*) __p, _LIBCUDACXX_ALIGNOF(_Tp));
85
+ }
86
+
87
+ _LIBCUDACXX_END_NAMESPACE_STD
88
+
89
+ #endif // _LIBCUDACXX___MEMORY_TEMPORARY_BUFFER_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__preprocessor ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #if defined(__GNUC__)
12
+ # pragma GCC system_header
13
+ #endif
14
+
15
+ // For all compilers and dialects this header defines:
16
+ // _NV_EVAL
17
+ // _NV_IF
18
+ // _NV_CONCAT_EVAL
19
+ // For C++11 and up it defines:
20
+ // _NV_STRIP_PAREN
21
+ // _NV_DISPATCH_N_ARY
22
+ // _NV_FIRST_ARG
23
+ // _NV_REMOVE_PAREN
24
+
25
+ #if defined(_NV_TARGET_CPP11)
26
+ # define _NV_EVAL1(...) __VA_ARGS__
27
+ # define _NV_EVAL(...) _NV_EVAL1(__VA_ARGS__)
28
+ #else
29
+ # define _NV_EVAL1(x) x
30
+ # define _NV_EVAL(x) _NV_EVAL1(x)
31
+ #endif // C++11
32
+
33
+ #define _NV_CONCAT_EVAL1(l, r) _NV_EVAL(l##r)
34
+ #define _NV_CONCAT_EVAL(l, r) _NV_CONCAT_EVAL1(l, r)
35
+
36
+ #define _NV_IF_0(t, f) f
37
+ #define _NV_IF_1(t, f) t
38
+
39
+ #define _NV_IF_BIT(b) _NV_EVAL(_NV_IF_##b)
40
+ #define _NV_IF__EVAL(fn, t, f) _NV_EVAL(fn(t, f))
41
+ #define _NV_IF_EVAL(cond, t, f) _NV_IF__EVAL(_NV_IF_BIT(cond), t, f)
42
+
43
+ #define _NV_IF1(cond, t, f) _NV_IF_EVAL(cond, t, f)
44
+ #define _NV_IF(cond, t, f) _NV_IF1(_NV_EVAL(cond), _NV_EVAL(t), _NV_EVAL(f))
45
+
46
+ #if defined(_NV_TARGET_CPP11)
47
+
48
+ // The below mechanisms were derived from: https://gustedt.wordpress.com/2010/06/08/detect-empty-macro-arguments/
49
+
50
+ # define _NV_ARG32(...) _NV_EVAL(_NV_ARG32_0(__VA_ARGS__))
51
+ # define _NV_ARG32_0( \
52
+ _0, \
53
+ _1, \
54
+ _2, \
55
+ _3, \
56
+ _4, \
57
+ _5, \
58
+ _6, \
59
+ _7, \
60
+ _8, \
61
+ _9, \
62
+ _10, \
63
+ _11, \
64
+ _12, \
65
+ _13, \
66
+ _14, \
67
+ _15, \
68
+ _16, \
69
+ _17, \
70
+ _18, \
71
+ _19, \
72
+ _20, \
73
+ _21, \
74
+ _22, \
75
+ _23, \
76
+ _24, \
77
+ _25, \
78
+ _26, \
79
+ _27, \
80
+ _28, \
81
+ _29, \
82
+ _30, \
83
+ _31, \
84
+ ...) \
85
+ _31
86
+
87
+ # define _NV_HAS_COMMA(...) \
88
+ _NV_ARG32(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
89
+
90
+ # define _NV_TRIGGER_PARENTHESIS_(...) ,
91
+
92
+ # define _NV_ISEMPTY(...) \
93
+ _NV_ISEMPTY0(/* test if there is just one argument, eventually an empty \
94
+ one */ \
95
+ _NV_EVAL(_NV_HAS_COMMA(__VA_ARGS__)), /* test if _TRIGGER_PARENTHESIS_ together with the argument \
96
+ adds a comma */ \
97
+ _NV_EVAL(_NV_HAS_COMMA(_NV_TRIGGER_PARENTHESIS_ __VA_ARGS__)), /* test if the argument together with \
98
+ a parenthesis adds a comma */ \
99
+ _NV_EVAL(_NV_HAS_COMMA(__VA_ARGS__(/*empty*/))), /* test if placing it between _TRIGGER_PARENTHESIS_ \
100
+ and the parenthesis adds a comma */ \
101
+ _NV_EVAL(_NV_HAS_COMMA(_NV_TRIGGER_PARENTHESIS_ __VA_ARGS__(/*empty*/))))
102
+
103
+ # define _NV_PASTE5(_0, _1, _2, _3, _4) _0##_1##_2##_3##_4
104
+ # define _NV_ISEMPTY0(_0, _1, _2, _3) _NV_HAS_COMMA(_NV_PASTE5(_NV_IS_EMPTY_CASE_, _0, _1, _2, _3))
105
+ # define _NV_IS_EMPTY_CASE_0001 ,
106
+
107
+ # define _NV_REMOVE_PAREN(...) _NV_REMOVE_PAREN1(__VA_ARGS__)
108
+ # define _NV_REMOVE_PAREN1(...) \
109
+ _NV_STRIP_PAREN(_NV_IF(_NV_TEST_PAREN(__VA_ARGS__), (_NV_STRIP_PAREN(__VA_ARGS__)), (__VA_ARGS__)))
110
+
111
+ # define _NV_STRIP_PAREN2(...) __VA_ARGS__
112
+ # define _NV_STRIP_PAREN1(...) _NV_STRIP_PAREN2 __VA_ARGS__
113
+ # define _NV_STRIP_PAREN(...) _NV_STRIP_PAREN1(__VA_ARGS__)
114
+
115
+ # define _NV_TEST_PAREN(...) _NV_TEST_PAREN1(__VA_ARGS__)
116
+ # define _NV_TEST_PAREN1(...) _NV_TEST_PAREN2(_NV_TEST_PAREN_DUMMY __VA_ARGS__)
117
+ # define _NV_TEST_PAREN2(...) _NV_TEST_PAREN3(_NV_CONCAT_EVAL(_, __VA_ARGS__))
118
+ # define _NV_TEST_PAREN3(...) _NV_EVAL(_NV_FIRST_ARG(__VA_ARGS__))
119
+
120
+ # define __NV_PAREN_YES 1
121
+ # define __NV_PAREN_NO 0
122
+
123
+ # define _NV_TEST_PAREN_DUMMY(...) _NV_PAREN_YES
124
+ # define __NV_TEST_PAREN_DUMMY __NV_PAREN_NO,
125
+
126
+ # define _NV_FIRST_ARG1(x, ...) x
127
+ # define _NV_FIRST_ARG(x, ...) _NV_FIRST_ARG1(x)
128
+
129
+ # define _NV_REMOVE_FIRST_ARGS1(...) __VA_ARGS__
130
+ # define _NV_REMOVE_FIRST_ARGS(x, ...) _NV_REMOVE_FIRST_ARGS1(__VA_ARGS__)
131
+
132
+ # define _NV_NUM_ARGS(...) _NV_NUM_ARGS0(__VA_ARGS__)
133
+ # define _NV_NUM_ARGS0(...) _NV_EVAL(_NV_NUM_ARGS1(__VA_ARGS__))
134
+ # define _NV_NUM_ARGS1(...) _NV_IF(_NV_ISEMPTY(__VA_ARGS__), 0, _NV_NUM_ARGS2(__VA_ARGS__))
135
+ # define _NV_NUM_ARGS2(...) \
136
+ _NV_ARG32( \
137
+ __VA_ARGS__, \
138
+ 31, \
139
+ 30, \
140
+ 29, \
141
+ 28, \
142
+ 27, \
143
+ 26, \
144
+ 25, \
145
+ 24, \
146
+ 23, \
147
+ 22, \
148
+ 21, \
149
+ 20, \
150
+ 19, \
151
+ 18, \
152
+ 17, \
153
+ 16, \
154
+ 15, \
155
+ 14, \
156
+ 13, \
157
+ 12, \
158
+ 11, \
159
+ 10, \
160
+ 9, \
161
+ 8, \
162
+ 7, \
163
+ 6, \
164
+ 5, \
165
+ 4, \
166
+ 3, \
167
+ 2, \
168
+ 1, \
169
+ 0)
170
+
171
+ # define _NV_DISPATCH_N_IMPL1(name, ...) _NV_EVAL(name(__VA_ARGS__))
172
+ # define _NV_DISPATCH_N_IMPL0(depth, name, ...) _NV_DISPATCH_N_IMPL1(_NV_CONCAT_EVAL(name, depth), __VA_ARGS__)
173
+ # define _NV_DISPATCH_N_IMPL(name, ...) _NV_DISPATCH_N_IMPL0(_NV_NUM_ARGS(__VA_ARGS__), name, __VA_ARGS__)
174
+ # define _NV_DISPATCH_N_ARY(name, ...) _NV_DISPATCH_N_IMPL(name, __VA_ARGS__)
175
+
176
+ #endif // C++11
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__target_macros ADDED
@@ -0,0 +1,610 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ #ifndef _NV__TARGET_MACROS
12
+ #define _NV__TARGET_MACROS
13
+
14
+ #include <nv/detail/__preprocessor>
15
+
16
+ #if defined(__GNUC__)
17
+ # pragma GCC system_header
18
+ #endif
19
+
20
+ #define _NV_TARGET_ARCH_TO_SELECTOR_350 nv::target::sm_35
21
+ #define _NV_TARGET_ARCH_TO_SELECTOR_370 nv::target::sm_37
22
+ #define _NV_TARGET_ARCH_TO_SELECTOR_500 nv::target::sm_50
23
+ #define _NV_TARGET_ARCH_TO_SELECTOR_520 nv::target::sm_52
24
+ #define _NV_TARGET_ARCH_TO_SELECTOR_530 nv::target::sm_53
25
+ #define _NV_TARGET_ARCH_TO_SELECTOR_600 nv::target::sm_60
26
+ #define _NV_TARGET_ARCH_TO_SELECTOR_610 nv::target::sm_61
27
+ #define _NV_TARGET_ARCH_TO_SELECTOR_620 nv::target::sm_62
28
+ #define _NV_TARGET_ARCH_TO_SELECTOR_700 nv::target::sm_70
29
+ #define _NV_TARGET_ARCH_TO_SELECTOR_720 nv::target::sm_72
30
+ #define _NV_TARGET_ARCH_TO_SELECTOR_750 nv::target::sm_75
31
+ #define _NV_TARGET_ARCH_TO_SELECTOR_800 nv::target::sm_80
32
+ #define _NV_TARGET_ARCH_TO_SELECTOR_860 nv::target::sm_86
33
+ #define _NV_TARGET_ARCH_TO_SELECTOR_870 nv::target::sm_87
34
+ #define _NV_TARGET_ARCH_TO_SELECTOR_890 nv::target::sm_89
35
+ #define _NV_TARGET_ARCH_TO_SELECTOR_900 nv::target::sm_90
36
+ #define _NV_TARGET_ARCH_TO_SELECTOR_1000 nv::target::sm_100
37
+ #define _NV_TARGET_ARCH_TO_SELECTOR_1010 nv::target::sm_101
38
+ #define _NV_TARGET_ARCH_TO_SELECTOR_1200 nv::target::sm_120
39
+
40
+ #define _NV_TARGET_ARCH_TO_SM_350 35
41
+ #define _NV_TARGET_ARCH_TO_SM_370 37
42
+ #define _NV_TARGET_ARCH_TO_SM_500 50
43
+ #define _NV_TARGET_ARCH_TO_SM_520 52
44
+ #define _NV_TARGET_ARCH_TO_SM_530 53
45
+ #define _NV_TARGET_ARCH_TO_SM_600 60
46
+ #define _NV_TARGET_ARCH_TO_SM_610 61
47
+ #define _NV_TARGET_ARCH_TO_SM_620 62
48
+ #define _NV_TARGET_ARCH_TO_SM_700 70
49
+ #define _NV_TARGET_ARCH_TO_SM_720 72
50
+ #define _NV_TARGET_ARCH_TO_SM_750 75
51
+ #define _NV_TARGET_ARCH_TO_SM_800 80
52
+ #define _NV_TARGET_ARCH_TO_SM_860 86
53
+ #define _NV_TARGET_ARCH_TO_SM_870 87
54
+ #define _NV_TARGET_ARCH_TO_SM_890 89
55
+ #define _NV_TARGET_ARCH_TO_SM_900 90
56
+ #define _NV_TARGET_ARCH_TO_SM_1000 100
57
+ #define _NV_TARGET_ARCH_TO_SM_1010 101
58
+ #define _NV_TARGET_ARCH_TO_SM_1200 120
59
+
60
+ // Only enable when compiling for CUDA/stdpar
61
+ #if defined(_NV_COMPILER_NVCXX) && defined(_NVHPC_CUDA)
62
+
63
+ # define _NV_TARGET_VAL_SM_35 nv::target::sm_35
64
+ # define _NV_TARGET_VAL_SM_37 nv::target::sm_37
65
+ # define _NV_TARGET_VAL_SM_50 nv::target::sm_50
66
+ # define _NV_TARGET_VAL_SM_52 nv::target::sm_52
67
+ # define _NV_TARGET_VAL_SM_53 nv::target::sm_53
68
+ # define _NV_TARGET_VAL_SM_60 nv::target::sm_60
69
+ # define _NV_TARGET_VAL_SM_61 nv::target::sm_61
70
+ # define _NV_TARGET_VAL_SM_62 nv::target::sm_62
71
+ # define _NV_TARGET_VAL_SM_70 nv::target::sm_70
72
+ # define _NV_TARGET_VAL_SM_72 nv::target::sm_72
73
+ # define _NV_TARGET_VAL_SM_75 nv::target::sm_75
74
+ # define _NV_TARGET_VAL_SM_80 nv::target::sm_80
75
+ # define _NV_TARGET_VAL_SM_86 nv::target::sm_86
76
+ # define _NV_TARGET_VAL_SM_87 nv::target::sm_87
77
+ # define _NV_TARGET_VAL_SM_89 nv::target::sm_89
78
+ # define _NV_TARGET_VAL_SM_90 nv::target::sm_90
79
+ # define _NV_TARGET_VAL_SM_100 nv::target::sm_100
80
+ # define _NV_TARGET_VAL_SM_101 nv::target::sm_101
81
+ # define _NV_TARGET_VAL_SM_120 nv::target::sm_120
82
+
83
+ # define _NV_TARGET___NV_IS_HOST nv::target::is_host
84
+ # define _NV_TARGET___NV_IS_DEVICE nv::target::is_device
85
+
86
+ # define _NV_TARGET___NV_ANY_TARGET (nv::target::any_target)
87
+ # define _NV_TARGET___NV_NO_TARGET (nv::target::no_target)
88
+
89
+ # if defined(NV_TARGET_SM_INTEGER_LIST)
90
+ # define NV_TARGET_MINIMUM_SM_SELECTOR _NV_FIRST_ARG(NV_TARGET_SM_SELECTOR_LIST)
91
+ # define NV_TARGET_MINIMUM_SM_INTEGER _NV_FIRST_ARG(NV_TARGET_SM_INTEGER_LIST)
92
+ # define __CUDA_MINIMUM_ARCH__ _NV_CONCAT_EVAL(_NV_FIRST_ARG(NV_TARGET_SM_INTEGER_LIST), 0)
93
+ # endif
94
+
95
+ # define _NV_TARGET_PROVIDES(q) nv::target::provides(q)
96
+ # define _NV_TARGET_IS_EXACTLY(q) nv::target::is_exactly(q)
97
+
98
+ #elif defined(_NV_COMPILER_NVCC) || defined(_NV_COMPILER_CLANG_CUDA)
99
+
100
+ # define _NV_TARGET_VAL_SM_35 350
101
+ # define _NV_TARGET_VAL_SM_37 370
102
+ # define _NV_TARGET_VAL_SM_50 500
103
+ # define _NV_TARGET_VAL_SM_52 520
104
+ # define _NV_TARGET_VAL_SM_53 530
105
+ # define _NV_TARGET_VAL_SM_60 600
106
+ # define _NV_TARGET_VAL_SM_61 610
107
+ # define _NV_TARGET_VAL_SM_62 620
108
+ # define _NV_TARGET_VAL_SM_70 700
109
+ # define _NV_TARGET_VAL_SM_72 720
110
+ # define _NV_TARGET_VAL_SM_75 750
111
+ # define _NV_TARGET_VAL_SM_80 800
112
+ # define _NV_TARGET_VAL_SM_86 860
113
+ # define _NV_TARGET_VAL_SM_87 870
114
+ # define _NV_TARGET_VAL_SM_89 890
115
+ # define _NV_TARGET_VAL_SM_90 900
116
+ # define _NV_TARGET_VAL_SM_100 1000
117
+ # define _NV_TARGET_VAL_SM_101 1010
118
+ # define _NV_TARGET_VAL_SM_120 1200
119
+
120
+ # if defined(__CUDA_ARCH__)
121
+ # define _NV_TARGET_VAL __CUDA_ARCH__
122
+ # define NV_TARGET_MINIMUM_SM_SELECTOR _NV_CONCAT_EVAL(_NV_TARGET_ARCH_TO_SELECTOR_, __CUDA_ARCH__)
123
+ # define NV_TARGET_MINIMUM_SM_INTEGER _NV_CONCAT_EVAL(_NV_TARGET_ARCH_TO_SM_, __CUDA_ARCH__)
124
+ # define __CUDA_MINIMUM_ARCH__ __CUDA_ARCH__
125
+ # endif
126
+
127
+ # if defined(__CUDA_ARCH__)
128
+ # define _NV_TARGET_IS_HOST 0
129
+ # define _NV_TARGET_IS_DEVICE 1
130
+ # else
131
+ # define _NV_TARGET_IS_HOST 1
132
+ # define _NV_TARGET_IS_DEVICE 0
133
+ # endif
134
+
135
+ # if defined(_NV_TARGET_VAL)
136
+ # define _NV_DEVICE_CHECK(q) (q)
137
+ # else
138
+ # define _NV_DEVICE_CHECK(q) (0)
139
+ # endif
140
+
141
+ # define _NV_TARGET_PROVIDES(q) _NV_DEVICE_CHECK(_NV_TARGET_VAL >= q)
142
+ # define _NV_TARGET_IS_EXACTLY(q) _NV_DEVICE_CHECK(_NV_TARGET_VAL == q)
143
+
144
+ // NVCC/NVCXX not being used, only host dispatches allowed
145
+ #else
146
+
147
+ # define _NV_COMPILER_NVCC
148
+
149
+ # define _NV_TARGET_VAL_SM_35 350
150
+ # define _NV_TARGET_VAL_SM_37 370
151
+ # define _NV_TARGET_VAL_SM_50 500
152
+ # define _NV_TARGET_VAL_SM_52 520
153
+ # define _NV_TARGET_VAL_SM_53 530
154
+ # define _NV_TARGET_VAL_SM_60 600
155
+ # define _NV_TARGET_VAL_SM_61 610
156
+ # define _NV_TARGET_VAL_SM_62 620
157
+ # define _NV_TARGET_VAL_SM_70 700
158
+ # define _NV_TARGET_VAL_SM_72 720
159
+ # define _NV_TARGET_VAL_SM_75 750
160
+ # define _NV_TARGET_VAL_SM_80 800
161
+ # define _NV_TARGET_VAL_SM_86 860
162
+ # define _NV_TARGET_VAL_SM_87 870
163
+ # define _NV_TARGET_VAL_SM_89 890
164
+ # define _NV_TARGET_VAL_SM_90 900
165
+ # define _NV_TARGET_VAL_SM_100 1000
166
+ # define _NV_TARGET_VAL_SM_101 1010
167
+ # define _NV_TARGET_VAL_SM_120 1200
168
+
169
+ # define _NV_TARGET_VAL 0
170
+
171
+ # define _NV_TARGET_IS_HOST 1
172
+ # define _NV_TARGET_IS_DEVICE 0
173
+
174
+ # define _NV_DEVICE_CHECK(q) (false)
175
+
176
+ # define _NV_TARGET_PROVIDES(q) _NV_DEVICE_CHECK(_NV_TARGET_VAL >= q)
177
+ # define _NV_TARGET_IS_EXACTLY(q) _NV_DEVICE_CHECK(_NV_TARGET_VAL == q)
178
+
179
+ #endif
180
+
181
+ #define _NV_TARGET___NV_PROVIDES_SM_35 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_35))
182
+ #define _NV_TARGET___NV_PROVIDES_SM_37 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_37))
183
+ #define _NV_TARGET___NV_PROVIDES_SM_50 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_50))
184
+ #define _NV_TARGET___NV_PROVIDES_SM_52 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_52))
185
+ #define _NV_TARGET___NV_PROVIDES_SM_53 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_53))
186
+ #define _NV_TARGET___NV_PROVIDES_SM_60 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_60))
187
+ #define _NV_TARGET___NV_PROVIDES_SM_61 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_61))
188
+ #define _NV_TARGET___NV_PROVIDES_SM_62 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_62))
189
+ #define _NV_TARGET___NV_PROVIDES_SM_70 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_70))
190
+ #define _NV_TARGET___NV_PROVIDES_SM_72 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_72))
191
+ #define _NV_TARGET___NV_PROVIDES_SM_75 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_75))
192
+ #define _NV_TARGET___NV_PROVIDES_SM_80 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_80))
193
+ #define _NV_TARGET___NV_PROVIDES_SM_86 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_86))
194
+ #define _NV_TARGET___NV_PROVIDES_SM_87 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_87))
195
+ #define _NV_TARGET___NV_PROVIDES_SM_89 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_89))
196
+ #define _NV_TARGET___NV_PROVIDES_SM_90 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_90))
197
+ #define _NV_TARGET___NV_PROVIDES_SM_100 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_100))
198
+ #define _NV_TARGET___NV_PROVIDES_SM_101 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_101))
199
+ #define _NV_TARGET___NV_PROVIDES_SM_120 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_120))
200
+
201
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_35 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_35))
202
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_37 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_37))
203
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_50 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_50))
204
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_52 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_52))
205
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_53 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_53))
206
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_60 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_60))
207
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_61 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_61))
208
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_62 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_62))
209
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_70 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_70))
210
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_72 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_72))
211
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_75 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_75))
212
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_80 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_80))
213
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_86 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_86))
214
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_87 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_87))
215
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_89 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_89))
216
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_90 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_90))
217
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_100 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_100))
218
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_101 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_101))
219
+ #define _NV_TARGET___NV_IS_EXACTLY_SM_120 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_120))
220
+
221
+ #define NV_PROVIDES_SM_35 __NV_PROVIDES_SM_35
222
+ #define NV_PROVIDES_SM_37 __NV_PROVIDES_SM_37
223
+ #define NV_PROVIDES_SM_50 __NV_PROVIDES_SM_50
224
+ #define NV_PROVIDES_SM_52 __NV_PROVIDES_SM_52
225
+ #define NV_PROVIDES_SM_53 __NV_PROVIDES_SM_53
226
+ #define NV_PROVIDES_SM_60 __NV_PROVIDES_SM_60
227
+ #define NV_PROVIDES_SM_61 __NV_PROVIDES_SM_61
228
+ #define NV_PROVIDES_SM_62 __NV_PROVIDES_SM_62
229
+ #define NV_PROVIDES_SM_70 __NV_PROVIDES_SM_70
230
+ #define NV_PROVIDES_SM_72 __NV_PROVIDES_SM_72
231
+ #define NV_PROVIDES_SM_75 __NV_PROVIDES_SM_75
232
+ #define NV_PROVIDES_SM_80 __NV_PROVIDES_SM_80
233
+ #define NV_PROVIDES_SM_86 __NV_PROVIDES_SM_86
234
+ #define NV_PROVIDES_SM_87 __NV_PROVIDES_SM_87
235
+ #define NV_PROVIDES_SM_89 __NV_PROVIDES_SM_89
236
+ #define NV_PROVIDES_SM_90 __NV_PROVIDES_SM_90
237
+ #define NV_PROVIDES_SM_100 __NV_PROVIDES_SM_100
238
+ #define NV_PROVIDES_SM_101 __NV_PROVIDES_SM_101
239
+ #define NV_PROVIDES_SM_120 __NV_PROVIDES_SM_120
240
+
241
+ #define NV_IS_EXACTLY_SM_35 __NV_IS_EXACTLY_SM_35
242
+ #define NV_IS_EXACTLY_SM_37 __NV_IS_EXACTLY_SM_37
243
+ #define NV_IS_EXACTLY_SM_50 __NV_IS_EXACTLY_SM_50
244
+ #define NV_IS_EXACTLY_SM_52 __NV_IS_EXACTLY_SM_52
245
+ #define NV_IS_EXACTLY_SM_53 __NV_IS_EXACTLY_SM_53
246
+ #define NV_IS_EXACTLY_SM_60 __NV_IS_EXACTLY_SM_60
247
+ #define NV_IS_EXACTLY_SM_61 __NV_IS_EXACTLY_SM_61
248
+ #define NV_IS_EXACTLY_SM_62 __NV_IS_EXACTLY_SM_62
249
+ #define NV_IS_EXACTLY_SM_70 __NV_IS_EXACTLY_SM_70
250
+ #define NV_IS_EXACTLY_SM_72 __NV_IS_EXACTLY_SM_72
251
+ #define NV_IS_EXACTLY_SM_75 __NV_IS_EXACTLY_SM_75
252
+ #define NV_IS_EXACTLY_SM_80 __NV_IS_EXACTLY_SM_80
253
+ #define NV_IS_EXACTLY_SM_86 __NV_IS_EXACTLY_SM_86
254
+ #define NV_IS_EXACTLY_SM_87 __NV_IS_EXACTLY_SM_87
255
+ #define NV_IS_EXACTLY_SM_89 __NV_IS_EXACTLY_SM_89
256
+ #define NV_IS_EXACTLY_SM_90 __NV_IS_EXACTLY_SM_90
257
+ #define NV_IS_EXACTLY_SM_100 __NV_IS_EXACTLY_SM_100
258
+ #define NV_IS_EXACTLY_SM_101 __NV_IS_EXACTLY_SM_101
259
+ #define NV_IS_EXACTLY_SM_120 __NV_IS_EXACTLY_SM_120
260
+
261
+ // Disable SM_90a support on non-supporting compilers.
262
+ // Will re-enable for nvcc below.
263
+ #define NV_HAS_FEATURE_SM_90a NV_NO_TARGET
264
+ #define NV_HAS_FEATURE_SM_100a NV_NO_TARGET
265
+ #define NV_HAS_FEATURE_SM_101a NV_NO_TARGET
266
+
267
+ #define NV_IS_HOST __NV_IS_HOST
268
+ #define NV_IS_DEVICE __NV_IS_DEVICE
269
+
270
+ #define NV_ANY_TARGET __NV_ANY_TARGET
271
+ #define NV_NO_TARGET __NV_NO_TARGET
272
+
273
+ // Platform invoke mechanisms
274
+ #if defined(_NV_COMPILER_NVCXX) && defined(_NVHPC_CUDA)
275
+
276
+ # define _NV_ARCH_COND(q) (_NV_TARGET_##q)
277
+
278
+ # define _NV_BLOCK_EXPAND(...) _NV_REMOVE_PAREN(__VA_ARGS__)
279
+
280
+ # define _NV_TARGET_IF(cond, t, ...) \
281
+ (if target _NV_ARCH_COND(cond) { _NV_BLOCK_EXPAND(t) } else {_NV_BLOCK_EXPAND(__VA_ARGS__)})
282
+
283
+ #elif defined(_NV_COMPILER_NVCC) || defined(_NV_COMPILER_CLANG_CUDA)
284
+
285
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_35)
286
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_35 1
287
+ # else
288
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_35 0
289
+ # endif
290
+
291
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_37)
292
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_37 1
293
+ # else
294
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_37 0
295
+ # endif
296
+
297
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_50)
298
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_50 1
299
+ # else
300
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_50 0
301
+ # endif
302
+
303
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_52)
304
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_52 1
305
+ # else
306
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_52 0
307
+ # endif
308
+
309
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_53)
310
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_53 1
311
+ # else
312
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_53 0
313
+ # endif
314
+
315
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_60)
316
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_60 1
317
+ # else
318
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_60 0
319
+ # endif
320
+
321
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_61)
322
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_61 1
323
+ # else
324
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_61 0
325
+ # endif
326
+
327
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_62)
328
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_62 1
329
+ # else
330
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_62 0
331
+ # endif
332
+
333
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_70)
334
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_70 1
335
+ # else
336
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_70 0
337
+ # endif
338
+
339
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_72)
340
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_72 1
341
+ # else
342
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_72 0
343
+ # endif
344
+
345
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_75)
346
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_75 1
347
+ # else
348
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_75 0
349
+ # endif
350
+
351
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_80)
352
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_80 1
353
+ # else
354
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_80 0
355
+ # endif
356
+
357
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_86)
358
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_86 1
359
+ # else
360
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_86 0
361
+ # endif
362
+
363
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_87)
364
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_87 1
365
+ # else
366
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_87 0
367
+ # endif
368
+
369
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_89)
370
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_89 1
371
+ # else
372
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_89 0
373
+ # endif
374
+
375
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_90)
376
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_90 1
377
+ # else
378
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_90 0
379
+ # endif
380
+
381
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_100)
382
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_100 1
383
+ # else
384
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_100 0
385
+ # endif
386
+
387
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_101)
388
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_101 1
389
+ # else
390
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_101 0
391
+ # endif
392
+
393
+ # if (_NV_TARGET___NV_IS_EXACTLY_SM_120)
394
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_120 1
395
+ # else
396
+ # define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_120 0
397
+ # endif
398
+
399
+ // Re-enable sm_90a support in nvcc.
400
+ # undef NV_HAS_FEATURE_SM_90a
401
+ # define NV_HAS_FEATURE_SM_90a __NV_HAS_FEATURE_SM_90a
402
+ # if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 900) && defined(__CUDA_ARCH_FEAT_SM90_ALL))
403
+ # define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_90a 1
404
+ # else
405
+ # define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_90a 0
406
+ # endif
407
+
408
+ // Re-enable sm_100a support in nvcc.
409
+ # undef NV_HAS_FEATURE_SM_100a
410
+ # define NV_HAS_FEATURE_SM_100a __NV_HAS_FEATURE_SM_100a
411
+ # if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 1000) && defined(__CUDA_ARCH_FEAT_SM100_ALL))
412
+ # define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_100a 1
413
+ # else
414
+ # define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_100a 0
415
+ # endif
416
+
417
+ // Re-enable sm_101a support in nvcc.
418
+ # undef NV_HAS_FEATURE_SM_101a
419
+ # define NV_HAS_FEATURE_SM_101a __NV_HAS_FEATURE_SM_101a
420
+ # if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 1010) && defined(__CUDA_ARCH_FEAT_SM101_ALL))
421
+ # define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_101a 1
422
+ # else
423
+ # define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_101a 0
424
+ # endif
425
+
426
+ # if (_NV_TARGET_IS_HOST)
427
+ # define _NV_TARGET_BOOL___NV_IS_HOST 1
428
+ # define _NV_TARGET_BOOL___NV_IS_DEVICE 0
429
+ # else
430
+ # define _NV_TARGET_BOOL___NV_IS_HOST 0
431
+ # define _NV_TARGET_BOOL___NV_IS_DEVICE 1
432
+ # endif
433
+
434
+ # define _NV_TARGET_BOOL___NV_ANY_TARGET 1
435
+ # define _NV_TARGET_BOOL___NV_NO_TARGET 0
436
+
437
+ // NVCC Greater than stuff
438
+
439
+ # if (_NV_TARGET___NV_PROVIDES_SM_35)
440
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_35 1
441
+ # else
442
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_35 0
443
+ # endif
444
+
445
+ # if (_NV_TARGET___NV_PROVIDES_SM_37)
446
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_37 1
447
+ # else
448
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_37 0
449
+ # endif
450
+
451
+ # if (_NV_TARGET___NV_PROVIDES_SM_50)
452
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_50 1
453
+ # else
454
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_50 0
455
+ # endif
456
+
457
+ # if (_NV_TARGET___NV_PROVIDES_SM_52)
458
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_52 1
459
+ # else
460
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_52 0
461
+ # endif
462
+
463
+ # if (_NV_TARGET___NV_PROVIDES_SM_53)
464
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_53 1
465
+ # else
466
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_53 0
467
+ # endif
468
+
469
+ # if (_NV_TARGET___NV_PROVIDES_SM_60)
470
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_60 1
471
+ # else
472
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_60 0
473
+ # endif
474
+
475
+ # if (_NV_TARGET___NV_PROVIDES_SM_61)
476
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_61 1
477
+ # else
478
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_61 0
479
+ # endif
480
+
481
+ # if (_NV_TARGET___NV_PROVIDES_SM_62)
482
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_62 1
483
+ # else
484
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_62 0
485
+ # endif
486
+
487
+ # if (_NV_TARGET___NV_PROVIDES_SM_70)
488
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_70 1
489
+ # else
490
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_70 0
491
+ # endif
492
+
493
+ # if (_NV_TARGET___NV_PROVIDES_SM_72)
494
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_72 1
495
+ # else
496
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_72 0
497
+ # endif
498
+
499
+ # if (_NV_TARGET___NV_PROVIDES_SM_75)
500
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_75 1
501
+ # else
502
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_75 0
503
+ # endif
504
+
505
+ # if (_NV_TARGET___NV_PROVIDES_SM_80)
506
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_80 1
507
+ # else
508
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_80 0
509
+ # endif
510
+
511
+ # if (_NV_TARGET___NV_PROVIDES_SM_86)
512
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_86 1
513
+ # else
514
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_86 0
515
+ # endif
516
+
517
+ # if (_NV_TARGET___NV_PROVIDES_SM_87)
518
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_87 1
519
+ # else
520
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_87 0
521
+ # endif
522
+
523
+ # if (_NV_TARGET___NV_PROVIDES_SM_89)
524
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_89 1
525
+ # else
526
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_89 0
527
+ # endif
528
+
529
+ # if (_NV_TARGET___NV_PROVIDES_SM_90)
530
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_90 1
531
+ # else
532
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_90 0
533
+ # endif
534
+
535
+ # if (_NV_TARGET___NV_PROVIDES_SM_100)
536
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_100 1
537
+ # else
538
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_100 0
539
+ # endif
540
+
541
+ # if (_NV_TARGET___NV_PROVIDES_SM_101)
542
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_101 1
543
+ # else
544
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_101 0
545
+ # endif
546
+
547
+ # if (_NV_TARGET___NV_PROVIDES_SM_120)
548
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_120 1
549
+ # else
550
+ # define _NV_TARGET_BOOL___NV_PROVIDES_SM_120 0
551
+ # endif
552
+
553
+ # define _NV_ARCH_COND_CAT1(cond) _NV_TARGET_BOOL_##cond
554
+ # define _NV_ARCH_COND_CAT(cond) _NV_EVAL(_NV_ARCH_COND_CAT1(cond))
555
+
556
+ # define _NV_TARGET_EMPTY_PARAM ;
557
+
558
+ # if defined(_NV_TARGET_CPP11)
559
+
560
+ # define _NV_BLOCK_EXPAND(...) {_NV_REMOVE_PAREN(__VA_ARGS__)}
561
+ # define _NV_TARGET_IF(cond, t, ...) _NV_IF(_NV_ARCH_COND_CAT(cond), t, __VA_ARGS__)
562
+
563
+ # else // <C++11 fallback
564
+
565
+ # define _NV_BLOCK_EXPAND(x) {x}
566
+
567
+ # define _NV_TARGET_IF(cond, t) _NV_IF(_NV_ARCH_COND_CAT(cond), t, _NV_TARGET_EMPTY_PARAM)
568
+ # define _NV_TARGET_IF_ELSE(cond, t, f) _NV_IF(_NV_ARCH_COND_CAT(cond), t, f)
569
+
570
+ # endif
571
+
572
+ #endif // _NV_COMPILER_NVCC
573
+
574
+ #if defined(_NV_TARGET_CPP11)
575
+
576
+ # define _NV_TARGET_DISPATCH_HANDLE0()
577
+ # define _NV_TARGET_DISPATCH_HANDLE2(q, fn) _NV_TARGET_IF(q, fn)
578
+ # define _NV_TARGET_DISPATCH_HANDLE4(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE2(__VA_ARGS__))
579
+ # define _NV_TARGET_DISPATCH_HANDLE6(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE4(__VA_ARGS__))
580
+ # define _NV_TARGET_DISPATCH_HANDLE8(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE6(__VA_ARGS__))
581
+ # define _NV_TARGET_DISPATCH_HANDLE10(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE8(__VA_ARGS__))
582
+ # define _NV_TARGET_DISPATCH_HANDLE12(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE10(__VA_ARGS__))
583
+ # define _NV_TARGET_DISPATCH_HANDLE14(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE12(__VA_ARGS__))
584
+ # define _NV_TARGET_DISPATCH_HANDLE16(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE14(__VA_ARGS__))
585
+ # define _NV_TARGET_DISPATCH_HANDLE18(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE16(__VA_ARGS__))
586
+ # define _NV_TARGET_DISPATCH_HANDLE20(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE18(__VA_ARGS__))
587
+ # define _NV_TARGET_DISPATCH_HANDLE22(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE20(__VA_ARGS__))
588
+ # define _NV_TARGET_DISPATCH_HANDLE24(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE22(__VA_ARGS__))
589
+ # define _NV_TARGET_DISPATCH_HANDLE26(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE24(__VA_ARGS__))
590
+ # define _NV_TARGET_DISPATCH_HANDLE28(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE26(__VA_ARGS__))
591
+ # define _NV_TARGET_DISPATCH_HANDLE30(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE28(__VA_ARGS__))
592
+ # define _NV_TARGET_DISPATCH_HANDLE32(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE30(__VA_ARGS__))
593
+ # define _NV_TARGET_DISPATCH_HANDLE34(q, fn, ...) _NV_TARGET_IF(q, fn, _NV_TARGET_DISPATCH_HANDLE32(__VA_ARGS__))
594
+
595
+ # define _NV_TARGET_DISPATCH(...) _NV_BLOCK_EXPAND(_NV_DISPATCH_N_ARY(_NV_TARGET_DISPATCH_HANDLE, __VA_ARGS__))
596
+
597
+ // NV_IF_TARGET supports a false statement provided as a variadic macro
598
+ # define NV_IF_TARGET(cond, ...) _NV_BLOCK_EXPAND(_NV_TARGET_IF(cond, __VA_ARGS__))
599
+ # define NV_IF_ELSE_TARGET(cond, t, f) _NV_BLOCK_EXPAND(_NV_TARGET_IF(cond, t, f))
600
+ # define NV_DISPATCH_TARGET(...) _NV_TARGET_DISPATCH(__VA_ARGS__)
601
+
602
+ #else // <C++11 fallback
603
+
604
+ // NV_IF_TARGET does not support a fallback false statement in C++03 or C dialects
605
+ # define NV_IF_TARGET(cond, t) _NV_BLOCK_EXPAND(_NV_TARGET_IF(cond, t))
606
+ # define NV_IF_ELSE_TARGET(cond, t, f) _NV_BLOCK_EXPAND(_NV_TARGET_IF_ELSE(cond, t, f))
607
+
608
+ #endif
609
+
610
+ #endif // _NV__TARGET_MACROS
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/target ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of libcu++, the C++ Standard Library for your entire system,
4
+ // under the Apache License v2.0 with LLVM Exceptions.
5
+ // See https://llvm.org/LICENSE.txt for license information.
6
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
+ // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
8
+ //
9
+ //===----------------------------------------------------------------------===//
10
+
11
+ // This header contains a preview of a portability system that enables
12
+ // CUDA C++ development with NVC++, NVCC, and supported host compilers.
13
+ // These interfaces are not guaranteed to be stable.
14
+
15
+ #ifndef __NV_TARGET_H
16
+ #define __NV_TARGET_H
17
+
18
+ #if defined(__NVCC__) || defined(__CUDACC_RTC__)
19
+ # define _NV_COMPILER_NVCC
20
+ #elif defined(__NVCOMPILER) && __cplusplus >= 201103L
21
+ # define _NV_COMPILER_NVCXX
22
+ #elif defined(__clang__) && defined(__CUDA__) && defined(__CUDA_ARCH__)
23
+ // clang compiling CUDA code, device mode.
24
+ # define _NV_COMPILER_CLANG_CUDA
25
+ #endif
26
+
27
+ #if ((defined(__cplusplus) && __cplusplus >= 201103L) || (defined(_MSC_VER) && _MSVC_LANG >= 201103L))
28
+ # define _NV_TARGET_CPP11
29
+ #endif
30
+
31
+ // Hide `if target` support from NVRTC
32
+ #if defined(_NV_TARGET_CPP11) && !defined(__CUDACC_RTC__)
33
+
34
+ # if defined(_NV_COMPILER_NVCXX)
35
+ # define _NV_BITSET_ATTRIBUTE [[nv::__target_bitset]]
36
+ # else
37
+ # define _NV_BITSET_ATTRIBUTE
38
+ # endif
39
+
40
+ namespace nv
41
+ {
42
+ namespace target
43
+ {
44
+ namespace detail
45
+ {
46
+
47
+ typedef unsigned long long base_int_t;
48
+
49
+ // No host specialization
50
+ constexpr base_int_t all_hosts = 1;
51
+
52
+ // NVIDIA GPUs
53
+ constexpr base_int_t sm_35_bit = 1 << 1;
54
+ constexpr base_int_t sm_37_bit = 1 << 2;
55
+ constexpr base_int_t sm_50_bit = 1 << 3;
56
+ constexpr base_int_t sm_52_bit = 1 << 4;
57
+ constexpr base_int_t sm_53_bit = 1 << 5;
58
+ constexpr base_int_t sm_60_bit = 1 << 6;
59
+ constexpr base_int_t sm_61_bit = 1 << 7;
60
+ constexpr base_int_t sm_62_bit = 1 << 8;
61
+ constexpr base_int_t sm_70_bit = 1 << 9;
62
+ constexpr base_int_t sm_72_bit = 1 << 10;
63
+ constexpr base_int_t sm_75_bit = 1 << 11;
64
+ constexpr base_int_t sm_80_bit = 1 << 12;
65
+ constexpr base_int_t sm_86_bit = 1 << 13;
66
+ constexpr base_int_t sm_87_bit = 1 << 14;
67
+ constexpr base_int_t sm_89_bit = 1 << 15;
68
+ constexpr base_int_t sm_90_bit = 1 << 16;
69
+ constexpr base_int_t sm_100_bit = 1 << 17;
70
+ constexpr base_int_t sm_101_bit = 1 << 18;
71
+ constexpr base_int_t sm_120_bit = 1 << 19;
72
+ constexpr base_int_t all_devices =
73
+ sm_35_bit | sm_37_bit | sm_50_bit | sm_52_bit | sm_53_bit | sm_60_bit | sm_61_bit | sm_62_bit | sm_70_bit | sm_72_bit
74
+ | sm_75_bit | sm_80_bit | sm_86_bit | sm_87_bit | sm_89_bit | sm_90_bit | sm_100_bit | sm_101_bit | sm_120_bit;
75
+
76
+ // Store a set of targets as a set of bits
77
+ struct _NV_BITSET_ATTRIBUTE target_description
78
+ {
79
+ base_int_t targets;
80
+
81
+ constexpr target_description(base_int_t a)
82
+ : targets(a)
83
+ {}
84
+ };
85
+
86
+ // The type of the user-visible names of the NVIDIA GPU targets
87
+ enum class sm_selector : base_int_t
88
+ {
89
+ sm_35 = 35,
90
+ sm_37 = 37,
91
+ sm_50 = 50,
92
+ sm_52 = 52,
93
+ sm_53 = 53,
94
+ sm_60 = 60,
95
+ sm_61 = 61,
96
+ sm_62 = 62,
97
+ sm_70 = 70,
98
+ sm_72 = 72,
99
+ sm_75 = 75,
100
+ sm_80 = 80,
101
+ sm_86 = 86,
102
+ sm_87 = 87,
103
+ sm_89 = 89,
104
+ sm_90 = 90,
105
+ sm_100 = 100,
106
+ sm_101 = 101,
107
+ sm_120 = 120,
108
+ };
109
+
110
+ constexpr base_int_t toint(sm_selector a)
111
+ {
112
+ return static_cast<base_int_t>(a);
113
+ }
114
+
115
+ constexpr base_int_t bitexact(sm_selector a)
116
+ {
117
+ return toint(a) == 35 ? sm_35_bit
118
+ : toint(a) == 37 ? sm_37_bit
119
+ : toint(a) == 50 ? sm_50_bit
120
+ : toint(a) == 52 ? sm_52_bit
121
+ : toint(a) == 53 ? sm_53_bit
122
+ : toint(a) == 60 ? sm_60_bit
123
+ : toint(a) == 61 ? sm_61_bit
124
+ : toint(a) == 62 ? sm_62_bit
125
+ : toint(a) == 70 ? sm_70_bit
126
+ : toint(a) == 72 ? sm_72_bit
127
+ : toint(a) == 75 ? sm_75_bit
128
+ : toint(a) == 80 ? sm_80_bit
129
+ : toint(a) == 86 ? sm_86_bit
130
+ : toint(a) == 87 ? sm_87_bit
131
+ : toint(a) == 89 ? sm_89_bit
132
+ : toint(a) == 90 ? sm_90_bit
133
+ : toint(a) == 100 ? sm_100_bit
134
+ : toint(a) == 101 ? sm_101_bit
135
+ : toint(a) == 120 ? sm_120_bit
136
+ : 0;
137
+ }
138
+
139
+ constexpr base_int_t bitrounddown(sm_selector a)
140
+ {
141
+ return toint(a) >= 120 ? sm_120_bit
142
+ : toint(a) >= 101 ? sm_101_bit
143
+ : toint(a) >= 100 ? sm_100_bit
144
+ : toint(a) >= 90 ? sm_90_bit
145
+ : toint(a) >= 89 ? sm_89_bit
146
+ : toint(a) >= 87 ? sm_87_bit
147
+ : toint(a) >= 86 ? sm_86_bit
148
+ : toint(a) >= 80 ? sm_80_bit
149
+ : toint(a) >= 75 ? sm_75_bit
150
+ : toint(a) >= 72 ? sm_72_bit
151
+ : toint(a) >= 70 ? sm_70_bit
152
+ : toint(a) >= 62 ? sm_62_bit
153
+ : toint(a) >= 61 ? sm_61_bit
154
+ : toint(a) >= 60 ? sm_60_bit
155
+ : toint(a) >= 53 ? sm_53_bit
156
+ : toint(a) >= 52 ? sm_52_bit
157
+ : toint(a) >= 50 ? sm_50_bit
158
+ : toint(a) >= 37 ? sm_37_bit
159
+ : toint(a) >= 35 ? sm_35_bit
160
+ : 0;
161
+ }
162
+
163
+ // Public API for NVIDIA GPUs
164
+
165
+ constexpr target_description is_exactly(sm_selector a)
166
+ {
167
+ return target_description(bitexact(a));
168
+ }
169
+
170
+ constexpr target_description provides(sm_selector a)
171
+ {
172
+ return target_description(~(bitrounddown(a) - 1) & all_devices);
173
+ }
174
+
175
+ // Boolean operations on target sets
176
+
177
+ constexpr target_description operator&&(target_description a, target_description b)
178
+ {
179
+ return target_description(a.targets & b.targets);
180
+ }
181
+
182
+ constexpr target_description operator||(target_description a, target_description b)
183
+ {
184
+ return target_description(a.targets | b.targets);
185
+ }
186
+
187
+ constexpr target_description operator!(target_description a)
188
+ {
189
+ return target_description(~a.targets & (all_devices | all_hosts));
190
+ }
191
+ } // namespace detail
192
+
193
+ using detail::sm_selector;
194
+ using detail::target_description;
195
+
196
+ // The predicates for basic host/device selection
197
+ constexpr target_description is_host = target_description(detail::all_hosts);
198
+ constexpr target_description is_device = target_description(detail::all_devices);
199
+ constexpr target_description any_target = target_description(detail::all_hosts | detail::all_devices);
200
+ constexpr target_description no_target = target_description(0);
201
+
202
+ // The public names for NVIDIA GPU architectures
203
+ constexpr sm_selector sm_35 = sm_selector::sm_35;
204
+ constexpr sm_selector sm_37 = sm_selector::sm_37;
205
+ constexpr sm_selector sm_50 = sm_selector::sm_50;
206
+ constexpr sm_selector sm_52 = sm_selector::sm_52;
207
+ constexpr sm_selector sm_53 = sm_selector::sm_53;
208
+ constexpr sm_selector sm_60 = sm_selector::sm_60;
209
+ constexpr sm_selector sm_61 = sm_selector::sm_61;
210
+ constexpr sm_selector sm_62 = sm_selector::sm_62;
211
+ constexpr sm_selector sm_70 = sm_selector::sm_70;
212
+ constexpr sm_selector sm_72 = sm_selector::sm_72;
213
+ constexpr sm_selector sm_75 = sm_selector::sm_75;
214
+ constexpr sm_selector sm_80 = sm_selector::sm_80;
215
+ constexpr sm_selector sm_86 = sm_selector::sm_86;
216
+ constexpr sm_selector sm_87 = sm_selector::sm_87;
217
+ constexpr sm_selector sm_89 = sm_selector::sm_89;
218
+ constexpr sm_selector sm_90 = sm_selector::sm_90;
219
+ constexpr sm_selector sm_100 = sm_selector::sm_100;
220
+ constexpr sm_selector sm_101 = sm_selector::sm_101;
221
+ constexpr sm_selector sm_120 = sm_selector::sm_120;
222
+
223
+ using detail::is_exactly;
224
+ using detail::provides;
225
+ } // namespace target
226
+ } // namespace nv
227
+
228
+ #endif // C++11 && !defined(__CUDACC_RTC__)
229
+
230
+ #include <nv/detail/__target_macros>
231
+
232
+ #endif // __NV_TARGET_H
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/adjacent_difference.h ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 adjacent_difference.h
18
+ * \brief Compute difference between consecutive elements of a range
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/execution_policy.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ /*! \addtogroup transformations Transformations
37
+ * \{
38
+ */
39
+
40
+ /*! \p adjacent_difference calculates the differences of adjacent elements in the
41
+ * range <tt>[first, last)</tt>. That is, <tt>\*first</tt> is assigned to
42
+ * <tt>\*result</tt>, and, for each iterator \p i in the range
43
+ * <tt>[first + 1, last)</tt>, the difference of <tt>\*i</tt> and <tt>*(i - 1)</tt>
44
+ * is assigned to <tt>\*(result + (i - first))</tt>.
45
+ *
46
+ * This version of \p adjacent_difference uses <tt>operator-</tt> to calculate
47
+ * differences.
48
+ *
49
+ * The algorithm's execution is parallelized as determined by \p exec.
50
+ *
51
+ * \param exec The execution policy to use for parallelization.
52
+ * \param first The beginning of the input range.
53
+ * \param last The end of the input range.
54
+ * \param result The beginning of the output range.
55
+ * \return The iterator <tt>result + (last - first)</tt>
56
+ *
57
+ * \tparam DerivedPolicy The name of the derived execution policy.
58
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
59
+ * Iterator</a>, and \c x and \c y are objects of \p InputIterator's \c value_type, then \c x - \c is defined, and \p
60
+ * InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, and the return
61
+ * type of <tt>x - y</tt> is convertible to a type in \p OutputIterator's set of \c value_types. \tparam OutputIterator
62
+ * is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>.
63
+ *
64
+ * \remark Note that \p result is permitted to be the same iterator as \p first. This is
65
+ * useful for computing differences "in place".
66
+ *
67
+ * The following code snippet demonstrates how to use \p adjacent_difference to compute
68
+ * the difference between adjacent elements of a range using the \p thrust::device execution policy:
69
+ *
70
+ * \code
71
+ * #include <thrust/adjacent_difference.h>
72
+ * #include <thrust/device_vector.h>
73
+ * #include <thrust/execution_policy.h>
74
+ * ...
75
+ * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
76
+ * thrust::device_vector<int> d_data(h_data, h_data + 8);
77
+ * thrust::device_vector<int> d_result(8);
78
+ *
79
+ * thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin());
80
+ *
81
+ * // d_result is now [1, 1, -1, 1, -1, 1, -1, 1]
82
+ * \endcode
83
+ *
84
+ * \see https://en.cppreference.com/w/cpp/algorithm/adjacent_difference
85
+ * \see inclusive_scan
86
+ */
87
+ template <typename DerivedPolicy, typename InputIterator, typename OutputIterator>
88
+ _CCCL_HOST_DEVICE OutputIterator adjacent_difference(
89
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
90
+ InputIterator first,
91
+ InputIterator last,
92
+ OutputIterator result);
93
+
94
+ /*! \p adjacent_difference calculates the differences of adjacent elements in the
95
+ * range <tt>[first, last)</tt>. That is, <tt>*first</tt> is assigned to
96
+ * <tt>\*result</tt>, and, for each iterator \p i in the range
97
+ * <tt>[first + 1, last)</tt>, <tt>binary_op(\*i, \*(i - 1))</tt> is assigned to
98
+ * <tt>\*(result + (i - first))</tt>.
99
+ *
100
+ * This version of \p adjacent_difference uses the binary function \p binary_op to
101
+ * calculate differences.
102
+ *
103
+ * The algorithm's execution is parallelized as determined by \p exec.
104
+ *
105
+ * \param exec The execution policy to use for parallelization.
106
+ * \param first The beginning of the input range.
107
+ * \param last The end of the input range.
108
+ * \param result The beginning of the output range.
109
+ * \param binary_op The binary function used to compute differences.
110
+ * \return The iterator <tt>result + (last - first)</tt>
111
+ *
112
+ * \tparam DerivedPolicy The name of the derived execution policy.
113
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
114
+ * Iterator</a>, and \p InputIterator's \c value_type is convertible to \p BinaryFunction's \c first_argument_type and
115
+ * \c second_argument_type, and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of
116
+ * \c value_types. \tparam OutputIterator is a model of <a
117
+ * href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. \tparam BinaryFunction's \c
118
+ * result_type is convertible to a type in \p OutputIterator's set of \c value_types.
119
+ *
120
+ * \remark Note that \p result is permitted to be the same iterator as \p first. This is
121
+ * useful for computing differences "in place".
122
+ *
123
+ * The following code snippet demonstrates how to use \p adjacent_difference to compute
124
+ * the sum between adjacent elements of a range using the \p thrust::device execution policy:
125
+ *
126
+ * \code
127
+ * #include <thrust/adjacent_difference.h>
128
+ * #include <thrust/functional.h>
129
+ * #include <thrust/device_vector.h>
130
+ * #include <thrust/execution_policy.h>
131
+ * ...
132
+ * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
133
+ * thrust::device_vector<int> d_data(h_data, h_data + 8);
134
+ * thrust::device_vector<int> d_result(8);
135
+ *
136
+ * thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin(), thrust::plus<int>());
137
+ *
138
+ * // d_result is now [1, 3, 3, 3, 3, 3, 3, 3]
139
+ * \endcode
140
+ *
141
+ * \see https://en.cppreference.com/w/cpp/algorithm/adjacent_difference
142
+ * \see inclusive_scan
143
+ */
144
+ template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename BinaryFunction>
145
+ _CCCL_HOST_DEVICE OutputIterator adjacent_difference(
146
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
147
+ InputIterator first,
148
+ InputIterator last,
149
+ OutputIterator result,
150
+ BinaryFunction binary_op);
151
+
152
+ /*! \p adjacent_difference calculates the differences of adjacent elements in the
153
+ * range <tt>[first, last)</tt>. That is, <tt>\*first</tt> is assigned to
154
+ * <tt>\*result</tt>, and, for each iterator \p i in the range
155
+ * <tt>[first + 1, last)</tt>, the difference of <tt>\*i</tt> and <tt>*(i - 1)</tt>
156
+ * is assigned to <tt>\*(result + (i - first))</tt>.
157
+ *
158
+ * This version of \p adjacent_difference uses <tt>operator-</tt> to calculate
159
+ * differences.
160
+ *
161
+ * \param first The beginning of the input range.
162
+ * \param last The end of the input range.
163
+ * \param result The beginning of the output range.
164
+ * \return The iterator <tt>result + (last - first)</tt>
165
+ *
166
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
167
+ * Iterator</a>, and \c x and \c y are objects of \p InputIterator's \c value_type, then \c x - \c is defined, and \p
168
+ * InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, and the return
169
+ * type of <tt>x - y</tt> is convertible to a type in \p OutputIterator's set of \c value_types. \tparam OutputIterator
170
+ * is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>.
171
+ *
172
+ * \remark Note that \p result is permitted to be the same iterator as \p first. This is
173
+ * useful for computing differences "in place".
174
+ *
175
+ * The following code snippet demonstrates how to use \p adjacent_difference to compute
176
+ * the difference between adjacent elements of a range.
177
+ *
178
+ * \code
179
+ * #include <thrust/adjacent_difference.h>
180
+ * #include <thrust/device_vector.h>
181
+ * ...
182
+ * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
183
+ * thrust::device_vector<int> d_data(h_data, h_data + 8);
184
+ * thrust::device_vector<int> d_result(8);
185
+ *
186
+ * thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin());
187
+ *
188
+ * // d_result is now [1, 1, -1, 1, -1, 1, -1, 1]
189
+ * \endcode
190
+ *
191
+ * \see https://en.cppreference.com/w/cpp/algorithm/adjacent_difference
192
+ * \see inclusive_scan
193
+ */
194
+ template <typename InputIterator, typename OutputIterator>
195
+ OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);
196
+
197
+ /*! \p adjacent_difference calculates the differences of adjacent elements in the
198
+ * range <tt>[first, last)</tt>. That is, <tt>*first</tt> is assigned to
199
+ * <tt>\*result</tt>, and, for each iterator \p i in the range
200
+ * <tt>[first + 1, last)</tt>, <tt>binary_op(\*i, \*(i - 1))</tt> is assigned to
201
+ * <tt>\*(result + (i - first))</tt>.
202
+ *
203
+ * This version of \p adjacent_difference uses the binary function \p binary_op to
204
+ * calculate differences.
205
+ *
206
+ * \param first The beginning of the input range.
207
+ * \param last The end of the input range.
208
+ * \param result The beginning of the output range.
209
+ * \param binary_op The binary function used to compute differences.
210
+ * \return The iterator <tt>result + (last - first)</tt>
211
+ *
212
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
213
+ * Iterator</a>, and \p InputIterator's \c value_type is convertible to \p BinaryFunction's \c first_argument_type and
214
+ * \c second_argument_type, and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of
215
+ * \c value_types. \tparam OutputIterator is a model of <a
216
+ * href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. \tparam BinaryFunction's \c
217
+ * result_type is convertible to a type in \p OutputIterator's set of \c value_types.
218
+ *
219
+ * \remark Note that \p result is permitted to be the same iterator as \p first. This is
220
+ * useful for computing differences "in place".
221
+ *
222
+ * The following code snippet demonstrates how to use \p adjacent_difference to compute
223
+ * the sum between adjacent elements of a range.
224
+ *
225
+ * \code
226
+ * #include <thrust/adjacent_difference.h>
227
+ * #include <thrust/functional.h>
228
+ * #include <thrust/device_vector.h>
229
+ * ...
230
+ * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2};
231
+ * thrust::device_vector<int> d_data(h_data, h_data + 8);
232
+ * thrust::device_vector<int> d_result(8);
233
+ *
234
+ * thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin(), thrust::plus<int>());
235
+ *
236
+ * // d_result is now [1, 3, 3, 3, 3, 3, 3, 3]
237
+ * \endcode
238
+ *
239
+ * \see https://en.cppreference.com/w/cpp/algorithm/adjacent_difference
240
+ * \see inclusive_scan
241
+ */
242
+ template <typename InputIterator, typename OutputIterator, typename BinaryFunction>
243
+ OutputIterator
244
+ adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryFunction binary_op);
245
+
246
+ /*! \}
247
+ */
248
+
249
+ THRUST_NAMESPACE_END
250
+
251
+ #include <thrust/detail/adjacent_difference.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/advance.h ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 advance.h
18
+ * \brief Advance an iterator by a given distance.
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
+ THRUST_NAMESPACE_BEGIN
34
+
35
+ /*! \addtogroup iterators
36
+ * \{
37
+ */
38
+
39
+ /*! \p advance(i, n) increments the iterator \p i by the distance \p n.
40
+ * If <tt>n > 0</tt> it is equivalent to executing <tt>++i</tt> \p n
41
+ * times, and if <tt>n < 0</tt> it is equivalent to executing <tt>--i</tt>
42
+ * \p n times. If <tt>n == 0</tt>, the call has no effect.
43
+ *
44
+ * \param i The iterator to be advanced.
45
+ * \param n The distance by which to advance the iterator.
46
+ *
47
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
48
+ * Iterator</a>. \tparam Distance is an integral type that is convertible to \p InputIterator's distance type.
49
+ *
50
+ * \pre \p n shall be negative only for bidirectional and random access iterators.
51
+ *
52
+ * The following code snippet demonstrates how to use \p advance to increment
53
+ * an iterator a given number of times.
54
+ *
55
+ * \code
56
+ * #include <thrust/advance.h>
57
+ * #include <thrust/device_vector.h>
58
+ * ...
59
+ * thrust::device_vector<int> vec(13);
60
+ * thrust::device_vector<int>::iterator iter = vec.begin();
61
+ *
62
+ * thrust::advance(iter, 7);
63
+ *
64
+ * // iter - vec.begin() == 7
65
+ * \endcode
66
+ *
67
+ * \see https://en.cppreference.com/w/cpp/iterator/advance
68
+ */
69
+ template <typename InputIterator, typename Distance>
70
+ _CCCL_HOST_DEVICE void advance(InputIterator& i, Distance n);
71
+
72
+ /*! \p next(i, n) returns the \p n th successor of the iterator \p i.
73
+ *
74
+ * \param i An iterator.
75
+ * \param n The number of elements to advance.
76
+ *
77
+ * \tparam InputIterator must meet the <a
78
+ * href="https://en.cppreference.com/w/cpp/named_req/InputIterator">InputIterator</a>.
79
+ *
80
+ * \pre \p n shall be negative only for bidirectional and random access iterators.
81
+ *
82
+ * The following code snippet demonstrates how to use \p next.
83
+ *
84
+ * \code
85
+ * #include <thrust/advance.h>
86
+ * #include <thrust/device_vector.h>
87
+ * ...
88
+ * thrust::device_vector<int> vec(13);
89
+ * thrust::device_vector<int>::iterator i0 = vec.begin();
90
+ *
91
+ * auto i1 = thrust::next(i0);
92
+ *
93
+ * // i0 - vec.begin() == 0
94
+ * // i1 - vec.begin() == 1
95
+ * \endcode
96
+ *
97
+ * \see https://en.cppreference.com/w/cpp/iterator/next
98
+ */
99
+ #if 0 // Doxygen only
100
+ template <typename InputIterator, typename Distance>
101
+ _CCCL_HOST_DEVICE
102
+ InputIterator next(
103
+ InputIterator i
104
+ , typename iterator_traits<InputIterator>::difference_type n = 1
105
+ );
106
+ #endif
107
+
108
+ /*! \p prev(i, n) returns the \p n th predecessor of the iterator \p i.
109
+ *
110
+ * \param i An iterator.
111
+ * \param n The number of elements to descend.
112
+ *
113
+ * \tparam BidirectionalIterator must meet the <a
114
+ * href="https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator">BidirectionalIterator</a>.
115
+ *
116
+ * The following code snippet demonstrates how to use \p prev.
117
+ *
118
+ * \code
119
+ * #include <thrust/advance.h>
120
+ * #include <thrust/device_vector.h>
121
+ * ...
122
+ * thrust::device_vector<int> vec(13);
123
+ * thrust::device_vector<int>::iterator i0 = vec.end();
124
+ *
125
+ * auto i1 = thrust::prev(i0);
126
+ *
127
+ * // vec.end() - i0 == 0
128
+ * // vec.end() - i1 == 1
129
+ * \endcode
130
+ *
131
+ * \see https://en.cppreference.com/w/cpp/iterator/prev
132
+ */
133
+ #if 0 // Doxygen only
134
+ template <typename BidirectionalIterator, typename Distance>
135
+ _CCCL_HOST_DEVICE
136
+ BidirectionalIterator prev(
137
+ BidirectionalIterator i
138
+ , typename iterator_traits<BidirectionalIterator>::difference_type n = 1
139
+ );
140
+ #endif
141
+
142
+ /*! \} // end iterators
143
+ */
144
+
145
+ THRUST_NAMESPACE_END
146
+
147
+ #include <thrust/detail/advance.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/allocate_unique.h ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright (c) 2018 NVIDIA Corporation
2
+ // Author: Bryce Adelstein Lelbach <brycelelbach@gmail.com>
3
+ //
4
+ // Distributed under the Boost Software License v1.0 (boost.org/LICENSE_1_0.txt)
5
+
6
+ #pragma once
7
+
8
+ #include <thrust/detail/config.h>
9
+
10
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
11
+ # pragma GCC system_header
12
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
13
+ # pragma clang system_header
14
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
15
+ # pragma system_header
16
+ #endif // no system header
17
+ #include <thrust/detail/allocator/allocator_traits.h>
18
+ #include <thrust/detail/memory_algorithms.h>
19
+ #include <thrust/detail/memory_wrapper.h>
20
+ #include <thrust/detail/raw_pointer_cast.h>
21
+ #include <thrust/detail/type_deduction.h>
22
+
23
+ #include <cuda/std/utility>
24
+
25
+ THRUST_NAMESPACE_BEGIN
26
+
27
+ // wg21.link/p0316r0
28
+
29
+ ///////////////////////////////////////////////////////////////////////////////
30
+
31
+ namespace detail
32
+ {
33
+
34
+ template <typename Allocator, typename Pointer>
35
+ void allocator_delete_impl(Allocator const& alloc, Pointer p, std::false_type)
36
+ {
37
+ using traits =
38
+ typename detail::allocator_traits<typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>;
39
+
40
+ typename traits::allocator_type alloc_T(alloc);
41
+
42
+ if (nullptr != pointer_traits<Pointer>::get(p))
43
+ {
44
+ traits::destroy(alloc_T, thrust::raw_pointer_cast(p));
45
+ traits::deallocate(alloc_T, p, 1);
46
+ }
47
+ }
48
+
49
+ template <typename Allocator, typename Pointer>
50
+ void allocator_delete_impl(Allocator const& alloc, Pointer p, std::true_type)
51
+ {
52
+ using traits =
53
+ typename detail::allocator_traits<typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>;
54
+
55
+ typename traits::allocator_type alloc_T(alloc);
56
+
57
+ if (nullptr != pointer_traits<Pointer>::get(p))
58
+ {
59
+ traits::deallocate(alloc_T, p, 1);
60
+ }
61
+ }
62
+
63
+ } // namespace detail
64
+
65
+ template <typename T, typename Allocator, bool Uninitialized = false>
66
+ struct allocator_delete final
67
+ {
68
+ using allocator_type =
69
+ typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type::template rebind<T>::other;
70
+ using pointer = typename detail::allocator_traits<allocator_type>::pointer;
71
+
72
+ template <typename UAllocator>
73
+ allocator_delete(UAllocator&& other) noexcept
74
+ : alloc_(THRUST_FWD(other))
75
+ {}
76
+
77
+ template <typename U, typename UAllocator>
78
+ allocator_delete(allocator_delete<U, UAllocator> const& other) noexcept
79
+ : alloc_(other.get_allocator())
80
+ {}
81
+ template <typename U, typename UAllocator>
82
+ allocator_delete(allocator_delete<U, UAllocator>&& other) noexcept
83
+ : alloc_(std::move(other.get_allocator()))
84
+ {}
85
+
86
+ template <typename U, typename UAllocator>
87
+ allocator_delete& operator=(allocator_delete<U, UAllocator> const& other) noexcept
88
+ {
89
+ alloc_ = other.get_allocator();
90
+ return *this;
91
+ }
92
+ template <typename U, typename UAllocator>
93
+ allocator_delete& operator=(allocator_delete<U, UAllocator>&& other) noexcept
94
+ {
95
+ alloc_ = std::move(other.get_allocator());
96
+ return *this;
97
+ }
98
+
99
+ void operator()(pointer p)
100
+ {
101
+ std::integral_constant<bool, Uninitialized> ic;
102
+
103
+ detail::allocator_delete_impl(get_allocator(), p, ic);
104
+ }
105
+
106
+ allocator_type& get_allocator() noexcept
107
+ {
108
+ return alloc_;
109
+ }
110
+ allocator_type const& get_allocator() const noexcept
111
+ {
112
+ return alloc_;
113
+ }
114
+
115
+ void swap(allocator_delete& other) noexcept
116
+ {
117
+ using ::cuda::std::swap;
118
+ swap(alloc_, other.alloc_);
119
+ }
120
+
121
+ private:
122
+ allocator_type alloc_;
123
+ };
124
+
125
+ template <typename T, typename Allocator>
126
+ using uninitialized_allocator_delete = allocator_delete<T, Allocator, true>;
127
+
128
+ namespace detail
129
+ {
130
+
131
+ template <typename Allocator, typename Pointer, typename Size>
132
+ void array_allocator_delete_impl(Allocator const& alloc, Pointer p, Size count, std::false_type)
133
+ {
134
+ using traits =
135
+ typename detail::allocator_traits<typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>;
136
+
137
+ typename traits::allocator_type alloc_T(alloc);
138
+
139
+ if (nullptr != pointer_traits<Pointer>::get(p))
140
+ {
141
+ destroy_n(alloc_T, p, count);
142
+ traits::deallocate(alloc_T, p, count);
143
+ }
144
+ }
145
+
146
+ template <typename Allocator, typename Pointer, typename Size>
147
+ void array_allocator_delete_impl(Allocator const& alloc, Pointer p, Size count, std::true_type)
148
+ {
149
+ using traits =
150
+ typename detail::allocator_traits<typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>;
151
+
152
+ typename traits::allocator_type alloc_T(alloc);
153
+
154
+ if (nullptr != pointer_traits<Pointer>::get(p))
155
+ {
156
+ traits::deallocate(alloc_T, p, count);
157
+ }
158
+ }
159
+
160
+ } // namespace detail
161
+
162
+ template <typename T, typename Allocator, bool Uninitialized = false>
163
+ struct array_allocator_delete final
164
+ {
165
+ using allocator_type =
166
+ typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type::template rebind<T>::other;
167
+ using pointer = typename detail::allocator_traits<allocator_type>::pointer;
168
+
169
+ template <typename UAllocator>
170
+ array_allocator_delete(UAllocator&& other, std::size_t n) noexcept
171
+ : alloc_(THRUST_FWD(other))
172
+ , count_(n)
173
+ {}
174
+
175
+ template <typename U, typename UAllocator>
176
+ array_allocator_delete(array_allocator_delete<U, UAllocator> const& other) noexcept
177
+ : alloc_(other.get_allocator())
178
+ , count_(other.count_)
179
+ {}
180
+ template <typename U, typename UAllocator>
181
+ array_allocator_delete(array_allocator_delete<U, UAllocator>&& other) noexcept
182
+ : alloc_(std::move(other.get_allocator()))
183
+ , count_(other.count_)
184
+ {}
185
+
186
+ template <typename U, typename UAllocator>
187
+ array_allocator_delete& operator=(array_allocator_delete<U, UAllocator> const& other) noexcept
188
+ {
189
+ alloc_ = other.get_allocator();
190
+ count_ = other.count_;
191
+ return *this;
192
+ }
193
+ template <typename U, typename UAllocator>
194
+ array_allocator_delete& operator=(array_allocator_delete<U, UAllocator>&& other) noexcept
195
+ {
196
+ alloc_ = std::move(other.get_allocator());
197
+ count_ = other.count_;
198
+ return *this;
199
+ }
200
+
201
+ void operator()(pointer p)
202
+ {
203
+ std::integral_constant<bool, Uninitialized> ic;
204
+
205
+ detail::array_allocator_delete_impl(get_allocator(), p, count_, ic);
206
+ }
207
+
208
+ allocator_type& get_allocator() noexcept
209
+ {
210
+ return alloc_;
211
+ }
212
+ allocator_type const& get_allocator() const noexcept
213
+ {
214
+ return alloc_;
215
+ }
216
+
217
+ void swap(array_allocator_delete& other) noexcept
218
+ {
219
+ using ::cuda::std::swap;
220
+ swap(alloc_, other.alloc_);
221
+ swap(count_, other.count_);
222
+ }
223
+
224
+ private:
225
+ allocator_type alloc_;
226
+ std::size_t count_;
227
+ };
228
+
229
+ template <typename T, typename Allocator>
230
+ using uninitialized_array_allocator_delete = array_allocator_delete<T, Allocator, true>;
231
+
232
+ ///////////////////////////////////////////////////////////////////////////////
233
+
234
+ template <typename Pointer, typename Lambda>
235
+ struct tagged_deleter : Lambda
236
+ {
237
+ _CCCL_HOST_DEVICE tagged_deleter(Lambda&& l)
238
+ : Lambda(THRUST_FWD(l))
239
+ {}
240
+
241
+ using pointer = Pointer;
242
+ };
243
+
244
+ template <typename Pointer, typename Lambda>
245
+ _CCCL_HOST_DEVICE tagged_deleter<Pointer, Lambda> make_tagged_deleter(Lambda&& l)
246
+ {
247
+ return tagged_deleter<Pointer, Lambda>(THRUST_FWD(l));
248
+ }
249
+
250
+ ///////////////////////////////////////////////////////////////////////////////
251
+
252
+ template <typename T, typename Allocator, typename... Args>
253
+ _CCCL_HOST std::unique_ptr<
254
+ T,
255
+ allocator_delete<T,
256
+ typename detail::allocator_traits<typename std::remove_cv<
257
+ typename std::remove_reference<Allocator>::type>::type>::template rebind_traits<T>::allocator_type>>
258
+ allocate_unique(Allocator const& alloc, Args&&... args)
259
+ {
260
+ using traits = typename detail::allocator_traits<
261
+ typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>::template rebind_traits<T>;
262
+
263
+ typename traits::allocator_type alloc_T(alloc);
264
+
265
+ auto hold_deleter = make_tagged_deleter<typename traits::pointer>([&alloc_T](typename traits::pointer p) {
266
+ traits::deallocate(alloc_T, p, 1);
267
+ });
268
+ using hold_t = std::unique_ptr<T, decltype(hold_deleter)>;
269
+ auto hold = hold_t(traits::allocate(alloc_T, 1), hold_deleter);
270
+
271
+ traits::construct(alloc_T, thrust::raw_pointer_cast(hold.get()), THRUST_FWD(args)...);
272
+ auto deleter = allocator_delete<T, typename traits::allocator_type>(alloc);
273
+ return std::unique_ptr<T, decltype(deleter)>(hold.release(), std::move(deleter));
274
+ }
275
+
276
+ template <typename T, typename Allocator>
277
+ _CCCL_HOST
278
+ std::unique_ptr<T,
279
+ uninitialized_allocator_delete<
280
+ T,
281
+ typename detail::allocator_traits<typename std::remove_cv<
282
+ typename std::remove_reference<Allocator>::type>::type>::template rebind_traits<T>::allocator_type>>
283
+ uninitialized_allocate_unique(Allocator const& alloc)
284
+ {
285
+ using traits = typename detail::allocator_traits<
286
+ typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>::template rebind_traits<T>;
287
+
288
+ typename traits::allocator_type alloc_T(alloc);
289
+
290
+ auto hold_deleter = make_tagged_deleter<typename traits::pointer>([&alloc_T](typename traits::pointer p) {
291
+ traits::deallocate(alloc_T, p, 1);
292
+ });
293
+ using hold_t = std::unique_ptr<T, decltype(hold_deleter)>;
294
+ auto hold = hold_t(traits::allocate(alloc_T, 1), hold_deleter);
295
+
296
+ auto deleter = uninitialized_allocator_delete<T, typename traits::allocator_type>(alloc_T);
297
+ return std::unique_ptr<T, decltype(deleter)>(hold.release(), std::move(deleter));
298
+ }
299
+
300
+ template <typename T, typename Allocator, typename Size, typename... Args>
301
+ _CCCL_HOST std::unique_ptr<
302
+ T[],
303
+ array_allocator_delete<T,
304
+ typename detail::allocator_traits<typename std::remove_cv<typename std::remove_reference<
305
+ Allocator>::type>::type>::template rebind_traits<T>::allocator_type>>
306
+ allocate_unique_n(Allocator const& alloc, Size n, Args&&... args)
307
+ {
308
+ using traits = typename detail::allocator_traits<
309
+ typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>::template rebind_traits<T>;
310
+
311
+ typename traits::allocator_type alloc_T(alloc);
312
+
313
+ auto hold_deleter = make_tagged_deleter<typename traits::pointer>([n, &alloc_T](typename traits::pointer p) {
314
+ traits::deallocate(alloc_T, p, n);
315
+ });
316
+ using hold_t = std::unique_ptr<T[], decltype(hold_deleter)>;
317
+ auto hold = hold_t(traits::allocate(alloc_T, n), hold_deleter);
318
+
319
+ uninitialized_construct_n_with_allocator(alloc_T, hold.get(), n, THRUST_FWD(args)...);
320
+ auto deleter = array_allocator_delete<T, typename traits::allocator_type>(alloc_T, n);
321
+ return std::unique_ptr<T[], decltype(deleter)>(hold.release(), std::move(deleter));
322
+ }
323
+
324
+ template <typename T, typename Allocator, typename Size>
325
+ _CCCL_HOST
326
+ std::unique_ptr<T[],
327
+ uninitialized_array_allocator_delete<
328
+ T,
329
+ typename detail::allocator_traits<typename std::remove_cv<
330
+ typename std::remove_reference<Allocator>::type>::type>::template rebind_traits<T>::allocator_type>>
331
+ uninitialized_allocate_unique_n(Allocator const& alloc, Size n)
332
+ {
333
+ using traits = typename detail::allocator_traits<
334
+ typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>::template rebind_traits<T>;
335
+
336
+ typename traits::allocator_type alloc_T(alloc);
337
+
338
+ auto hold_deleter = make_tagged_deleter<typename traits::pointer>([n, &alloc_T](typename traits::pointer p) {
339
+ traits::deallocate(alloc_T, p, n);
340
+ });
341
+ using hold_t = std::unique_ptr<T[], decltype(hold_deleter)>;
342
+ auto hold = hold_t(traits::allocate(alloc_T, n), hold_deleter);
343
+
344
+ auto deleter = uninitialized_array_allocator_delete<T, typename traits::allocator_type>(alloc_T, n);
345
+ return std::unique_ptr<T[], decltype(deleter)>(hold.release(), std::move(deleter));
346
+ }
347
+
348
+ ///////////////////////////////////////////////////////////////////////////////
349
+
350
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/binary_search.h ADDED
@@ -0,0 +1,1887 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 binary_search.h
18
+ * \brief Search for values in sorted ranges.
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/execution_policy.h>
33
+ #include <thrust/pair.h>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+ /*! \addtogroup algorithms
38
+ */
39
+
40
+ /*! \addtogroup searching
41
+ * \ingroup algorithms
42
+ * \{
43
+ */
44
+
45
+ /*! \addtogroup binary_search Binary Search
46
+ * \ingroup searching
47
+ * \{
48
+ */
49
+
50
+ //////////////////////
51
+ // Scalar Functions //
52
+ //////////////////////
53
+
54
+ /*! \p lower_bound is a version of binary search: it attempts to find
55
+ * the element value in an ordered range <tt>[first, last)</tt>.
56
+ * Specifically, it returns the first position where value could be
57
+ * inserted without violating the ordering. This version of
58
+ * \p lower_bound uses <tt>operator<</tt> for comparison and returns
59
+ * the furthermost iterator \c i in <tt>[first, last)</tt> such that,
60
+ * for every iterator \c j in <tt>[first, i)</tt>, <tt>*j < value</tt>.
61
+ *
62
+ * The algorithm's execution is parallelized as determined by \p exec.
63
+ *
64
+ * \param exec The execution policy to use for parallelization.
65
+ * \param first The beginning of the ordered sequence.
66
+ * \param last The end of the ordered sequence.
67
+ * \param value The value to be searched.
68
+ * \return The furthermost iterator \c i, such that <tt>*i < value</tt>.
69
+ *
70
+ * \tparam DerivedPolicy The name of the derived execution policy.
71
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
72
+ * Iterator</a>. \tparam LessThanComparable is a model of <a
73
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
74
+ *
75
+ * The following code snippet demonstrates how to use \p lower_bound
76
+ * to search for values in a ordered range using the \p thrust::device execution policy for parallelization:
77
+ *
78
+ * \code
79
+ * #include <thrust/binary_search.h>
80
+ * #include <thrust/device_vector.h>
81
+ * #include <thrust/execution_policy.h>
82
+ * ...
83
+ * thrust::device_vector<int> input(5);
84
+ *
85
+ * input[0] = 0;
86
+ * input[1] = 2;
87
+ * input[2] = 5;
88
+ * input[3] = 7;
89
+ * input[4] = 8;
90
+ *
91
+ * thrust::lower_bound(thrust::device, input.begin(), input.end(), 0); // returns input.begin()
92
+ * thrust::lower_bound(thrust::device, input.begin(), input.end(), 1); // returns input.begin() + 1
93
+ * thrust::lower_bound(thrust::device, input.begin(), input.end(), 2); // returns input.begin() + 1
94
+ * thrust::lower_bound(thrust::device, input.begin(), input.end(), 3); // returns input.begin() + 2
95
+ * thrust::lower_bound(thrust::device, input.begin(), input.end(), 8); // returns input.begin() + 4
96
+ * thrust::lower_bound(thrust::device, input.begin(), input.end(), 9); // returns input.end()
97
+ * \endcode
98
+ *
99
+ * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound
100
+ * \see \p upper_bound
101
+ * \see \p equal_range
102
+ * \see \p binary_search
103
+ */
104
+ template <typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
105
+ _CCCL_HOST_DEVICE ForwardIterator lower_bound(
106
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
107
+ ForwardIterator first,
108
+ ForwardIterator last,
109
+ const LessThanComparable& value);
110
+
111
+ /*! \p lower_bound is a version of binary search: it attempts to find
112
+ * the element value in an ordered range <tt>[first, last)</tt>.
113
+ * Specifically, it returns the first position where value could be
114
+ * inserted without violating the ordering. This version of
115
+ * \p lower_bound uses <tt>operator<</tt> for comparison and returns
116
+ * the furthermost iterator \c i in <tt>[first, last)</tt> such that,
117
+ * for every iterator \c j in <tt>[first, i)</tt>, <tt>*j < value</tt>.
118
+ *
119
+ * \param first The beginning of the ordered sequence.
120
+ * \param last The end of the ordered sequence.
121
+ * \param value The value to be searched.
122
+ * \return The furthermost iterator \c i, such that <tt>*i < value</tt>.
123
+ *
124
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
125
+ * Iterator</a>. \tparam LessThanComparable is a model of <a
126
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
127
+ *
128
+ * The following code snippet demonstrates how to use \p lower_bound
129
+ * to search for values in a ordered range.
130
+ *
131
+ * \code
132
+ * #include <thrust/binary_search.h>
133
+ * #include <thrust/device_vector.h>
134
+ * ...
135
+ * thrust::device_vector<int> input(5);
136
+ *
137
+ * input[0] = 0;
138
+ * input[1] = 2;
139
+ * input[2] = 5;
140
+ * input[3] = 7;
141
+ * input[4] = 8;
142
+ *
143
+ * thrust::lower_bound(input.begin(), input.end(), 0); // returns input.begin()
144
+ * thrust::lower_bound(input.begin(), input.end(), 1); // returns input.begin() + 1
145
+ * thrust::lower_bound(input.begin(), input.end(), 2); // returns input.begin() + 1
146
+ * thrust::lower_bound(input.begin(), input.end(), 3); // returns input.begin() + 2
147
+ * thrust::lower_bound(input.begin(), input.end(), 8); // returns input.begin() + 4
148
+ * thrust::lower_bound(input.begin(), input.end(), 9); // returns input.end()
149
+ * \endcode
150
+ *
151
+ * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound
152
+ * \see \p upper_bound
153
+ * \see \p equal_range
154
+ * \see \p binary_search
155
+ */
156
+ template <class ForwardIterator, class LessThanComparable>
157
+ ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const LessThanComparable& value);
158
+
159
+ /*! \p lower_bound is a version of binary search: it attempts to find
160
+ * the element value in an ordered range <tt>[first, last)</tt>.
161
+ * Specifically, it returns the first position where value could be
162
+ * inserted without violating the ordering. This version of
163
+ * \p lower_bound uses function object \c comp for comparison
164
+ * and returns the furthermost iterator \c i in <tt>[first, last)</tt>
165
+ * such that, for every iterator \c j in <tt>[first, i)</tt>,
166
+ * <tt>comp(*j, value)</tt> is \c true.
167
+ *
168
+ * The algorithm's execution is parallelized as determined by \p exec.
169
+ *
170
+ * \param exec The execution policy to use for parallelization.
171
+ * \param first The beginning of the ordered sequence.
172
+ * \param last The end of the ordered sequence.
173
+ * \param value The value to be searched.
174
+ * \param comp The comparison operator.
175
+ * \return The furthermost iterator \c i, such that <tt>comp(*i, value)</tt> is \c true.
176
+ *
177
+ * \tparam DerivedPolicy The name of the derived execution policy.
178
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
179
+ * Iterator</a>. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of
180
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
181
+ *
182
+ * The following code snippet demonstrates how to use \p lower_bound
183
+ * to search for values in a ordered range using the \p thrust::device execution policy for parallelization:
184
+ *
185
+ * \code
186
+ * #include <thrust/binary_search.h>
187
+ * #include <thrust/device_vector.h>
188
+ * #include <thrust/functional.h>
189
+ * #include <thrust/execution_policy.h>
190
+ * ...
191
+ * thrust::device_vector<int> input(5);
192
+ *
193
+ * input[0] = 0;
194
+ * input[1] = 2;
195
+ * input[2] = 5;
196
+ * input[3] = 7;
197
+ * input[4] = 8;
198
+ *
199
+ * thrust::lower_bound(input.begin(), input.end(), 0, thrust::less<int>()); // returns input.begin()
200
+ * thrust::lower_bound(input.begin(), input.end(), 1, thrust::less<int>()); // returns input.begin() + 1
201
+ * thrust::lower_bound(input.begin(), input.end(), 2, thrust::less<int>()); // returns input.begin() + 1
202
+ * thrust::lower_bound(input.begin(), input.end(), 3, thrust::less<int>()); // returns input.begin() + 2
203
+ * thrust::lower_bound(input.begin(), input.end(), 8, thrust::less<int>()); // returns input.begin() + 4
204
+ * thrust::lower_bound(input.begin(), input.end(), 9, thrust::less<int>()); // returns input.end()
205
+ * \endcode
206
+ *
207
+ * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound
208
+ * \see \p upper_bound
209
+ * \see \p equal_range
210
+ * \see \p binary_search
211
+ */
212
+ template <typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
213
+ _CCCL_HOST_DEVICE ForwardIterator lower_bound(
214
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
215
+ ForwardIterator first,
216
+ ForwardIterator last,
217
+ const T& value,
218
+ StrictWeakOrdering comp);
219
+
220
+ /*! \p lower_bound is a version of binary search: it attempts to find
221
+ * the element value in an ordered range <tt>[first, last)</tt>.
222
+ * Specifically, it returns the first position where value could be
223
+ * inserted without violating the ordering. This version of
224
+ * \p lower_bound uses function object \c comp for comparison
225
+ * and returns the furthermost iterator \c i in <tt>[first, last)</tt>
226
+ * such that, for every iterator \c j in <tt>[first, i)</tt>,
227
+ * <tt>comp(*j, value)</tt> is \c true.
228
+ *
229
+ * \param first The beginning of the ordered sequence.
230
+ * \param last The end of the ordered sequence.
231
+ * \param value The value to be searched.
232
+ * \param comp The comparison operator.
233
+ * \return The furthermost iterator \c i, such that <tt>comp(*i, value)</tt> is \c true.
234
+ *
235
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
236
+ * Iterator</a>. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of
237
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
238
+ *
239
+ * The following code snippet demonstrates how to use \p lower_bound
240
+ * to search for values in a ordered range.
241
+ *
242
+ * \code
243
+ * #include <thrust/binary_search.h>
244
+ * #include <thrust/device_vector.h>
245
+ * #include <thrust/functional.h>
246
+ * ...
247
+ * thrust::device_vector<int> input(5);
248
+ *
249
+ * input[0] = 0;
250
+ * input[1] = 2;
251
+ * input[2] = 5;
252
+ * input[3] = 7;
253
+ * input[4] = 8;
254
+ *
255
+ * thrust::lower_bound(input.begin(), input.end(), 0, thrust::less<int>()); // returns input.begin()
256
+ * thrust::lower_bound(input.begin(), input.end(), 1, thrust::less<int>()); // returns input.begin() + 1
257
+ * thrust::lower_bound(input.begin(), input.end(), 2, thrust::less<int>()); // returns input.begin() + 1
258
+ * thrust::lower_bound(input.begin(), input.end(), 3, thrust::less<int>()); // returns input.begin() + 2
259
+ * thrust::lower_bound(input.begin(), input.end(), 8, thrust::less<int>()); // returns input.begin() + 4
260
+ * thrust::lower_bound(input.begin(), input.end(), 9, thrust::less<int>()); // returns input.end()
261
+ * \endcode
262
+ *
263
+ * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound
264
+ * \see \p upper_bound
265
+ * \see \p equal_range
266
+ * \see \p binary_search
267
+ */
268
+ template <class ForwardIterator, class T, class StrictWeakOrdering>
269
+ ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp);
270
+
271
+ /*! \p upper_bound is a version of binary search: it attempts to find
272
+ * the element value in an ordered range <tt>[first, last)</tt>.
273
+ * Specifically, it returns the last position where value could be
274
+ * inserted without violating the ordering. This version of
275
+ * \p upper_bound uses <tt>operator<</tt> for comparison and returns
276
+ * the furthermost iterator \c i in <tt>[first, last)</tt> such that,
277
+ * for every iterator \c j in <tt>[first, i)</tt>, <tt>value < *j</tt>
278
+ * is \c false.
279
+ *
280
+ * The algorithm's execution is parallelized as determined by \p exec.
281
+ *
282
+ * \param exec The execution policy to use for parallelization.
283
+ * \param first The beginning of the ordered sequence.
284
+ * \param last The end of the ordered sequence.
285
+ * \param value The value to be searched.
286
+ * \return The furthermost iterator \c i, such that <tt>value < *i</tt> is \c false.
287
+ *
288
+ * \tparam DerivedPolicy The name of the derived execution policy.
289
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
290
+ * Iterator</a>. \tparam LessThanComparable is a model of <a
291
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
292
+ *
293
+ * The following code snippet demonstrates how to use \p upper_bound
294
+ * to search for values in a ordered range using the \p thrust::device execution policy for parallelism:
295
+ *
296
+ * \code
297
+ * #include <thrust/binary_search.h>
298
+ * #include <thrust/device_vector.h>
299
+ * #include <thrust/execution_policy.h>
300
+ * ...
301
+ * thrust::device_vector<int> input(5);
302
+ *
303
+ * input[0] = 0;
304
+ * input[1] = 2;
305
+ * input[2] = 5;
306
+ * input[3] = 7;
307
+ * input[4] = 8;
308
+ *
309
+ * thrust::upper_bound(thrust::device, input.begin(), input.end(), 0); // returns input.begin() + 1
310
+ * thrust::upper_bound(thrust::device, input.begin(), input.end(), 1); // returns input.begin() + 1
311
+ * thrust::upper_bound(thrust::device, input.begin(), input.end(), 2); // returns input.begin() + 2
312
+ * thrust::upper_bound(thrust::device, input.begin(), input.end(), 3); // returns input.begin() + 2
313
+ * thrust::upper_bound(thrust::device, input.begin(), input.end(), 8); // returns input.end()
314
+ * thrust::upper_bound(thrust::device, input.begin(), input.end(), 9); // returns input.end()
315
+ * \endcode
316
+ *
317
+ * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound
318
+ * \see \p lower_bound
319
+ * \see \p equal_range
320
+ * \see \p binary_search
321
+ */
322
+ template <typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
323
+ _CCCL_HOST_DEVICE ForwardIterator upper_bound(
324
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
325
+ ForwardIterator first,
326
+ ForwardIterator last,
327
+ const LessThanComparable& value);
328
+
329
+ /*! \p upper_bound is a version of binary search: it attempts to find
330
+ * the element value in an ordered range <tt>[first, last)</tt>.
331
+ * Specifically, it returns the last position where value could be
332
+ * inserted without violating the ordering. This version of
333
+ * \p upper_bound uses <tt>operator<</tt> for comparison and returns
334
+ * the furthermost iterator \c i in <tt>[first, last)</tt> such that,
335
+ * for every iterator \c j in <tt>[first, i)</tt>, <tt>value < *j</tt>
336
+ * is \c false.
337
+ *
338
+ * \param first The beginning of the ordered sequence.
339
+ * \param last The end of the ordered sequence.
340
+ * \param value The value to be searched.
341
+ * \return The furthermost iterator \c i, such that <tt>value < *i</tt> is \c false.
342
+ *
343
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
344
+ * Iterator</a>. \tparam LessThanComparable is a model of <a
345
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
346
+ *
347
+ * The following code snippet demonstrates how to use \p upper_bound
348
+ * to search for values in a ordered range.
349
+ *
350
+ * \code
351
+ * #include <thrust/binary_search.h>
352
+ * #include <thrust/device_vector.h>
353
+ * ...
354
+ * thrust::device_vector<int> input(5);
355
+ *
356
+ * input[0] = 0;
357
+ * input[1] = 2;
358
+ * input[2] = 5;
359
+ * input[3] = 7;
360
+ * input[4] = 8;
361
+ *
362
+ * thrust::upper_bound(input.begin(), input.end(), 0); // returns input.begin() + 1
363
+ * thrust::upper_bound(input.begin(), input.end(), 1); // returns input.begin() + 1
364
+ * thrust::upper_bound(input.begin(), input.end(), 2); // returns input.begin() + 2
365
+ * thrust::upper_bound(input.begin(), input.end(), 3); // returns input.begin() + 2
366
+ * thrust::upper_bound(input.begin(), input.end(), 8); // returns input.end()
367
+ * thrust::upper_bound(input.begin(), input.end(), 9); // returns input.end()
368
+ * \endcode
369
+ *
370
+ * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound
371
+ * \see \p lower_bound
372
+ * \see \p equal_range
373
+ * \see \p binary_search
374
+ */
375
+ template <class ForwardIterator, class LessThanComparable>
376
+ ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const LessThanComparable& value);
377
+
378
+ /*! \p upper_bound is a version of binary search: it attempts to find
379
+ * the element value in an ordered range <tt>[first, last)</tt>.
380
+ * Specifically, it returns the last position where value could be
381
+ * inserted without violating the ordering. This version of
382
+ * \p upper_bound uses function object \c comp for comparison and returns
383
+ * the furthermost iterator \c i in <tt>[first, last)</tt> such that,
384
+ * for every iterator \c j in <tt>[first, i)</tt>, <tt>comp(value, *j)</tt>
385
+ * is \c false.
386
+ *
387
+ * The algorithm's execution is parallelized as determined by \p exec.
388
+ *
389
+ * \param exec The execution policy to use for parallelization.
390
+ * \param first The beginning of the ordered sequence.
391
+ * \param last The end of the ordered sequence.
392
+ * \param value The value to be searched.
393
+ * \param comp The comparison operator.
394
+ * \return The furthermost iterator \c i, such that <tt>comp(value, *i)</tt> is \c false.
395
+ *
396
+ * \tparam DerivedPolicy The name of the derived execution policy.
397
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
398
+ * Iterator</a>. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of
399
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
400
+ *
401
+ * The following code snippet demonstrates how to use \p upper_bound
402
+ * to search for values in a ordered range using the \p thrust::device execution policy for parallelization:
403
+ *
404
+ * \code
405
+ * #include <thrust/binary_search.h>
406
+ * #include <thrust/device_vector.h>
407
+ * #include <thrust/functional.h>
408
+ * #include <thrust/execution_policy.h>
409
+ * ...
410
+ * thrust::device_vector<int> input(5);
411
+ *
412
+ * input[0] = 0;
413
+ * input[1] = 2;
414
+ * input[2] = 5;
415
+ * input[3] = 7;
416
+ * input[4] = 8;
417
+ *
418
+ * thrust::upper_bound(thrust::device, input.begin(), input.end(), 0, thrust::less<int>()); // returns input.begin() +
419
+ * 1 thrust::upper_bound(thrust::device, input.begin(), input.end(), 1, thrust::less<int>()); // returns input.begin() +
420
+ * 1 thrust::upper_bound(thrust::device, input.begin(), input.end(), 2, thrust::less<int>()); // returns input.begin() +
421
+ * 2 thrust::upper_bound(thrust::device, input.begin(), input.end(), 3, thrust::less<int>()); // returns input.begin() +
422
+ * 2 thrust::upper_bound(thrust::device, input.begin(), input.end(), 8, thrust::less<int>()); // returns input.end()
423
+ * thrust::upper_bound(thrust::device, input.begin(), input.end(), 9, thrust::less<int>()); // returns input.end()
424
+ * \endcode
425
+ *
426
+ * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound
427
+ * \see \p lower_bound
428
+ * \see \p equal_range
429
+ * \see \p binary_search
430
+ */
431
+ template <typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
432
+ _CCCL_HOST_DEVICE ForwardIterator upper_bound(
433
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
434
+ ForwardIterator first,
435
+ ForwardIterator last,
436
+ const T& value,
437
+ StrictWeakOrdering comp);
438
+
439
+ /*! \p upper_bound is a version of binary search: it attempts to find
440
+ * the element value in an ordered range <tt>[first, last)</tt>.
441
+ * Specifically, it returns the last position where value could be
442
+ * inserted without violating the ordering. This version of
443
+ * \p upper_bound uses function object \c comp for comparison and returns
444
+ * the furthermost iterator \c i in <tt>[first, last)</tt> such that,
445
+ * for every iterator \c j in <tt>[first, i)</tt>, <tt>comp(value, *j)</tt>
446
+ * is \c false.
447
+ *
448
+ * \param first The beginning of the ordered sequence.
449
+ * \param last The end of the ordered sequence.
450
+ * \param value The value to be searched.
451
+ * \param comp The comparison operator.
452
+ * \return The furthermost iterator \c i, such that <tt>comp(value, *i)</tt> is \c false.
453
+ *
454
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
455
+ * Iterator</a>. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of
456
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
457
+ *
458
+ * The following code snippet demonstrates how to use \p upper_bound
459
+ * to search for values in a ordered range.
460
+ *
461
+ * \code
462
+ * #include <thrust/binary_search.h>
463
+ * #include <thrust/device_vector.h>
464
+ * #include <thrust/functional.h>
465
+ * ...
466
+ * thrust::device_vector<int> input(5);
467
+ *
468
+ * input[0] = 0;
469
+ * input[1] = 2;
470
+ * input[2] = 5;
471
+ * input[3] = 7;
472
+ * input[4] = 8;
473
+ *
474
+ * thrust::upper_bound(input.begin(), input.end(), 0, thrust::less<int>()); // returns input.begin() + 1
475
+ * thrust::upper_bound(input.begin(), input.end(), 1, thrust::less<int>()); // returns input.begin() + 1
476
+ * thrust::upper_bound(input.begin(), input.end(), 2, thrust::less<int>()); // returns input.begin() + 2
477
+ * thrust::upper_bound(input.begin(), input.end(), 3, thrust::less<int>()); // returns input.begin() + 2
478
+ * thrust::upper_bound(input.begin(), input.end(), 8, thrust::less<int>()); // returns input.end()
479
+ * thrust::upper_bound(input.begin(), input.end(), 9, thrust::less<int>()); // returns input.end()
480
+ * \endcode
481
+ *
482
+ * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound
483
+ * \see \p lower_bound
484
+ * \see \p equal_range
485
+ * \see \p binary_search
486
+ */
487
+ template <class ForwardIterator, class T, class StrictWeakOrdering>
488
+ ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp);
489
+
490
+ /*! \p binary_search is a version of binary search: it attempts to find
491
+ * the element value in an ordered range <tt>[first, last)</tt>.
492
+ * It returns \c true if an element that is equivalent to \c value
493
+ * is present in <tt>[first, last)</tt> and \c false if no such element
494
+ * exists. Specifically, this version returns \c true if and only if
495
+ * there exists an iterator \c i in <tt>[first, last)</tt> such that
496
+ * <tt>*i < value</tt> and <tt>value < *i</tt> are both \c false.
497
+ *
498
+ * The algorithm's execution is parallelized as determined by \p exec.
499
+ *
500
+ * \param exec The execution policy to use for parallelization.
501
+ * \param first The beginning of the ordered sequence.
502
+ * \param last The end of the ordered sequence.
503
+ * \param value The value to be searched.
504
+ * \return \c true if an equivalent element exists in <tt>[first, last)</tt>, otherwise \c false.
505
+ *
506
+ * \tparam DerivedPolicy The name of the derived execution policy.
507
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
508
+ * Iterator</a>. \tparam LessThanComparable is a model of <a
509
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
510
+ *
511
+ * The following code snippet demonstrates how to use \p binary_search
512
+ * to search for values in a ordered range using the \p thrust::device execution policy for parallelization:
513
+ *
514
+ * \code
515
+ * #include <thrust/binary_search.h>
516
+ * #include <thrust/device_vector.h>
517
+ * #include <thrust/execution_policy.h>
518
+ * ...
519
+ * thrust::device_vector<int> input(5);
520
+ *
521
+ * input[0] = 0;
522
+ * input[1] = 2;
523
+ * input[2] = 5;
524
+ * input[3] = 7;
525
+ * input[4] = 8;
526
+ *
527
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 0); // returns true
528
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 1); // returns false
529
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 2); // returns true
530
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 3); // returns false
531
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 8); // returns true
532
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 9); // returns false
533
+ * \endcode
534
+ *
535
+ * \see https://en.cppreference.com/w/cpp/algorithm/binary_search
536
+ * \see \p lower_bound
537
+ * \see \p upper_bound
538
+ * \see \p equal_range
539
+ */
540
+ template <typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
541
+ _CCCL_HOST_DEVICE bool binary_search(
542
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
543
+ ForwardIterator first,
544
+ ForwardIterator last,
545
+ const LessThanComparable& value);
546
+
547
+ /*! \p binary_search is a version of binary search: it attempts to find
548
+ * the element value in an ordered range <tt>[first, last)</tt>.
549
+ * It returns \c true if an element that is equivalent to \c value
550
+ * is present in <tt>[first, last)</tt> and \c false if no such element
551
+ * exists. Specifically, this version returns \c true if and only if
552
+ * there exists an iterator \c i in <tt>[first, last)</tt> such that
553
+ * <tt>*i < value</tt> and <tt>value < *i</tt> are both \c false.
554
+ *
555
+ * \param first The beginning of the ordered sequence.
556
+ * \param last The end of the ordered sequence.
557
+ * \param value The value to be searched.
558
+ * \return \c true if an equivalent element exists in <tt>[first, last)</tt>, otherwise \c false.
559
+ *
560
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
561
+ * Iterator</a>. \tparam LessThanComparable is a model of <a
562
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
563
+ *
564
+ * The following code snippet demonstrates how to use \p binary_search
565
+ * to search for values in a ordered range.
566
+ *
567
+ * \code
568
+ * #include <thrust/binary_search.h>
569
+ * #include <thrust/device_vector.h>
570
+ * ...
571
+ * thrust::device_vector<int> input(5);
572
+ *
573
+ * input[0] = 0;
574
+ * input[1] = 2;
575
+ * input[2] = 5;
576
+ * input[3] = 7;
577
+ * input[4] = 8;
578
+ *
579
+ * thrust::binary_search(input.begin(), input.end(), 0); // returns true
580
+ * thrust::binary_search(input.begin(), input.end(), 1); // returns false
581
+ * thrust::binary_search(input.begin(), input.end(), 2); // returns true
582
+ * thrust::binary_search(input.begin(), input.end(), 3); // returns false
583
+ * thrust::binary_search(input.begin(), input.end(), 8); // returns true
584
+ * thrust::binary_search(input.begin(), input.end(), 9); // returns false
585
+ * \endcode
586
+ *
587
+ * \see https://en.cppreference.com/w/cpp/algorithm/binary_search
588
+ * \see \p lower_bound
589
+ * \see \p upper_bound
590
+ * \see \p equal_range
591
+ */
592
+ template <class ForwardIterator, class LessThanComparable>
593
+ bool binary_search(ForwardIterator first, ForwardIterator last, const LessThanComparable& value);
594
+
595
+ /*! \p binary_search is a version of binary search: it attempts to find
596
+ * the element value in an ordered range <tt>[first, last)</tt>.
597
+ * It returns \c true if an element that is equivalent to \c value
598
+ * is present in <tt>[first, last)</tt> and \c false if no such element
599
+ * exists. Specifically, this version returns \c true if and only if
600
+ * there exists an iterator \c i in <tt>[first, last)</tt> such that
601
+ * <tt>comp(*i, value)</tt> and <tt>comp(value, *i)</tt> are both \c false.
602
+ *
603
+ * The algorithm's execution is parallelized as determined by \p exec.
604
+ *
605
+ * \param exec The execution policy to use for parallelization.
606
+ * \param first The beginning of the ordered sequence.
607
+ * \param last The end of the ordered sequence.
608
+ * \param value The value to be searched.
609
+ * \param comp The comparison operator.
610
+ * \return \c true if an equivalent element exists in <tt>[first, last)</tt>, otherwise \c false.
611
+ *
612
+ * \tparam DerivedPolicy The name of the derived execution policy.
613
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
614
+ * Iterator</a>. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of
615
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
616
+ *
617
+ * The following code snippet demonstrates how to use \p binary_search
618
+ * to search for values in a ordered range using the \p thrust::device execution policy for parallelization:
619
+ *
620
+ * \code
621
+ * #include <thrust/binary_search.h>
622
+ * #include <thrust/device_vector.h>
623
+ * #include <thrust/functional.h>
624
+ * #include <thrust/execution_policy.h>
625
+ * ...
626
+ * thrust::device_vector<int> input(5);
627
+ *
628
+ * input[0] = 0;
629
+ * input[1] = 2;
630
+ * input[2] = 5;
631
+ * input[3] = 7;
632
+ * input[4] = 8;
633
+ *
634
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 0, thrust::less<int>()); // returns true
635
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 1, thrust::less<int>()); // returns false
636
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 2, thrust::less<int>()); // returns true
637
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 3, thrust::less<int>()); // returns false
638
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 8, thrust::less<int>()); // returns true
639
+ * thrust::binary_search(thrust::device, input.begin(), input.end(), 9, thrust::less<int>()); // returns false
640
+ * \endcode
641
+ *
642
+ * \see https://en.cppreference.com/w/cpp/algorithm/binary_search
643
+ * \see \p lower_bound
644
+ * \see \p upper_bound
645
+ * \see \p equal_range
646
+ */
647
+ template <typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
648
+ _CCCL_HOST_DEVICE bool binary_search(
649
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
650
+ ForwardIterator first,
651
+ ForwardIterator last,
652
+ const T& value,
653
+ StrictWeakOrdering comp);
654
+
655
+ /*! \p binary_search is a version of binary search: it attempts to find
656
+ * the element value in an ordered range <tt>[first, last)</tt>.
657
+ * It returns \c true if an element that is equivalent to \c value
658
+ * is present in <tt>[first, last)</tt> and \c false if no such element
659
+ * exists. Specifically, this version returns \c true if and only if
660
+ * there exists an iterator \c i in <tt>[first, last)</tt> such that
661
+ * <tt>comp(*i, value)</tt> and <tt>comp(value, *i)</tt> are both \c false.
662
+ *
663
+ * \param first The beginning of the ordered sequence.
664
+ * \param last The end of the ordered sequence.
665
+ * \param value The value to be searched.
666
+ * \param comp The comparison operator.
667
+ * \return \c true if an equivalent element exists in <tt>[first, last)</tt>, otherwise \c false.
668
+ *
669
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
670
+ * Iterator</a>. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of
671
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
672
+ *
673
+ * The following code snippet demonstrates how to use \p binary_search
674
+ * to search for values in a ordered range.
675
+ *
676
+ * \code
677
+ * #include <thrust/binary_search.h>
678
+ * #include <thrust/device_vector.h>
679
+ * #include <thrust/functional.h>
680
+ * ...
681
+ * thrust::device_vector<int> input(5);
682
+ *
683
+ * input[0] = 0;
684
+ * input[1] = 2;
685
+ * input[2] = 5;
686
+ * input[3] = 7;
687
+ * input[4] = 8;
688
+ *
689
+ * thrust::binary_search(input.begin(), input.end(), 0, thrust::less<int>()); // returns true
690
+ * thrust::binary_search(input.begin(), input.end(), 1, thrust::less<int>()); // returns false
691
+ * thrust::binary_search(input.begin(), input.end(), 2, thrust::less<int>()); // returns true
692
+ * thrust::binary_search(input.begin(), input.end(), 3, thrust::less<int>()); // returns false
693
+ * thrust::binary_search(input.begin(), input.end(), 8, thrust::less<int>()); // returns true
694
+ * thrust::binary_search(input.begin(), input.end(), 9, thrust::less<int>()); // returns false
695
+ * \endcode
696
+ *
697
+ * \see https://en.cppreference.com/w/cpp/algorithm/binary_search
698
+ * \see \p lower_bound
699
+ * \see \p upper_bound
700
+ * \see \p equal_range
701
+ */
702
+ template <class ForwardIterator, class T, class StrictWeakOrdering>
703
+ bool binary_search(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp);
704
+
705
+ /*! \p equal_range is a version of binary search: it attempts to find
706
+ * the element value in an ordered range <tt>[first, last)</tt>. The
707
+ * value returned by \p equal_range is essentially a combination of
708
+ * the values returned by \p lower_bound and \p upper_bound: it returns
709
+ * a \p pair of iterators \c i and \c j such that \c i is the first
710
+ * position where value could be inserted without violating the
711
+ * ordering and \c j is the last position where value could be inserted
712
+ * without violating the ordering. It follows that every element in the
713
+ * range <tt>[i, j)</tt> is equivalent to value, and that
714
+ * <tt>[i, j)</tt> is the largest subrange of <tt>[first, last)</tt> that
715
+ * has this property.
716
+ *
717
+ * This version of \p equal_range returns a \p pair of iterators
718
+ * <tt>[i, j)</tt>, where \c i is the furthermost iterator in
719
+ * <tt>[first, last)</tt> such that, for every iterator \c k in
720
+ * <tt>[first, i)</tt>, <tt>*k < value</tt>. \c j is the furthermost
721
+ * iterator in <tt>[first, last)</tt> such that, for every iterator
722
+ * \c k in <tt>[first, j)</tt>, <tt>value < *k</tt> is \c false.
723
+ * For every iterator \c k in <tt>[i, j)</tt>, neither
724
+ * <tt>value < *k</tt> nor <tt>*k < value</tt> is \c true.
725
+ *
726
+ * The algorithm's execution is parallelized as determined by \p exec.
727
+ *
728
+ * \param exec The execution policy to use for parallelization.
729
+ * \param first The beginning of the ordered sequence.
730
+ * \param last The end of the ordered sequence.
731
+ * \param value The value to be searched.
732
+ * \return A \p pair of iterators <tt>[i, j)</tt> that define the range of equivalent elements.
733
+ *
734
+ * \tparam DerivedPolicy The name of the derived execution policy.
735
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
736
+ * Iterator</a>. \tparam LessThanComparable is a model of <a
737
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
738
+ *
739
+ * The following code snippet demonstrates how to use \p equal_range
740
+ * to search for values in a ordered range using the \p thrust::device execution policy for parallelization:
741
+ *
742
+ * \code
743
+ * #include <thrust/binary_search.h>
744
+ * #include <thrust/device_vector.h>
745
+ * #include <thrust/execution_policy.h>
746
+ * ...
747
+ * thrust::device_vector<int> input(5);
748
+ *
749
+ * input[0] = 0;
750
+ * input[1] = 2;
751
+ * input[2] = 5;
752
+ * input[3] = 7;
753
+ * input[4] = 8;
754
+ *
755
+ * thrust::equal_range(thrust::device, input.begin(), input.end(), 0); // returns [input.begin(), input.begin() + 1)
756
+ * thrust::equal_range(thrust::device, input.begin(), input.end(), 1); // returns [input.begin() + 1, input.begin() +
757
+ * 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 2); // returns [input.begin() + 1, input.begin() +
758
+ * 2) thrust::equal_range(thrust::device, input.begin(), input.end(), 3); // returns [input.begin() + 2, input.begin() +
759
+ * 2) thrust::equal_range(thrust::device, input.begin(), input.end(), 8); // returns [input.begin() + 4, input.end())
760
+ * thrust::equal_range(thrust::device, input.begin(), input.end(), 9); // returns [input.end(), input.end())
761
+ * \endcode
762
+ *
763
+ * \see https://en.cppreference.com/w/cpp/algorithm/equal_range
764
+ * \see \p lower_bound
765
+ * \see \p upper_bound
766
+ * \see \p binary_search
767
+ */
768
+ template <typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
769
+ _CCCL_HOST_DEVICE thrust::pair<ForwardIterator, ForwardIterator> equal_range(
770
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
771
+ ForwardIterator first,
772
+ ForwardIterator last,
773
+ const LessThanComparable& value);
774
+
775
+ /*! \p equal_range is a version of binary search: it attempts to find
776
+ * the element value in an ordered range <tt>[first, last)</tt>. The
777
+ * value returned by \p equal_range is essentially a combination of
778
+ * the values returned by \p lower_bound and \p upper_bound: it returns
779
+ * a \p pair of iterators \c i and \c j such that \c i is the first
780
+ * position where value could be inserted without violating the
781
+ * ordering and \c j is the last position where value could be inserted
782
+ * without violating the ordering. It follows that every element in the
783
+ * range <tt>[i, j)</tt> is equivalent to value, and that
784
+ * <tt>[i, j)</tt> is the largest subrange of <tt>[first, last)</tt> that
785
+ * has this property.
786
+ *
787
+ * This version of \p equal_range returns a \p pair of iterators
788
+ * <tt>[i, j)</tt>, where \c i is the furthermost iterator in
789
+ * <tt>[first, last)</tt> such that, for every iterator \c k in
790
+ * <tt>[first, i)</tt>, <tt>*k < value</tt>. \c j is the furthermost
791
+ * iterator in <tt>[first, last)</tt> such that, for every iterator
792
+ * \c k in <tt>[first, j)</tt>, <tt>value < *k</tt> is \c false.
793
+ * For every iterator \c k in <tt>[i, j)</tt>, neither
794
+ * <tt>value < *k</tt> nor <tt>*k < value</tt> is \c true.
795
+ *
796
+ * \param first The beginning of the ordered sequence.
797
+ * \param last The end of the ordered sequence.
798
+ * \param value The value to be searched.
799
+ * \return A \p pair of iterators <tt>[i, j)</tt> that define the range of equivalent elements.
800
+ *
801
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
802
+ * Iterator</a>. \tparam LessThanComparable is a model of <a
803
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
804
+ *
805
+ * The following code snippet demonstrates how to use \p equal_range
806
+ * to search for values in a ordered range.
807
+ *
808
+ * \code
809
+ * #include <thrust/binary_search.h>
810
+ * #include <thrust/device_vector.h>
811
+ * ...
812
+ * thrust::device_vector<int> input(5);
813
+ *
814
+ * input[0] = 0;
815
+ * input[1] = 2;
816
+ * input[2] = 5;
817
+ * input[3] = 7;
818
+ * input[4] = 8;
819
+ *
820
+ * thrust::equal_range(input.begin(), input.end(), 0); // returns [input.begin(), input.begin() + 1)
821
+ * thrust::equal_range(input.begin(), input.end(), 1); // returns [input.begin() + 1, input.begin() + 1)
822
+ * thrust::equal_range(input.begin(), input.end(), 2); // returns [input.begin() + 1, input.begin() + 2)
823
+ * thrust::equal_range(input.begin(), input.end(), 3); // returns [input.begin() + 2, input.begin() + 2)
824
+ * thrust::equal_range(input.begin(), input.end(), 8); // returns [input.begin() + 4, input.end())
825
+ * thrust::equal_range(input.begin(), input.end(), 9); // returns [input.end(), input.end())
826
+ * \endcode
827
+ *
828
+ * \see https://en.cppreference.com/w/cpp/algorithm/equal_range
829
+ * \see \p lower_bound
830
+ * \see \p upper_bound
831
+ * \see \p binary_search
832
+ */
833
+ template <class ForwardIterator, class LessThanComparable>
834
+ thrust::pair<ForwardIterator, ForwardIterator>
835
+ equal_range(ForwardIterator first, ForwardIterator last, const LessThanComparable& value);
836
+
837
+ /*! \p equal_range is a version of binary search: it attempts to find
838
+ * the element value in an ordered range <tt>[first, last)</tt>. The
839
+ * value returned by \p equal_range is essentially a combination of
840
+ * the values returned by \p lower_bound and \p upper_bound: it returns
841
+ * a \p pair of iterators \c i and \c j such that \c i is the first
842
+ * position where value could be inserted without violating the
843
+ * ordering and \c j is the last position where value could be inserted
844
+ * without violating the ordering. It follows that every element in the
845
+ * range <tt>[i, j)</tt> is equivalent to value, and that
846
+ * <tt>[i, j)</tt> is the largest subrange of <tt>[first, last)</tt> that
847
+ * has this property.
848
+ *
849
+ * This version of \p equal_range returns a \p pair of iterators
850
+ * <tt>[i, j)</tt>. \c i is the furthermost iterator in
851
+ * <tt>[first, last)</tt> such that, for every iterator \c k in
852
+ * <tt>[first, i)</tt>, <tt>comp(*k, value)</tt> is \c true.
853
+ * \c j is the furthermost iterator in <tt>[first, last)</tt> such
854
+ * that, for every iterator \c k in <tt>[first, last)</tt>,
855
+ * <tt>comp(value, *k)</tt> is \c false. For every iterator \c k
856
+ * in <tt>[i, j)</tt>, neither <tt>comp(value, *k)</tt> nor
857
+ * <tt>comp(*k, value)</tt> is \c true.
858
+ *
859
+ * The algorithm's execution is parallelized as determined by \p exec.
860
+ *
861
+ * \param exec The execution policy to use for parallelization.
862
+ * \param first The beginning of the ordered sequence.
863
+ * \param last The end of the ordered sequence.
864
+ * \param value The value to be searched.
865
+ * \param comp The comparison operator.
866
+ * \return A \p pair of iterators <tt>[i, j)</tt> that define the range of equivalent elements.
867
+ *
868
+ * \tparam DerivedPolicy The name of the derived execution policy.
869
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
870
+ * Iterator</a>. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of
871
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
872
+ *
873
+ * The following code snippet demonstrates how to use \p equal_range
874
+ * to search for values in a ordered range using the \p thrust::device execution policy for parallelization:
875
+ *
876
+ * \code
877
+ * #include <thrust/binary_search.h>
878
+ * #include <thrust/device_vector.h>
879
+ * #include <thrust/functional.h>
880
+ * #include <thrust/execution_policy.h>
881
+ * ...
882
+ * thrust::device_vector<int> input(5);
883
+ *
884
+ * input[0] = 0;
885
+ * input[1] = 2;
886
+ * input[2] = 5;
887
+ * input[3] = 7;
888
+ * input[4] = 8;
889
+ *
890
+ * thrust::equal_range(thrust::device, input.begin(), input.end(), 0, thrust::less<int>()); // returns [input.begin(),
891
+ * input.begin() + 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 1, thrust::less<int>()); //
892
+ * returns [input.begin() + 1, input.begin() + 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 2,
893
+ * thrust::less<int>()); // returns [input.begin() + 1, input.begin() + 2) thrust::equal_range(thrust::device,
894
+ * input.begin(), input.end(), 3, thrust::less<int>()); // returns [input.begin() + 2, input.begin() + 2)
895
+ * thrust::equal_range(thrust::device, input.begin(), input.end(), 8, thrust::less<int>()); // returns [input.begin() +
896
+ * 4, input.end()) thrust::equal_range(thrust::device, input.begin(), input.end(), 9, thrust::less<int>()); // returns
897
+ * [input.end(), input.end()) \endcode
898
+ *
899
+ * \see https://en.cppreference.com/w/cpp/algorithm/equal_range
900
+ * \see \p lower_bound
901
+ * \see \p upper_bound
902
+ * \see \p binary_search
903
+ */
904
+ template <typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
905
+ _CCCL_HOST_DEVICE thrust::pair<ForwardIterator, ForwardIterator> equal_range(
906
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
907
+ ForwardIterator first,
908
+ ForwardIterator last,
909
+ const T& value,
910
+ StrictWeakOrdering comp);
911
+
912
+ /*! \p equal_range is a version of binary search: it attempts to find
913
+ * the element value in an ordered range <tt>[first, last)</tt>. The
914
+ * value returned by \p equal_range is essentially a combination of
915
+ * the values returned by \p lower_bound and \p upper_bound: it returns
916
+ * a \p pair of iterators \c i and \c j such that \c i is the first
917
+ * position where value could be inserted without violating the
918
+ * ordering and \c j is the last position where value could be inserted
919
+ * without violating the ordering. It follows that every element in the
920
+ * range <tt>[i, j)</tt> is equivalent to value, and that
921
+ * <tt>[i, j)</tt> is the largest subrange of <tt>[first, last)</tt> that
922
+ * has this property.
923
+ *
924
+ * This version of \p equal_range returns a \p pair of iterators
925
+ * <tt>[i, j)</tt>. \c i is the furthermost iterator in
926
+ * <tt>[first, last)</tt> such that, for every iterator \c k in
927
+ * <tt>[first, i)</tt>, <tt>comp(*k, value)</tt> is \c true.
928
+ * \c j is the furthermost iterator in <tt>[first, last)</tt> such
929
+ * that, for every iterator \c k in <tt>[first, last)</tt>,
930
+ * <tt>comp(value, *k)</tt> is \c false. For every iterator \c k
931
+ * in <tt>[i, j)</tt>, neither <tt>comp(value, *k)</tt> nor
932
+ * <tt>comp(*k, value)</tt> is \c true.
933
+ *
934
+ * \param first The beginning of the ordered sequence.
935
+ * \param last The end of the ordered sequence.
936
+ * \param value The value to be searched.
937
+ * \param comp The comparison operator.
938
+ * \return A \p pair of iterators <tt>[i, j)</tt> that define the range of equivalent elements.
939
+ *
940
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
941
+ * Iterator</a>. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of
942
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
943
+ *
944
+ * The following code snippet demonstrates how to use \p equal_range
945
+ * to search for values in a ordered range.
946
+ *
947
+ * \code
948
+ * #include <thrust/binary_search.h>
949
+ * #include <thrust/device_vector.h>
950
+ * #include <thrust/functional.h>
951
+ * ...
952
+ * thrust::device_vector<int> input(5);
953
+ *
954
+ * input[0] = 0;
955
+ * input[1] = 2;
956
+ * input[2] = 5;
957
+ * input[3] = 7;
958
+ * input[4] = 8;
959
+ *
960
+ * thrust::equal_range(input.begin(), input.end(), 0, thrust::less<int>()); // returns [input.begin(), input.begin() +
961
+ * 1) thrust::equal_range(input.begin(), input.end(), 1, thrust::less<int>()); // returns [input.begin() + 1,
962
+ * input.begin() + 1) thrust::equal_range(input.begin(), input.end(), 2, thrust::less<int>()); // returns [input.begin()
963
+ * + 1, input.begin() + 2) thrust::equal_range(input.begin(), input.end(), 3, thrust::less<int>()); // returns
964
+ * [input.begin() + 2, input.begin() + 2) thrust::equal_range(input.begin(), input.end(), 8, thrust::less<int>()); //
965
+ * returns [input.begin() + 4, input.end()) thrust::equal_range(input.begin(), input.end(), 9, thrust::less<int>()); //
966
+ * returns [input.end(), input.end()) \endcode
967
+ *
968
+ * \see https://en.cppreference.com/w/cpp/algorithm/equal_range
969
+ * \see \p lower_bound
970
+ * \see \p upper_bound
971
+ * \see \p binary_search
972
+ */
973
+ template <class ForwardIterator, class T, class StrictWeakOrdering>
974
+ thrust::pair<ForwardIterator, ForwardIterator>
975
+ equal_range(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp);
976
+
977
+ /*! \addtogroup vectorized_binary_search Vectorized Searches
978
+ * \ingroup binary_search
979
+ * \{
980
+ */
981
+
982
+ //////////////////////
983
+ // Vector Functions //
984
+ //////////////////////
985
+
986
+ /*! \p lower_bound is a vectorized version of binary search: for each
987
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
988
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
989
+ * Specifically, it returns the index of first position where value could
990
+ * be inserted without violating the ordering.
991
+ *
992
+ * The algorithm's execution is parallelized as determined by \p exec.
993
+ *
994
+ * \param exec The execution policy to use for parallelization.
995
+ * \param first The beginning of the ordered sequence.
996
+ * \param last The end of the ordered sequence.
997
+ * \param values_first The beginning of the search values sequence.
998
+ * \param values_last The end of the search values sequence.
999
+ * \param result The beginning of the output sequence.
1000
+ *
1001
+ * \tparam DerivedPolicy The name of the derived execution policy.
1002
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1003
+ * Iterator</a>. \tparam InputIterator is a model of <a
1004
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1005
+ * value_type is <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
1006
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
1007
+ * Iterator</a>. and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1008
+ *
1009
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1010
+ *
1011
+ * The following code snippet demonstrates how to use \p lower_bound
1012
+ * to search for multiple values in a ordered range using the \p thrust::device execution policy for
1013
+ * parallelization:
1014
+ *
1015
+ * \code
1016
+ * #include <thrust/binary_search.h>
1017
+ * #include <thrust/device_vector.h>
1018
+ * #include <thrust/execution_policy.h>
1019
+ * ...
1020
+ * thrust::device_vector<int> input(5);
1021
+ *
1022
+ * input[0] = 0;
1023
+ * input[1] = 2;
1024
+ * input[2] = 5;
1025
+ * input[3] = 7;
1026
+ * input[4] = 8;
1027
+ *
1028
+ * thrust::device_vector<int> values(6);
1029
+ * values[0] = 0;
1030
+ * values[1] = 1;
1031
+ * values[2] = 2;
1032
+ * values[3] = 3;
1033
+ * values[4] = 8;
1034
+ * values[5] = 9;
1035
+ *
1036
+ * thrust::device_vector<unsigned int> output(6);
1037
+ *
1038
+ * thrust::lower_bound(thrust::device,
1039
+ * input.begin(), input.end(),
1040
+ * values.begin(), values.end(),
1041
+ * output.begin());
1042
+ *
1043
+ * // output is now [0, 1, 1, 2, 4, 5]
1044
+ * \endcode
1045
+ *
1046
+ * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound
1047
+ * \see \p upper_bound
1048
+ * \see \p equal_range
1049
+ * \see \p binary_search
1050
+ */
1051
+ template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
1052
+ _CCCL_HOST_DEVICE OutputIterator lower_bound(
1053
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
1054
+ ForwardIterator first,
1055
+ ForwardIterator last,
1056
+ InputIterator values_first,
1057
+ InputIterator values_last,
1058
+ OutputIterator result);
1059
+
1060
+ /*! \p lower_bound is a vectorized version of binary search: for each
1061
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1062
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1063
+ * Specifically, it returns the index of first position where value could
1064
+ * be inserted without violating the ordering.
1065
+ *
1066
+ * \param first The beginning of the ordered sequence.
1067
+ * \param last The end of the ordered sequence.
1068
+ * \param values_first The beginning of the search values sequence.
1069
+ * \param values_last The end of the search values sequence.
1070
+ * \param result The beginning of the output sequence.
1071
+ *
1072
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1073
+ * Iterator</a>. \tparam InputIterator is a model of <a
1074
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1075
+ * value_type is <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
1076
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
1077
+ * Iterator</a>. and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1078
+ *
1079
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1080
+ *
1081
+ * The following code snippet demonstrates how to use \p lower_bound
1082
+ * to search for multiple values in a ordered range.
1083
+ *
1084
+ * \code
1085
+ * #include <thrust/binary_search.h>
1086
+ * #include <thrust/device_vector.h>
1087
+ * ...
1088
+ * thrust::device_vector<int> input(5);
1089
+ *
1090
+ * input[0] = 0;
1091
+ * input[1] = 2;
1092
+ * input[2] = 5;
1093
+ * input[3] = 7;
1094
+ * input[4] = 8;
1095
+ *
1096
+ * thrust::device_vector<int> values(6);
1097
+ * values[0] = 0;
1098
+ * values[1] = 1;
1099
+ * values[2] = 2;
1100
+ * values[3] = 3;
1101
+ * values[4] = 8;
1102
+ * values[5] = 9;
1103
+ *
1104
+ * thrust::device_vector<unsigned int> output(6);
1105
+ *
1106
+ * thrust::lower_bound(input.begin(), input.end(),
1107
+ * values.begin(), values.end(),
1108
+ * output.begin());
1109
+ *
1110
+ * // output is now [0, 1, 1, 2, 4, 5]
1111
+ * \endcode
1112
+ *
1113
+ * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound
1114
+ * \see \p upper_bound
1115
+ * \see \p equal_range
1116
+ * \see \p binary_search
1117
+ */
1118
+ template <class ForwardIterator, class InputIterator, class OutputIterator>
1119
+ OutputIterator lower_bound(
1120
+ ForwardIterator first,
1121
+ ForwardIterator last,
1122
+ InputIterator values_first,
1123
+ InputIterator values_last,
1124
+ OutputIterator result);
1125
+
1126
+ /*! \p lower_bound is a vectorized version of binary search: for each
1127
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1128
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1129
+ * Specifically, it returns the index of first position where value could
1130
+ * be inserted without violating the ordering. This version of
1131
+ * \p lower_bound uses function object \c comp for comparison.
1132
+ *
1133
+ * The algorithm's execution is parallelized as determined by \p exec.
1134
+ *
1135
+ * \param exec The execution policy to use for parallelization.
1136
+ * \param first The beginning of the ordered sequence.
1137
+ * \param last The end of the ordered sequence.
1138
+ * \param values_first The beginning of the search values sequence.
1139
+ * \param values_last The end of the search values sequence.
1140
+ * \param result The beginning of the output sequence.
1141
+ * \param comp The comparison operator.
1142
+ *
1143
+ * \tparam DerivedPolicy The name of the derived execution policy.
1144
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1145
+ * Iterator</a>. \tparam InputIterator is a model of <a
1146
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1147
+ * value_type is comparable to \p ForwardIterator's \c value_type. \tparam OutputIterator is a model of <a
1148
+ * href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. and \c ForwardIterator's
1149
+ * difference_type is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of <a
1150
+ * href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
1151
+ *
1152
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1153
+ *
1154
+ * The following code snippet demonstrates how to use \p lower_bound
1155
+ * to search for multiple values in a ordered range.
1156
+ *
1157
+ * \code
1158
+ * #include <thrust/binary_search.h>
1159
+ * #include <thrust/device_vector.h>
1160
+ * #include <thrust/functional.h>
1161
+ * #include <thrust/execution_policy.h>
1162
+ * ...
1163
+ * thrust::device_vector<int> input(5);
1164
+ *
1165
+ * input[0] = 0;
1166
+ * input[1] = 2;
1167
+ * input[2] = 5;
1168
+ * input[3] = 7;
1169
+ * input[4] = 8;
1170
+ *
1171
+ * thrust::device_vector<int> values(6);
1172
+ * values[0] = 0;
1173
+ * values[1] = 1;
1174
+ * values[2] = 2;
1175
+ * values[3] = 3;
1176
+ * values[4] = 8;
1177
+ * values[5] = 9;
1178
+ *
1179
+ * thrust::device_vector<unsigned int> output(6);
1180
+ *
1181
+ * thrust::lower_bound(input.begin(), input.end(),
1182
+ * values.begin(), values.end(),
1183
+ * output.begin(),
1184
+ * thrust::less<int>());
1185
+ *
1186
+ * // output is now [0, 1, 1, 2, 4, 5]
1187
+ * \endcode
1188
+ *
1189
+ * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound
1190
+ * \see \p upper_bound
1191
+ * \see \p equal_range
1192
+ * \see \p binary_search
1193
+ */
1194
+ template <typename DerivedPolicy,
1195
+ typename ForwardIterator,
1196
+ typename InputIterator,
1197
+ typename OutputIterator,
1198
+ typename StrictWeakOrdering>
1199
+ _CCCL_HOST_DEVICE OutputIterator lower_bound(
1200
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
1201
+ ForwardIterator first,
1202
+ ForwardIterator last,
1203
+ InputIterator values_first,
1204
+ InputIterator values_last,
1205
+ OutputIterator result,
1206
+ StrictWeakOrdering comp);
1207
+
1208
+ /*! \p lower_bound is a vectorized version of binary search: for each
1209
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1210
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1211
+ * Specifically, it returns the index of first position where value could
1212
+ * be inserted without violating the ordering. This version of
1213
+ * \p lower_bound uses function object \c comp for comparison.
1214
+ *
1215
+ * \param first The beginning of the ordered sequence.
1216
+ * \param last The end of the ordered sequence.
1217
+ * \param values_first The beginning of the search values sequence.
1218
+ * \param values_last The end of the search values sequence.
1219
+ * \param result The beginning of the output sequence.
1220
+ * \param comp The comparison operator.
1221
+ *
1222
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1223
+ * Iterator</a>. \tparam InputIterator is a model of <a
1224
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1225
+ * value_type is comparable to \p ForwardIterator's \c value_type. \tparam OutputIterator is a model of <a
1226
+ * href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. and \c ForwardIterator's
1227
+ * difference_type is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of <a
1228
+ * href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
1229
+ *
1230
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1231
+ *
1232
+ * The following code snippet demonstrates how to use \p lower_bound
1233
+ * to search for multiple values in a ordered range.
1234
+ *
1235
+ * \code
1236
+ * #include <thrust/binary_search.h>
1237
+ * #include <thrust/device_vector.h>
1238
+ * #include <thrust/functional.h>
1239
+ * ...
1240
+ * thrust::device_vector<int> input(5);
1241
+ *
1242
+ * input[0] = 0;
1243
+ * input[1] = 2;
1244
+ * input[2] = 5;
1245
+ * input[3] = 7;
1246
+ * input[4] = 8;
1247
+ *
1248
+ * thrust::device_vector<int> values(6);
1249
+ * values[0] = 0;
1250
+ * values[1] = 1;
1251
+ * values[2] = 2;
1252
+ * values[3] = 3;
1253
+ * values[4] = 8;
1254
+ * values[5] = 9;
1255
+ *
1256
+ * thrust::device_vector<unsigned int> output(6);
1257
+ *
1258
+ * thrust::lower_bound(input.begin(), input.end(),
1259
+ * values.begin(), values.end(),
1260
+ * output.begin(),
1261
+ * thrust::less<int>());
1262
+ *
1263
+ * // output is now [0, 1, 1, 2, 4, 5]
1264
+ * \endcode
1265
+ *
1266
+ * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound
1267
+ * \see \p upper_bound
1268
+ * \see \p equal_range
1269
+ * \see \p binary_search
1270
+ */
1271
+ template <class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
1272
+ OutputIterator lower_bound(
1273
+ ForwardIterator first,
1274
+ ForwardIterator last,
1275
+ InputIterator values_first,
1276
+ InputIterator values_last,
1277
+ OutputIterator result,
1278
+ StrictWeakOrdering comp);
1279
+
1280
+ /*! \p upper_bound is a vectorized version of binary search: for each
1281
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1282
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1283
+ * Specifically, it returns the index of last position where value could
1284
+ * be inserted without violating the ordering.
1285
+ *
1286
+ * The algorithm's execution is parallelized as determined by \p exec.
1287
+ *
1288
+ * \param exec The execution policy to use for parallelization.
1289
+ * \param first The beginning of the ordered sequence.
1290
+ * \param last The end of the ordered sequence.
1291
+ * \param values_first The beginning of the search values sequence.
1292
+ * \param values_last The end of the search values sequence.
1293
+ * \param result The beginning of the output sequence.
1294
+ *
1295
+ * \tparam DerivedPolicy The name of the derived execution policy.
1296
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1297
+ * Iterator</a>. \tparam InputIterator is a model of <a
1298
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1299
+ * value_type is <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
1300
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
1301
+ * Iterator</a>. and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1302
+ *
1303
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1304
+ *
1305
+ * The following code snippet demonstrates how to use \p upper_bound
1306
+ * to search for multiple values in a ordered range using the \p thrust::device execution policy for
1307
+ * parallelization:
1308
+ *
1309
+ * \code
1310
+ * #include <thrust/binary_search.h>
1311
+ * #include <thrust/device_vector.h>
1312
+ * #include <thrust/execution_policy.h>
1313
+ * ...
1314
+ * thrust::device_vector<int> input(5);
1315
+ *
1316
+ * input[0] = 0;
1317
+ * input[1] = 2;
1318
+ * input[2] = 5;
1319
+ * input[3] = 7;
1320
+ * input[4] = 8;
1321
+ *
1322
+ * thrust::device_vector<int> values(6);
1323
+ * values[0] = 0;
1324
+ * values[1] = 1;
1325
+ * values[2] = 2;
1326
+ * values[3] = 3;
1327
+ * values[4] = 8;
1328
+ * values[5] = 9;
1329
+ *
1330
+ * thrust::device_vector<unsigned int> output(6);
1331
+ *
1332
+ * thrust::upper_bound(thrust::device,
1333
+ * input.begin(), input.end(),
1334
+ * values.begin(), values.end(),
1335
+ * output.begin());
1336
+ *
1337
+ * // output is now [1, 1, 2, 2, 5, 5]
1338
+ * \endcode
1339
+ *
1340
+ * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound
1341
+ * \see \p upper_bound
1342
+ * \see \p equal_range
1343
+ * \see \p binary_search
1344
+ */
1345
+ template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
1346
+ _CCCL_HOST_DEVICE OutputIterator upper_bound(
1347
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
1348
+ ForwardIterator first,
1349
+ ForwardIterator last,
1350
+ InputIterator values_first,
1351
+ InputIterator values_last,
1352
+ OutputIterator result);
1353
+
1354
+ /*! \p upper_bound is a vectorized version of binary search: for each
1355
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1356
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1357
+ * Specifically, it returns the index of last position where value could
1358
+ * be inserted without violating the ordering.
1359
+ *
1360
+ * \param first The beginning of the ordered sequence.
1361
+ * \param last The end of the ordered sequence.
1362
+ * \param values_first The beginning of the search values sequence.
1363
+ * \param values_last The end of the search values sequence.
1364
+ * \param result The beginning of the output sequence.
1365
+ *
1366
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1367
+ * Iterator</a>. \tparam InputIterator is a model of <a
1368
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1369
+ * value_type is <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
1370
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
1371
+ * Iterator</a>. and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1372
+ *
1373
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1374
+ *
1375
+ * The following code snippet demonstrates how to use \p upper_bound
1376
+ * to search for multiple values in a ordered range.
1377
+ *
1378
+ * \code
1379
+ * #include <thrust/binary_search.h>
1380
+ * #include <thrust/device_vector.h>
1381
+ * ...
1382
+ * thrust::device_vector<int> input(5);
1383
+ *
1384
+ * input[0] = 0;
1385
+ * input[1] = 2;
1386
+ * input[2] = 5;
1387
+ * input[3] = 7;
1388
+ * input[4] = 8;
1389
+ *
1390
+ * thrust::device_vector<int> values(6);
1391
+ * values[0] = 0;
1392
+ * values[1] = 1;
1393
+ * values[2] = 2;
1394
+ * values[3] = 3;
1395
+ * values[4] = 8;
1396
+ * values[5] = 9;
1397
+ *
1398
+ * thrust::device_vector<unsigned int> output(6);
1399
+ *
1400
+ * thrust::upper_bound(input.begin(), input.end(),
1401
+ * values.begin(), values.end(),
1402
+ * output.begin());
1403
+ *
1404
+ * // output is now [1, 1, 2, 2, 5, 5]
1405
+ * \endcode
1406
+ *
1407
+ * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound
1408
+ * \see \p upper_bound
1409
+ * \see \p equal_range
1410
+ * \see \p binary_search
1411
+ */
1412
+ template <class ForwardIterator, class InputIterator, class OutputIterator>
1413
+ OutputIterator upper_bound(
1414
+ ForwardIterator first,
1415
+ ForwardIterator last,
1416
+ InputIterator values_first,
1417
+ InputIterator values_last,
1418
+ OutputIterator result);
1419
+
1420
+ /*! \p upper_bound is a vectorized version of binary search: for each
1421
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1422
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1423
+ * Specifically, it returns the index of first position where value could
1424
+ * be inserted without violating the ordering. This version of
1425
+ * \p upper_bound uses function object \c comp for comparison.
1426
+ *
1427
+ * The algorithm's execution is parallelized as determined by \p exec.
1428
+ *
1429
+ * \param exec The execution policy to use for parallelization.
1430
+ * \param first The beginning of the ordered sequence.
1431
+ * \param last The end of the ordered sequence.
1432
+ * \param values_first The beginning of the search values sequence.
1433
+ * \param values_last The end of the search values sequence.
1434
+ * \param result The beginning of the output sequence.
1435
+ * \param comp The comparison operator.
1436
+ *
1437
+ * \tparam DerivedPolicy The name of the derived execution policy.
1438
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1439
+ * Iterator</a>. \tparam InputIterator is a model of <a
1440
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1441
+ * value_type is comparable to \p ForwardIterator's \c value_type. \tparam OutputIterator is a model of <a
1442
+ * href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. and \c ForwardIterator's
1443
+ * difference_type is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of <a
1444
+ * href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
1445
+ *
1446
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1447
+ *
1448
+ * The following code snippet demonstrates how to use \p upper_bound
1449
+ * to search for multiple values in a ordered range using the \p thrust::device execution policy for
1450
+ * parallelization:
1451
+ *
1452
+ * \code
1453
+ * #include <thrust/binary_search.h>
1454
+ * #include <thrust/device_vector.h>
1455
+ * #include <thrust/functional.h>
1456
+ * #include <thrust/execution_policy.h>
1457
+ * ...
1458
+ * thrust::device_vector<int> input(5);
1459
+ *
1460
+ * input[0] = 0;
1461
+ * input[1] = 2;
1462
+ * input[2] = 5;
1463
+ * input[3] = 7;
1464
+ * input[4] = 8;
1465
+ *
1466
+ * thrust::device_vector<int> values(6);
1467
+ * values[0] = 0;
1468
+ * values[1] = 1;
1469
+ * values[2] = 2;
1470
+ * values[3] = 3;
1471
+ * values[4] = 8;
1472
+ * values[5] = 9;
1473
+ *
1474
+ * thrust::device_vector<unsigned int> output(6);
1475
+ *
1476
+ * thrust::upper_bound(thrust::device,
1477
+ * input.begin(), input.end(),
1478
+ * values.begin(), values.end(),
1479
+ * output.begin(),
1480
+ * thrust::less<int>());
1481
+ *
1482
+ * // output is now [1, 1, 2, 2, 5, 5]
1483
+ * \endcode
1484
+ *
1485
+ * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound
1486
+ * \see \p lower_bound
1487
+ * \see \p equal_range
1488
+ * \see \p binary_search
1489
+ */
1490
+ template <typename DerivedPolicy,
1491
+ typename ForwardIterator,
1492
+ typename InputIterator,
1493
+ typename OutputIterator,
1494
+ typename StrictWeakOrdering>
1495
+ _CCCL_HOST_DEVICE OutputIterator upper_bound(
1496
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
1497
+ ForwardIterator first,
1498
+ ForwardIterator last,
1499
+ InputIterator values_first,
1500
+ InputIterator values_last,
1501
+ OutputIterator result,
1502
+ StrictWeakOrdering comp);
1503
+
1504
+ /*! \p upper_bound is a vectorized version of binary search: for each
1505
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1506
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1507
+ * Specifically, it returns the index of first position where value could
1508
+ * be inserted without violating the ordering. This version of
1509
+ * \p upper_bound uses function object \c comp for comparison.
1510
+ *
1511
+ * \param first The beginning of the ordered sequence.
1512
+ * \param last The end of the ordered sequence.
1513
+ * \param values_first The beginning of the search values sequence.
1514
+ * \param values_last The end of the search values sequence.
1515
+ * \param result The beginning of the output sequence.
1516
+ * \param comp The comparison operator.
1517
+ *
1518
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1519
+ * Iterator</a>. \tparam InputIterator is a model of <a
1520
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1521
+ * value_type is comparable to \p ForwardIterator's \c value_type. \tparam OutputIterator is a model of <a
1522
+ * href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. and \c ForwardIterator's
1523
+ * difference_type is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of <a
1524
+ * href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
1525
+ *
1526
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1527
+ *
1528
+ * The following code snippet demonstrates how to use \p upper_bound
1529
+ * to search for multiple values in a ordered range.
1530
+ *
1531
+ * \code
1532
+ * #include <thrust/binary_search.h>
1533
+ * #include <thrust/device_vector.h>
1534
+ * #include <thrust/functional.h>
1535
+ * ...
1536
+ * thrust::device_vector<int> input(5);
1537
+ *
1538
+ * input[0] = 0;
1539
+ * input[1] = 2;
1540
+ * input[2] = 5;
1541
+ * input[3] = 7;
1542
+ * input[4] = 8;
1543
+ *
1544
+ * thrust::device_vector<int> values(6);
1545
+ * values[0] = 0;
1546
+ * values[1] = 1;
1547
+ * values[2] = 2;
1548
+ * values[3] = 3;
1549
+ * values[4] = 8;
1550
+ * values[5] = 9;
1551
+ *
1552
+ * thrust::device_vector<unsigned int> output(6);
1553
+ *
1554
+ * thrust::upper_bound(input.begin(), input.end(),
1555
+ * values.begin(), values.end(),
1556
+ * output.begin(),
1557
+ * thrust::less<int>());
1558
+ *
1559
+ * // output is now [1, 1, 2, 2, 5, 5]
1560
+ * \endcode
1561
+ *
1562
+ * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound
1563
+ * \see \p lower_bound
1564
+ * \see \p equal_range
1565
+ * \see \p binary_search
1566
+ */
1567
+ template <class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
1568
+ OutputIterator upper_bound(
1569
+ ForwardIterator first,
1570
+ ForwardIterator last,
1571
+ InputIterator values_first,
1572
+ InputIterator values_last,
1573
+ OutputIterator result,
1574
+ StrictWeakOrdering comp);
1575
+
1576
+ /*! \p binary_search is a vectorized version of binary search: for each
1577
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1578
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1579
+ * It returns \c true if an element that is equivalent to \c value
1580
+ * is present in <tt>[first, last)</tt> and \c false if no such element
1581
+ * exists.
1582
+ *
1583
+ * The algorithm's execution is parallelized as determined by \p exec.
1584
+ *
1585
+ * \param exec The execution policy to use for parallelization.
1586
+ * \param first The beginning of the ordered sequence.
1587
+ * \param last The end of the ordered sequence.
1588
+ * \param values_first The beginning of the search values sequence.
1589
+ * \param values_last The end of the search values sequence.
1590
+ * \param result The beginning of the output sequence.
1591
+ *
1592
+ * \tparam DerivedPolicy The name of the derived execution policy.
1593
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1594
+ * Iterator</a>. \tparam InputIterator is a model of <a
1595
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1596
+ * value_type is <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
1597
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
1598
+ * Iterator</a>. and bool is convertible to \c OutputIterator's \c value_type.
1599
+ *
1600
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1601
+ *
1602
+ * The following code snippet demonstrates how to use \p binary_search
1603
+ * to search for multiple values in a ordered range using the \p thrust::device execution policy for
1604
+ * parallelization:
1605
+ *
1606
+ * \code
1607
+ * #include <thrust/binary_search.h>
1608
+ * #include <thrust/device_vector.h>
1609
+ * #include <thrust/execution_policy.h>
1610
+ * ...
1611
+ * thrust::device_vector<int> input(5);
1612
+ *
1613
+ * input[0] = 0;
1614
+ * input[1] = 2;
1615
+ * input[2] = 5;
1616
+ * input[3] = 7;
1617
+ * input[4] = 8;
1618
+ *
1619
+ * thrust::device_vector<int> values(6);
1620
+ * values[0] = 0;
1621
+ * values[1] = 1;
1622
+ * values[2] = 2;
1623
+ * values[3] = 3;
1624
+ * values[4] = 8;
1625
+ * values[5] = 9;
1626
+ *
1627
+ * thrust::device_vector<bool> output(6);
1628
+ *
1629
+ * thrust::binary_search(thrust::device,
1630
+ * input.begin(), input.end(),
1631
+ * values.begin(), values.end(),
1632
+ * output.begin());
1633
+ *
1634
+ * // output is now [true, false, true, false, true, false]
1635
+ * \endcode
1636
+ *
1637
+ * \see https://en.cppreference.com/w/cpp/algorithm/binary_search
1638
+ * \see \p lower_bound
1639
+ * \see \p upper_bound
1640
+ * \see \p equal_range
1641
+ */
1642
+ template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
1643
+ _CCCL_HOST_DEVICE OutputIterator binary_search(
1644
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
1645
+ ForwardIterator first,
1646
+ ForwardIterator last,
1647
+ InputIterator values_first,
1648
+ InputIterator values_last,
1649
+ OutputIterator result);
1650
+
1651
+ /*! \p binary_search is a vectorized version of binary search: for each
1652
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1653
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1654
+ * It returns \c true if an element that is equivalent to \c value
1655
+ * is present in <tt>[first, last)</tt> and \c false if no such element
1656
+ * exists.
1657
+ *
1658
+ * \param first The beginning of the ordered sequence.
1659
+ * \param last The end of the ordered sequence.
1660
+ * \param values_first The beginning of the search values sequence.
1661
+ * \param values_last The end of the search values sequence.
1662
+ * \param result The beginning of the output sequence.
1663
+ *
1664
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1665
+ * Iterator</a>. \tparam InputIterator is a model of <a
1666
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1667
+ * value_type is <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
1668
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
1669
+ * Iterator</a>. and bool is convertible to \c OutputIterator's \c value_type.
1670
+ *
1671
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1672
+ *
1673
+ * The following code snippet demonstrates how to use \p binary_search
1674
+ * to search for multiple values in a ordered range.
1675
+ *
1676
+ * \code
1677
+ * #include <thrust/binary_search.h>
1678
+ * #include <thrust/device_vector.h>
1679
+ * ...
1680
+ * thrust::device_vector<int> input(5);
1681
+ *
1682
+ * input[0] = 0;
1683
+ * input[1] = 2;
1684
+ * input[2] = 5;
1685
+ * input[3] = 7;
1686
+ * input[4] = 8;
1687
+ *
1688
+ * thrust::device_vector<int> values(6);
1689
+ * values[0] = 0;
1690
+ * values[1] = 1;
1691
+ * values[2] = 2;
1692
+ * values[3] = 3;
1693
+ * values[4] = 8;
1694
+ * values[5] = 9;
1695
+ *
1696
+ * thrust::device_vector<bool> output(6);
1697
+ *
1698
+ * thrust::binary_search(input.begin(), input.end(),
1699
+ * values.begin(), values.end(),
1700
+ * output.begin());
1701
+ *
1702
+ * // output is now [true, false, true, false, true, false]
1703
+ * \endcode
1704
+ *
1705
+ * \see https://en.cppreference.com/w/cpp/algorithm/binary_search
1706
+ * \see \p lower_bound
1707
+ * \see \p upper_bound
1708
+ * \see \p equal_range
1709
+ */
1710
+ template <class ForwardIterator, class InputIterator, class OutputIterator>
1711
+ OutputIterator binary_search(
1712
+ ForwardIterator first,
1713
+ ForwardIterator last,
1714
+ InputIterator values_first,
1715
+ InputIterator values_last,
1716
+ OutputIterator result);
1717
+
1718
+ /*! \p binary_search is a vectorized version of binary search: for each
1719
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1720
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1721
+ * It returns \c true if an element that is equivalent to \c value
1722
+ * is present in <tt>[first, last)</tt> and \c false if no such element
1723
+ * exists. This version of \p binary_search uses function object
1724
+ * \c comp for comparison.
1725
+ *
1726
+ * The algorithm's execution is parallelized as determined by \p exec.
1727
+ *
1728
+ * \param exec The execution policy to use for parallelization.
1729
+ * \param first The beginning of the ordered sequence.
1730
+ * \param last The end of the ordered sequence.
1731
+ * \param values_first The beginning of the search values sequence.
1732
+ * \param values_last The end of the search values sequence.
1733
+ * \param result The beginning of the output sequence.
1734
+ * \param comp The comparison operator.
1735
+ *
1736
+ * \tparam DerivedPolicy The name of the derived execution policy.
1737
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1738
+ * Iterator</a>. \tparam InputIterator is a model of <a
1739
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1740
+ * value_type is <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
1741
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
1742
+ * Iterator</a>. and bool is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of
1743
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
1744
+ *
1745
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1746
+ *
1747
+ * The following code snippet demonstrates how to use \p binary_search
1748
+ * to search for multiple values in a ordered range using the \p thrust::device execution policy for
1749
+ * parallelization:
1750
+ *
1751
+ * \code
1752
+ * #include <thrust/binary_search.h>
1753
+ * #include <thrust/device_vector.h>
1754
+ * #include <thrust/functional.h>
1755
+ * #include <thrust/execution_policy.h>
1756
+ * ...
1757
+ * thrust::device_vector<int> input(5);
1758
+ *
1759
+ * input[0] = 0;
1760
+ * input[1] = 2;
1761
+ * input[2] = 5;
1762
+ * input[3] = 7;
1763
+ * input[4] = 8;
1764
+ *
1765
+ * thrust::device_vector<int> values(6);
1766
+ * values[0] = 0;
1767
+ * values[1] = 1;
1768
+ * values[2] = 2;
1769
+ * values[3] = 3;
1770
+ * values[4] = 8;
1771
+ * values[5] = 9;
1772
+ *
1773
+ * thrust::device_vector<bool> output(6);
1774
+ *
1775
+ * thrust::binary_search(thrust::device,
1776
+ * input.begin(), input.end(),
1777
+ * values.begin(), values.end(),
1778
+ * output.begin(),
1779
+ * thrust::less<T>());
1780
+ *
1781
+ * // output is now [true, false, true, false, true, false]
1782
+ * \endcode
1783
+ *
1784
+ * \see https://en.cppreference.com/w/cpp/algorithm/binary_search
1785
+ * \see \p lower_bound
1786
+ * \see \p upper_bound
1787
+ * \see \p equal_range
1788
+ */
1789
+ template <typename DerivedPolicy,
1790
+ typename ForwardIterator,
1791
+ typename InputIterator,
1792
+ typename OutputIterator,
1793
+ typename StrictWeakOrdering>
1794
+ _CCCL_HOST_DEVICE OutputIterator binary_search(
1795
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
1796
+ ForwardIterator first,
1797
+ ForwardIterator last,
1798
+ InputIterator values_first,
1799
+ InputIterator values_last,
1800
+ OutputIterator result,
1801
+ StrictWeakOrdering comp);
1802
+
1803
+ /*! \p binary_search is a vectorized version of binary search: for each
1804
+ * iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1805
+ * find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1806
+ * It returns \c true if an element that is equivalent to \c value
1807
+ * is present in <tt>[first, last)</tt> and \c false if no such element
1808
+ * exists. This version of \p binary_search uses function object
1809
+ * \c comp for comparison.
1810
+ *
1811
+ * \param first The beginning of the ordered sequence.
1812
+ * \param last The end of the ordered sequence.
1813
+ * \param values_first The beginning of the search values sequence.
1814
+ * \param values_last The end of the search values sequence.
1815
+ * \param result The beginning of the output sequence.
1816
+ * \param comp The comparison operator.
1817
+ *
1818
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
1819
+ * Iterator</a>. \tparam InputIterator is a model of <a
1820
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>. and \c InputIterator's \c
1821
+ * value_type is <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThanComparable</a>.
1822
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
1823
+ * Iterator</a>. and bool is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of
1824
+ * <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
1825
+ *
1826
+ * \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1827
+ *
1828
+ * The following code snippet demonstrates how to use \p binary_search
1829
+ * to search for multiple values in a ordered range.
1830
+ *
1831
+ * \code
1832
+ * #include <thrust/binary_search.h>
1833
+ * #include <thrust/device_vector.h>
1834
+ * #include <thrust/functional.h>
1835
+ * ...
1836
+ * thrust::device_vector<int> input(5);
1837
+ *
1838
+ * input[0] = 0;
1839
+ * input[1] = 2;
1840
+ * input[2] = 5;
1841
+ * input[3] = 7;
1842
+ * input[4] = 8;
1843
+ *
1844
+ * thrust::device_vector<int> values(6);
1845
+ * values[0] = 0;
1846
+ * values[1] = 1;
1847
+ * values[2] = 2;
1848
+ * values[3] = 3;
1849
+ * values[4] = 8;
1850
+ * values[5] = 9;
1851
+ *
1852
+ * thrust::device_vector<bool> output(6);
1853
+ *
1854
+ * thrust::binary_search(input.begin(), input.end(),
1855
+ * values.begin(), values.end(),
1856
+ * output.begin(),
1857
+ * thrust::less<T>());
1858
+ *
1859
+ * // output is now [true, false, true, false, true, false]
1860
+ * \endcode
1861
+ *
1862
+ * \see https://en.cppreference.com/w/cpp/algorithm/binary_search
1863
+ * \see \p lower_bound
1864
+ * \see \p upper_bound
1865
+ * \see \p equal_range
1866
+ */
1867
+ template <class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
1868
+ OutputIterator binary_search(
1869
+ ForwardIterator first,
1870
+ ForwardIterator last,
1871
+ InputIterator values_first,
1872
+ InputIterator values_last,
1873
+ OutputIterator result,
1874
+ StrictWeakOrdering comp);
1875
+
1876
+ /*! \} // end vectorized_binary_search
1877
+ */
1878
+
1879
+ /*! \} // end binary_search
1880
+ */
1881
+
1882
+ /*! \} // end searching
1883
+ */
1884
+
1885
+ THRUST_NAMESPACE_END
1886
+
1887
+ #include <thrust/detail/binary_search.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/complex.h ADDED
@@ -0,0 +1,854 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2008-2019 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
+ /*! \file complex.h
19
+ * \brief Complex numbers
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/type_traits.h>
35
+ #include <thrust/type_traits/is_trivially_relocatable.h>
36
+
37
+ #include <cmath>
38
+ #include <complex>
39
+ #include <sstream>
40
+
41
+ #define THRUST_STD_COMPLEX_REAL(z) \
42
+ reinterpret_cast<const typename ::cuda::std::remove_reference_t<decltype(z)>::value_type(&)[2]>(z)[0]
43
+ #define THRUST_STD_COMPLEX_IMAG(z) \
44
+ reinterpret_cast<const typename ::cuda::std::remove_reference_t<decltype(z)>::value_type(&)[2]>(z)[1]
45
+ #define THRUST_STD_COMPLEX_DEVICE _CCCL_DEVICE
46
+
47
+ THRUST_NAMESPACE_BEGIN
48
+
49
+ /*
50
+ * Calls to the standard math library from inside the thrust namespace
51
+ * with real arguments require explicit scope otherwise they will fail
52
+ * to resolve as it will find the equivalent complex function but then
53
+ * fail to match the template, and give up looking for other scopes.
54
+ */
55
+
56
+ /*! \addtogroup numerics
57
+ * \{
58
+ */
59
+
60
+ /*! \addtogroup complex_numbers Complex Numbers
61
+ * \{
62
+ */
63
+
64
+ /*! \p complex is the Thrust equivalent to <tt>std::complex</tt>. It is
65
+ * functionally identical to it, but can also be used in device code which
66
+ * <tt>std::complex</tt> currently cannot.
67
+ *
68
+ * \tparam T The type used to hold the real and imaginary parts. Should be
69
+ * <tt>float</tt> or <tt>double</tt>. Others types are not supported.
70
+ *
71
+ */
72
+ template <typename T>
73
+ struct complex
74
+ {
75
+ public:
76
+ /*! \p value_type is the type of \p complex's real and imaginary parts.
77
+ */
78
+ using value_type = T;
79
+
80
+ /* --- Constructors --- */
81
+
82
+ /*! Construct a complex number with an imaginary part of 0.
83
+ *
84
+ * \param re The real part of the number.
85
+ */
86
+ _CCCL_HOST_DEVICE complex(const T& re);
87
+
88
+ /*! Construct a complex number from its real and imaginary parts.
89
+ *
90
+ * \param re The real part of the number.
91
+ * \param im The imaginary part of the number.
92
+ */
93
+ _CCCL_HOST_DEVICE complex(const T& re, const T& im);
94
+
95
+ /*! Default construct a complex number.
96
+ */
97
+ complex() = default;
98
+
99
+ /*! This copy constructor copies from a \p complex with a type that is
100
+ * convertible to this \p complex's \c value_type.
101
+ *
102
+ * \param z The \p complex to copy from.
103
+ */
104
+ complex(const complex<T>& z) = default;
105
+
106
+ /*! This converting copy constructor copies from a \p complex with a type
107
+ * that is convertible to this \p complex's \c value_type.
108
+ *
109
+ * \param z The \p complex to copy from.
110
+ *
111
+ * \tparam U is convertible to \c value_type.
112
+ */
113
+ template <typename U>
114
+ _CCCL_HOST_DEVICE complex(const complex<U>& z);
115
+
116
+ /*! This converting copy constructor copies from a <tt>std::complex</tt> with
117
+ * a type that is convertible to this \p complex's \c value_type.
118
+ *
119
+ * \param z The \p complex to copy from.
120
+ */
121
+ _CCCL_HOST THRUST_STD_COMPLEX_DEVICE complex(const std::complex<T>& z);
122
+
123
+ /*! This converting copy constructor copies from a <tt>std::complex</tt> with
124
+ * a type that is convertible to this \p complex's \c value_type.
125
+ *
126
+ * \param z The \p complex to copy from.
127
+ *
128
+ * \tparam U is convertible to \c value_type.
129
+ */
130
+ template <typename U>
131
+ _CCCL_HOST THRUST_STD_COMPLEX_DEVICE complex(const std::complex<U>& z);
132
+
133
+ /* --- Assignment Operators --- */
134
+
135
+ /*! Assign `re` to the real part of this \p complex and set the imaginary part
136
+ * to 0.
137
+ *
138
+ * \param re The real part of the number.
139
+ */
140
+ _CCCL_HOST_DEVICE complex& operator=(const T& re);
141
+
142
+ /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
143
+ * \p complex respectively.
144
+ *
145
+ * \param z The \p complex to copy from.
146
+ */
147
+ complex& operator=(const complex<T>& z) = default;
148
+
149
+ /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
150
+ * \p complex respectively.
151
+ *
152
+ * \param z The \p complex to copy from.
153
+ *
154
+ * \tparam U is convertible to \c value_type.
155
+ */
156
+ template <typename U>
157
+ _CCCL_HOST_DEVICE complex& operator=(const complex<U>& z);
158
+
159
+ /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
160
+ * \p complex respectively.
161
+ *
162
+ * \param z The \p complex to copy from.
163
+ */
164
+ _CCCL_HOST THRUST_STD_COMPLEX_DEVICE complex& operator=(const std::complex<T>& z);
165
+
166
+ /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this
167
+ * \p complex respectively.
168
+ *
169
+ * \param z The \p complex to copy from.
170
+ *
171
+ * \tparam U is convertible to \c value_type.
172
+ */
173
+ template <typename U>
174
+ _CCCL_HOST THRUST_STD_COMPLEX_DEVICE complex& operator=(const std::complex<U>& z);
175
+
176
+ /* --- Compound Assignment Operators --- */
177
+
178
+ /*! Adds a \p complex to this \p complex and assigns the result to this
179
+ * \p complex.
180
+ *
181
+ * \param z The \p complex to be added.
182
+ *
183
+ * \tparam U is convertible to \c value_type.
184
+ */
185
+ template <typename U>
186
+ _CCCL_HOST_DEVICE complex<T>& operator+=(const complex<U>& z);
187
+
188
+ /*! Subtracts a \p complex from this \p complex and assigns the result to
189
+ * this \p complex.
190
+ *
191
+ * \param z The \p complex to be subtracted.
192
+ *
193
+ * \tparam U is convertible to \c value_type.
194
+ */
195
+ template <typename U>
196
+ _CCCL_HOST_DEVICE complex<T>& operator-=(const complex<U>& z);
197
+
198
+ /*! Multiplies this \p complex by another \p complex and assigns the result
199
+ * to this \p complex.
200
+ *
201
+ * \param z The \p complex to be multiplied.
202
+ *
203
+ * \tparam U is convertible to \c value_type.
204
+ */
205
+ template <typename U>
206
+ _CCCL_HOST_DEVICE complex<T>& operator*=(const complex<U>& z);
207
+
208
+ /*! Divides this \p complex by another \p complex and assigns the result to
209
+ * this \p complex.
210
+ *
211
+ * \param z The \p complex to be divided.
212
+ *
213
+ * \tparam U is convertible to \c value_type.
214
+ */
215
+ template <typename U>
216
+ _CCCL_HOST_DEVICE complex<T>& operator/=(const complex<U>& z);
217
+
218
+ /*! Adds a scalar to this \p complex and assigns the result to this
219
+ * \p complex.
220
+ *
221
+ * \param z The \p complex to be added.
222
+ *
223
+ * \tparam U is convertible to \c value_type.
224
+ */
225
+ template <typename U>
226
+ _CCCL_HOST_DEVICE complex<T>& operator+=(const U& z);
227
+
228
+ /*! Subtracts a scalar from this \p complex and assigns the result to
229
+ * this \p complex.
230
+ *
231
+ * \param z The scalar to be subtracted.
232
+ *
233
+ * \tparam U is convertible to \c value_type.
234
+ */
235
+ template <typename U>
236
+ _CCCL_HOST_DEVICE complex<T>& operator-=(const U& z);
237
+
238
+ /*! Multiplies this \p complex by a scalar and assigns the result
239
+ * to this \p complex.
240
+ *
241
+ * \param z The scalar to be multiplied.
242
+ *
243
+ * \tparam U is convertible to \c value_type.
244
+ */
245
+ template <typename U>
246
+ _CCCL_HOST_DEVICE complex<T>& operator*=(const U& z);
247
+
248
+ /*! Divides this \p complex by a scalar and assigns the result to
249
+ * this \p complex.
250
+ *
251
+ * \param z The scalar to be divided.
252
+ *
253
+ * \tparam U is convertible to \c value_type.
254
+ */
255
+ template <typename U>
256
+ _CCCL_HOST_DEVICE complex<T>& operator/=(const U& z);
257
+
258
+ /* --- Getter functions ---
259
+ * The volatile ones are there to help for example
260
+ * with certain reductions optimizations
261
+ */
262
+
263
+ /*! Returns the real part of this \p complex.
264
+ */
265
+ _CCCL_HOST_DEVICE T real() const volatile
266
+ {
267
+ return data.x;
268
+ }
269
+
270
+ /*! Returns the imaginary part of this \p complex.
271
+ */
272
+ _CCCL_HOST_DEVICE T imag() const volatile
273
+ {
274
+ return data.y;
275
+ }
276
+
277
+ /*! Returns the real part of this \p complex.
278
+ */
279
+ _CCCL_HOST_DEVICE T real() const
280
+ {
281
+ return data.x;
282
+ }
283
+
284
+ /*! Returns the imaginary part of this \p complex.
285
+ */
286
+ _CCCL_HOST_DEVICE T imag() const
287
+ {
288
+ return data.y;
289
+ }
290
+
291
+ /* --- Setter functions ---
292
+ * The volatile ones are there to help for example
293
+ * with certain reductions optimizations
294
+ */
295
+
296
+ /*! Sets the real part of this \p complex.
297
+ *
298
+ * \param re The new real part of this \p complex.
299
+ */
300
+ _CCCL_HOST_DEVICE void real(T re) volatile
301
+ {
302
+ data.x = re;
303
+ }
304
+
305
+ /*! Sets the imaginary part of this \p complex.
306
+ *
307
+ * \param im The new imaginary part of this \p complex.e
308
+ */
309
+ _CCCL_HOST_DEVICE void imag(T im) volatile
310
+ {
311
+ data.y = im;
312
+ }
313
+
314
+ /*! Sets the real part of this \p complex.
315
+ *
316
+ * \param re The new real part of this \p complex.
317
+ */
318
+ _CCCL_HOST_DEVICE void real(T re)
319
+ {
320
+ data.x = re;
321
+ }
322
+
323
+ /*! Sets the imaginary part of this \p complex.
324
+ *
325
+ * \param im The new imaginary part of this \p complex.
326
+ */
327
+ _CCCL_HOST_DEVICE void imag(T im)
328
+ {
329
+ data.y = im;
330
+ }
331
+
332
+ /* --- Casting functions --- */
333
+
334
+ /*! Casts this \p complex to a <tt>std::complex</tt> of the same type.
335
+ */
336
+ _CCCL_HOST operator std::complex<T>() const
337
+ {
338
+ return std::complex<T>(real(), imag());
339
+ }
340
+
341
+ private:
342
+ #if _CCCL_CUDA_COMPILER(NVCC, <, 11, 7)
343
+ struct __align__(sizeof(T) * 2) storage
344
+ #elif _CCCL_COMPILER(ICC)
345
+ struct storage
346
+ #else // !(_CCCL_COMPILER(ICC) || _CCCL_CUDA_COMPILER(NVCC, <, 11, 7))
347
+ struct alignas(sizeof(T) * 2) storage
348
+ #endif // !(_CCCL_COMPILER(ICC) || _CCCL_CUDA_COMPILER(NVCC, <, 11, 7))
349
+ {
350
+ T x;
351
+ T y;
352
+ }
353
+ #if _CCCL_COMPILER(ICC)
354
+ __attribute__((aligned(sizeof(T) * 2)))
355
+ #endif // _CCCL_COMPILER(ICC)
356
+ ;
357
+ storage data;
358
+ };
359
+
360
+ /* --- General Functions --- */
361
+
362
+ /*! Returns the magnitude (also known as absolute value) of a \p complex.
363
+ *
364
+ * \param z The \p complex from which to calculate the absolute value.
365
+ */
366
+ template <typename T>
367
+ _CCCL_HOST_DEVICE T abs(const complex<T>& z);
368
+
369
+ /*! Returns the phase angle (also known as argument) in radians of a \p complex.
370
+ *
371
+ * \param z The \p complex from which to calculate the phase angle.
372
+ */
373
+ template <typename T>
374
+ _CCCL_HOST_DEVICE T arg(const complex<T>& z);
375
+
376
+ /*! Returns the square of the magnitude of a \p complex.
377
+ *
378
+ * \param z The \p complex from which to calculate the norm.
379
+ */
380
+ template <typename T>
381
+ _CCCL_HOST_DEVICE T norm(const complex<T>& z);
382
+
383
+ /*! Returns the complex conjugate of a \p complex.
384
+ *
385
+ * \param z The \p complex from which to calculate the complex conjugate.
386
+ */
387
+ template <typename T>
388
+ _CCCL_HOST_DEVICE complex<T> conj(const complex<T>& z);
389
+
390
+ /*! Returns a \p complex with the specified magnitude and phase.
391
+ *
392
+ * \param m The magnitude of the returned \p complex.
393
+ * \param theta The phase of the returned \p complex in radians.
394
+ */
395
+ template <typename T0, typename T1>
396
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> polar(const T0& m, const T1& theta = T1());
397
+
398
+ /*! Returns the projection of a \p complex on the Riemann sphere.
399
+ * For all finite \p complex it returns the argument. For \p complexs
400
+ * with a non finite part returns (INFINITY,+/-0) where the sign of
401
+ * the zero matches the sign of the imaginary part of the argument.
402
+ *
403
+ * \param z The \p complex argument.
404
+ */
405
+ template <typename T>
406
+ _CCCL_HOST_DEVICE complex<T> proj(const T& z);
407
+
408
+ /* --- Binary Arithmetic operators --- */
409
+
410
+ /*! Adds two \p complex numbers.
411
+ *
412
+ * The value types of the two \p complex types should be compatible and the
413
+ * type of the returned \p complex is the promoted type of the two arguments.
414
+ *
415
+ * \param x The first \p complex.
416
+ * \param y The second \p complex.
417
+ */
418
+ template <typename T0, typename T1>
419
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator+(const complex<T0>& x, const complex<T1>& y);
420
+
421
+ /*! Adds a scalar to a \p complex number.
422
+ *
423
+ * The value type of the \p complex should be compatible with the scalar and
424
+ * the type of the returned \p complex is the promoted type of the two arguments.
425
+ *
426
+ * \param x The \p complex.
427
+ * \param y The scalar.
428
+ */
429
+ template <typename T0, typename T1>
430
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator+(const complex<T0>& x, const T1& y);
431
+
432
+ /*! Adds a \p complex number to a scalar.
433
+ *
434
+ * The value type of the \p complex should be compatible with the scalar and
435
+ * the type of the returned \p complex is the promoted type of the two arguments.
436
+ *
437
+ * \param x The scalar.
438
+ * \param y The \p complex.
439
+ */
440
+ template <typename T0, typename T1>
441
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator+(const T0& x, const complex<T1>& y);
442
+
443
+ /*! Subtracts two \p complex numbers.
444
+ *
445
+ * The value types of the two \p complex types should be compatible and the
446
+ * type of the returned \p complex is the promoted type of the two arguments.
447
+ *
448
+ * \param x The first \p complex (minuend).
449
+ * \param y The second \p complex (subtrahend).
450
+ */
451
+ template <typename T0, typename T1>
452
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator-(const complex<T0>& x, const complex<T1>& y);
453
+
454
+ /*! Subtracts a scalar from a \p complex number.
455
+ *
456
+ * The value type of the \p complex should be compatible with the scalar and
457
+ * the type of the returned \p complex is the promoted type of the two arguments.
458
+ *
459
+ * \param x The \p complex (minuend).
460
+ * \param y The scalar (subtrahend).
461
+ */
462
+ template <typename T0, typename T1>
463
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator-(const complex<T0>& x, const T1& y);
464
+
465
+ /*! Subtracts a \p complex number from a scalar.
466
+ *
467
+ * The value type of the \p complex should be compatible with the scalar and
468
+ * the type of the returned \p complex is the promoted type of the two arguments.
469
+ *
470
+ * \param x The scalar (minuend).
471
+ * \param y The \p complex (subtrahend).
472
+ */
473
+ template <typename T0, typename T1>
474
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator-(const T0& x, const complex<T1>& y);
475
+
476
+ /*! Multiplies two \p complex numbers.
477
+ *
478
+ * The value types of the two \p complex types should be compatible and the
479
+ * type of the returned \p complex is the promoted type of the two arguments.
480
+ *
481
+ * \param x The first \p complex.
482
+ * \param y The second \p complex.
483
+ */
484
+ template <typename T0, typename T1>
485
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator*(const complex<T0>& x, const complex<T1>& y);
486
+
487
+ /*! Multiplies a \p complex number by a scalar.
488
+ *
489
+ * \param x The \p complex.
490
+ * \param y The scalar.
491
+ */
492
+ template <typename T0, typename T1>
493
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator*(const complex<T0>& x, const T1& y);
494
+
495
+ /*! Multiplies a scalar by a \p complex number.
496
+ *
497
+ * The value type of the \p complex should be compatible with the scalar and
498
+ * the type of the returned \p complex is the promoted type of the two arguments.
499
+ *
500
+ * \param x The scalar.
501
+ * \param y The \p complex.
502
+ */
503
+ template <typename T0, typename T1>
504
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator*(const T0& x, const complex<T1>& y);
505
+
506
+ /*! Divides two \p complex numbers.
507
+ *
508
+ * The value types of the two \p complex types should be compatible and the
509
+ * type of the returned \p complex is the promoted type of the two arguments.
510
+ *
511
+ * \param x The numerator (dividend).
512
+ * \param y The denomimator (divisor).
513
+ */
514
+ template <typename T0, typename T1>
515
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator/(const complex<T0>& x, const complex<T1>& y);
516
+
517
+ /*! Divides a \p complex number by a scalar.
518
+ *
519
+ * The value type of the \p complex should be compatible with the scalar and
520
+ * the type of the returned \p complex is the promoted type of the two arguments.
521
+ *
522
+ * \param x The complex numerator (dividend).
523
+ * \param y The scalar denomimator (divisor).
524
+ */
525
+ template <typename T0, typename T1>
526
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator/(const complex<T0>& x, const T1& y);
527
+
528
+ /*! Divides a scalar by a \p complex number.
529
+ *
530
+ * The value type of the \p complex should be compatible with the scalar and
531
+ * the type of the returned \p complex is the promoted type of the two arguments.
532
+ *
533
+ * \param x The scalar numerator (dividend).
534
+ * \param y The complex denomimator (divisor).
535
+ */
536
+ template <typename T0, typename T1>
537
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> operator/(const T0& x, const complex<T1>& y);
538
+
539
+ /* --- Unary Arithmetic operators --- */
540
+
541
+ /*! Unary plus, returns its \p complex argument.
542
+ *
543
+ * \param y The \p complex argument.
544
+ */
545
+ template <typename T>
546
+ _CCCL_HOST_DEVICE complex<T> operator+(const complex<T>& y);
547
+
548
+ /*! Unary minus, returns the additive inverse (negation) of its \p complex
549
+ * argument.
550
+ *
551
+ * \param y The \p complex argument.
552
+ */
553
+ template <typename T>
554
+ _CCCL_HOST_DEVICE complex<T> operator-(const complex<T>& y);
555
+
556
+ /* --- Exponential Functions --- */
557
+
558
+ /*! Returns the complex exponential of a \p complex number.
559
+ *
560
+ * \param z The \p complex argument.
561
+ */
562
+ template <typename T>
563
+ _CCCL_HOST_DEVICE complex<T> exp(const complex<T>& z);
564
+
565
+ /*! Returns the complex natural logarithm of a \p complex number.
566
+ *
567
+ * \param z The \p complex argument.
568
+ */
569
+ template <typename T>
570
+ _CCCL_HOST_DEVICE complex<T> log(const complex<T>& z);
571
+
572
+ /*! Returns the complex base 10 logarithm of a \p complex number.
573
+ *
574
+ * \param z The \p complex argument.
575
+ */
576
+ template <typename T>
577
+ _CCCL_HOST_DEVICE complex<T> log10(const complex<T>& z);
578
+
579
+ /* --- Power Functions --- */
580
+
581
+ /*! Returns a \p complex number raised to another.
582
+ *
583
+ * The value types of the two \p complex types should be compatible and the
584
+ * type of the returned \p complex is the promoted type of the two arguments.
585
+ *
586
+ * \param x The base.
587
+ * \param y The exponent.
588
+ */
589
+ template <typename T0, typename T1>
590
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> pow(const complex<T0>& x, const complex<T1>& y);
591
+
592
+ /*! Returns a \p complex number raised to a scalar.
593
+ *
594
+ * The value type of the \p complex should be compatible with the scalar and
595
+ * the type of the returned \p complex is the promoted type of the two arguments.
596
+ *
597
+ * \param x The base.
598
+ * \param y The exponent.
599
+ */
600
+ template <typename T0, typename T1>
601
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> pow(const complex<T0>& x, const T1& y);
602
+
603
+ /*! Returns a scalar raised to a \p complex number.
604
+ *
605
+ * The value type of the \p complex should be compatible with the scalar and
606
+ * the type of the returned \p complex is the promoted type of the two arguments.
607
+ *
608
+ * \param x The base.
609
+ * \param y The exponent.
610
+ */
611
+ template <typename T0, typename T1>
612
+ _CCCL_HOST_DEVICE complex<::cuda::std::common_type_t<T0, T1>> pow(const T0& x, const complex<T1>& y);
613
+
614
+ /*! Returns the complex square root of a \p complex number.
615
+ *
616
+ * \param z The \p complex argument.
617
+ */
618
+ template <typename T>
619
+ _CCCL_HOST_DEVICE complex<T> sqrt(const complex<T>& z);
620
+
621
+ /* --- Trigonometric Functions --- */
622
+
623
+ /*! Returns the complex cosine of a \p complex number.
624
+ *
625
+ * \param z The \p complex argument.
626
+ */
627
+ template <typename T>
628
+ _CCCL_HOST_DEVICE complex<T> cos(const complex<T>& z);
629
+
630
+ /*! Returns the complex sine of a \p complex number.
631
+ *
632
+ * \param z The \p complex argument.
633
+ */
634
+ template <typename T>
635
+ _CCCL_HOST_DEVICE complex<T> sin(const complex<T>& z);
636
+
637
+ /*! Returns the complex tangent of a \p complex number.
638
+ *
639
+ * \param z The \p complex argument.
640
+ */
641
+ template <typename T>
642
+ _CCCL_HOST_DEVICE complex<T> tan(const complex<T>& z);
643
+
644
+ /* --- Hyperbolic Functions --- */
645
+
646
+ /*! Returns the complex hyperbolic cosine of a \p complex number.
647
+ *
648
+ * \param z The \p complex argument.
649
+ */
650
+ template <typename T>
651
+ _CCCL_HOST_DEVICE complex<T> cosh(const complex<T>& z);
652
+
653
+ /*! Returns the complex hyperbolic sine of a \p complex number.
654
+ *
655
+ * \param z The \p complex argument.
656
+ */
657
+ template <typename T>
658
+ _CCCL_HOST_DEVICE complex<T> sinh(const complex<T>& z);
659
+
660
+ /*! Returns the complex hyperbolic tangent of a \p complex number.
661
+ *
662
+ * \param z The \p complex argument.
663
+ */
664
+ template <typename T>
665
+ _CCCL_HOST_DEVICE complex<T> tanh(const complex<T>& z);
666
+
667
+ /* --- Inverse Trigonometric Functions --- */
668
+
669
+ /*! Returns the complex arc cosine of a \p complex number.
670
+ *
671
+ * The range of the real part of the result is [0, Pi] and
672
+ * the range of the imaginary part is [-inf, +inf]
673
+ *
674
+ * \param z The \p complex argument.
675
+ */
676
+ template <typename T>
677
+ _CCCL_HOST_DEVICE complex<T> acos(const complex<T>& z);
678
+
679
+ /*! Returns the complex arc sine of a \p complex number.
680
+ *
681
+ * The range of the real part of the result is [-Pi/2, Pi/2] and
682
+ * the range of the imaginary part is [-inf, +inf]
683
+ *
684
+ * \param z The \p complex argument.
685
+ */
686
+ template <typename T>
687
+ _CCCL_HOST_DEVICE complex<T> asin(const complex<T>& z);
688
+
689
+ /*! Returns the complex arc tangent of a \p complex number.
690
+ *
691
+ * The range of the real part of the result is [-Pi/2, Pi/2] and
692
+ * the range of the imaginary part is [-inf, +inf]
693
+ *
694
+ * \param z The \p complex argument.
695
+ */
696
+ template <typename T>
697
+ _CCCL_HOST_DEVICE complex<T> atan(const complex<T>& z);
698
+
699
+ /* --- Inverse Hyperbolic Functions --- */
700
+
701
+ /*! Returns the complex inverse hyperbolic cosine of a \p complex number.
702
+ *
703
+ * The range of the real part of the result is [0, +inf] and
704
+ * the range of the imaginary part is [-Pi, Pi]
705
+ *
706
+ * \param z The \p complex argument.
707
+ */
708
+ template <typename T>
709
+ _CCCL_HOST_DEVICE complex<T> acosh(const complex<T>& z);
710
+
711
+ /*! Returns the complex inverse hyperbolic sine of a \p complex number.
712
+ *
713
+ * The range of the real part of the result is [-inf, +inf] and
714
+ * the range of the imaginary part is [-Pi/2, Pi/2]
715
+ *
716
+ * \param z The \p complex argument.
717
+ */
718
+ template <typename T>
719
+ _CCCL_HOST_DEVICE complex<T> asinh(const complex<T>& z);
720
+
721
+ /*! Returns the complex inverse hyperbolic tangent of a \p complex number.
722
+ *
723
+ * The range of the real part of the result is [-inf, +inf] and
724
+ * the range of the imaginary part is [-Pi/2, Pi/2]
725
+ *
726
+ * \param z The \p complex argument.
727
+ */
728
+ template <typename T>
729
+ _CCCL_HOST_DEVICE complex<T> atanh(const complex<T>& z);
730
+
731
+ /* --- Stream Operators --- */
732
+
733
+ /*! Writes to an output stream a \p complex number in the form (real, imaginary).
734
+ *
735
+ * \param os The output stream.
736
+ * \param z The \p complex number to output.
737
+ */
738
+ template <typename T, typename CharT, typename Traits>
739
+ std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const complex<T>& z);
740
+
741
+ /*! Reads a \p complex number from an input stream.
742
+ *
743
+ * The recognized formats are:
744
+ * - real
745
+ * - (real)
746
+ * - (real, imaginary)
747
+ *
748
+ * The values read must be convertible to the \p complex's \c value_type
749
+ *
750
+ * \param is The input stream.
751
+ * \param z The \p complex number to set.
752
+ */
753
+ template <typename T, typename CharT, typename Traits>
754
+ _CCCL_HOST std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, complex<T>& z);
755
+
756
+ /* --- Equality Operators --- */
757
+
758
+ /*! Returns true if two \p complex numbers are equal and false otherwise.
759
+ *
760
+ * \param x The first \p complex.
761
+ * \param y The second \p complex.
762
+ */
763
+ template <typename T0, typename T1>
764
+ _CCCL_HOST_DEVICE bool operator==(const complex<T0>& x, const complex<T1>& y);
765
+
766
+ /*! Returns true if two \p complex numbers are equal and false otherwise.
767
+ *
768
+ * \param x The first \p complex.
769
+ * \param y The second \p complex.
770
+ */
771
+ template <typename T0, typename T1>
772
+ _CCCL_HOST THRUST_STD_COMPLEX_DEVICE bool operator==(const complex<T0>& x, const std::complex<T1>& y);
773
+
774
+ /*! Returns true if two \p complex numbers are equal and false otherwise.
775
+ *
776
+ * \param x The first \p complex.
777
+ * \param y The second \p complex.
778
+ */
779
+ template <typename T0, typename T1>
780
+ _CCCL_HOST THRUST_STD_COMPLEX_DEVICE bool operator==(const std::complex<T0>& x, const complex<T1>& y);
781
+
782
+ /*! Returns true if the imaginary part of the \p complex number is zero and
783
+ * the real part is equal to the scalar. Returns false otherwise.
784
+ *
785
+ * \param x The scalar.
786
+ * \param y The \p complex.
787
+ */
788
+ template <typename T0, typename T1>
789
+ _CCCL_HOST_DEVICE bool operator==(const T0& x, const complex<T1>& y);
790
+
791
+ /*! Returns true if the imaginary part of the \p complex number is zero and
792
+ * the real part is equal to the scalar. Returns false otherwise.
793
+ *
794
+ * \param x The \p complex.
795
+ * \param y The scalar.
796
+ */
797
+ template <typename T0, typename T1>
798
+ _CCCL_HOST_DEVICE bool operator==(const complex<T0>& x, const T1& y);
799
+
800
+ /*! Returns true if two \p complex numbers are different and false otherwise.
801
+ *
802
+ * \param x The first \p complex.
803
+ * \param y The second \p complex.
804
+ */
805
+ template <typename T0, typename T1>
806
+ _CCCL_HOST_DEVICE bool operator!=(const complex<T0>& x, const complex<T1>& y);
807
+
808
+ /*! Returns true if two \p complex numbers are different and false otherwise.
809
+ *
810
+ * \param x The first \p complex.
811
+ * \param y The second \p complex.
812
+ */
813
+ template <typename T0, typename T1>
814
+ _CCCL_HOST THRUST_STD_COMPLEX_DEVICE bool operator!=(const complex<T0>& x, const std::complex<T1>& y);
815
+
816
+ /*! Returns true if two \p complex numbers are different and false otherwise.
817
+ *
818
+ * \param x The first \p complex.
819
+ * \param y The second \p complex.
820
+ */
821
+ template <typename T0, typename T1>
822
+ _CCCL_HOST THRUST_STD_COMPLEX_DEVICE bool operator!=(const std::complex<T0>& x, const complex<T1>& y);
823
+
824
+ /*! Returns true if the imaginary part of the \p complex number is not zero or
825
+ * the real part is different from the scalar. Returns false otherwise.
826
+ *
827
+ * \param x The scalar.
828
+ * \param y The \p complex.
829
+ */
830
+ template <typename T0, typename T1>
831
+ _CCCL_HOST_DEVICE bool operator!=(const T0& x, const complex<T1>& y);
832
+
833
+ /*! Returns true if the imaginary part of the \p complex number is not zero or
834
+ * the real part is different from the scalar. Returns false otherwise.
835
+ *
836
+ * \param x The \p complex.
837
+ * \param y The scalar.
838
+ */
839
+ template <typename T0, typename T1>
840
+ _CCCL_HOST_DEVICE bool operator!=(const complex<T0>& x, const T1& y);
841
+
842
+ THRUST_NAMESPACE_END
843
+
844
+ #include <thrust/detail/complex/complex.inl>
845
+
846
+ #undef THRUST_STD_COMPLEX_REAL
847
+ #undef THRUST_STD_COMPLEX_IMAG
848
+ #undef THRUST_STD_COMPLEX_DEVICE
849
+
850
+ /*! \} // complex_numbers
851
+ */
852
+
853
+ /*! \} // numerics
854
+ */
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/count.h ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 count.h
18
+ * \brief Counting elements in a range
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/execution_policy.h>
33
+ #include <thrust/iterator/iterator_traits.h>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+ /*! \addtogroup algorithms
38
+ */
39
+
40
+ /*! \addtogroup reductions
41
+ * \ingroup algorithms
42
+ * \{
43
+ */
44
+
45
+ /*! \addtogroup counting
46
+ * \ingroup reductions
47
+ * \{
48
+ */
49
+
50
+ /*! \p count finds the number of elements in <tt>[first,last)</tt> that are equal
51
+ * to \p value. More precisely, \p count returns the number of iterators \c i in
52
+ * <tt>[first, last)</tt> such that <tt>*i == value</tt>.
53
+ *
54
+ * The algorithm's execution is parallelized as determined by \p exec.
55
+ *
56
+ * \param exec The execution policy to use for parallelization.
57
+ * \param first The beginning of the sequence.
58
+ * \param last The end of the sequence.
59
+ * \param value The value to be counted.
60
+ * \return The number of elements equal to \p value.
61
+ *
62
+ * \tparam DerivedPolicy The name of the derived execution policy.
63
+ * \tparam InputIterator must be a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
64
+ * Iterator</a> and \c InputIterator's \c value_type must be a model of must be a model of <a
65
+ * href="https://en.cppreference.com/w/cpp/concepts/equality_comparable">Equality Comparable</a>. \tparam
66
+ * EqualityComparable must be a model of <a
67
+ * href="https://en.cppreference.com/w/cpp/concepts/equality_comparable">Equality Comparable</a> and can be compared for
68
+ * equality with \c InputIterator's \c value_type
69
+ *
70
+ * The following code snippet demonstrates how to use \p count to
71
+ * count the number of instances in a range of a value of interest using the \p thrust::device execution policy:
72
+ *
73
+ * \code
74
+ * #include <thrust/count.h>
75
+ * #include <thrust/device_vector.h>
76
+ * #include <thrust/execution_policy.h>
77
+ * ...
78
+ * // put 3 1s in a device_vector
79
+ * thrust::device_vector<int> vec(5,0);
80
+ * vec[1] = 1;
81
+ * vec[3] = 1;
82
+ * vec[4] = 1;
83
+ *
84
+ * // count the 1s
85
+ * int result = thrust::count(thrust::device, vec.begin(), vec.end(), 1);
86
+ * // result == 3
87
+ * \endcode
88
+ *
89
+ * \see https://en.cppreference.com/w/cpp/algorithm/count
90
+ */
91
+ template <typename DerivedPolicy, typename InputIterator, typename EqualityComparable>
92
+ _CCCL_HOST_DEVICE typename thrust::iterator_traits<InputIterator>::difference_type
93
+ count(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
94
+ InputIterator first,
95
+ InputIterator last,
96
+ const EqualityComparable& value);
97
+
98
+ /*! \p count finds the number of elements in <tt>[first,last)</tt> that are equal
99
+ * to \p value. More precisely, \p count returns the number of iterators \c i in
100
+ * <tt>[first, last)</tt> such that <tt>*i == value</tt>.
101
+ *
102
+ * \param first The beginning of the sequence.
103
+ * \param last The end of the sequence.
104
+ * \param value The value to be counted.
105
+ * \return The number of elements equal to \p value.
106
+ *
107
+ * \tparam InputIterator must be a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
108
+ * Iterator</a> and \c InputIterator's \c value_type must be a model of must be a model of <a
109
+ * href="https://en.cppreference.com/w/cpp/concepts/equality_comparable">Equality Comparable</a>. \tparam
110
+ * EqualityComparable must be a model of <a
111
+ * href="https://en.cppreference.com/w/cpp/concepts/equality_comparable">Equality Comparable</a> and can be compared for
112
+ * equality with \c InputIterator's \c value_type
113
+ *
114
+ * The following code snippet demonstrates how to use \p count to
115
+ * count the number of instances in a range of a value of interest.
116
+ * \code
117
+ * #include <thrust/count.h>
118
+ * #include <thrust/device_vector.h>
119
+ * ...
120
+ * // put 3 1s in a device_vector
121
+ * thrust::device_vector<int> vec(5,0);
122
+ * vec[1] = 1;
123
+ * vec[3] = 1;
124
+ * vec[4] = 1;
125
+ *
126
+ * // count the 1s
127
+ * int result = thrust::count(vec.begin(), vec.end(), 1);
128
+ * // result == 3
129
+ * \endcode
130
+ *
131
+ * \see https://en.cppreference.com/w/cpp/algorithm/count
132
+ */
133
+ template <typename InputIterator, typename EqualityComparable>
134
+ typename thrust::iterator_traits<InputIterator>::difference_type
135
+ count(InputIterator first, InputIterator last, const EqualityComparable& value);
136
+
137
+ /*! \p count_if finds the number of elements in <tt>[first,last)</tt> for which
138
+ * a predicate is \c true. More precisely, \p count_if returns the number of iterators
139
+ * \c i in <tt>[first, last)</tt> such that <tt>pred(*i) == true</tt>.
140
+ *
141
+ * The algorithm's execution is parallelized as determined by \p exec.
142
+ *
143
+ * \param exec The execution policy to use for parallelization.
144
+ * \param first The beginning of the sequence.
145
+ * \param last The end of the sequence.
146
+ * \param pred The predicate.
147
+ * \return The number of elements where \p pred is \c true.
148
+ *
149
+ * \tparam DerivedPolicy The name of the derived execution policy.
150
+ * \tparam InputIterator must be a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
151
+ * Iterator</a> and \c InputIterator's \c value_type must be convertible to \c Predicate's \c argument_type. \tparam
152
+ * Predicate must be a model of <a href="https://en.cppreference.com/w/cpp/concepts/predicate">Predicate</a>.
153
+ *
154
+ * The following code snippet demonstrates how to use \p count to
155
+ * count the number of odd numbers in a range using the \p thrust::device execution policy:
156
+ *
157
+ * \code
158
+ * #include <thrust/count.h>
159
+ * #include <thrust/device_vector.h>
160
+ * #include <thrust/execution_policy.h>
161
+ * ...
162
+ * struct is_odd
163
+ * {
164
+ * __host__ __device__
165
+ * bool operator()(int &x)
166
+ * {
167
+ * return x & 1;
168
+ * }
169
+ * };
170
+ * ...
171
+ * // fill a device_vector with even & odd numbers
172
+ * thrust::device_vector<int> vec(5);
173
+ * vec[0] = 0;
174
+ * vec[1] = 1;
175
+ * vec[2] = 2;
176
+ * vec[3] = 3;
177
+ * vec[4] = 4;
178
+ *
179
+ * // count the odd elements in vec
180
+ * int result = thrust::count_if(thrust::device, vec.begin(), vec.end(), is_odd());
181
+ * // result == 2
182
+ * \endcode
183
+ *
184
+ * \see https://en.cppreference.com/w/cpp/algorithm/count
185
+ */
186
+ template <typename DerivedPolicy, typename InputIterator, typename Predicate>
187
+ _CCCL_HOST_DEVICE typename thrust::iterator_traits<InputIterator>::difference_type
188
+ count_if(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
189
+ InputIterator first,
190
+ InputIterator last,
191
+ Predicate pred);
192
+
193
+ /*! \p count_if finds the number of elements in <tt>[first,last)</tt> for which
194
+ * a predicate is \c true. More precisely, \p count_if returns the number of iterators
195
+ * \c i in <tt>[first, last)</tt> such that <tt>pred(*i) == true</tt>.
196
+ *
197
+ * \param first The beginning of the sequence.
198
+ * \param last The end of the sequence.
199
+ * \param pred The predicate.
200
+ * \return The number of elements where \p pred is \c true.
201
+ *
202
+ * \tparam InputIterator must be a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
203
+ * Iterator</a> and \c InputIterator's \c value_type must be convertible to \c Predicate's \c argument_type. \tparam
204
+ * Predicate must be a model of <a href="https://en.cppreference.com/w/cpp/concepts/predicate">Predicate</a>.
205
+ *
206
+ * The following code snippet demonstrates how to use \p count to
207
+ * count the number of odd numbers in a range.
208
+ * \code
209
+ * #include <thrust/count.h>
210
+ * #include <thrust/device_vector.h>
211
+ * ...
212
+ * struct is_odd
213
+ * {
214
+ * __host__ __device__
215
+ * bool operator()(int &x)
216
+ * {
217
+ * return x & 1;
218
+ * }
219
+ * };
220
+ * ...
221
+ * // fill a device_vector with even & odd numbers
222
+ * thrust::device_vector<int> vec(5);
223
+ * vec[0] = 0;
224
+ * vec[1] = 1;
225
+ * vec[2] = 2;
226
+ * vec[3] = 3;
227
+ * vec[4] = 4;
228
+ *
229
+ * // count the odd elements in vec
230
+ * int result = thrust::count_if(vec.begin(), vec.end(), is_odd());
231
+ * // result == 2
232
+ * \endcode
233
+ *
234
+ * \see https://en.cppreference.com/w/cpp/algorithm/count
235
+ */
236
+ template <typename InputIterator, typename Predicate>
237
+ typename thrust::iterator_traits<InputIterator>::difference_type
238
+ count_if(InputIterator first, InputIterator last, Predicate pred);
239
+
240
+ /*! \} // end counting
241
+ * \} // end reductions
242
+ */
243
+
244
+ THRUST_NAMESPACE_END
245
+
246
+ #include <thrust/detail/count.h>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_delete.h ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
18
+ * \brief Deletes variables in device memory.
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/device_ptr.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ /*! \addtogroup memory_management Memory Management
37
+ * \{
38
+ */
39
+
40
+ /*! \p device_delete deletes a \p device_ptr allocated with
41
+ * \p device_new.
42
+ *
43
+ * \param ptr The \p device_ptr to delete, assumed to have
44
+ * been allocated with \p device_new.
45
+ * \param n The number of objects to destroy at \p ptr. Defaults to \c 1
46
+ * similar to \p device_new.
47
+ *
48
+ * \see device_ptr
49
+ * \see device_new
50
+ */
51
+ template <typename T>
52
+ inline void device_delete(thrust::device_ptr<T> ptr, const size_t n = 1);
53
+
54
+ /*! \} // memory_management
55
+ */
56
+
57
+ THRUST_NAMESPACE_END
58
+
59
+ #include <thrust/detail/device_delete.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_free.h ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
18
+ * \brief Deallocates storage allocated by \p device_malloc.
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/device_ptr.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ /*! \addtogroup memory_management Memory Management
37
+ * \{
38
+ */
39
+
40
+ /*! \p device_free deallocates memory allocated by the function \p device_malloc.
41
+ *
42
+ * \param ptr A \p device_ptr pointing to memory to be deallocated.
43
+ *
44
+ * The following code snippet demonstrates how to use \p device_free to
45
+ * deallocate memory allocated by \p device_malloc.
46
+ *
47
+ * \code
48
+ * #include <thrust/device_malloc.h>
49
+ * #include <thrust/device_free.h>
50
+ * ...
51
+ * // allocate some integers with device_malloc
52
+ * const int N = 100;
53
+ * thrust::device_ptr<int> int_array = thrust::device_malloc<int>(N);
54
+ *
55
+ * // manipulate integers
56
+ * ...
57
+ *
58
+ * // deallocate with device_free
59
+ * thrust::device_free(int_array);
60
+ * \endcode
61
+ *
62
+ * \see device_ptr
63
+ * \see device_malloc
64
+ */
65
+ inline void device_free(thrust::device_ptr<void> ptr);
66
+
67
+ /*! \} // memory_management
68
+ */
69
+
70
+ THRUST_NAMESPACE_END
71
+
72
+ #include <thrust/detail/device_free.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_make_unique.h ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 device_make_unique.h
18
+ * \brief A factory function for creating `unique_ptr`s to device objects.
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/allocate_unique.h>
33
+ #include <thrust/detail/type_deduction.h>
34
+ #include <thrust/device_allocator.h>
35
+ #include <thrust/device_new.h>
36
+ #include <thrust/device_ptr.h>
37
+
38
+ THRUST_NAMESPACE_BEGIN
39
+
40
+ ///////////////////////////////////////////////////////////////////////////////
41
+
42
+ template <typename T, typename... Args>
43
+ _CCCL_HOST auto device_make_unique(Args&&... args)
44
+ -> decltype(uninitialized_allocate_unique<T>(::cuda::std::declval<device_allocator<T>>()))
45
+ {
46
+ // FIXME: This is crude - we construct an unnecessary T on the host for
47
+ // `device_new`. We need a proper dispatched `construct` algorithm to
48
+ // do this properly.
49
+ auto p = uninitialized_allocate_unique<T>(device_allocator<T>());
50
+ device_new<T>(p.get(), T(THRUST_FWD(args)...));
51
+ return p;
52
+ }
53
+
54
+ ///////////////////////////////////////////////////////////////////////////////
55
+
56
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc.h ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
18
+ * \brief Allocates storage in device memory.
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/device_ptr.h>
33
+
34
+ #include <cstddef> // for std::size_t
35
+
36
+ THRUST_NAMESPACE_BEGIN
37
+
38
+ /*! \addtogroup memory_management Memory Management
39
+ * \{
40
+ */
41
+
42
+ /*! This version of \p device_malloc allocates sequential device storage
43
+ * for bytes.
44
+ *
45
+ * \param n The number of bytes to allocate sequentially
46
+ * in device memory.
47
+ * \return A \p device_ptr to the newly allocated memory.
48
+ *
49
+ * The following code snippet demonstrates how to use \p device_malloc to
50
+ * allocate a range of device memory.
51
+ *
52
+ * \code
53
+ * #include <thrust/device_malloc.h>
54
+ * #include <thrust/device_free.h>
55
+ * ...
56
+ * // allocate some memory with device_malloc
57
+ * const int N = 100;
58
+ * thrust::device_ptr<void> void_ptr = thrust::device_malloc(N);
59
+ *
60
+ * // manipulate memory
61
+ * ...
62
+ *
63
+ * // deallocate with device_free
64
+ * thrust::device_free(void_ptr);
65
+ * \endcode
66
+ *
67
+ * \see device_ptr
68
+ * \see device_free
69
+ */
70
+ inline thrust::device_ptr<void> device_malloc(const std::size_t n);
71
+
72
+ /*! This version of \p device_malloc allocates sequential device storage for
73
+ * new objects of the given type.
74
+ *
75
+ * \param n The number of objects of type T to allocate
76
+ * sequentially in device memory.
77
+ * \return A \p device_ptr to the newly allocated memory.
78
+ *
79
+ * The following code snippet demonstrates how to use \p device_malloc to
80
+ * allocate a range of device memory.
81
+ *
82
+ * \code
83
+ * #include <thrust/device_malloc.h>
84
+ * #include <thrust/device_free.h>
85
+ * ...
86
+ * // allocate some integers with device_malloc
87
+ * const int N = 100;
88
+ * thrust::device_ptr<int> int_array = thrust::device_malloc<int>(N);
89
+ *
90
+ * // manipulate integers
91
+ * ...
92
+ *
93
+ * // deallocate with device_free
94
+ * thrust::device_free(int_array);
95
+ * \endcode
96
+ *
97
+ * \see device_ptr
98
+ * \see device_free
99
+ */
100
+ template <typename T>
101
+ inline thrust::device_ptr<T> device_malloc(const std::size_t n);
102
+
103
+ /*! \} // memory_management
104
+ */
105
+
106
+ THRUST_NAMESPACE_END
107
+
108
+ #include <thrust/detail/device_malloc.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc_allocator.h ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
18
+ * \brief An allocator which allocates storage with \p device_malloc.
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/device_free.h>
33
+ #include <thrust/device_malloc.h>
34
+ #include <thrust/device_ptr.h>
35
+ #include <thrust/device_reference.h>
36
+
37
+ #include <limits>
38
+ #include <stdexcept>
39
+
40
+ THRUST_NAMESPACE_BEGIN
41
+
42
+ // forward declarations to WAR circular #includes
43
+ #ifndef _CCCL_DOXYGEN_INVOKED // Do not document
44
+ template <typename>
45
+ class device_ptr;
46
+ template <typename T>
47
+ device_ptr<T> device_malloc(const std::size_t n);
48
+ #endif // _CCCL_DOXYGEN_INVOKED
49
+
50
+ /*! \addtogroup allocators Allocators
51
+ * \ingroup memory_management
52
+ * \{
53
+ */
54
+
55
+ /*! \p device_malloc_allocator is a device memory allocator that employs the
56
+ * \p device_malloc function for allocation.
57
+ *
58
+ * \p device_malloc_allocator is deprecated in favor of <tt>thrust::mr</tt>
59
+ * memory resource-based allocators.
60
+ *
61
+ * \see device_malloc
62
+ * \see device_ptr
63
+ * \see device_allocator
64
+ * \see https://en.cppreference.com/w/cpp/memory/allocator
65
+ */
66
+ template <typename T>
67
+ class device_malloc_allocator
68
+ {
69
+ public:
70
+ /*! Type of element allocated, \c T. */
71
+ using value_type = T;
72
+
73
+ /*! Pointer to allocation, \c device_ptr<T>. */
74
+ using pointer = device_ptr<T>;
75
+
76
+ /*! \c const pointer to allocation, \c device_ptr<const T>. */
77
+ using const_pointer = device_ptr<const T>;
78
+
79
+ /*! Reference to allocated element, \c device_reference<T>. */
80
+ using reference = device_reference<T>;
81
+
82
+ /*! \c const reference to allocated element, \c device_reference<const T>. */
83
+ using const_reference = device_reference<const T>;
84
+
85
+ /*! Type of allocation size, \c std::size_t. */
86
+ using size_type = std::size_t;
87
+
88
+ /*! Type of allocation difference, \c pointer::difference_type. */
89
+ using difference_type = typename pointer::difference_type;
90
+
91
+ /*! The \p rebind metafunction provides the type of a \p device_malloc_allocator
92
+ * instantiated with another type.
93
+ *
94
+ * \tparam U The other type to use for instantiation.
95
+ */
96
+ template <typename U>
97
+ struct rebind
98
+ {
99
+ /*! The alias \p other gives the type of the rebound \p device_malloc_allocator.
100
+ */
101
+ using other = device_malloc_allocator<U>;
102
+ }; // end rebind
103
+
104
+ /*! No-argument constructor has no effect. */
105
+ _CCCL_HOST_DEVICE inline device_malloc_allocator() {}
106
+
107
+ /*! No-argument destructor has no effect. */
108
+ _CCCL_HOST_DEVICE inline ~device_malloc_allocator() {}
109
+
110
+ /*! Copy constructor has no effect. */
111
+ _CCCL_HOST_DEVICE inline device_malloc_allocator(device_malloc_allocator const&) {}
112
+
113
+ /*! Constructor from other \p device_malloc_allocator has no effect. */
114
+ template <typename U>
115
+ _CCCL_HOST_DEVICE inline device_malloc_allocator(device_malloc_allocator<U> const&)
116
+ {}
117
+
118
+ device_malloc_allocator& operator=(const device_malloc_allocator&) = default;
119
+
120
+ /*! Returns the address of an allocated object.
121
+ * \return <tt>&r</tt>.
122
+ */
123
+ _CCCL_HOST_DEVICE inline pointer address(reference r)
124
+ {
125
+ return &r;
126
+ }
127
+
128
+ /*! Returns the address an allocated object.
129
+ * \return <tt>&r</tt>.
130
+ */
131
+ _CCCL_HOST_DEVICE inline const_pointer address(const_reference r)
132
+ {
133
+ return &r;
134
+ }
135
+
136
+ /*! Allocates storage for \p cnt objects.
137
+ * \param cnt The number of objects to allocate.
138
+ * \return A \p pointer to uninitialized storage for \p cnt objects.
139
+ * \note Memory allocated by this function must be deallocated with \p deallocate.
140
+ */
141
+ _CCCL_HOST inline pointer allocate(size_type cnt, const_pointer = const_pointer(static_cast<T*>(0)))
142
+ {
143
+ if (cnt > this->max_size())
144
+ {
145
+ throw std::bad_alloc();
146
+ } // end if
147
+
148
+ return pointer(device_malloc<T>(cnt));
149
+ } // end allocate()
150
+
151
+ /*! Deallocates storage for objects allocated with \p allocate.
152
+ * \param p A \p pointer to the storage to deallocate.
153
+ * \param cnt The size of the previous allocation.
154
+ * \note Memory deallocated by this function must previously have been
155
+ * allocated with \p allocate.
156
+ */
157
+ _CCCL_HOST inline void deallocate(pointer p, size_type cnt) noexcept
158
+ {
159
+ // silence unused parameter warning while still leaving the parameter name for Doxygen
160
+ (void) (cnt);
161
+
162
+ device_free(p);
163
+ } // end deallocate()
164
+
165
+ /*! Returns the largest value \c n for which <tt>allocate(n)</tt> might succeed.
166
+ * \return The largest value \c n for which <tt>allocate(n)</tt> might succeed.
167
+ */
168
+ inline size_type max_size() const
169
+ {
170
+ return (std::numeric_limits<size_type>::max)() / sizeof(T);
171
+ } // end max_size()
172
+
173
+ /*! Compares against another \p device_malloc_allocator for equality.
174
+ * \return \c true
175
+ */
176
+ _CCCL_HOST_DEVICE inline bool operator==(device_malloc_allocator const&) const
177
+ {
178
+ return true;
179
+ }
180
+
181
+ /*! Compares against another \p device_malloc_allocator for inequality.
182
+ * \return \c false
183
+ */
184
+ _CCCL_HOST_DEVICE inline bool operator!=(device_malloc_allocator const& a) const
185
+ {
186
+ return !operator==(a);
187
+ }
188
+ }; // end device_malloc_allocator
189
+
190
+ /*! \} // allocators
191
+ */
192
+
193
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new.h ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 device_new.h
18
+ * \brief Constructs new elements in device memory
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 this for size_t
34
+ #include <thrust/device_ptr.h>
35
+
36
+ #include <cstddef>
37
+
38
+ THRUST_NAMESPACE_BEGIN
39
+
40
+ /*!
41
+ * \addtogroup memory_management Memory Management
42
+ * \{
43
+ */
44
+
45
+ /*! \p device_new implements the placement \c new operator for types
46
+ * resident in device memory. \p device_new calls <tt>T</tt>'s null
47
+ * constructor on a array of objects in device memory.
48
+ * No memory is allocated by this function.
49
+ *
50
+ * \param p A \p device_ptr to a region of device memory into which
51
+ * to construct one or many <tt>T</tt>s.
52
+ * \param n The number of objects to construct at \p p.
53
+ * \return p, casted to <tt>T</tt>'s type.
54
+ *
55
+ * \see device_ptr
56
+ */
57
+ template <typename T>
58
+ device_ptr<T> device_new(device_ptr<void> p, const size_t n = 1);
59
+
60
+ /*! \p device_new implements the placement new operator for types
61
+ * resident in device memory. \p device_new calls <tt>T</tt>'s copy
62
+ * constructor on a array of objects in device memory. No memory is
63
+ * allocated by this function.
64
+ *
65
+ * \param p A \p device_ptr to a region of device memory into which to
66
+ * construct one or many <tt>T</tt>s.
67
+ * \param exemplar The value from which to copy.
68
+ * \param n The number of objects to construct at \p p.
69
+ * \return p, casted to <tt>T</tt>'s type.
70
+ *
71
+ * \see device_ptr
72
+ * \see fill
73
+ */
74
+ template <typename T>
75
+ device_ptr<T> device_new(device_ptr<void> p, const T& exemplar, const size_t n = 1);
76
+
77
+ /*! \p device_new implements the new operator for types resident in device memory.
78
+ * It allocates device memory large enough to hold \p n new objects of type \c T.
79
+ *
80
+ * \param n The number of objects to allocate. Defaults to \c 1.
81
+ * \return A \p device_ptr to the newly allocated region of device memory.
82
+ */
83
+ template <typename T>
84
+ device_ptr<T> device_new(const size_t n = 1);
85
+
86
+ /*! \} // memory_management
87
+ */
88
+
89
+ THRUST_NAMESPACE_END
90
+
91
+ #include <thrust/detail/device_new.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new_allocator.h ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
18
+ * \brief An allocator which allocates storage with \p device_new.
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/device_delete.h>
33
+ #include <thrust/device_new.h>
34
+ #include <thrust/device_ptr.h>
35
+ #include <thrust/device_reference.h>
36
+
37
+ #include <cuda/std/cstdint>
38
+ #include <cuda/std/limits>
39
+
40
+ #include <stdexcept>
41
+
42
+ THRUST_NAMESPACE_BEGIN
43
+
44
+ /*! \addtogroup allocators Allocators
45
+ * \ingroup memory_management
46
+ * \{
47
+ */
48
+
49
+ /*! \p device_new_allocator is a device memory allocator that employs the
50
+ * \p device_new function for allocation.
51
+ *
52
+ * \see device_new
53
+ * \see device_ptr
54
+ * \see https://en.cppreference.com/w/cpp/memory/allocator
55
+ */
56
+ template <typename T>
57
+ class device_new_allocator
58
+ {
59
+ public:
60
+ /*! Type of element allocated, \c T. */
61
+ using value_type = T;
62
+
63
+ /*! Pointer to allocation, \c device_ptr<T>. */
64
+ using pointer = device_ptr<T>;
65
+
66
+ /*! \c const pointer to allocation, \c device_ptr<const T>. */
67
+ using const_pointer = device_ptr<const T>;
68
+
69
+ /*! Reference to allocated element, \c device_reference<T>. */
70
+ using reference = device_reference<T>;
71
+
72
+ /*! \c const reference to allocated element, \c device_reference<const T>. */
73
+ using const_reference = device_reference<const T>;
74
+
75
+ /*! Type of allocation size, \c ::cuda::std::size_t. */
76
+ using size_type = ::cuda::std::size_t;
77
+
78
+ /*! Type of allocation difference, \c pointer::difference_type. */
79
+ using difference_type = typename pointer::difference_type;
80
+
81
+ /*! The \p rebind metafunction provides the type of a \p device_new_allocator
82
+ * instantiated with another type.
83
+ *
84
+ * \tparam U The other type to use for instantiation.
85
+ */
86
+ template <typename U>
87
+ struct rebind
88
+ {
89
+ /*! The alias \p other gives the type of the rebound \p device_new_allocator.
90
+ */
91
+ using other = device_new_allocator<U>;
92
+ }; // end rebind
93
+
94
+ /*! No-argument constructor has no effect. */
95
+ _CCCL_HOST_DEVICE inline device_new_allocator() {}
96
+
97
+ /*! No-argument destructor has no effect. */
98
+ _CCCL_HOST_DEVICE inline ~device_new_allocator() {}
99
+
100
+ /*! Copy constructor has no effect. */
101
+ _CCCL_HOST_DEVICE inline device_new_allocator(device_new_allocator const&) {}
102
+
103
+ /*! Constructor from other \p device_malloc_allocator has no effect. */
104
+ template <typename U>
105
+ _CCCL_HOST_DEVICE inline device_new_allocator(device_new_allocator<U> const&)
106
+ {}
107
+
108
+ /*! Returns the address of an allocated object.
109
+ * \return <tt>&r</tt>.
110
+ */
111
+ _CCCL_HOST_DEVICE inline pointer address(reference r)
112
+ {
113
+ return &r;
114
+ }
115
+
116
+ /*! Returns the address an allocated object.
117
+ * \return <tt>&r</tt>.
118
+ */
119
+ _CCCL_HOST_DEVICE inline const_pointer address(const_reference r)
120
+ {
121
+ return &r;
122
+ }
123
+
124
+ /*! Allocates storage for \p cnt objects.
125
+ * \param cnt The number of objects to allocate.
126
+ * \return A \p pointer to uninitialized storage for \p cnt objects.
127
+ * \note Memory allocated by this function must be deallocated with \p deallocate.
128
+ */
129
+ _CCCL_HOST inline pointer allocate(size_type cnt, const_pointer = const_pointer(static_cast<T*>(0)))
130
+ {
131
+ if (cnt > this->max_size())
132
+ {
133
+ throw std::bad_alloc();
134
+ } // end if
135
+
136
+ // use "::operator new" rather than keyword new
137
+ return pointer(device_new<T>(cnt));
138
+ } // end allocate()
139
+
140
+ /*! Deallocates storage for objects allocated with \p allocate.
141
+ * \param p A \p pointer to the storage to deallocate.
142
+ * \param cnt The size of the previous allocation.
143
+ * \note Memory deallocated by this function must previously have been
144
+ * allocated with \p allocate.
145
+ */
146
+ _CCCL_HOST inline void deallocate(pointer p, size_type cnt) noexcept
147
+ {
148
+ // use "::operator delete" rather than keyword delete
149
+ (void) cnt;
150
+ device_delete(p);
151
+ } // end deallocate()
152
+
153
+ /*! Returns the largest value \c n for which <tt>allocate(n)</tt> might succeed.
154
+ * \return The largest value \c n for which <tt>allocate(n)</tt> might succeed.
155
+ */
156
+ _CCCL_HOST_DEVICE inline size_type max_size() const
157
+ {
158
+ return ::cuda::std::numeric_limits<size_type>::max THRUST_PREVENT_MACRO_SUBSTITUTION() / sizeof(T);
159
+ } // end max_size()
160
+
161
+ /*! Compares against another \p device_malloc_allocator for equality.
162
+ * \return \c true
163
+ */
164
+ _CCCL_HOST_DEVICE inline bool operator==(device_new_allocator const&)
165
+ {
166
+ return true;
167
+ }
168
+
169
+ /*! Compares against another \p device_malloc_allocator for inequality.
170
+ * \return \c false
171
+ */
172
+ _CCCL_HOST_DEVICE inline bool operator!=(device_new_allocator const& a)
173
+ {
174
+ return !operator==(a);
175
+ }
176
+ }; // end device_new_allocator
177
+
178
+ /*! \} // allocators
179
+ */
180
+
181
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_reference.h ADDED
@@ -0,0 +1,977 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
18
+ * \brief A reference to an object which resides in memory associated with the
19
+ * device system.
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/detail/reference.h>
34
+ #include <thrust/detail/type_traits.h>
35
+ #include <thrust/device_ptr.h>
36
+
37
+ THRUST_NAMESPACE_BEGIN
38
+
39
+ /*! \addtogroup memory_management Memory Management
40
+ * \{
41
+ */
42
+
43
+ /*! \p device_reference acts as a reference-like object to an object stored in device memory.
44
+ * \p device_reference is not intended to be used directly; rather, this type
45
+ * is the result of dereferencing a \p device_ptr. Similarly, taking the address of
46
+ * a \p device_reference yields a \p device_ptr.
47
+ *
48
+ * \p device_reference may often be used from host code in place of operations defined on
49
+ * its associated \c value_type. For example, when \p device_reference refers to an
50
+ * arithmetic type, arithmetic operations on it are legal:
51
+ *
52
+ * \code
53
+ * #include <thrust/device_vector.h>
54
+ *
55
+ * int main()
56
+ * {
57
+ * thrust::device_vector<int> vec(1, 13);
58
+ *
59
+ * thrust::device_reference<int> ref_to_thirteen = vec[0];
60
+ *
61
+ * int x = ref_to_thirteen + 1;
62
+ *
63
+ * // x is 14
64
+ *
65
+ * return 0;
66
+ * }
67
+ * \endcode
68
+ *
69
+ * Similarly, we can print the value of \c ref_to_thirteen in the above code by using an
70
+ * \c iostream:
71
+ *
72
+ * \code
73
+ * #include <thrust/device_vector.h>
74
+ * #include <iostream>
75
+ *
76
+ * int main()
77
+ * {
78
+ * thrust::device_vector<int> vec(1, 13);
79
+ *
80
+ * thrust::device_reference<int> ref_to_thirteen = vec[0];
81
+ *
82
+ * std::cout << ref_to_thirteen << std::endl;
83
+ *
84
+ * // 13 is printed
85
+ *
86
+ * return 0;
87
+ * }
88
+ * \endcode
89
+ *
90
+ * Of course, we needn't explicitly create a \p device_reference in the previous
91
+ * example, because one is returned by \p device_vector's bracket operator. A more natural
92
+ * way to print the value of a \p device_vector element might be:
93
+ *
94
+ * \code
95
+ * #include <thrust/device_vector.h>
96
+ * #include <iostream>
97
+ *
98
+ * int main()
99
+ * {
100
+ * thrust::device_vector<int> vec(1, 13);
101
+ *
102
+ * std::cout << vec[0] << std::endl;
103
+ *
104
+ * // 13 is printed
105
+ *
106
+ * return 0;
107
+ * }
108
+ * \endcode
109
+ *
110
+ * These kinds of operations should be used sparingly in performance-critical code, because
111
+ * they imply a potentially expensive copy between host and device space.
112
+ *
113
+ * Some operations which are possible with regular objects are impossible with their
114
+ * corresponding \p device_reference objects due to the requirements of the C++ language. For
115
+ * example, because the member access operator cannot be overloaded, member variables and functions
116
+ * of a referent object cannot be directly accessed through its \p device_reference.
117
+ *
118
+ * The following code, which generates a compiler error, illustrates:
119
+ *
120
+ * \code
121
+ * #include <thrust/device_vector.h>
122
+ *
123
+ * struct foo
124
+ * {
125
+ * int x;
126
+ * };
127
+ *
128
+ * int main()
129
+ * {
130
+ * thrust::device_vector<foo> foo_vec(1);
131
+ *
132
+ * thrust::device_reference<foo> foo_ref = foo_vec[0];
133
+ *
134
+ * foo_ref.x = 13; // ERROR: x cannot be accessed through foo_ref
135
+ *
136
+ * return 0;
137
+ * }
138
+ * \endcode
139
+ *
140
+ * Instead, a host space copy must be created to access \c foo's \c x member:
141
+ *
142
+ * \code
143
+ * #include <thrust/device_vector.h>
144
+ *
145
+ * struct foo
146
+ * {
147
+ * int x;
148
+ * };
149
+ *
150
+ * int main()
151
+ * {
152
+ * thrust::device_vector<foo> foo_vec(1);
153
+ *
154
+ * // create a local host-side foo object
155
+ * foo host_foo;
156
+ * host_foo.x = 13;
157
+ *
158
+ * thrust::device_reference<foo> foo_ref = foo_vec[0];
159
+ *
160
+ * foo_ref = host_foo;
161
+ *
162
+ * // foo_ref's x member is 13
163
+ *
164
+ * return 0;
165
+ * }
166
+ * \endcode
167
+ *
168
+ * Another common case where a \p device_reference cannot directly be used in place of
169
+ * its referent object occurs when passing them as parameters to functions like \c printf
170
+ * which have varargs parameters. Because varargs parameters must be Plain Old Data, a
171
+ * \p device_reference to a POD type requires a cast when passed to \c printf:
172
+ *
173
+ * \code
174
+ * #include <stdio.h>
175
+ * #include <thrust/device_vector.h>
176
+ *
177
+ * int main()
178
+ * {
179
+ * thrust::device_vector<int> vec(1,13);
180
+ *
181
+ * // vec[0] must be cast to int when passing to printf
182
+ * printf("%d\n", (int) vec[0]);
183
+ *
184
+ * return 0;
185
+ * }
186
+ * \endcode
187
+ *
188
+ * \see device_ptr
189
+ * \see device_vector
190
+ */
191
+ template <typename T>
192
+ class device_reference : public thrust::reference<T, thrust::device_ptr<T>, thrust::device_reference<T>>
193
+ {
194
+ private:
195
+ using super_t = thrust::reference<T, thrust::device_ptr<T>, thrust::device_reference<T>>;
196
+
197
+ public:
198
+ /*! The type of the value referenced by this type of \p device_reference.
199
+ */
200
+ using value_type = typename super_t::value_type;
201
+
202
+ /*! The type of the expression <tt>&ref</tt>, where <tt>ref</tt> is a \p device_reference.
203
+ */
204
+ using pointer = typename super_t::pointer;
205
+
206
+ /*! This copy constructor accepts a const reference to another
207
+ * \p device_reference. After this \p device_reference is constructed,
208
+ * it shall refer to the same object as \p other.
209
+ *
210
+ * \param other A \p device_reference to copy from.
211
+ *
212
+ * The following code snippet demonstrates the semantics of this
213
+ * copy constructor.
214
+ *
215
+ * \code
216
+ * #include <thrust/device_vector.h>
217
+ * #include <assert.h>
218
+ * ...
219
+ * thrust::device_vector<int> v(1,0);
220
+ * thrust::device_reference<int> ref = v[0];
221
+ *
222
+ * // ref equals the object at v[0]
223
+ * assert(ref == v[0]);
224
+ *
225
+ * // the address of ref equals the address of v[0]
226
+ * assert(&ref == &v[0]);
227
+ *
228
+ * // modifying v[0] modifies ref
229
+ * v[0] = 13;
230
+ * assert(ref == 13);
231
+ * \endcode
232
+ *
233
+ * \note This constructor is templated primarily to allow initialization of
234
+ * <tt>device_reference<const T></tt> from <tt>device_reference<T></tt>.
235
+ */
236
+ template <typename OtherT>
237
+ _CCCL_HOST_DEVICE
238
+ device_reference(const device_reference<OtherT>& other,
239
+ thrust::detail::enable_if_convertible_t<typename device_reference<OtherT>::pointer, pointer>* = 0)
240
+ : super_t(other)
241
+ {}
242
+
243
+ /*! This copy constructor initializes this \p device_reference
244
+ * to refer to an object pointed to by the given \p device_ptr. After
245
+ * this \p device_reference is constructed, it shall refer to the
246
+ * object pointed to by \p ptr.
247
+ *
248
+ * \param ptr A \p device_ptr to copy from.
249
+ *
250
+ * The following code snippet demonstrates the semantic of this
251
+ * copy constructor.
252
+ *
253
+ * \code
254
+ * #include <thrust/device_vector.h>
255
+ * #include <assert.h>
256
+ * ...
257
+ * thrust::device_vector<int> v(1,0);
258
+ * thrust::device_ptr<int> ptr = &v[0];
259
+ * thrust::device_reference<int> ref(ptr);
260
+ *
261
+ * // ref equals the object pointed to by ptr
262
+ * assert(ref == *ptr);
263
+ *
264
+ * // the address of ref equals ptr
265
+ * assert(&ref == ptr);
266
+ *
267
+ * // modifying *ptr modifies ref
268
+ * *ptr = 13;
269
+ * assert(ref == 13);
270
+ * \endcode
271
+ */
272
+ _CCCL_HOST_DEVICE explicit device_reference(const pointer& ptr)
273
+ : super_t(ptr)
274
+ {}
275
+
276
+ /*! This assignment operator assigns the value of the object referenced by
277
+ * the given \p device_reference to the object referenced by this
278
+ * \p device_reference.
279
+ *
280
+ * \param other The \p device_reference to assign from.
281
+ * \return <tt>*this</tt>
282
+ */
283
+ template <typename OtherT>
284
+ _CCCL_HOST_DEVICE device_reference& operator=(const device_reference<OtherT>& other)
285
+ {
286
+ return super_t::operator=(other);
287
+ }
288
+
289
+ /*! Assignment operator assigns the value of the given value to the
290
+ * value referenced by this \p device_reference.
291
+ *
292
+ * \param x The value to assign from.
293
+ * \return <tt>*this</tt>
294
+ */
295
+ _CCCL_HOST_DEVICE device_reference& operator=(const value_type& x)
296
+ {
297
+ return super_t::operator=(x);
298
+ }
299
+
300
+ // declare these members for the purpose of Doxygenating them
301
+ // they actually exist in a base class
302
+ #if 0
303
+ /*! Address-of operator returns a \p device_ptr pointing to the object
304
+ * referenced by this \p device_reference. It does not return the
305
+ * address of this \p device_reference.
306
+ *
307
+ * \return A \p device_ptr pointing to the object this
308
+ * \p device_reference references.
309
+ */
310
+ _CCCL_HOST_DEVICE
311
+ pointer operator&(void) const;
312
+
313
+ /*! Conversion operator converts this \p device_reference to T
314
+ * by returning a copy of the object referenced by this
315
+ * \p device_reference.
316
+ *
317
+ * \return A copy of the object referenced by this \p device_reference.
318
+ */
319
+ _CCCL_HOST_DEVICE
320
+ operator value_type (void) const;
321
+
322
+ /*! swaps the value this \p device_reference references with another.
323
+ * \p other The other \p device_reference with which to swap.
324
+ */
325
+ _CCCL_HOST_DEVICE
326
+ void swap(device_reference &other);
327
+
328
+ /*! Prefix increment operator increments the object referenced by this
329
+ * \p device_reference.
330
+ *
331
+ * \return <tt>*this</tt>
332
+ *
333
+ * The following code snippet demonstrates the semantics of
334
+ * \p device_reference's prefix increment operator.
335
+ *
336
+ * \code
337
+ * #include <thrust/device_vector.h>
338
+ * #include <assert.h>
339
+ * ...
340
+ * thrust::device_vector<int> v(1,0);
341
+ * thrust::device_ptr<int> ptr = &v[0];
342
+ * thrust::device_reference<int> ref(ptr);
343
+ *
344
+ * // ref equals 0
345
+ * assert(ref == 0);
346
+ *
347
+ * // the object pointed to by ptr equals 1
348
+ * assert(*ptr == 1);
349
+ *
350
+ * // v[0] equals 1
351
+ * assert(v[0] == 1);
352
+ *
353
+ * // increment ref
354
+ * ++ref;
355
+ *
356
+ * // ref equals 1
357
+ * assert(ref == 1);
358
+ *
359
+ * // the object pointed to by ptr equals 1
360
+ * assert(*ptr == 1);
361
+ *
362
+ * // v[0] equals 1
363
+ * assert(v[0] == 1);
364
+ * \endcode
365
+ *
366
+ * \note The increment executes as if it were executed on the host.
367
+ * This may change in a later version.
368
+ */
369
+ device_reference &operator++(void);
370
+
371
+ /*! Postfix increment operator copies the object referenced by this
372
+ * \p device_reference, increments the object referenced by this
373
+ * \p device_reference, and returns the copy.
374
+ *
375
+ * \return A copy of the object referenced by this \p device_reference
376
+ * before being incremented.
377
+ *
378
+ * The following code snippet demonstrates the semantics of
379
+ * \p device_reference's postfix increment operator.
380
+ *
381
+ * \code
382
+ * #include <thrust/device_vector.h>
383
+ * #include <assert.h>
384
+ * ...
385
+ * thrust::device_vector<int> v(1,0);
386
+ * thrust::device_ptr<int> ptr = &v[0];
387
+ * thrust::device_reference<int> ref(ptr);
388
+ *
389
+ * // ref equals 0
390
+ * assert(ref == 0);
391
+ *
392
+ * // the object pointed to by ptr equals 0
393
+ * assert(*ptr == 0);
394
+ *
395
+ * // v[0] equals 0
396
+ * assert(v[0] == 0);
397
+ *
398
+ * // increment ref
399
+ * int x = ref++;
400
+ *
401
+ * // x equals 0
402
+ * assert(x == 0)
403
+ *
404
+ * // ref equals 1
405
+ * assert(ref == 1);
406
+ *
407
+ * // the object pointed to by ptr equals 1
408
+ * assert(*ptr == 1);
409
+ *
410
+ * // v[0] equals 1
411
+ * assert(v[0] == 1);
412
+ * \endcode
413
+ *
414
+ * \note The increment executes as if it were executed on the host.
415
+ * This may change in a later version.
416
+ */
417
+ value_type operator++(int);
418
+
419
+ /*! Addition assignment operator add-assigns the object referenced by this
420
+ * \p device_reference and returns this \p device_reference.
421
+ *
422
+ * \param rhs The right hand side of the add-assignment.
423
+ * \return <tt>*this</tt>.
424
+ *
425
+ * The following code snippet demonstrates the semantics of
426
+ * \p device_reference's addition assignment operator.
427
+ *
428
+ * \code
429
+ * #include <thrust/device_vector.h>
430
+ * #include <assert.h>
431
+ * ...
432
+ * thrust::device_vector<int> v(1,0);
433
+ * thrust::device_ptr<int> ptr = &v[0];
434
+ * thrust::device_reference<int> ref(ptr);
435
+ *
436
+ * // ref equals 0
437
+ * assert(ref == 0);
438
+ *
439
+ * // the object pointed to by ptr equals 0
440
+ * assert(*ptr == 0);
441
+ *
442
+ * // v[0] equals 0
443
+ * assert(v[0] == 0);
444
+ *
445
+ * // add-assign ref
446
+ * ref += 5;
447
+ *
448
+ * // ref equals 5
449
+ * assert(ref == 5);
450
+ *
451
+ * // the object pointed to by ptr equals 5
452
+ * assert(*ptr == 5);
453
+ *
454
+ * // v[0] equals 5
455
+ * assert(v[0] == 5);
456
+ * \endcode
457
+ *
458
+ * \note The add-assignment executes as as if it were executed on the host.
459
+ * This may change in a later version.
460
+ */
461
+ device_reference &operator+=(const T &rhs);
462
+
463
+ /*! Prefix decrement operator decrements the object referenced by this
464
+ * \p device_reference.
465
+ *
466
+ * \return <tt>*this</tt>
467
+ *
468
+ * The following code snippet demonstrates the semantics of
469
+ * \p device_reference's prefix decrement operator.
470
+ *
471
+ * \code
472
+ * #include <thrust/device_vector.h>
473
+ * #include <assert.h>
474
+ * ...
475
+ * thrust::device_vector<int> v(1,0);
476
+ * thrust::device_ptr<int> ptr = &v[0];
477
+ * thrust::device_reference<int> ref(ptr);
478
+ *
479
+ * // ref equals 0
480
+ * assert(ref == 0);
481
+ *
482
+ * // the object pointed to by ptr equals 0
483
+ * assert(*ptr == 0);
484
+ *
485
+ * // v[0] equals 0
486
+ * assert(v[0] == 0);
487
+ *
488
+ * // decrement ref
489
+ * --ref;
490
+ *
491
+ * // ref equals -1
492
+ * assert(ref == -1);
493
+ *
494
+ * // the object pointed to by ptr equals -1
495
+ * assert(*ptr == -1);
496
+ *
497
+ * // v[0] equals -1
498
+ * assert(v[0] == -1);
499
+ * \endcode
500
+ *
501
+ * \note The decrement executes as if it were executed on the host.
502
+ * This may change in a later version.
503
+ */
504
+ device_reference &operator--(void);
505
+
506
+ /*! Postfix decrement operator copies the object referenced by this
507
+ * \p device_reference, decrements the object referenced by this
508
+ * \p device_reference, and returns the copy.
509
+ *
510
+ * \return A copy of the object referenced by this \p device_reference
511
+ * before being decremented.
512
+ *
513
+ * The following code snippet demonstrates the semantics of
514
+ * \p device_reference's postfix decrement operator.
515
+ *
516
+ * \code
517
+ * #include <thrust/device_vector.h>
518
+ * #include <assert.h>
519
+ * ...
520
+ * thrust::device_vector<int> v(1,0);
521
+ * thrust::device_ptr<int> ptr = &v[0];
522
+ * thrust::device_reference<int> ref(ptr);
523
+ *
524
+ * // ref equals 0
525
+ * assert(ref == 0);
526
+ *
527
+ * // the object pointed to by ptr equals 0
528
+ * assert(*ptr == 0);
529
+ *
530
+ * // v[0] equals 0
531
+ * assert(v[0] == 0);
532
+ *
533
+ * // decrement ref
534
+ * int x = ref--;
535
+ *
536
+ * // x equals 0
537
+ * assert(x == 0)
538
+ *
539
+ * // ref equals -1
540
+ * assert(ref == -1);
541
+ *
542
+ * // the object pointed to by ptr equals -1
543
+ * assert(*ptr == -1);
544
+ *
545
+ * // v[0] equals -1
546
+ * assert(v[0] == -1);
547
+ * \endcode
548
+ *
549
+ * \note The decrement executes as if it were executed on the host.
550
+ * This may change in a later version.
551
+ */
552
+ value_type operator--(int);
553
+
554
+ /*! Subtraction assignment operator subtract-assigns the object referenced by this
555
+ * \p device_reference and returns this \p device_reference.
556
+ *
557
+ * \param rhs The right hand side of the subtraction-assignment.
558
+ * \return <tt>*this</tt>.
559
+ *
560
+ * The following code snippet demonstrates the semantics of
561
+ * \p device_reference's addition assignment operator.
562
+ *
563
+ * \code
564
+ * #include <thrust/device_vector.h>
565
+ * #include <assert.h>
566
+ * ...
567
+ * thrust::device_vector<int> v(1,0);
568
+ * thrust::device_ptr<int> ptr = &v[0];
569
+ * thrust::device_reference<int> ref(ptr);
570
+ *
571
+ * // ref equals 0
572
+ * assert(ref == 0);
573
+ *
574
+ * // the object pointed to by ptr equals 0
575
+ * assert(*ptr == 0);
576
+ *
577
+ * // v[0] equals 0
578
+ * assert(v[0] == 0);
579
+ *
580
+ * // subtract-assign ref
581
+ * ref -= 5;
582
+ *
583
+ * // ref equals -5
584
+ * assert(ref == -5);
585
+ *
586
+ * // the object pointed to by ptr equals -5
587
+ * assert(*ptr == -5);
588
+ *
589
+ * // v[0] equals -5
590
+ * assert(v[0] == -5);
591
+ * \endcode
592
+ *
593
+ * \note The subtract-assignment executes as as if it were executed on the host.
594
+ * This may change in a later version.
595
+ */
596
+ device_reference &operator-=(const T &rhs);
597
+
598
+ /*! Multiplication assignment operator multiply-assigns the object referenced by this
599
+ * \p device_reference and returns this \p device_reference.
600
+ *
601
+ * \param rhs The right hand side of the multiply-assignment.
602
+ * \return <tt>*this</tt>.
603
+ *
604
+ * The following code snippet demonstrates the semantics of
605
+ * \p device_reference's multiply assignment operator.
606
+ *
607
+ * \code
608
+ * #include <thrust/device_vector.h>
609
+ * #include <assert.h>
610
+ * ...
611
+ * thrust::device_vector<int> v(1,1);
612
+ * thrust::device_ptr<int> ptr = &v[0];
613
+ * thrust::device_reference<int> ref(ptr);
614
+ *
615
+ * // ref equals 1
616
+ * assert(ref == 1);
617
+ *
618
+ * // the object pointed to by ptr equals 1
619
+ * assert(*ptr == 1);
620
+ *
621
+ * // v[0] equals 1
622
+ * assert(v[0] == 1);
623
+ *
624
+ * // multiply-assign ref
625
+ * ref *= 5;
626
+ *
627
+ * // ref equals 5
628
+ * assert(ref == 5);
629
+ *
630
+ * // the object pointed to by ptr equals 5
631
+ * assert(*ptr == 5);
632
+ *
633
+ * // v[0] equals 5
634
+ * assert(v[0] == 5);
635
+ * \endcode
636
+ *
637
+ * \note The multiply-assignment executes as as if it were executed on the host.
638
+ * This may change in a later version.
639
+ */
640
+ device_reference &operator*=(const T &rhs);
641
+
642
+ /*! Division assignment operator divide-assigns the object referenced by this
643
+ * \p device_reference and returns this \p device_reference.
644
+ *
645
+ * \param rhs The right hand side of the divide-assignment.
646
+ * \return <tt>*this</tt>.
647
+ *
648
+ * The following code snippet demonstrates the semantics of
649
+ * \p device_reference's divide assignment operator.
650
+ *
651
+ * \code
652
+ * #include <thrust/device_vector.h>
653
+ * #include <assert.h>
654
+ * ...
655
+ * thrust::device_vector<int> v(1,5);
656
+ * thrust::device_ptr<int> ptr = &v[0];
657
+ * thrust::device_reference<int> ref(ptr);
658
+ *
659
+ * // ref equals 5
660
+ * assert(ref == 5);
661
+ *
662
+ * // the object pointed to by ptr equals 5
663
+ * assert(*ptr == 5);
664
+ *
665
+ * // v[0] equals 5
666
+ * assert(v[0] == 5);
667
+ *
668
+ * // divide-assign ref
669
+ * ref /= 5;
670
+ *
671
+ * // ref equals 1
672
+ * assert(ref == 1);
673
+ *
674
+ * // the object pointed to by ptr equals 1
675
+ * assert(*ptr == 1);
676
+ *
677
+ * // v[0] equals 1
678
+ * assert(v[0] == 1);
679
+ * \endcode
680
+ *
681
+ * \note The divide-assignment executes as as if it were executed on the host.
682
+ * This may change in a later version.
683
+ */
684
+ device_reference &operator/=(const T &rhs);
685
+
686
+ /*! Modulation assignment operator modulus-assigns the object referenced by this
687
+ * \p device_reference and returns this \p device_reference.
688
+ *
689
+ * \param rhs The right hand side of the divide-assignment.
690
+ * \return <tt>*this</tt>.
691
+ *
692
+ * The following code snippet demonstrates the semantics of
693
+ * \p device_reference's divide assignment operator.
694
+ *
695
+ * \code
696
+ * #include <thrust/device_vector.h>
697
+ * #include <assert.h>
698
+ * ...
699
+ * thrust::device_vector<int> v(1,5);
700
+ * thrust::device_ptr<int> ptr = &v[0];
701
+ * thrust::device_reference<int> ref(ptr);
702
+ *
703
+ * // ref equals 5
704
+ * assert(ref == 5);
705
+ *
706
+ * // the object pointed to by ptr equals 5
707
+ * assert(*ptr == 5);
708
+ *
709
+ * // v[0] equals 5
710
+ * assert(v[0] == 5);
711
+ *
712
+ * // modulus-assign ref
713
+ * ref %= 5;
714
+ *
715
+ * // ref equals 0
716
+ * assert(ref == 0);
717
+ *
718
+ * // the object pointed to by ptr equals 0
719
+ * assert(*ptr == 0);
720
+ *
721
+ * // v[0] equals 0
722
+ * assert(v[0] == 0);
723
+ * \endcode
724
+ *
725
+ * \note The modulus-assignment executes as as if it were executed on the host.
726
+ * This may change in a later version.
727
+ */
728
+ device_reference &operator%=(const T &rhs);
729
+
730
+ /*! Bitwise left shift assignment operator left shift-assigns the object referenced by this
731
+ * \p device_reference and returns this \p device_reference.
732
+ *
733
+ * \param rhs The right hand side of the left shift-assignment.
734
+ * \return <tt>*this</tt>.
735
+ *
736
+ * The following code snippet demonstrates the semantics of
737
+ * \p device_reference's left shift assignment operator.
738
+ *
739
+ * \code
740
+ * #include <thrust/device_vector.h>
741
+ * #include <assert.h>
742
+ * ...
743
+ * thrust::device_vector<int> v(1,1);
744
+ * thrust::device_ptr<int> ptr = &v[0];
745
+ * thrust::device_reference<int> ref(ptr);
746
+ *
747
+ * // ref equals 1
748
+ * assert(ref == 1);
749
+ *
750
+ * // the object pointed to by ptr equals 1
751
+ * assert(*ptr == 1);
752
+ *
753
+ * // v[0] equals 1
754
+ * assert(v[0] == 1);
755
+ *
756
+ * // left shift-assign ref
757
+ * ref <<= 1;
758
+ *
759
+ * // ref equals 2
760
+ * assert(ref == 2);
761
+ *
762
+ * // the object pointed to by ptr equals 2
763
+ * assert(*ptr == 2);
764
+ *
765
+ * // v[0] equals 2
766
+ * assert(v[0] == 2);
767
+ * \endcode
768
+ *
769
+ * \note The left shift-assignment executes as as if it were executed on the host.
770
+ * This may change in a later version.
771
+ */
772
+ device_reference &operator<<=(const T &rhs);
773
+
774
+ /*! Bitwise right shift assignment operator right shift-assigns the object referenced by this
775
+ * \p device_reference and returns this \p device_reference.
776
+ *
777
+ * \param rhs The right hand side of the right shift-assignment.
778
+ * \return <tt>*this</tt>.
779
+ *
780
+ * The following code snippet demonstrates the semantics of
781
+ * \p device_reference's right shift assignment operator.
782
+ *
783
+ * \code
784
+ * #include <thrust/device_vector.h>
785
+ * #include <assert.h>
786
+ * ...
787
+ * thrust::device_vector<int> v(1,2);
788
+ * thrust::device_ptr<int> ptr = &v[0];
789
+ * thrust::device_reference<int> ref(ptr);
790
+ *
791
+ * // ref equals 2
792
+ * assert(ref == 2);
793
+ *
794
+ * // the object pointed to by ptr equals 2
795
+ * assert(*ptr == 2);
796
+ *
797
+ * // v[0] equals 2
798
+ * assert(v[0] == 2);
799
+ *
800
+ * // right shift-assign ref
801
+ * ref >>= 1;
802
+ *
803
+ * // ref equals 1
804
+ * assert(ref == 1);
805
+ *
806
+ * // the object pointed to by ptr equals 1
807
+ * assert(*ptr == 1);
808
+ *
809
+ * // v[0] equals 1
810
+ * assert(v[0] == 1);
811
+ * \endcode
812
+ *
813
+ * \note The right shift-assignment executes as as if it were executed on the host.
814
+ * This may change in a later version.
815
+ */
816
+ device_reference &operator>>=(const T &rhs);
817
+
818
+ /*! Bitwise AND assignment operator AND-assigns the object referenced by this
819
+ * \p device_reference and returns this \p device_reference.
820
+ *
821
+ * \param rhs The right hand side of the AND-assignment.
822
+ * \return <tt>*this</tt>.
823
+ *
824
+ * The following code snippet demonstrates the semantics of
825
+ * \p device_reference's AND assignment operator.
826
+ *
827
+ * \code
828
+ * #include <thrust/device_vector.h>
829
+ * #include <assert.h>
830
+ * ...
831
+ * thrust::device_vector<int> v(1,1);
832
+ * thrust::device_ptr<int> ptr = &v[0];
833
+ * thrust::device_reference<int> ref(ptr);
834
+ *
835
+ * // ref equals 1
836
+ * assert(ref == 1);
837
+ *
838
+ * // the object pointed to by ptr equals 1
839
+ * assert(*ptr == 1);
840
+ *
841
+ * // v[0] equals 1
842
+ * assert(v[0] == 1);
843
+ *
844
+ * // right AND-assign ref
845
+ * ref &= 0;
846
+ *
847
+ * // ref equals 0
848
+ * assert(ref == 0);
849
+ *
850
+ * // the object pointed to by ptr equals 0
851
+ * assert(*ptr == 0);
852
+ *
853
+ * // v[0] equals 0
854
+ * assert(v[0] == 0);
855
+ * \endcode
856
+ *
857
+ * \note The AND-assignment executes as as if it were executed on the host.
858
+ * This may change in a later version.
859
+ */
860
+ device_reference &operator&=(const T &rhs);
861
+
862
+ /*! Bitwise OR assignment operator OR-assigns the object referenced by this
863
+ * \p device_reference and returns this \p device_reference.
864
+ *
865
+ * \param rhs The right hand side of the OR-assignment.
866
+ * \return <tt>*this</tt>.
867
+ *
868
+ * The following code snippet demonstrates the semantics of
869
+ * \p device_reference's OR assignment operator.
870
+ *
871
+ * \code
872
+ * #include <thrust/device_vector.h>
873
+ * #include <assert.h>
874
+ * ...
875
+ * thrust::device_vector<int> v(1,0);
876
+ * thrust::device_ptr<int> ptr = &v[0];
877
+ * thrust::device_reference<int> ref(ptr);
878
+ *
879
+ * // ref equals 0
880
+ * assert(ref == 0);
881
+ *
882
+ * // the object pointed to by ptr equals 0
883
+ * assert(*ptr == 0);
884
+ *
885
+ * // v[0] equals 0
886
+ * assert(v[0] == 0);
887
+ *
888
+ * // right OR-assign ref
889
+ * ref |= 1;
890
+ *
891
+ * // ref equals 1
892
+ * assert(ref == 1);
893
+ *
894
+ * // the object pointed to by ptr equals 1
895
+ * assert(*ptr == 1);
896
+ *
897
+ * // v[0] equals 1
898
+ * assert(v[0] == 1);
899
+ * \endcode
900
+ *
901
+ * \note The OR-assignment executes as as if it were executed on the host.
902
+ * This may change in a later version.
903
+ */
904
+ device_reference &operator|=(const T &rhs);
905
+
906
+ /*! Bitwise XOR assignment operator XOR-assigns the object referenced by this
907
+ * \p device_reference and returns this \p device_reference.
908
+ *
909
+ * \param rhs The right hand side of the XOR-assignment.
910
+ * \return <tt>*this</tt>.
911
+ *
912
+ * The following code snippet demonstrates the semantics of
913
+ * \p device_reference's XOR assignment operator.
914
+ *
915
+ * \code
916
+ * #include <thrust/device_vector.h>
917
+ * #include <assert.h>
918
+ * ...
919
+ * thrust::device_vector<int> v(1,1);
920
+ * thrust::device_ptr<int> ptr = &v[0];
921
+ * thrust::device_reference<int> ref(ptr);
922
+ *
923
+ * // ref equals 1
924
+ * assert(ref == 1);
925
+ *
926
+ * // the object pointed to by ptr equals 1
927
+ * assert(*ptr == 1);
928
+ *
929
+ * // v[0] equals 1
930
+ * assert(v[0] == 1);
931
+ *
932
+ * // right XOR-assign ref
933
+ * ref ^= 1;
934
+ *
935
+ * // ref equals 0
936
+ * assert(ref == 0);
937
+ *
938
+ * // the object pointed to by ptr equals 0
939
+ * assert(*ptr == 0);
940
+ *
941
+ * // v[0] equals 0
942
+ * assert(v[0] == 0);
943
+ * \endcode
944
+ *
945
+ * \note The XOR-assignment executes as as if it were executed on the host.
946
+ * This may change in a later version.
947
+ */
948
+ device_reference &operator^=(const T &rhs);
949
+ #endif // end doxygen-only members
950
+
951
+ /*! swaps the value of one \p device_reference with another.
952
+ * \p x The first \p device_reference of interest.
953
+ * \p y The second \p device_reference of interest.
954
+ */
955
+ _CCCL_HOST_DEVICE friend void swap(device_reference& x, device_reference& y) noexcept(noexcept(x.swap(y)))
956
+ {
957
+ x.swap(y);
958
+ }
959
+ }; // end device_reference
960
+
961
+ // declare these methods for the purpose of Doxygenating them
962
+ // they actually are defined for a base class
963
+ #ifdef _CCCL_DOXYGEN_INVOKED
964
+ /*! Writes to an output stream the value of a \p device_reference.
965
+ *
966
+ * \param os The output stream.
967
+ * \param y The \p device_reference to output.
968
+ * \return os.
969
+ */
970
+ template <typename T, typename charT, typename traits>
971
+ std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const device_reference<T>& y);
972
+ #endif
973
+
974
+ /*! \} // memory_management
975
+ */
976
+
977
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_vector.h ADDED
@@ -0,0 +1,547 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
18
+ * \brief A dynamically-sizable array of elements which resides in memory
19
+ * accessible to devices.
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/detail/vector_base.h>
34
+ #include <thrust/device_allocator.h>
35
+
36
+ #include <initializer_list>
37
+ #include <utility>
38
+ #include <vector>
39
+
40
+ THRUST_NAMESPACE_BEGIN
41
+
42
+ /*! \addtogroup containers Containers
43
+ * \{
44
+ */
45
+
46
+ /*! A \p device_vector is a container that supports random access to elements,
47
+ * constant time removal of elements at the end, and linear time insertion
48
+ * and removal of elements at the beginning or in the middle. The number of
49
+ * elements in a \p device_vector may vary dynamically; memory management is
50
+ * automatic. The memory associated with a \p device_vector resides in the
51
+ * memory accessible to devices.
52
+ *
53
+ * \see https://en.cppreference.com/w/cpp/container/vector
54
+ * \see device_allocator
55
+ * \see host_vector
56
+ * \see universal_vector
57
+ */
58
+ template <typename T, typename Alloc = thrust::device_allocator<T>>
59
+ class device_vector : public detail::vector_base<T, Alloc>
60
+ {
61
+ private:
62
+ using Parent = detail::vector_base<T, Alloc>;
63
+
64
+ public:
65
+ /*! \cond
66
+ */
67
+ using size_type = typename Parent::size_type;
68
+ using value_type = typename Parent::value_type;
69
+ /*! \endcond
70
+ */
71
+
72
+ /*! This constructor creates an empty \p device_vector.
73
+ */
74
+ device_vector()
75
+ : Parent()
76
+ {}
77
+
78
+ /*! This constructor creates an empty \p device_vector.
79
+ * \param alloc The allocator to use by this device_vector.
80
+ */
81
+ device_vector(const Alloc& alloc)
82
+ : Parent(alloc)
83
+ {}
84
+
85
+ /*! The destructor erases the elements.
86
+ */
87
+ // Define an empty destructor to explicitly specify
88
+ // its execution space qualifier, as a workaround for nvcc warning
89
+ ~device_vector() {}
90
+
91
+ /*! This constructor creates a \p device_vector with the given
92
+ * size.
93
+ * \param n The number of elements to initially create.
94
+ */
95
+ explicit device_vector(size_type n)
96
+ : Parent(n)
97
+ {}
98
+
99
+ /*! This constructor creates a \p device_vector with the given
100
+ * size.
101
+ * \param n The number of elements to initially create.
102
+ * \param alloc The allocator to use by this device_vector.
103
+ */
104
+ explicit device_vector(size_type n, const Alloc& alloc)
105
+ : Parent(n, alloc)
106
+ {}
107
+
108
+ /*! This constructor creates a \p device_vector with copies
109
+ * of an exemplar element.
110
+ * \param n The number of elements to initially create.
111
+ * \param value An element to copy.
112
+ */
113
+ explicit device_vector(size_type n, const value_type& value)
114
+ : Parent(n, value)
115
+ {}
116
+
117
+ /*! This constructor creates a \p device_vector with copies
118
+ * of an exemplar element.
119
+ * \param n The number of elements to initially create.
120
+ * \param value An element to copy.
121
+ * \param alloc The allocator to use by this device_vector.
122
+ */
123
+ explicit device_vector(size_type n, const value_type& value, const Alloc& alloc)
124
+ : Parent(n, value, alloc)
125
+ {}
126
+
127
+ /*! Copy constructor copies from an exemplar \p device_vector.
128
+ * \param v The \p device_vector to copy.
129
+ */
130
+ device_vector(const device_vector& v)
131
+ : Parent(v)
132
+ {}
133
+
134
+ /*! Copy constructor copies from an exemplar \p device_vector.
135
+ * \param v The \p device_vector to copy.
136
+ * \param alloc The allocator to use by this device_vector.
137
+ */
138
+ device_vector(const device_vector& v, const Alloc& alloc)
139
+ : Parent(v, alloc)
140
+ {}
141
+
142
+ /*! Move constructor moves from another \p device_vector.
143
+ * \param v The device_vector to move.
144
+ */
145
+ device_vector(device_vector&& v)
146
+ : Parent(std::move(v))
147
+ {}
148
+
149
+ /*! Move constructor moves from another \p device_vector.
150
+ * \param v The device_vector to move.
151
+ * \param alloc The allocator to use by this device_vector.
152
+ */
153
+ device_vector(device_vector&& v, const Alloc& alloc)
154
+ : Parent(std::move(v), alloc)
155
+ {}
156
+
157
+ /*! Copy assign operator copies another \p device_vector with the same type.
158
+ * \param v The \p device_vector to copy.
159
+ */
160
+ device_vector& operator=(const device_vector& v)
161
+ {
162
+ Parent::operator=(v);
163
+ return *this;
164
+ }
165
+
166
+ /*! Move assign operator moves from another \p device_vector.
167
+ * \param v The device_vector to move.
168
+ */
169
+ device_vector& operator=(device_vector&& v)
170
+ {
171
+ Parent::operator=(std::move(v));
172
+ return *this;
173
+ }
174
+
175
+ /*! Copy constructor copies from an exemplar \p device_vector with different type.
176
+ * \param v The \p device_vector to copy.
177
+ */
178
+ template <typename OtherT, typename OtherAlloc>
179
+ explicit device_vector(const device_vector<OtherT, OtherAlloc>& v)
180
+ : Parent(v)
181
+ {}
182
+
183
+ /*! Assign operator copies from an exemplar \p device_vector with different type.
184
+ * \param v The \p device_vector to copy.
185
+ */
186
+ template <typename OtherT, typename OtherAlloc>
187
+ device_vector& operator=(const device_vector<OtherT, OtherAlloc>& v)
188
+ {
189
+ Parent::operator=(v);
190
+ return *this;
191
+ }
192
+
193
+ /*! Copy constructor copies from an exemplar \c std::vector.
194
+ * \param v The <tt>std::vector</tt> to copy.
195
+ */
196
+ template <typename OtherT, typename OtherAlloc>
197
+ device_vector(const std::vector<OtherT, OtherAlloc>& v)
198
+ : Parent(v)
199
+ {}
200
+
201
+ /*! Assign operator copies from an exemplar <tt>std::vector</tt>.
202
+ * \param v The <tt>std::vector</tt> to copy.
203
+ */
204
+ template <typename OtherT, typename OtherAlloc>
205
+ device_vector& operator=(const std::vector<OtherT, OtherAlloc>& v)
206
+ {
207
+ Parent::operator=(v);
208
+ return *this;
209
+ }
210
+
211
+ /*! Copy construct from a \p vector_base whose element type is convertible
212
+ * to \c T.
213
+ *
214
+ * \param v The \p vector_base to copy.
215
+ */
216
+ template <typename OtherT, typename OtherAlloc>
217
+ device_vector(const detail::vector_base<OtherT, OtherAlloc>& v)
218
+ : Parent(v)
219
+ {}
220
+
221
+ /*! Assign a \p vector_base whose element type is convertible to \c T.
222
+ * \param v The \p vector_base to copy.
223
+ */
224
+ template <typename OtherT, typename OtherAlloc>
225
+ device_vector& operator=(const detail::vector_base<OtherT, OtherAlloc>& v)
226
+ {
227
+ Parent::operator=(v);
228
+ return *this;
229
+ }
230
+
231
+ /*! This constructor builds a \p device_vector from an intializer_list.
232
+ * \param il The intializer_list.
233
+ */
234
+ device_vector(std::initializer_list<T> il)
235
+ : Parent(il)
236
+ {}
237
+
238
+ /*! This constructor builds a \p device_vector from an intializer_list.
239
+ * \param il The intializer_list.
240
+ * \param alloc The allocator to use by this device_vector.
241
+ */
242
+ device_vector(std::initializer_list<T> il, const Alloc& alloc)
243
+ : Parent(il, alloc)
244
+ {}
245
+
246
+ /*! Assign an \p intializer_list with a matching element type
247
+ * \param il The intializer_list.
248
+ */
249
+ device_vector& operator=(std::initializer_list<T> il)
250
+ {
251
+ Parent::operator=(il);
252
+ return *this;
253
+ }
254
+
255
+ /*! This constructor builds a \p device_vector from a range.
256
+ * \param first The beginning of the range.
257
+ * \param last The end of the range.
258
+ */
259
+ template <typename InputIterator>
260
+ device_vector(InputIterator first, InputIterator last)
261
+ : Parent(first, last)
262
+ {}
263
+
264
+ /*! This constructor builds a \p device_vector from a range.
265
+ * \param first The beginning of the range.
266
+ * \param last The end of the range.
267
+ * \param alloc The allocator to use by this device_vector.
268
+ */
269
+ template <typename InputIterator>
270
+ device_vector(InputIterator first, InputIterator last, const Alloc& alloc)
271
+ : Parent(first, last, alloc)
272
+ {}
273
+
274
+ /*! Exchanges the values of two vectors.
275
+ * \p x The first \p device_vector of interest.
276
+ * \p y The second \p device_vector of interest.
277
+ */
278
+ friend void swap(device_vector& a, device_vector& b) noexcept(noexcept(a.swap(b)))
279
+ {
280
+ a.swap(b);
281
+ }
282
+
283
+ // declare these members for the purpose of Doxygenating them
284
+ // they actually exist in a base class
285
+ #if 0
286
+ /*! \brief Resizes this vector to the specified number of elements.
287
+ * \param new_size Number of elements this vector should contain.
288
+ * \param x Data with which new elements should be populated.
289
+ * \throw std::length_error If n exceeds max_size().
290
+ *
291
+ * This method will resize this vector to the specified number of
292
+ * elements. If the number is smaller than this vector's current
293
+ * size this vector is truncated, otherwise this vector is
294
+ * extended and new elements are populated with given data.
295
+ */
296
+ void resize(size_type new_size, const value_type &x = value_type());
297
+
298
+ /*! Returns the number of elements in this vector.
299
+ */
300
+ size_type size() const;
301
+
302
+ /*! Returns the size() of the largest possible vector.
303
+ * \return The largest possible return value of size().
304
+ */
305
+ size_type max_size() const;
306
+
307
+ /*! \brief If n is less than or equal to capacity(), this call has no effect.
308
+ * Otherwise, this method is a request for allocation of additional memory. If
309
+ * the request is successful, then capacity() is greater than or equal to
310
+ * n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
311
+ * \throw std::length_error If n exceeds max_size().
312
+ */
313
+ void reserve(size_type n);
314
+
315
+ /*! Returns the number of elements which have been reserved in this
316
+ * vector.
317
+ */
318
+ size_type capacity() const;
319
+
320
+ /*! This method shrinks the capacity of this vector to exactly
321
+ * fit its elements.
322
+ */
323
+ void shrink_to_fit();
324
+
325
+ /*! \brief Subscript access to the data contained in this vector_dev.
326
+ * \param n The index of the element for which data should be accessed.
327
+ * \return Read/write reference to data.
328
+ *
329
+ * This operator allows for easy, array-style, data access.
330
+ * Note that data access with this operator is unchecked and
331
+ * out_of_range lookups are not defined.
332
+ */
333
+ reference operator[](size_type n);
334
+
335
+ /*! \brief Subscript read access to the data contained in this vector_dev.
336
+ * \param n The index of the element for which data should be accessed.
337
+ * \return Read reference to data.
338
+ *
339
+ * This operator allows for easy, array-style, data access.
340
+ * Note that data access with this operator is unchecked and
341
+ * out_of_range lookups are not defined.
342
+ */
343
+ const_reference operator[](size_type n) const;
344
+
345
+ /*! This method returns an iterator pointing to the beginning of
346
+ * this vector.
347
+ * \return mStart
348
+ */
349
+ iterator begin();
350
+
351
+ /*! This method returns a const_iterator pointing to the beginning
352
+ * of this vector.
353
+ * \return mStart
354
+ */
355
+ const_iterator begin() const;
356
+
357
+ /*! This method returns a const_iterator pointing to the beginning
358
+ * of this vector.
359
+ * \return mStart
360
+ */
361
+ const_iterator cbegin() const;
362
+
363
+ /*! This method returns a reverse_iterator pointing to the beginning of
364
+ * this vector's reversed sequence.
365
+ * \return A reverse_iterator pointing to the beginning of this
366
+ * vector's reversed sequence.
367
+ */
368
+ reverse_iterator rbegin();
369
+
370
+ /*! This method returns a const_reverse_iterator pointing to the beginning of
371
+ * this vector's reversed sequence.
372
+ * \return A const_reverse_iterator pointing to the beginning of this
373
+ * vector's reversed sequence.
374
+ */
375
+ const_reverse_iterator rbegin() const;
376
+
377
+ /*! This method returns a const_reverse_iterator pointing to the beginning of
378
+ * this vector's reversed sequence.
379
+ * \return A const_reverse_iterator pointing to the beginning of this
380
+ * vector's reversed sequence.
381
+ */
382
+ const_reverse_iterator crbegin() const;
383
+
384
+ /*! This method returns an iterator pointing to one element past the
385
+ * last of this vector.
386
+ * \return begin() + size().
387
+ */
388
+ iterator end();
389
+
390
+ /*! This method returns a const_iterator pointing to one element past the
391
+ * last of this vector.
392
+ * \return begin() + size().
393
+ */
394
+ const_iterator end() const;
395
+
396
+ /*! This method returns a const_iterator pointing to one element past the
397
+ * last of this vector.
398
+ * \return begin() + size().
399
+ */
400
+ const_iterator cend() const;
401
+
402
+ /*! This method returns a reverse_iterator pointing to one element past the
403
+ * last of this vector's reversed sequence.
404
+ * \return rbegin() + size().
405
+ */
406
+ reverse_iterator rend();
407
+
408
+ /*! This method returns a const_reverse_iterator pointing to one element past the
409
+ * last of this vector's reversed sequence.
410
+ * \return rbegin() + size().
411
+ */
412
+ const_reverse_iterator rend() const;
413
+
414
+ /*! This method returns a const_reverse_iterator pointing to one element past the
415
+ * last of this vector's reversed sequence.
416
+ * \return rbegin() + size().
417
+ */
418
+ const_reverse_iterator crend() const;
419
+
420
+ /*! This method returns a const_reference referring to the first element of this
421
+ * vector.
422
+ * \return The first element of this vector.
423
+ */
424
+ const_reference front() const;
425
+
426
+ /*! This method returns a reference pointing to the first element of this
427
+ * vector.
428
+ * \return The first element of this vector.
429
+ */
430
+ reference front();
431
+
432
+ /*! This method returns a const reference pointing to the last element of
433
+ * this vector.
434
+ * \return The last element of this vector.
435
+ */
436
+ const_reference back() const;
437
+
438
+ /*! This method returns a reference referring to the last element of
439
+ * this vector_dev.
440
+ * \return The last element of this vector.
441
+ */
442
+ reference back();
443
+
444
+ /*! This method returns a pointer to this vector's first element.
445
+ * \return A pointer to the first element of this vector.
446
+ */
447
+ pointer data();
448
+
449
+ /*! This method returns a const_pointer to this vector's first element.
450
+ * \return a const_pointer to the first element of this vector.
451
+ */
452
+ const_pointer data() const;
453
+
454
+ /*! This method resizes this vector to 0.
455
+ */
456
+ void clear();
457
+
458
+ /*! This method returns true iff size() == 0.
459
+ * \return true if size() == 0; false, otherwise.
460
+ */
461
+ bool empty() const;
462
+
463
+ /*! This method appends the given element to the end of this vector.
464
+ * \param x The element to append.
465
+ */
466
+ void push_back(const value_type &x);
467
+
468
+ /*! This method erases the last element of this vector, invalidating
469
+ * all iterators and references to it.
470
+ */
471
+ void pop_back();
472
+
473
+ /*! This method swaps the contents of this device_vector with another vector.
474
+ * \param v The vector with which to swap.
475
+ */
476
+ void swap(device_vector &v);
477
+
478
+ /*! This method removes the element at position pos.
479
+ * \param pos The position of the element of interest.
480
+ * \return An iterator pointing to the new location of the element that followed the element
481
+ * at position pos.
482
+ */
483
+ iterator erase(iterator pos);
484
+
485
+ /*! This method removes the range of elements [first,last) from this vector.
486
+ * \param first The beginning of the range of elements to remove.
487
+ * \param last The end of the range of elements to remove.
488
+ * \return An iterator pointing to the new location of the element that followed the last
489
+ * element in the sequence [first,last).
490
+ */
491
+ iterator erase(iterator first, iterator last);
492
+
493
+ /*! This method inserts a single copy of a given exemplar value at the
494
+ * specified position in this vector.
495
+ * \param position The insertion position.
496
+ * \param x The exemplar element to copy & insert.
497
+ * \return An iterator pointing to the newly inserted element.
498
+ */
499
+ iterator insert(iterator position, const T &x);
500
+
501
+ /*! This method inserts a copy of an exemplar value to a range at the
502
+ * specified position in this vector.
503
+ * \param position The insertion position
504
+ * \param n The number of insertions to perform.
505
+ * \param x The value to replicate and insert.
506
+ */
507
+ void insert(iterator position, size_type n, const T &x);
508
+
509
+ /*! This method inserts a copy of an input range at the specified position
510
+ * in this vector.
511
+ * \param position The insertion position.
512
+ * \param first The beginning of the range to copy.
513
+ * \param last The end of the range to copy.
514
+ *
515
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator>Input Iterator</a>,
516
+ * and \p InputIterator's \c value_type is a model of <a href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>.
517
+ */
518
+ template<typename InputIterator>
519
+ void insert(iterator position, InputIterator first, InputIterator last);
520
+
521
+ /*! This version of \p assign replicates a given exemplar
522
+ * \p n times into this vector.
523
+ * \param n The number of times to copy \p x.
524
+ * \param x The exemplar element to replicate.
525
+ */
526
+ void assign(size_type n, const T &x);
527
+
528
+ /*! This version of \p assign makes this vector a copy of a given input range.
529
+ * \param first The beginning of the range to copy.
530
+ * \param last The end of the range to copy.
531
+ *
532
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/named_req/InputIterator">Input Iterator</a>.
533
+ */
534
+ template<typename InputIterator>
535
+ void assign(InputIterator first, InputIterator last);
536
+
537
+ /*! This method returns a copy of this vector's allocator.
538
+ * \return A copy of the allocator used by this vector.
539
+ */
540
+ allocator_type get_allocator() const;
541
+ #endif // end doxygen-only members
542
+ };
543
+
544
+ /*! \} // containres
545
+ */
546
+
547
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/equal.h ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 equal.h
18
+ * \brief Equality between ranges
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/execution_policy.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ /*! \addtogroup reductions
37
+ * \{
38
+ * \addtogroup comparisons
39
+ * \ingroup reductions
40
+ * \{
41
+ */
42
+
43
+ /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
44
+ * and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
45
+ * compared element-by-element, and otherwise returns \c false.
46
+ *
47
+ * This version of \p equal returns \c true if and only if for every
48
+ * iterator \c i in <tt>[first1, last1)</tt>, <tt>*i == *(first2 + (i - first1))</tt>.
49
+ *
50
+ * The algorithm's execution is parallelized as determined by \p exec.
51
+ *
52
+ * \param exec The execution policy to use for parallelization.
53
+ * \param first1 The beginning of the first sequence.
54
+ * \param last1 The end of the first sequence.
55
+ * \param first2 The beginning of the second sequence.
56
+ * \return \c true, if the sequences are equal; \c false, otherwise.
57
+ *
58
+ * \tparam DerivedPolicy The name of the derived execution policy.
59
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
60
+ * Iterator</a>, and \p InputIterator1's \c value_type is a model of <a
61
+ * href="https://en.cppreference.com/w/cpp/concepts/equality_comparable">Equality Comparable</a>, and \p
62
+ * InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type. \tparam
63
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
64
+ * and \p InputIterator2's \c value_type is a model of <a
65
+ * href="https://en.cppreference.com/w/cpp/concepts/equality_comparable">Equality Comparable</a>, and \p
66
+ * InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type.
67
+ *
68
+ * The following code snippet demonstrates how to use \p equal to test
69
+ * two ranges for equality using the \p thrust::host execution policy:
70
+ *
71
+ * \code
72
+ * #include <thrust/equal.h>
73
+ * #include <thrust/execution_policy.h>
74
+ * ...
75
+ * int A1[7] = {3, 1, 4, 1, 5, 9, 3};
76
+ * int A2[7] = {3, 1, 4, 2, 8, 5, 7};
77
+ * ...
78
+ * bool result = thrust::equal(thrust::host, A1, A1 + 7, A2);
79
+ *
80
+ * // result == false
81
+ * \endcode
82
+ *
83
+ * \see https://en.cppreference.com/w/cpp/algorithm/equal
84
+ */
85
+ template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2>
86
+ _CCCL_HOST_DEVICE bool
87
+ equal(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
88
+ InputIterator1 first1,
89
+ InputIterator1 last1,
90
+ InputIterator2 first2);
91
+
92
+ /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
93
+ * and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
94
+ * compared element-by-element, and otherwise returns \c false.
95
+ *
96
+ * This version of \p equal returns \c true if and only if for every
97
+ * iterator \c i in <tt>[first1, last1)</tt>, <tt>*i == *(first2 + (i - first1))</tt>.
98
+ *
99
+ * \param first1 The beginning of the first sequence.
100
+ * \param last1 The end of the first sequence.
101
+ * \param first2 The beginning of the second sequence.
102
+ * \return \c true, if the sequences are equal; \c false, otherwise.
103
+ *
104
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
105
+ * Iterator</a>, and \p InputIterator1's \c value_type is a model of <a
106
+ * href="https://en.cppreference.com/w/cpp/concepts/equality_comparable">Equality Comparable</a>, and \p
107
+ * InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type. \tparam
108
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
109
+ * and \p InputIterator2's \c value_type is a model of <a
110
+ * href="https://en.cppreference.com/w/cpp/concepts/equality_comparable">Equality Comparable</a>, and \p
111
+ * InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type.
112
+ *
113
+ * The following code snippet demonstrates how to use \p equal to test
114
+ * two ranges for equality.
115
+ *
116
+ * \code
117
+ * #include <thrust/equal.h>
118
+ * ...
119
+ * int A1[7] = {3, 1, 4, 1, 5, 9, 3};
120
+ * int A2[7] = {3, 1, 4, 2, 8, 5, 7};
121
+ * ...
122
+ * bool result = thrust::equal(A1, A1 + 7, A2);
123
+ *
124
+ * // result == false
125
+ * \endcode
126
+ *
127
+ * \see https://en.cppreference.com/w/cpp/algorithm/equal
128
+ */
129
+ template <typename InputIterator1, typename InputIterator2>
130
+ bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
131
+
132
+ /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
133
+ * and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
134
+ * compared element-by-element, and otherwise returns \c false.
135
+ *
136
+ * This version of \p equal returns \c true if and only if for every
137
+ * iterator \c i in <tt>[first1, last1)</tt>,
138
+ * <tt>binary_pred(*i, *(first2 + (i - first1)))</tt> is \c true.
139
+ *
140
+ * The algorithm's execution is parallelized as determined by \p exec.
141
+ *
142
+ * \param exec The execution policy to use for parallelization.
143
+ * \param first1 The beginning of the first sequence.
144
+ * \param last1 The end of the first sequence.
145
+ * \param first2 The beginning of the second sequence.
146
+ * \param binary_pred Binary predicate used to test element equality.
147
+ * \return \c true, if the sequences are equal; \c false, otherwise.
148
+ *
149
+ * \tparam DerivedPolicy The name of the derived execution policy.
150
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
151
+ * Iterator</a>, and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type.
152
+ * \tparam InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
153
+ * Iterator</a>, and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type.
154
+ * \tparam BinaryPredicate is a model of <a href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">Binary
155
+ * Predicate</a>.
156
+ *
157
+ * The following code snippet demonstrates how to use \p equal to compare the
158
+ * elements in two ranges modulo 2 using the \p thrust::host execution policy.
159
+ *
160
+ * \code
161
+ * #include <thrust/equal.h>
162
+ * #include <thrust/execution_policy.h>
163
+ * ...
164
+ *
165
+ * struct compare_modulo_two
166
+ * {
167
+ * __host__ __device__
168
+ * bool operator()(int x, int y) const
169
+ * {
170
+ * return (x % 2) == (y % 2);
171
+ * }
172
+ * };
173
+ * ...
174
+ * int x[6] = {0, 2, 4, 6, 8, 10};
175
+ * int y[6] = {1, 3, 5, 7, 9, 11};
176
+ *
177
+ * bool result = thrust::equal(x, x + 6, y, compare_modulo_two());
178
+ *
179
+ * // result is false
180
+ * \endcode
181
+ *
182
+ * \see https://en.cppreference.com/w/cpp/algorithm/equal
183
+ */
184
+ template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
185
+ _CCCL_HOST_DEVICE bool
186
+ equal(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
187
+ InputIterator1 first1,
188
+ InputIterator1 last1,
189
+ InputIterator2 first2,
190
+ BinaryPredicate binary_pred);
191
+
192
+ /*! \p equal returns \c true if the two ranges <tt>[first1, last1)</tt>
193
+ * and <tt>[first2, first2 + (last1 - first1))</tt> are identical when
194
+ * compared element-by-element, and otherwise returns \c false.
195
+ *
196
+ * This version of \p equal returns \c true if and only if for every
197
+ * iterator \c i in <tt>[first1, last1)</tt>,
198
+ * <tt>binary_pred(*i, *(first2 + (i - first1)))</tt> is \c true.
199
+ *
200
+ * \param first1 The beginning of the first sequence.
201
+ * \param last1 The end of the first sequence.
202
+ * \param first2 The beginning of the second sequence.
203
+ * \param binary_pred Binary predicate used to test element equality.
204
+ * \return \c true, if the sequences are equal; \c false, otherwise.
205
+ *
206
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
207
+ * Iterator</a>, and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type.
208
+ * \tparam InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
209
+ * Iterator</a>, and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type.
210
+ * \tparam BinaryPredicate is a model of <a href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">Binary
211
+ * Predicate</a>.
212
+ *
213
+ * The following code snippet demonstrates how to use \p equal to compare the
214
+ * elements in two ranges modulo 2.
215
+ *
216
+ * \code
217
+ * #include <thrust/equal.h>
218
+ *
219
+ * struct compare_modulo_two
220
+ * {
221
+ * __host__ __device__
222
+ * bool operator()(int x, int y) const
223
+ * {
224
+ * return (x % 2) == (y % 2);
225
+ * }
226
+ * };
227
+ * ...
228
+ * int x[6] = {0, 2, 4, 6, 8, 10};
229
+ * int y[6] = {1, 3, 5, 7, 9, 11};
230
+ *
231
+ * bool result = thrust::equal(x, x + 5, y, compare_modulo_two());
232
+ *
233
+ * // result is true
234
+ * \endcode
235
+ *
236
+ * \see https://en.cppreference.com/w/cpp/algorithm/equal
237
+ */
238
+ template <typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
239
+ bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred);
240
+
241
+ /*! \} // end comparisons
242
+ * \} // end reductions
243
+ */
244
+
245
+ THRUST_NAMESPACE_END
246
+
247
+ #include <thrust/detail/equal.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/event.h ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/event.h
18
+ * \brief `thrust::event`, an asynchronous handle type.
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 <thrust/future.h>
34
+
35
+ // TODO: Actually separate `<thrust/future.h>` into two headers.
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/execution_policy.h ADDED
@@ -0,0 +1,384 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/execution_policy.h
18
+ * \brief Thrust execution policies.
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/execute_with_allocator.h>
33
+ #include <thrust/detail/execution_policy.h>
34
+ #include <thrust/detail/seq.h>
35
+
36
+ //! \cond
37
+
38
+ // #include the host system's execution_policy header
39
+ #define __THRUST_HOST_SYSTEM_EXECUTION_POLICY_HEADER <__THRUST_HOST_SYSTEM_ROOT/execution_policy.h>
40
+ #include __THRUST_HOST_SYSTEM_EXECUTION_POLICY_HEADER
41
+ #undef __THRUST_HOST_SYSTEM_EXECUTION_POLICY_HEADER
42
+
43
+ // #include the device system's execution_policy.h header
44
+ #define __THRUST_DEVICE_SYSTEM_EXECUTION_POLICY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/execution_policy.h>
45
+ #include __THRUST_DEVICE_SYSTEM_EXECUTION_POLICY_HEADER
46
+ #undef __THRUST_DEVICE_SYSTEM_EXECUTION_POLICY_HEADER
47
+
48
+ //! \endcond
49
+
50
+ THRUST_NAMESPACE_BEGIN
51
+
52
+ /*! \cond
53
+ */
54
+
55
+ namespace detail
56
+ {
57
+
58
+ using host_t = thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::detail::par_t;
59
+
60
+ using device_t = thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::detail::par_t;
61
+
62
+ } // namespace detail
63
+
64
+ /*! \endcond
65
+ */
66
+
67
+ /*! \addtogroup execution_policies Parallel Execution Policies
68
+ * \{
69
+ */
70
+
71
+ // define execution_policy for the purpose of Doxygenating it
72
+ // it is actually defined elsewhere
73
+ #if 0
74
+ /*! \p execution_policy is the base class for all Thrust parallel execution policies
75
+ * like \p thrust::host, \p thrust::device, and each backend system's tag type.
76
+ *
77
+ * Custom user-defined backends should derive a policy from this type in order to
78
+ * interoperate with Thrust algorithm dispatch.
79
+ *
80
+ * The following code snippet demonstrates how to derive a standalone custom execution policy
81
+ * from \p thrust::execution_policy to implement a backend which only implements \p for_each:
82
+ *
83
+ * \code
84
+ * #include <thrust/execution_policy.h>
85
+ * #include <iostream>
86
+ *
87
+ * // define a type derived from thrust::execution_policy to distinguish our custom execution policy:
88
+ * struct my_policy : thrust::execution_policy<my_policy> {};
89
+ *
90
+ * // overload for_each on my_policy
91
+ * template<typename Iterator, typename Function>
92
+ * Iterator for_each(my_policy, Iterator first, Iterator last, Function f)
93
+ * {
94
+ * std::cout << "Hello, world from for_each(my_policy)!" << std::endl;
95
+ *
96
+ * for(; first < last; ++first)
97
+ * {
98
+ * f(*first);
99
+ * }
100
+ *
101
+ * return first;
102
+ * }
103
+ *
104
+ * struct ignore_argument
105
+ * {
106
+ * void operator()(int) {}
107
+ * };
108
+ *
109
+ * int main()
110
+ * {
111
+ * int data[4];
112
+ *
113
+ * // dispatch thrust::for_each using our custom policy:
114
+ * my_policy exec;
115
+ * thrust::for_each(exec, data, data + 4, ignore_argument());
116
+ *
117
+ * // can't dispatch thrust::transform because no overload exists for my_policy:
118
+ * //thrust::transform(exec, data, data, + 4, data, thrust::identity<int>()); // error!
119
+ *
120
+ * return 0;
121
+ * }
122
+ * \endcode
123
+ *
124
+ * \see host_execution_policy
125
+ * \see device_execution_policy
126
+ */
127
+ template<typename DerivedPolicy>
128
+ struct execution_policy : thrust::detail::execution_policy_base<DerivedPolicy>
129
+ {};
130
+ #endif
131
+
132
+ /*! \p host_execution_policy is the base class for all Thrust parallel execution policies
133
+ * which are derived from Thrust's default host backend system configured with the \p THRUST_HOST_SYSTEM
134
+ * macro.
135
+ *
136
+ * Custom user-defined backends which wish to inherit the functionality of Thrust's host backend system
137
+ * should derive a policy from this type in order to interoperate with Thrust algorithm dispatch.
138
+ *
139
+ * The following code snippet demonstrates how to derive a standalone custom execution policy from
140
+ * \p thrust::host_execution_policy to implement a backend which specializes \p for_each while inheriting
141
+ * the behavior of every other algorithm from the host system:
142
+ *
143
+ * \code
144
+ * #include <thrust/execution_policy.h>
145
+ * #include <iostream>
146
+ *
147
+ * // define a type derived from thrust::host_execution_policy to distinguish our custom execution policy:
148
+ * struct my_policy : thrust::host_execution_policy<my_policy> {};
149
+ *
150
+ * // overload for_each on my_policy
151
+ * template<typename Iterator, typename Function>
152
+ * Iterator for_each(my_policy, Iterator first, Iterator last, Function f)
153
+ * {
154
+ * std::cout << "Hello, world from for_each(my_policy)!" << std::endl;
155
+ *
156
+ * for(; first < last; ++first)
157
+ * {
158
+ * f(*first);
159
+ * }
160
+ *
161
+ * return first;
162
+ * }
163
+ *
164
+ * struct ignore_argument
165
+ * {
166
+ * void operator()(int) {}
167
+ * };
168
+ *
169
+ * int main()
170
+ * {
171
+ * int data[4];
172
+ *
173
+ * // dispatch thrust::for_each using our custom policy:
174
+ * my_policy exec;
175
+ * thrust::for_each(exec, data, data + 4, ignore_argument());
176
+ *
177
+ * // dispatch thrust::transform whose behavior our policy inherits
178
+ * thrust::transform(exec, data, data, + 4, data, thrust::identity<int>());
179
+ *
180
+ * return 0;
181
+ * }
182
+ * \endcode
183
+ *
184
+ * \see execution_policy
185
+ * \see device_execution_policy
186
+ */
187
+ template <typename DerivedPolicy>
188
+ struct host_execution_policy : thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::execution_policy<DerivedPolicy>
189
+ {};
190
+
191
+ /*! \p device_execution_policy is the base class for all Thrust parallel execution policies
192
+ * which are derived from Thrust's default device backend system configured with the \p THRUST_DEVICE_SYSTEM
193
+ * macro.
194
+ *
195
+ * Custom user-defined backends which wish to inherit the functionality of Thrust's device backend system
196
+ * should derive a policy from this type in order to interoperate with Thrust algorithm dispatch.
197
+ *
198
+ * The following code snippet demonstrates how to derive a standalone custom execution policy from
199
+ * \p thrust::device_execution_policy to implement a backend which specializes \p for_each while inheriting
200
+ * the behavior of every other algorithm from the device system:
201
+ *
202
+ * \code
203
+ * #include <thrust/execution_policy.h>
204
+ * #include <iostream>
205
+ *
206
+ * // define a type derived from thrust::device_execution_policy to distinguish our custom execution policy:
207
+ * struct my_policy : thrust::device_execution_policy<my_policy> {};
208
+ *
209
+ * // overload for_each on my_policy
210
+ * template<typename Iterator, typename Function>
211
+ * Iterator for_each(my_policy, Iterator first, Iterator last, Function f)
212
+ * {
213
+ * std::cout << "Hello, world from for_each(my_policy)!" << std::endl;
214
+ *
215
+ * for(; first < last; ++first)
216
+ * {
217
+ * f(*first);
218
+ * }
219
+ *
220
+ * return first;
221
+ * }
222
+ *
223
+ * struct ignore_argument
224
+ * {
225
+ * void operator()(int) {}
226
+ * };
227
+ *
228
+ * int main()
229
+ * {
230
+ * int data[4];
231
+ *
232
+ * // dispatch thrust::for_each using our custom policy:
233
+ * my_policy exec;
234
+ * thrust::for_each(exec, data, data + 4, ignore_argument());
235
+ *
236
+ * // dispatch thrust::transform whose behavior our policy inherits
237
+ * thrust::transform(exec, data, data, + 4, data, thrust::identity<int>());
238
+ *
239
+ * return 0;
240
+ * }
241
+ * \endcode
242
+ *
243
+ * \see execution_policy
244
+ * \see host_execution_policy
245
+ */
246
+ template <typename DerivedPolicy>
247
+ struct device_execution_policy : thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::execution_policy<DerivedPolicy>
248
+ {};
249
+
250
+ /*! \p thrust::host is the default parallel execution policy associated with Thrust's host backend system
251
+ * configured by the \p THRUST_HOST_SYSTEM macro.
252
+ *
253
+ * Instead of relying on implicit algorithm dispatch through iterator system tags, users may directly target
254
+ * algorithm dispatch at Thrust's host system by providing \p thrust::host as an algorithm parameter.
255
+ *
256
+ * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such as
257
+ * \p thrust::host_vector.
258
+ *
259
+ * Note that even though \p thrust::host targets the host CPU, it is a parallel execution policy. That is,
260
+ * the order that an algorithm invokes functors or dereferences iterators is not defined.
261
+ *
262
+ * The type of \p thrust::host is implementation-defined.
263
+ *
264
+ * The following code snippet demonstrates how to use \p thrust::host to explicitly dispatch an invocation
265
+ * of \p thrust::for_each to the host backend system:
266
+ *
267
+ * \code
268
+ * #include <thrust/for_each.h>
269
+ * #include <thrust/execution_policy.h>
270
+ * #include <cstdio>
271
+ *
272
+ * struct printf_functor
273
+ * {
274
+ * __host__ __device__
275
+ * void operator()(int x)
276
+ * {
277
+ * printf("%d\n", x);
278
+ * }
279
+ * };
280
+ * ...
281
+ * int vec[] = { 0, 1, 2 };
282
+ *
283
+ * thrust::for_each(thrust::host, vec, vec + 3, printf_functor());
284
+ *
285
+ * // 0 1 2 is printed to standard output in some unspecified order
286
+ * \endcode
287
+ *
288
+ * \see host_execution_policy
289
+ * \see thrust::device
290
+ */
291
+ static const detail::host_t host;
292
+
293
+ /*! \p thrust::device is the default parallel execution policy associated with Thrust's device backend system
294
+ * configured by the \p THRUST_DEVICE_SYSTEM macro.
295
+ *
296
+ * Instead of relying on implicit algorithm dispatch through iterator system tags, users may directly target
297
+ * algorithm dispatch at Thrust's device system by providing \p thrust::device as an algorithm parameter.
298
+ *
299
+ * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such as
300
+ * \p thrust::device_vector or to avoid wrapping e.g. raw pointers allocated by the CUDA API with types
301
+ * such as \p thrust::device_ptr.
302
+ *
303
+ * The user must take care to guarantee that the iterators provided to an algorithm are compatible with
304
+ * the device backend system. For example, raw pointers allocated by <tt>std::malloc</tt> typically
305
+ * cannot be dereferenced by a GPU. For this reason, raw pointers allocated by host APIs should not be mixed
306
+ * with a \p thrust::device algorithm invocation when the device backend is CUDA.
307
+ *
308
+ * The type of \p thrust::device is implementation-defined.
309
+ *
310
+ * The following code snippet demonstrates how to use \p thrust::device to explicitly dispatch an invocation
311
+ * of \p thrust::for_each to the device backend system:
312
+ *
313
+ * \code
314
+ * #include <thrust/for_each.h>
315
+ * #include <thrust/device_vector.h>
316
+ * #include <thrust/execution_policy.h>
317
+ * #include <cstdio>
318
+ *
319
+ * struct printf_functor
320
+ * {
321
+ * __host__ __device__
322
+ * void operator()(int x)
323
+ * {
324
+ * printf("%d\n", x);
325
+ * }
326
+ * };
327
+ * ...
328
+ * thrust::device_vector<int> vec(3);
329
+ * vec[0] = 0; vec[1] = 1; vec[2] = 2;
330
+ *
331
+ * thrust::for_each(thrust::device, vec.begin(), vec.end(), printf_functor());
332
+ *
333
+ * // 0 1 2 is printed to standard output in some unspecified order
334
+ * \endcode
335
+ *
336
+ * \see host_execution_policy
337
+ * \see thrust::device
338
+ */
339
+ _CCCL_GLOBAL_CONSTANT detail::device_t device;
340
+
341
+ // define seq for the purpose of Doxygenating it
342
+ // it is actually defined elsewhere
343
+ #if 0
344
+ /*! \p thrust::seq is an execution policy which requires an algorithm invocation to execute sequentially
345
+ * in the current thread. It can not be configured by a compile-time macro.
346
+ *
347
+ * The type of \p thrust::seq is implementation-defined.
348
+ *
349
+ * The following code snippet demonstrates how to use \p thrust::seq to explicitly execute an invocation
350
+ * of \p thrust::for_each sequentially:
351
+ *
352
+ * \code
353
+ * #include <thrust/for_each.h>
354
+ * #include <thrust/execution_policy.h>
355
+ * #include <vector>
356
+ * #include <cstdio>
357
+ *
358
+ * struct printf_functor
359
+ * {
360
+ * __host__ __device__
361
+ * void operator()(int x)
362
+ * {
363
+ * printf("%d\n", x);
364
+ * }
365
+ * };
366
+ * ...
367
+ * std::vector<int> vec(3);
368
+ * vec[0] = 0; vec[1] = 1; vec[2] = 2;
369
+ *
370
+ * thrust::for_each(thrust::seq, vec.begin(), vec.end(), printf_functor());
371
+ *
372
+ * // 0 1 2 is printed to standard output in sequential order
373
+ * \endcode
374
+ *
375
+ * \see thrust::host
376
+ * \see thrust::device
377
+ */
378
+ static const detail::seq_t seq;
379
+ #endif
380
+
381
+ /*! \}
382
+ */
383
+
384
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/extrema.h ADDED
@@ -0,0 +1,800 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 extrema.h
18
+ * \brief Functions for computing computing extremal values
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/execution_policy.h>
33
+ #include <thrust/pair.h>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+ /*! This version of \p min returns the smaller of two values, given a comparison operation.
38
+ * \param lhs The first value to compare.
39
+ * \param rhs The second value to compare.
40
+ * \param comp A comparison operation.
41
+ * \return The smaller element.
42
+ *
43
+ * \tparam T is convertible to \p BinaryPredicate's first argument type and to its second argument type.
44
+ * \tparam BinaryPredicate is a model of <a
45
+ * href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">BinaryPredicate</a>.
46
+ *
47
+ * The following code snippet demonstrates how to use \p min to compute the smaller of two
48
+ * key-value objects.
49
+ *
50
+ * \code
51
+ * #include <thrust/extrema.h>
52
+ * ...
53
+ * struct key_value
54
+ * {
55
+ * int key;
56
+ * int value;
57
+ * };
58
+ *
59
+ * struct compare_key_value
60
+ * {
61
+ * __host__ __device__
62
+ * bool operator()(key_value lhs, key_value rhs)
63
+ * {
64
+ * return lhs.key < rhs.key;
65
+ * }
66
+ * };
67
+ *
68
+ * ...
69
+ * key_value a = {13, 0};
70
+ * key_value b = { 7, 1);
71
+ *
72
+ * key_value smaller = thrust::min(a, b, compare_key_value());
73
+ *
74
+ * // smaller is {7, 1}
75
+ * \endcode
76
+ *
77
+ * \note Returns the first argument when the arguments are equivalent.
78
+ * \see max
79
+ */
80
+ template <typename T, typename BinaryPredicate>
81
+ _CCCL_HOST_DEVICE T min THRUST_PREVENT_MACRO_SUBSTITUTION(const T& lhs, const T& rhs, BinaryPredicate comp);
82
+
83
+ /*! This version of \p min returns the smaller of two values.
84
+ * \param lhs The first value to compare.
85
+ * \param rhs The second value to compare.
86
+ * \return The smaller element.
87
+ *
88
+ * \tparam T is a model of <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan
89
+ * Comparable</a>.
90
+ *
91
+ * The following code snippet demonstrates how to use \p min to compute the smaller of two
92
+ * integers.
93
+ *
94
+ * \code
95
+ * #include <thrust/extrema.h>
96
+ * ...
97
+ * int a = 13;
98
+ * int b = 7;
99
+ *
100
+ * int smaller = thrust::min(a, b);
101
+ *
102
+ * // smaller is 7
103
+ * \endcode
104
+ *
105
+ * \note Returns the first argument when the arguments are equivalent.
106
+ * \see max
107
+ */
108
+ template <typename T>
109
+ _CCCL_HOST_DEVICE T min THRUST_PREVENT_MACRO_SUBSTITUTION(const T& lhs, const T& rhs);
110
+
111
+ /*! This version of \p max returns the larger of two values, given a comparison operation.
112
+ * \param lhs The first value to compare.
113
+ * \param rhs The second value to compare.
114
+ * \param comp A comparison operation.
115
+ * \return The larger element.
116
+ *
117
+ * \tparam T is convertible to \p BinaryPredicate's first argument type and to its second argument type.
118
+ * \tparam BinaryPredicate is a model of <a
119
+ * href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">BinaryPredicate</a>.
120
+ *
121
+ * The following code snippet demonstrates how to use \p max to compute the larger of two
122
+ * key-value objects.
123
+ *
124
+ * \code
125
+ * #include <thrust/extrema.h>
126
+ * ...
127
+ * struct key_value
128
+ * {
129
+ * int key;
130
+ * int value;
131
+ * };
132
+ *
133
+ * struct compare_key_value
134
+ * {
135
+ * __host__ __device__
136
+ * bool operator()(key_value lhs, key_value rhs)
137
+ * {
138
+ * return lhs.key < rhs.key;
139
+ * }
140
+ * };
141
+ *
142
+ * ...
143
+ * key_value a = {13, 0};
144
+ * key_value b = { 7, 1);
145
+ *
146
+ * key_value larger = thrust::max(a, b, compare_key_value());
147
+ *
148
+ * // larger is {13, 0}
149
+ * \endcode
150
+ *
151
+ * \note Returns the first argument when the arguments are equivalent.
152
+ * \see min
153
+ */
154
+ template <typename T, typename BinaryPredicate>
155
+ _CCCL_HOST_DEVICE T max THRUST_PREVENT_MACRO_SUBSTITUTION(const T& lhs, const T& rhs, BinaryPredicate comp);
156
+
157
+ /*! This version of \p max returns the larger of two values.
158
+ * \param lhs The first value to compare.
159
+ * \param rhs The second value to compare.
160
+ * \return The larger element.
161
+ *
162
+ * \tparam T is a model of <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan
163
+ * Comparable</a>.
164
+ *
165
+ * The following code snippet demonstrates how to use \p max to compute the larger of two
166
+ * integers.
167
+ *
168
+ * \code
169
+ * #include <thrust/extrema.h>
170
+ * ...
171
+ * int a = 13;
172
+ * int b = 7;
173
+ *
174
+ * int larger = thrust::min(a, b);
175
+ *
176
+ * // larger is 13
177
+ * \endcode
178
+ *
179
+ * \note Returns the first argument when the arguments are equivalent.
180
+ * \see min
181
+ */
182
+ template <typename T>
183
+ _CCCL_HOST_DEVICE T max THRUST_PREVENT_MACRO_SUBSTITUTION(const T& lhs, const T& rhs);
184
+
185
+ /*! \addtogroup reductions
186
+ * \{
187
+ * \addtogroup extrema
188
+ * \ingroup reductions
189
+ * \{
190
+ */
191
+
192
+ /*! \p min_element finds the smallest element in the range <tt>[first, last)</tt>.
193
+ * It returns the first iterator \c i in <tt>[first, last)</tt>
194
+ * such that no other iterator in <tt>[first, last)</tt> points to a value smaller
195
+ * than \c *i. The return value is \p last if and only if <tt>[first, last)</tt> is an
196
+ * empty range.
197
+ *
198
+ * The two versions of \p min_element differ in how they define whether one element is
199
+ * less than another. This version compares objects using \c operator<. Specifically,
200
+ * this version of \p min_element returns the first iterator \c i in <tt>[first, last)</tt>
201
+ * such that, for every iterator \c j in <tt>[first, last)</tt>, <tt>*j < *i</tt> is
202
+ * \c false.
203
+ *
204
+ * The algorithm's execution is parallelized as determined by \p exec.
205
+ *
206
+ * \param exec The execution policy to use for parallelization.
207
+ * \param first The beginning of the sequence.
208
+ * \param last The end of the sequence.
209
+ * \return An iterator pointing to the smallest element of the range <tt>[first, last)</tt>,
210
+ * if it is not an empty range; \p last, otherwise.
211
+ *
212
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
213
+ * Iterator</a>, and \c ForwardIterator's \c value_type is a model of <a
214
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>.
215
+ *
216
+ * \code
217
+ * #include <thrust/extrema.h>
218
+ * #include <thrust/execution_policy.h>
219
+ * ...
220
+ * int data[6] = {1, 0, 2, 2, 1, 3};
221
+ * int *result = thrust::min_element(thrust::host, data, data + 6);
222
+ *
223
+ * // result is data + 1
224
+ * // *result is 0
225
+ * \endcode
226
+ *
227
+ * \see https://en.cppreference.com/w/cpp/algorithm/min_element
228
+ */
229
+ template <typename DerivedPolicy, typename ForwardIterator>
230
+ _CCCL_HOST_DEVICE ForwardIterator min_element(
231
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last);
232
+
233
+ /*! \p min_element finds the smallest element in the range <tt>[first, last)</tt>.
234
+ * It returns the first iterator \c i in <tt>[first, last)</tt>
235
+ * such that no other iterator in <tt>[first, last)</tt> points to a value smaller
236
+ * than \c *i. The return value is \p last if and only if <tt>[first, last)</tt> is an
237
+ * empty range.
238
+ *
239
+ * The two versions of \p min_element differ in how they define whether one element is
240
+ * less than another. This version compares objects using \c operator<. Specifically,
241
+ * this version of \p min_element returns the first iterator \c i in <tt>[first, last)</tt>
242
+ * such that, for every iterator \c j in <tt>[first, last)</tt>, <tt>*j < *i</tt> is
243
+ * \c false.
244
+ *
245
+ * \param first The beginning of the sequence.
246
+ * \param last The end of the sequence.
247
+ * \return An iterator pointing to the smallest element of the range <tt>[first, last)</tt>,
248
+ * if it is not an empty range; \p last, otherwise.
249
+ *
250
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
251
+ * Iterator</a>, and \c ForwardIterator's \c value_type is a model of <a
252
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>.
253
+ *
254
+ * \code
255
+ * #include <thrust/extrema.h>
256
+ * ...
257
+ * int data[6] = {1, 0, 2, 2, 1, 3};
258
+ * int *result = thrust::min_element(data, data + 6);
259
+ *
260
+ * // result is data + 1
261
+ * // *result is 0
262
+ * \endcode
263
+ *
264
+ * \see https://en.cppreference.com/w/cpp/algorithm/min_element
265
+ */
266
+ template <typename ForwardIterator>
267
+ ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
268
+
269
+ /*! \p min_element finds the smallest element in the range <tt>[first, last)</tt>.
270
+ * It returns the first iterator \c i in <tt>[first, last)</tt>
271
+ * such that no other iterator in <tt>[first, last)</tt> points to a value smaller
272
+ * than \c *i. The return value is \p last if and only if <tt>[first, last)</tt> is an
273
+ * empty range.
274
+ *
275
+ * The two versions of \p min_element differ in how they define whether one element is
276
+ * less than another. This version compares objects using a function object \p comp.
277
+ * Specifically, this version of \p min_element returns the first iterator \c i in <tt>[first, last)</tt>
278
+ * such that, for every iterator \c j in <tt>[first, last)</tt>, <tt>comp(*j, *i)</tt> is
279
+ * \c false.
280
+ *
281
+ * The algorithm's execution is parallelized as determined by \p exec.
282
+ *
283
+ * \param exec The execution policy to use for parallelization.
284
+ * \param first The beginning of the sequence.
285
+ * \param last The end of the sequence.
286
+ * \param comp A binary predicate used for comparison.
287
+ * \return An iterator pointing to the smallest element of the range <tt>[first, last)</tt>,
288
+ * if it is not an empty range; \p last, otherwise.
289
+ *
290
+ * \tparam DerivedPolicy The name of the derived execution policy.
291
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
292
+ * Iterator</a>, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c
293
+ * second_argument_type. \tparam BinaryPredicate is a model of <a
294
+ * href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">Binary Predicate</a>.
295
+ *
296
+ * The following code snippet demonstrates how to use \p min_element to find the smallest element
297
+ * of a collection of key-value pairs using the \p thrust::host execution policy for parallelization:
298
+ *
299
+ * \code
300
+ * #include <thrust/extrema.h>
301
+ * #include <thrust/execution_policy.h>
302
+ * ...
303
+ *
304
+ * struct key_value
305
+ * {
306
+ * int key;
307
+ * int value;
308
+ * };
309
+ *
310
+ * struct compare_key_value
311
+ * {
312
+ * __host__ __device__
313
+ * bool operator()(key_value lhs, key_value rhs)
314
+ * {
315
+ * return lhs.key < rhs.key;
316
+ * }
317
+ * };
318
+ *
319
+ * ...
320
+ * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
321
+ *
322
+ * key_value *smallest = thrust::min_element(thrust::host, data, data + 4, compare_key_value());
323
+ *
324
+ * // smallest == data + 1
325
+ * // *smallest == {0,7}
326
+ * \endcode
327
+ *
328
+ * \see https://en.cppreference.com/w/cpp/algorithm/min_element
329
+ */
330
+ template <typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
331
+ _CCCL_HOST_DEVICE ForwardIterator min_element(
332
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
333
+ ForwardIterator first,
334
+ ForwardIterator last,
335
+ BinaryPredicate comp);
336
+
337
+ /*! \p min_element finds the smallest element in the range <tt>[first, last)</tt>.
338
+ * It returns the first iterator \c i in <tt>[first, last)</tt>
339
+ * such that no other iterator in <tt>[first, last)</tt> points to a value smaller
340
+ * than \c *i. The return value is \p last if and only if <tt>[first, last)</tt> is an
341
+ * empty range.
342
+ *
343
+ * The two versions of \p min_element differ in how they define whether one element is
344
+ * less than another. This version compares objects using a function object \p comp.
345
+ * Specifically, this version of \p min_element returns the first iterator \c i in <tt>[first, last)</tt>
346
+ * such that, for every iterator \c j in <tt>[first, last)</tt>, <tt>comp(*j, *i)</tt> is
347
+ * \c false.
348
+ *
349
+ * \param first The beginning of the sequence.
350
+ * \param last The end of the sequence.
351
+ * \param comp A binary predicate used for comparison.
352
+ * \return An iterator pointing to the smallest element of the range <tt>[first, last)</tt>,
353
+ * if it is not an empty range; \p last, otherwise.
354
+ *
355
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
356
+ * Iterator</a>, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c
357
+ * second_argument_type. \tparam BinaryPredicate is a model of <a
358
+ * href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">Binary Predicate</a>.
359
+ *
360
+ * The following code snippet demonstrates how to use \p min_element to find the smallest element
361
+ * of a collection of key-value pairs.
362
+ *
363
+ * \code
364
+ * #include <thrust/extrema.h>
365
+ *
366
+ * struct key_value
367
+ * {
368
+ * int key;
369
+ * int value;
370
+ * };
371
+ *
372
+ * struct compare_key_value
373
+ * {
374
+ * __host__ __device__
375
+ * bool operator()(key_value lhs, key_value rhs)
376
+ * {
377
+ * return lhs.key < rhs.key;
378
+ * }
379
+ * };
380
+ *
381
+ * ...
382
+ * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
383
+ *
384
+ * key_value *smallest = thrust::min_element(data, data + 4, compare_key_value());
385
+ *
386
+ * // smallest == data + 1
387
+ * // *smallest == {0,7}
388
+ * \endcode
389
+ *
390
+ * \see https://en.cppreference.com/w/cpp/algorithm/min_element
391
+ */
392
+ template <typename ForwardIterator, typename BinaryPredicate>
393
+ ForwardIterator min_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp);
394
+
395
+ /*! \p max_element finds the largest element in the range <tt>[first, last)</tt>.
396
+ * It returns the first iterator \c i in <tt>[first, last)</tt>
397
+ * such that no other iterator in <tt>[first, last)</tt> points to a value larger
398
+ * than \c *i. The return value is \p last if and only if <tt>[first, last)</tt> is an
399
+ * empty range.
400
+ *
401
+ * The two versions of \p max_element differ in how they define whether one element is
402
+ * greater than another. This version compares objects using \c operator<. Specifically,
403
+ * this version of \p max_element returns the first iterator \c i in <tt>[first, last)</tt>
404
+ * such that, for every iterator \c j in <tt>[first, last)</tt>, <tt>*i < *j</tt> is
405
+ * \c false.
406
+ *
407
+ * The algorithm's execution is parallelized as determined by \p exec.
408
+ *
409
+ * \param exec The execution policy to use for parallelization.
410
+ * \param first The beginning of the sequence.
411
+ * \param last The end of the sequence.
412
+ * \return An iterator pointing to the largest element of the range <tt>[first, last)</tt>,
413
+ * if it is not an empty range; \p last, otherwise.
414
+ *
415
+ * \tparam A Thrust backend system.
416
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
417
+ * Iterator</a>, and \c ForwardIterator's \c value_type is a model of <a
418
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>.
419
+ *
420
+ * \code
421
+ * #include <thrust/extrema.h>
422
+ * #include <thrust/execution_policy.h>
423
+ * ...
424
+ * int data[6] = {1, 0, 2, 2, 1, 3};
425
+ * int *result = thrust::max_element(thrust::host, data, data + 6);
426
+ *
427
+ * // *result == 3
428
+ * \endcode
429
+ *
430
+ * \see https://en.cppreference.com/w/cpp/algorithm/max_element
431
+ */
432
+ template <typename DerivedPolicy, typename ForwardIterator>
433
+ _CCCL_HOST_DEVICE ForwardIterator max_element(
434
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last);
435
+
436
+ /*! \p max_element finds the largest element in the range <tt>[first, last)</tt>.
437
+ * It returns the first iterator \c i in <tt>[first, last)</tt>
438
+ * such that no other iterator in <tt>[first, last)</tt> points to a value larger
439
+ * than \c *i. The return value is \p last if and only if <tt>[first, last)</tt> is an
440
+ * empty range.
441
+ *
442
+ * The two versions of \p max_element differ in how they define whether one element is
443
+ * greater than another. This version compares objects using \c operator<. Specifically,
444
+ * this version of \p max_element returns the first iterator \c i in <tt>[first, last)</tt>
445
+ * such that, for every iterator \c j in <tt>[first, last)</tt>, <tt>*i < *j</tt> is
446
+ * \c false.
447
+ *
448
+ * \param first The beginning of the sequence.
449
+ * \param last The end of the sequence.
450
+ * \return An iterator pointing to the largest element of the range <tt>[first, last)</tt>,
451
+ * if it is not an empty range; \p last, otherwise.
452
+ *
453
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
454
+ * Iterator</a>, and \c ForwardIterator's \c value_type is a model of <a
455
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>.
456
+ *
457
+ * \code
458
+ * #include <thrust/extrema.h>
459
+ * ...
460
+ * int data[6] = {1, 0, 2, 2, 1, 3};
461
+ * int *result = thrust::max_element(data, data + 6);
462
+ *
463
+ * // *result == 3
464
+ * \endcode
465
+ *
466
+ * \see https://en.cppreference.com/w/cpp/algorithm/max_element
467
+ */
468
+ template <typename ForwardIterator>
469
+ ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
470
+
471
+ /*! \p max_element finds the largest element in the range <tt>[first, last)</tt>.
472
+ * It returns the first iterator \c i in <tt>[first, last)</tt>
473
+ * such that no other iterator in <tt>[first, last)</tt> points to a value larger
474
+ * than \c *i. The return value is \p last if and only if <tt>[first, last)</tt> is an
475
+ * empty range.
476
+ *
477
+ * The two versions of \p max_element differ in how they define whether one element is
478
+ * less than another. This version compares objects using a function object \p comp.
479
+ * Specifically, this version of \p max_element returns the first iterator \c i in <tt>[first, last)</tt>
480
+ * such that, for every iterator \c j in <tt>[first, last)</tt>, <tt>comp(*i, *j)</tt> is
481
+ * \c false.
482
+ *
483
+ * The algorithm's execution is parallelized as determined by \p exec.
484
+ *
485
+ * \param exec The execution policy to use for parallelization.
486
+ * \param first The beginning of the sequence.
487
+ * \param last The end of the sequence.
488
+ * \param comp A binary predicate used for comparison.
489
+ * \return An iterator pointing to the largest element of the range <tt>[first, last)</tt>,
490
+ * if it is not an empty range; \p last, otherwise.
491
+ *
492
+ * \tparam DerivedPolicy The name of the derived execution policy.
493
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
494
+ * Iterator</a>, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c
495
+ * second_argument_type. \tparam BinaryPredicate is a model of <a
496
+ * href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">Binary Predicate</a>.
497
+ *
498
+ * The following code snippet demonstrates how to use \p max_element to find the largest element
499
+ * of a collection of key-value pairs using the \p thrust::host execution policy for parallelization.
500
+ *
501
+ * \code
502
+ * #include <thrust/extrema.h>
503
+ * #include <thrust/execution_policy.h>
504
+ * ...
505
+ *
506
+ * struct key_value
507
+ * {
508
+ * int key;
509
+ * int value;
510
+ * };
511
+ *
512
+ * struct compare_key_value
513
+ * {
514
+ * __host__ __device__
515
+ * bool operator()(key_value lhs, key_value rhs)
516
+ * {
517
+ * return lhs.key < rhs.key;
518
+ * }
519
+ * };
520
+ *
521
+ * ...
522
+ * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
523
+ *
524
+ * key_value *largest = thrust::max_element(thrust::host, data, data + 4, compare_key_value());
525
+ *
526
+ * // largest == data + 3
527
+ * // *largest == {6,1}
528
+ * \endcode
529
+ *
530
+ * \see https://en.cppreference.com/w/cpp/algorithm/max_element
531
+ */
532
+ template <typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
533
+ _CCCL_HOST_DEVICE ForwardIterator max_element(
534
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
535
+ ForwardIterator first,
536
+ ForwardIterator last,
537
+ BinaryPredicate comp);
538
+
539
+ /*! \p max_element finds the largest element in the range <tt>[first, last)</tt>.
540
+ * It returns the first iterator \c i in <tt>[first, last)</tt>
541
+ * such that no other iterator in <tt>[first, last)</tt> points to a value larger
542
+ * than \c *i. The return value is \p last if and only if <tt>[first, last)</tt> is an
543
+ * empty range.
544
+ *
545
+ * The two versions of \p max_element differ in how they define whether one element is
546
+ * less than another. This version compares objects using a function object \p comp.
547
+ * Specifically, this version of \p max_element returns the first iterator \c i in <tt>[first, last)</tt>
548
+ * such that, for every iterator \c j in <tt>[first, last)</tt>, <tt>comp(*i, *j)</tt> is
549
+ * \c false.
550
+ *
551
+ * \param first The beginning of the sequence.
552
+ * \param last The end of the sequence.
553
+ * \param comp A binary predicate used for comparison.
554
+ * \return An iterator pointing to the largest element of the range <tt>[first, last)</tt>,
555
+ * if it is not an empty range; \p last, otherwise.
556
+ *
557
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
558
+ * Iterator</a>, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c
559
+ * second_argument_type. \tparam BinaryPredicate is a model of <a
560
+ * href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">Binary Predicate</a>.
561
+ *
562
+ * The following code snippet demonstrates how to use \p max_element to find the largest element
563
+ * of a collection of key-value pairs.
564
+ *
565
+ * \code
566
+ * #include <thrust/extrema.h>
567
+ *
568
+ * struct key_value
569
+ * {
570
+ * int key;
571
+ * int value;
572
+ * };
573
+ *
574
+ * struct compare_key_value
575
+ * {
576
+ * __host__ __device__
577
+ * bool operator()(key_value lhs, key_value rhs)
578
+ * {
579
+ * return lhs.key < rhs.key;
580
+ * }
581
+ * };
582
+ *
583
+ * ...
584
+ * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
585
+ *
586
+ * key_value *largest = thrust::max_element(data, data + 4, compare_key_value());
587
+ *
588
+ * // largest == data + 3
589
+ * // *largest == {6,1}
590
+ * \endcode
591
+ *
592
+ * \see https://en.cppreference.com/w/cpp/algorithm/max_element
593
+ */
594
+ template <typename ForwardIterator, typename BinaryPredicate>
595
+ ForwardIterator max_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp);
596
+
597
+ /*! \p minmax_element finds the smallest and largest elements in the range <tt>[first, last)</tt>.
598
+ * It returns a pair of iterators <tt>(imin, imax)</tt> where \c imin is the same iterator
599
+ * returned by \p min_element and \c imax is the same iterator returned by \p max_element.
600
+ * This function is potentially more efficient than separate calls to \p min_element and \p max_element.
601
+ *
602
+ * The algorithm's execution is parallelized as determined by \p exec.
603
+ *
604
+ * \param exec The execution policy to use for parallelization.
605
+ * \param first The beginning of the sequence.
606
+ * \param last The end of the sequence.
607
+ * \return A pair of iterator pointing to the smallest and largest elements of the range <tt>[first, last)</tt>,
608
+ * if it is not an empty range; \p last, otherwise.
609
+ *
610
+ * \tparam DerivedPolicy The name of the derived execution policy.
611
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
612
+ * Iterator</a>, and \c ForwardIterator's \c value_type is a model of <a
613
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>.
614
+ *
615
+ * \code
616
+ * #include <thrust/extrema.h>
617
+ * #include <thrust/execution_policy.h>
618
+ * ...
619
+ * int data[6] = {1, 0, 2, 2, 1, 3};
620
+ * thrust::pair<int *, int *> result = thrust::minmax_element(thrust::host, data, data + 6);
621
+ *
622
+ * // result.first is data + 1
623
+ * // result.second is data + 5
624
+ * // *result.first is 0
625
+ * // *result.second is 3
626
+ * \endcode
627
+ *
628
+ * \see min_element
629
+ * \see max_element
630
+ * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf
631
+ */
632
+ template <typename DerivedPolicy, typename ForwardIterator>
633
+ _CCCL_HOST_DEVICE thrust::pair<ForwardIterator, ForwardIterator> minmax_element(
634
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last);
635
+
636
+ /*! \p minmax_element finds the smallest and largest elements in the range <tt>[first, last)</tt>.
637
+ * It returns a pair of iterators <tt>(imin, imax)</tt> where \c imin is the same iterator
638
+ * returned by \p min_element and \c imax is the same iterator returned by \p max_element.
639
+ * This function is potentially more efficient than separate calls to \p min_element and \p max_element.
640
+ *
641
+ * \param first The beginning of the sequence.
642
+ * \param last The end of the sequence.
643
+ * \return A pair of iterator pointing to the smallest and largest elements of the range <tt>[first, last)</tt>,
644
+ * if it is not an empty range; \p last, otherwise.
645
+ *
646
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
647
+ * Iterator</a>, and \c ForwardIterator's \c value_type is a model of <a
648
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>.
649
+ *
650
+ * \code
651
+ * #include <thrust/extrema.h>
652
+ * ...
653
+ * int data[6] = {1, 0, 2, 2, 1, 3};
654
+ * thrust::pair<int *, int *> result = thrust::minmax_element(data, data + 6);
655
+ *
656
+ * // result.first is data + 1
657
+ * // result.second is data + 5
658
+ * // *result.first is 0
659
+ * // *result.second is 3
660
+ * \endcode
661
+ *
662
+ * \see min_element
663
+ * \see max_element
664
+ * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf
665
+ */
666
+ template <typename ForwardIterator>
667
+ thrust::pair<ForwardIterator, ForwardIterator> minmax_element(ForwardIterator first, ForwardIterator last);
668
+
669
+ /*! \p minmax_element finds the smallest and largest elements in the range <tt>[first, last)</tt>.
670
+ * It returns a pair of iterators <tt>(imin, imax)</tt> where \c imin is the same iterator
671
+ * returned by \p min_element and \c imax is the same iterator returned by \p max_element.
672
+ * This function is potentially more efficient than separate calls to \p min_element and \p max_element.
673
+ *
674
+ * The algorithm's execution is parallelized as determined by \p exec.
675
+ *
676
+ * \param exec The execution policy to use for parallelization.
677
+ * \param first The beginning of the sequence.
678
+ * \param last The end of the sequence.
679
+ * \param comp A binary predicate used for comparison.
680
+ * \return A pair of iterator pointing to the smallest and largest elements of the range <tt>[first, last)</tt>,
681
+ * if it is not an empty range; \p last, otherwise.
682
+ *
683
+ * \tparam DerivedPolicy The name of the derived execution policy.
684
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
685
+ * Iterator</a>, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c
686
+ * second_argument_type. \tparam BinaryPredicate is a model of <a
687
+ * href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">Binary Predicate</a>.
688
+ *
689
+ * The following code snippet demonstrates how to use \p minmax_element to find the smallest and largest elements
690
+ * of a collection of key-value pairs using the \p thrust::host execution policy for parallelization:
691
+ *
692
+ * \code
693
+ * #include <thrust/extrema.h>
694
+ * #include <thrust/pair.h>
695
+ * #include <thrust/execution_policy.h>
696
+ * ...
697
+ *
698
+ * struct key_value
699
+ * {
700
+ * int key;
701
+ * int value;
702
+ * };
703
+ *
704
+ * struct compare_key_value
705
+ * {
706
+ * __host__ __device__
707
+ * bool operator()(key_value lhs, key_value rhs)
708
+ * {
709
+ * return lhs.key < rhs.key;
710
+ * }
711
+ * };
712
+ *
713
+ * ...
714
+ * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
715
+ *
716
+ * thrust::pair<key_value*,key_value*> extrema = thrust::minmax_element(thrust::host, data, data + 4,
717
+ * compare_key_value());
718
+ *
719
+ * // extrema.first == data + 1
720
+ * // *extrema.first == {0,7}
721
+ * // extrema.second == data + 3
722
+ * // *extrema.second == {6,1}
723
+ * \endcode
724
+ *
725
+ * \see min_element
726
+ * \see max_element
727
+ * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf
728
+ */
729
+ template <typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
730
+ _CCCL_HOST_DEVICE thrust::pair<ForwardIterator, ForwardIterator> minmax_element(
731
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
732
+ ForwardIterator first,
733
+ ForwardIterator last,
734
+ BinaryPredicate comp);
735
+
736
+ /*! \p minmax_element finds the smallest and largest elements in the range <tt>[first, last)</tt>.
737
+ * It returns a pair of iterators <tt>(imin, imax)</tt> where \c imin is the same iterator
738
+ * returned by \p min_element and \c imax is the same iterator returned by \p max_element.
739
+ * This function is potentially more efficient than separate calls to \p min_element and \p max_element.
740
+ *
741
+ * \param first The beginning of the sequence.
742
+ * \param last The end of the sequence.
743
+ * \param comp A binary predicate used for comparison.
744
+ * \return A pair of iterator pointing to the smallest and largest elements of the range <tt>[first, last)</tt>,
745
+ * if it is not an empty range; \p last, otherwise.
746
+ *
747
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
748
+ * Iterator</a>, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c
749
+ * second_argument_type. \tparam BinaryPredicate is a model of <a
750
+ * href="https://en.cppreference.com/w/cpp/named_req/BinaryPredicate">Binary Predicate</a>.
751
+ *
752
+ * The following code snippet demonstrates how to use \p minmax_element to find the smallest and largest elements
753
+ * of a collection of key-value pairs.
754
+ *
755
+ * \code
756
+ * #include <thrust/extrema.h>
757
+ * #include <thrust/pair.h>
758
+ *
759
+ * struct key_value
760
+ * {
761
+ * int key;
762
+ * int value;
763
+ * };
764
+ *
765
+ * struct compare_key_value
766
+ * {
767
+ * __host__ __device__
768
+ * bool operator()(key_value lhs, key_value rhs)
769
+ * {
770
+ * return lhs.key < rhs.key;
771
+ * }
772
+ * };
773
+ *
774
+ * ...
775
+ * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} };
776
+ *
777
+ * thrust::pair<key_value*,key_value*> extrema = thrust::minmax_element(data, data + 4, compare_key_value());
778
+ *
779
+ * // extrema.first == data + 1
780
+ * // *extrema.first == {0,7}
781
+ * // extrema.second == data + 3
782
+ * // *extrema.second == {6,1}
783
+ * \endcode
784
+ *
785
+ * \see min_element
786
+ * \see max_element
787
+ * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf
788
+ */
789
+ template <typename ForwardIterator, typename BinaryPredicate>
790
+ thrust::pair<ForwardIterator, ForwardIterator>
791
+ minmax_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp);
792
+
793
+ /*! \} // end extrema
794
+ * \} // end reductions
795
+ */
796
+
797
+ THRUST_NAMESPACE_END
798
+
799
+ #include <thrust/detail/extrema.inl>
800
+ #include <thrust/detail/minmax.h>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/fill.h ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 fill.h
18
+ * \brief Fills a range with a constant value
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/execution_policy.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ /*! \addtogroup transformations
37
+ * \addtogroup filling
38
+ * \ingroup transformations
39
+ * \{
40
+ */
41
+
42
+ /*! \p fill assigns the value \p value to every element in
43
+ * the range <tt>[first, last)</tt>. That is, for every
44
+ * iterator \c i in <tt>[first, last)</tt>, it performs
45
+ * the assignment <tt>*i = value</tt>.
46
+ *
47
+ * The algorithm's execution is parallelized as determined by \p exec.
48
+ *
49
+ * \param exec The execution policy to use for parallelization.
50
+ * \param first The beginning of the sequence.
51
+ * \param last The end of the sequence.
52
+ * \param value The value to be copied.
53
+ *
54
+ * \tparam DerivedPolicy The name of the derived execution policy.
55
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
56
+ * Iterator</a>, and \p ForwardIterator is mutable. \tparam T is a model of <a
57
+ * href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>, and \p T's \c value_type is
58
+ * convertible to \p ForwardIterator's \c value_type.
59
+ *
60
+ * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's
61
+ * elements to a given value using the \p thrust::device execution policy for parallelization:
62
+ *
63
+ * \code
64
+ * #include <thrust/fill.h>
65
+ * #include <thrust/device_vector.h>
66
+ * #include <thrust/execution_policy.h>
67
+ * ...
68
+ * thrust::device_vector<int> v(4);
69
+ * thrust::fill(thrust::device, v.begin(), v.end(), 137);
70
+ *
71
+ * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137
72
+ * \endcode
73
+ *
74
+ * \see https://en.cppreference.com/w/cpp/algorithm/fill
75
+ * \see \c fill_n
76
+ * \see \c uninitialized_fill
77
+ */
78
+ template <typename DerivedPolicy, typename ForwardIterator, typename T>
79
+ _CCCL_HOST_DEVICE void
80
+ fill(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
81
+ ForwardIterator first,
82
+ ForwardIterator last,
83
+ const T& value);
84
+
85
+ /*! \p fill assigns the value \p value to every element in
86
+ * the range <tt>[first, last)</tt>. That is, for every
87
+ * iterator \c i in <tt>[first, last)</tt>, it performs
88
+ * the assignment <tt>*i = value</tt>.
89
+ *
90
+ * \param first The beginning of the sequence.
91
+ * \param last The end of the sequence.
92
+ * \param value The value to be copied.
93
+ *
94
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
95
+ * Iterator</a>, and \p ForwardIterator is mutable. \tparam T is a model of <a
96
+ * href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>, and \p T's \c value_type is
97
+ * convertible to \p ForwardIterator's \c value_type.
98
+ *
99
+ * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's
100
+ * elements to a given value.
101
+ *
102
+ * \code
103
+ * #include <thrust/fill.h>
104
+ * #include <thrust/device_vector.h>
105
+ * ...
106
+ * thrust::device_vector<int> v(4);
107
+ * thrust::fill(v.begin(), v.end(), 137);
108
+ *
109
+ * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137
110
+ * \endcode
111
+ *
112
+ * \see https://en.cppreference.com/w/cpp/algorithm/fill
113
+ * \see \c fill_n
114
+ * \see \c uninitialized_fill
115
+ */
116
+ template <typename ForwardIterator, typename T>
117
+ _CCCL_HOST_DEVICE void fill(ForwardIterator first, ForwardIterator last, const T& value);
118
+
119
+ /*! \p fill_n assigns the value \p value to every element in
120
+ * the range <tt>[first, first+n)</tt>. That is, for every
121
+ * iterator \c i in <tt>[first, first+n)</tt>, it performs
122
+ * the assignment <tt>*i = value</tt>.
123
+ *
124
+ * The algorithm's execution is parallelized as determined by \p exec.
125
+ *
126
+ * \param exec The execution policy to use for parallelization.
127
+ * \param first The beginning of the sequence.
128
+ * \param n The size of the sequence.
129
+ * \param value The value to be copied.
130
+ * \return <tt>first + n</tt>
131
+ *
132
+ * \tparam DerivedPolicy The name of the derived execution policy.
133
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
134
+ * Iterator</a>. \tparam T is a model of <a
135
+ * href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>, and \p T's \c value_type is
136
+ * convertible to a type in \p OutputIterator's set of \c value_type.
137
+ *
138
+ * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's
139
+ * elements to a given value using the \p thrust::device execution policy for parallelization:
140
+ *
141
+ * \code
142
+ * #include <thrust/fill.h>
143
+ * #include <thrust/device_vector.h>
144
+ * #include <thrust/execution_policy.h>
145
+ * ...
146
+ * thrust::device_vector<int> v(4);
147
+ * thrust::fill_n(thrust::device, v.begin(), v.size(), 137);
148
+ *
149
+ * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137
150
+ * \endcode
151
+ *
152
+ * \see https://en.cppreference.com/w/cpp/algorithm/fill_n
153
+ * \see \c fill
154
+ * \see \c uninitialized_fill_n
155
+ */
156
+ template <typename DerivedPolicy, typename OutputIterator, typename Size, typename T>
157
+ _CCCL_HOST_DEVICE OutputIterator
158
+ fill_n(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, OutputIterator first, Size n, const T& value);
159
+
160
+ /*! \p fill_n assigns the value \p value to every element in
161
+ * the range <tt>[first, first+n)</tt>. That is, for every
162
+ * iterator \c i in <tt>[first, first+n)</tt>, it performs
163
+ * the assignment <tt>*i = value</tt>.
164
+ *
165
+ * \param first The beginning of the sequence.
166
+ * \param n The size of the sequence.
167
+ * \param value The value to be copied.
168
+ * \return <tt>first + n</tt>
169
+ *
170
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
171
+ * Iterator</a>. \tparam T is a model of <a
172
+ * href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>, and \p T's \c value_type is
173
+ * convertible to a type in \p OutputIterator's set of \c value_type.
174
+ *
175
+ * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's
176
+ * elements to a given value.
177
+ *
178
+ * \code
179
+ * #include <thrust/fill.h>
180
+ * #include <thrust/device_vector.h>
181
+ * ...
182
+ * thrust::device_vector<int> v(4);
183
+ * thrust::fill_n(v.begin(), v.size(), 137);
184
+ *
185
+ * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137
186
+ * \endcode
187
+ *
188
+ * \see https://en.cppreference.com/w/cpp/algorithm/fill_n
189
+ * \see \c fill
190
+ * \see \c uninitialized_fill_n
191
+ */
192
+ template <typename OutputIterator, typename Size, typename T>
193
+ _CCCL_HOST_DEVICE OutputIterator fill_n(OutputIterator first, Size n, const T& value);
194
+
195
+ /*! \} // end filling
196
+ * \} // transformations
197
+ */
198
+
199
+ THRUST_NAMESPACE_END
200
+
201
+ #include <thrust/detail/fill.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/for_each.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
+ * * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ /*! \file thrust/for_each.h
17
+ * \brief Applies a function to each element in a range
18
+ */
19
+
20
+ #pragma once
21
+
22
+ #include <thrust/detail/config.h>
23
+
24
+ #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
25
+ # pragma GCC system_header
26
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
27
+ # pragma clang system_header
28
+ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
29
+ # pragma system_header
30
+ #endif // no system header
31
+ #include <thrust/detail/execution_policy.h>
32
+ #include <thrust/detail/type_traits.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ /*! \addtogroup modifying
37
+ * \ingroup transformations
38
+ * \{
39
+ */
40
+
41
+ /*! \p for_each applies the function object \p f to each element
42
+ * in the range <tt>[first, last)</tt>; \p f's return value, if any,
43
+ * is ignored. Unlike the C++ Standard Template Library function
44
+ * <tt>std::for_each</tt>, this version offers no guarantee on
45
+ * order of execution. For this reason, this version of \p for_each
46
+ * does not return a copy of the function object.
47
+ *
48
+ * The algorithm's execution is parallelized as determined by \p exec.
49
+ *
50
+ * \param exec The execution policy to use for parallelization.
51
+ * \param first The beginning of the sequence.
52
+ * \param last The end of the sequence.
53
+ * \param f The function object to apply to the range <tt>[first, last)</tt>.
54
+ * \return last
55
+ *
56
+ * \tparam DerivedPolicy The name of the derived execution policy.
57
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/named_req/InputIterator">Input
58
+ * Iterator</a>, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam
59
+ * UnaryFunction is a model of <a href="https://en.cppreference.com/w/cpp/utility/functional/unary_function">Unary
60
+ * Function</a>, and \p UnaryFunction does not apply any non-constant operation through its argument.
61
+ *
62
+ * The following code snippet demonstrates how to use \p for_each to print the elements
63
+ * of a \p thrust::device_vector using the \p thrust::device parallelization policy:
64
+ *
65
+ * \code
66
+ * #include <thrust/for_each.h>
67
+ * #include <thrust/device_vector.h>
68
+ * #include <thrust/execution_policy.h>
69
+ * #include <cstdio>
70
+ * ...
71
+ *
72
+ * struct printf_functor
73
+ * {
74
+ * __host__ __device__
75
+ * void operator()(int x)
76
+ * {
77
+ * // note that using printf in a __device__ function requires
78
+ * // code compiled for a GPU with compute capability 2.0 or
79
+ * // higher (nvcc --arch=sm_20)
80
+ * printf("%d\n", x);
81
+ * }
82
+ * };
83
+ * ...
84
+ * thrust::device_vector<int> d_vec(3);
85
+ * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2;
86
+ *
87
+ * thrust::for_each(thrust::device, d_vec.begin(), d_vec.end(), printf_functor());
88
+ *
89
+ * // 0 1 2 is printed to standard output in some unspecified order
90
+ * \endcode
91
+ *
92
+ * \see for_each_n
93
+ * \see https://en.cppreference.com/w/cpp/algorithm/for_each
94
+ */
95
+ template <typename DerivedPolicy, typename InputIterator, typename UnaryFunction>
96
+ _CCCL_HOST_DEVICE InputIterator for_each(
97
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
98
+ InputIterator first,
99
+ InputIterator last,
100
+ UnaryFunction f);
101
+
102
+ /*! \p for_each_n applies the function object \p f to each element
103
+ * in the range <tt>[first, first + n)</tt>; \p f's return value, if any,
104
+ * is ignored. Unlike the C++ Standard Template Library function
105
+ * <tt>std::for_each</tt>, this version offers no guarantee on
106
+ * order of execution.
107
+ *
108
+ * The algorithm's execution is parallelized as determined by \p exec.
109
+ *
110
+ * \param exec The execution policy to use for parallelization.
111
+ * \param first The beginning of the sequence.
112
+ * \param n The size of the input sequence.
113
+ * \param f The function object to apply to the range <tt>[first, first + n)</tt>.
114
+ * \return <tt>first + n</tt>
115
+ *
116
+ * \tparam DerivedPolicy The name of the derived execution policy.
117
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/named_req/InputIterator">Input
118
+ * Iterator</a>, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam
119
+ * Size is an integral type. \tparam UnaryFunction is a model of <a
120
+ * href="https://en.cppreference.com/w/cpp/utility/functional/unary_function">Unary Function</a>, and \p UnaryFunction
121
+ * does not apply any non-constant operation through its argument.
122
+ *
123
+ * The following code snippet demonstrates how to use \p for_each_n to print the elements
124
+ * of a \p device_vector using the \p thrust::device parallelization policy.
125
+ *
126
+ * \code
127
+ * #include <thrust/for_each.h>
128
+ * #include <thrust/device_vector.h>
129
+ * #include <thrust/execution_policy.h>
130
+ * #include <cstdio>
131
+ *
132
+ * struct printf_functor
133
+ * {
134
+ * __host__ __device__
135
+ * void operator()(int x)
136
+ * {
137
+ * // note that using printf in a __device__ function requires
138
+ * // code compiled for a GPU with compute capability 2.0 or
139
+ * // higher (nvcc --arch=sm_20)
140
+ * printf("%d\n", x);
141
+ * }
142
+ * };
143
+ * ...
144
+ * thrust::device_vector<int> d_vec(3);
145
+ * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2;
146
+ *
147
+ * thrust::for_each_n(thrust::device, d_vec.begin(), d_vec.size(), printf_functor());
148
+ *
149
+ * // 0 1 2 is printed to standard output in some unspecified order
150
+ * \endcode
151
+ *
152
+ * \see for_each
153
+ * \see https://en.cppreference.com/w/cpp/algorithm/for_each
154
+ */
155
+ template <typename DerivedPolicy, typename InputIterator, typename Size, typename UnaryFunction>
156
+ _CCCL_HOST_DEVICE InputIterator for_each_n(
157
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec, InputIterator first, Size n, UnaryFunction f);
158
+
159
+ /*! \p for_each applies the function object \p f to each element
160
+ * in the range <tt>[first, last)</tt>; \p f's return value, if any,
161
+ * is ignored. Unlike the C++ Standard Template Library function
162
+ * <tt>std::for_each</tt>, this version offers no guarantee on
163
+ * order of execution. For this reason, this version of \p for_each
164
+ * does not return a copy of the function object.
165
+ *
166
+ * \param first The beginning of the sequence.
167
+ * \param last The end of the sequence.
168
+ * \param f The function object to apply to the range <tt>[first, last)</tt>.
169
+ * \return last
170
+ *
171
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/named_req/InputIterator">Input
172
+ * Iterator</a>, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam
173
+ * UnaryFunction is a model of <a href="https://en.cppreference.com/w/cpp/utility/functional/unary_function">Unary
174
+ * Function</a>, and \p UnaryFunction does not apply any non-constant operation through its argument.
175
+ *
176
+ * The following code snippet demonstrates how to use \p for_each to print the elements
177
+ * of a \p device_vector.
178
+ *
179
+ * \code
180
+ * #include <thrust/for_each.h>
181
+ * #include <thrust/device_vector.h>
182
+ * #include <stdio.h>
183
+ *
184
+ * struct printf_functor
185
+ * {
186
+ * __host__ __device__
187
+ * void operator()(int x)
188
+ * {
189
+ * // note that using printf in a __device__ function requires
190
+ * // code compiled for a GPU with compute capability 2.0 or
191
+ * // higher (nvcc --arch=sm_20)
192
+ * printf("%d\n", x);
193
+ * }
194
+ * };
195
+ * ...
196
+ * thrust::device_vector<int> d_vec(3);
197
+ * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2;
198
+ *
199
+ * thrust::for_each(d_vec.begin(), d_vec.end(), printf_functor());
200
+ *
201
+ * // 0 1 2 is printed to standard output in some unspecified order
202
+ * \endcode
203
+ *
204
+ * \see for_each_n
205
+ * \see https://en.cppreference.com/w/cpp/algorithm/for_each
206
+ */
207
+ template <typename InputIterator, typename UnaryFunction>
208
+ InputIterator for_each(InputIterator first, InputIterator last, UnaryFunction f);
209
+
210
+ /*! \p for_each_n applies the function object \p f to each element
211
+ * in the range <tt>[first, first + n)</tt>; \p f's return value, if any,
212
+ * is ignored. Unlike the C++ Standard Template Library function
213
+ * <tt>std::for_each</tt>, this version offers no guarantee on
214
+ * order of execution.
215
+ *
216
+ * \param first The beginning of the sequence.
217
+ * \param n The size of the input sequence.
218
+ * \param f The function object to apply to the range <tt>[first, first + n)</tt>.
219
+ * \return <tt>first + n</tt>
220
+ *
221
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/named_req/InputIterator">Input
222
+ * Iterator</a>, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam
223
+ * Size is an integral type. \tparam UnaryFunction is a model of <a
224
+ * href="https://en.cppreference.com/w/cpp/utility/functional/unary_function">Unary Function</a>, and \p UnaryFunction
225
+ * does not apply any non-constant operation through its argument.
226
+ *
227
+ * The following code snippet demonstrates how to use \p for_each_n to print the elements
228
+ * of a \p device_vector.
229
+ *
230
+ * \code
231
+ * #include <thrust/for_each.h>
232
+ * #include <thrust/device_vector.h>
233
+ * #include <stdio.h>
234
+ *
235
+ * struct printf_functor
236
+ * {
237
+ * __host__ __device__
238
+ * void operator()(int x)
239
+ * {
240
+ * // note that using printf in a __device__ function requires
241
+ * // code compiled for a GPU with compute capability 2.0 or
242
+ * // higher (nvcc --arch=sm_20)
243
+ * printf("%d\n", x);
244
+ * }
245
+ * };
246
+ * ...
247
+ * thrust::device_vector<int> d_vec(3);
248
+ * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2;
249
+ *
250
+ * thrust::for_each_n(d_vec.begin(), d_vec.size(), printf_functor());
251
+ *
252
+ * // 0 1 2 is printed to standard output in some unspecified order
253
+ * \endcode
254
+ *
255
+ * \see for_each
256
+ * \see https://en.cppreference.com/w/cpp/algorithm/for_each
257
+ */
258
+ template <typename InputIterator, typename Size, typename UnaryFunction>
259
+ InputIterator for_each_n(InputIterator first, Size n, UnaryFunction f);
260
+
261
+ /*! \} // end modifying
262
+ */
263
+
264
+ THRUST_NAMESPACE_END
265
+
266
+ #include <thrust/detail/for_each.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/future.h ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/future.h
18
+ * \brief `thrust::future`, an asynchronous value type.
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/cpp14_required.h>
33
+
34
+ #if _CCCL_STD_VER >= 2014
35
+
36
+ # include <thrust/detail/static_assert.h>
37
+ # include <thrust/execution_policy.h>
38
+
39
+ # include <utility>
40
+
41
+ /*
42
+ // #include the host system's pointer.h header.
43
+ #define __THRUST_HOST_SYSTEM_POINTER_HEADER <__THRUST_HOST_SYSTEM_ROOT/pointer.h>
44
+ #include __THRUST_HOST_SYSTEM_POINTER_HEADER
45
+ #undef __THRUST_HOST_SYSTEM_POINTER_HEADER
46
+ */
47
+
48
+ // #include the device system's pointer.h header.
49
+ # define __THRUST_DEVICE_SYSTEM_POINTER_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/pointer.h>
50
+ # include __THRUST_DEVICE_SYSTEM_POINTER_HEADER
51
+ # undef __THRUST_DEVICE_SYSTEM_POINTER_HEADER
52
+
53
+ /*
54
+ // #include the host system's future.h header.
55
+ #define __THRUST_HOST_SYSTEM_FUTURE_HEADER <__THRUST_HOST_SYSTEM_ROOT/future.h>
56
+ #include __THRUST_HOST_SYSTEM_FUTURE_HEADER
57
+ #undef __THRUST_HOST_SYSTEM_FUTURE_HEADER
58
+ */
59
+
60
+ // #include the device system's future.h header.
61
+ # define __THRUST_DEVICE_SYSTEM_FUTURE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/future.h>
62
+ # include __THRUST_DEVICE_SYSTEM_FUTURE_HEADER
63
+ # undef __THRUST_DEVICE_SYSTEM_FUTURE_HEADER
64
+
65
+ _CCCL_SUPPRESS_DEPRECATED_PUSH
66
+ THRUST_NAMESPACE_BEGIN
67
+
68
+ ///////////////////////////////////////////////////////////////////////////////
69
+
70
+ // `select_unique_(future|event)_type` is a hook for choosing the
71
+ // `unique_eager_event`/`unique_eager_future` type for a system. `decltype` is
72
+ // used to determine the return type of an ADL call to
73
+ // `select_unique_eager_(future|event)_type(system)`; that return type should
74
+ // be the correct event/future type for `system`. Overloads should only be
75
+ // declared, not defined.
76
+
77
+ namespace unimplemented
78
+ {
79
+
80
+ struct CCCL_DEPRECATED no_unique_eager_event_type_found
81
+ {};
82
+
83
+ CCCL_DEPRECATED _CCCL_HOST inline no_unique_eager_event_type_found unique_eager_event_type(...) noexcept;
84
+
85
+ struct CCCL_DEPRECATED no_unique_eager_future_type_found
86
+ {};
87
+
88
+ template <typename T>
89
+ CCCL_DEPRECATED _CCCL_HOST no_unique_eager_future_type_found unique_eager_future_type(...) noexcept;
90
+
91
+ } // namespace unimplemented
92
+
93
+ namespace unique_eager_event_type_detail
94
+ {
95
+
96
+ using unimplemented::unique_eager_event_type;
97
+
98
+ template <typename System>
99
+ using select CCCL_DEPRECATED = decltype(unique_eager_event_type(std::declval<System>()));
100
+
101
+ } // namespace unique_eager_event_type_detail
102
+
103
+ namespace unique_eager_future_type_detail
104
+ {
105
+
106
+ using unimplemented::unique_eager_future_type;
107
+
108
+ template <typename System, typename T>
109
+ using select CCCL_DEPRECATED = decltype(unique_eager_future_type<T>(std::declval<System>()));
110
+
111
+ } // namespace unique_eager_future_type_detail
112
+
113
+ ///////////////////////////////////////////////////////////////////////////////
114
+
115
+ template <typename System>
116
+ using unique_eager_event CCCL_DEPRECATED = unique_eager_event_type_detail::select<System>;
117
+
118
+ template <typename System>
119
+ using event CCCL_DEPRECATED = unique_eager_event<System>;
120
+
121
+ ///////////////////////////////////////////////////////////////////////////////
122
+
123
+ template <typename System, typename T>
124
+ using unique_eager_future CCCL_DEPRECATED = unique_eager_future_type_detail::select<System, T>;
125
+
126
+ template <typename System, typename T>
127
+ using future CCCL_DEPRECATED = unique_eager_future<System, T>;
128
+
129
+ /*
130
+ ///////////////////////////////////////////////////////////////////////////////
131
+
132
+ using host_unique_eager_event = unique_eager_event_type_detail::select<
133
+ thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::tag
134
+ >;
135
+ using host_event = host_unique_eager_event;
136
+
137
+ ///////////////////////////////////////////////////////////////////////////////
138
+
139
+ template <typename T>
140
+ using host_unique_eager_future = unique_eager_future_type_detail::select<
141
+ thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::tag, T
142
+ >;
143
+ template <typename T>
144
+ using host_future = host_unique_eager_future<T>;
145
+ */
146
+
147
+ ///////////////////////////////////////////////////////////////////////////////
148
+
149
+ using device_unique_eager_event CCCL_DEPRECATED =
150
+ unique_eager_event_type_detail::select<thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::tag>;
151
+
152
+ using device_event CCCL_DEPRECATED = device_unique_eager_event;
153
+
154
+ ///////////////////////////////////////////////////////////////////////////////
155
+
156
+ template <typename T>
157
+ using device_unique_eager_future CCCL_DEPRECATED =
158
+ unique_eager_future_type_detail::select<thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::tag, T>;
159
+
160
+ template <typename T>
161
+ using device_future CCCL_DEPRECATED = device_unique_eager_future<T>;
162
+
163
+ ///////////////////////////////////////////////////////////////////////////////
164
+
165
+ struct CCCL_DEPRECATED new_stream_t final
166
+ {};
167
+
168
+ # ifndef CCCL_HEADER_MACRO_CHECK
169
+ // when building header tests, we get a deprecation warning from cudafe1.stub.c if we deprecate a global variable
170
+ CCCL_DEPRECATED
171
+ # endif
172
+ _CCCL_GLOBAL_CONSTANT new_stream_t new_stream{};
173
+
174
+ ///////////////////////////////////////////////////////////////////////////////
175
+
176
+ using thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::when_all;
177
+
178
+ ///////////////////////////////////////////////////////////////////////////////
179
+
180
+ _CCCL_SUPPRESS_DEPRECATED_POP
181
+ THRUST_NAMESPACE_END
182
+
183
+ #endif
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/generate.h ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 generate.h
18
+ * \brief Fills a range with values "generated" from a function of no arguments
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/execution_policy.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ /*! \addtogroup transformations
37
+ * \{
38
+ */
39
+
40
+ /*! \p generate assigns the result of invoking \p gen, a function object that takes no arguments,
41
+ * to each element in the range <tt>[first,last)</tt>.
42
+ *
43
+ * The algorithm's execution is parallelized as determined by \p exec.
44
+ *
45
+ * \param exec The execution policy to use for parallelization.
46
+ * \param first The first element in the range of interest.
47
+ * \param last The last element in the range of interest.
48
+ * \param gen A function argument, taking no parameters, used to generate values to assign to
49
+ * elements in the range <tt>[first,last)</tt>.
50
+ *
51
+ * \tparam DerivedPolicy The name of the derived execution policy.
52
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
53
+ * Iterator</a>, and \p ForwardIterator is mutable. \tparam Generator is a model of <a
54
+ * href="https://en.cppreference.com/w/cpp/utility/functional">Generator</a>, and \p Generator's \c result_type is
55
+ * convertible to \p ForwardIterator's \c value_type.
56
+ *
57
+ * The following code snippet demonstrates how to fill a \c host_vector with random numbers,
58
+ * using the standard C library function \c rand using the \p thrust::host execution policy for parallelization:
59
+ *
60
+ * \code
61
+ * #include <thrust/generate.h>
62
+ * #include <thrust/host_vector.h>
63
+ * #include <thrust/execution_policy.h>
64
+ * #include <cstdlib>
65
+ * ...
66
+ * thrust::host_vector<int> v(10);
67
+ * srand(13);
68
+ * thrust::generate(thrust::host, v.begin(), v.end(), rand);
69
+ *
70
+ * // the elements of v are now pseudo-random numbers
71
+ * \endcode
72
+ *
73
+ * \see generate_n
74
+ * \see https://en.cppreference.com/w/cpp/algorithm/generate
75
+ */
76
+ template <typename DerivedPolicy, typename ForwardIterator, typename Generator>
77
+ _CCCL_HOST_DEVICE void
78
+ generate(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
79
+ ForwardIterator first,
80
+ ForwardIterator last,
81
+ Generator gen);
82
+
83
+ /*! \p generate assigns the result of invoking \p gen, a function object that takes no arguments,
84
+ * to each element in the range <tt>[first,last)</tt>.
85
+ *
86
+ * \param first The first element in the range of interest.
87
+ * \param last The last element in the range of interest.
88
+ * \param gen A function argument, taking no parameters, used to generate values to assign to
89
+ * elements in the range <tt>[first,last)</tt>.
90
+ *
91
+ * \tparam ForwardIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/forward_iterator">Forward
92
+ * Iterator</a>, and \p ForwardIterator is mutable. \tparam Generator is a model of <a
93
+ * href="https://en.cppreference.com/w/cpp/utility/functional">Generator</a>, and \p Generator's \c result_type is
94
+ * convertible to \p ForwardIterator's \c value_type.
95
+ *
96
+ * The following code snippet demonstrates how to fill a \c host_vector with random numbers,
97
+ * using the standard C library function \c rand.
98
+ *
99
+ * \code
100
+ * #include <thrust/generate.h>
101
+ * #include <thrust/host_vector.h>
102
+ * #include <thrust/execution_policy.h>
103
+ * #include <cstdlib>
104
+ * ...
105
+ * thrust::host_vector<int> v(10);
106
+ * srand(13);
107
+ * thrust::generate(v.begin(), v.end(), rand);
108
+ *
109
+ * // the elements of v are now pseudo-random numbers
110
+ * \endcode
111
+ *
112
+ * \see generate_n
113
+ * \see https://en.cppreference.com/w/cpp/algorithm/generate
114
+ */
115
+ template <typename ForwardIterator, typename Generator>
116
+ void generate(ForwardIterator first, ForwardIterator last, Generator gen);
117
+
118
+ /*! \p generate_n assigns the result of invoking \p gen, a function object that takes no arguments,
119
+ * to each element in the range <tt>[first,first + n)</tt>. The return value is <tt>first + n</tt>.
120
+ *
121
+ * The algorithm's execution is parallelized as determined by \p exec.
122
+ *
123
+ * \param exec The execution policy to use for parallelization.
124
+ * \param first The first element in the range of interest.
125
+ * \param n The size of the range of interest.
126
+ * \param gen A function argument, taking no parameters, used to generate values to assign to
127
+ * elements in the range <tt>[first,first + n)</tt>.
128
+ *
129
+ * \tparam DerivedPolicy The name of the derived execution policy.
130
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
131
+ * Iterator</a>. \tparam Size is an integral type (either signed or unsigned). \tparam Generator is a model of <a
132
+ * href="https://en.cppreference.com/w/cpp/utility/functional">Generator</a>, and \p Generator's \c result_type is
133
+ * convertible to a type in \p OutputIterator's set of \c value_types.
134
+ *
135
+ * The following code snippet demonstrates how to fill a \c host_vector with random numbers,
136
+ * using the standard C library function \c rand using the \p thrust::host execution policy for parallelization:
137
+ *
138
+ * \code
139
+ * #include <thrust/generate.h>
140
+ * #include <thrust/host_vector.h>
141
+ * #include <thrust/execution_policy.h>
142
+ * #include <cstdlib>
143
+ * ...
144
+ * thrust::host_vector<int> v(10);
145
+ * srand(13);
146
+ * thrust::generate_n(thrust::host, v.begin(), 10, rand);
147
+ *
148
+ * // the elements of v are now pseudo-random numbers
149
+ * \endcode
150
+ *
151
+ * \see generate
152
+ * \see https://en.cppreference.com/w/cpp/algorithm/generate
153
+ */
154
+ template <typename DerivedPolicy, typename OutputIterator, typename Size, typename Generator>
155
+ _CCCL_HOST_DEVICE OutputIterator generate_n(
156
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec, OutputIterator first, Size n, Generator gen);
157
+
158
+ /*! \p generate_n assigns the result of invoking \p gen, a function object that takes no arguments,
159
+ * to each element in the range <tt>[first,first + n)</tt>. The return value is <tt>first + n</tt>.
160
+ *
161
+ * \param first The first element in the range of interest.
162
+ * \param n The size of the range of interest.
163
+ * \param gen A function argument, taking no parameters, used to generate values to assign to
164
+ * elements in the range <tt>[first,first + n)</tt>.
165
+ *
166
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
167
+ * Iterator</a>. \tparam Size is an integral type (either signed or unsigned). \tparam Generator is a model of <a
168
+ * href="https://en.cppreference.com/w/cpp/utility/functional">Generator</a>, and \p Generator's \c result_type is
169
+ * convertible to a type in \p OutputIterator's set of \c value_types.
170
+ *
171
+ * The following code snippet demonstrates how to fill a \c host_vector with random numbers,
172
+ * using the standard C library function \c rand.
173
+ *
174
+ * \code
175
+ * #include <thrust/generate.h>
176
+ * #include <thrust/host_vector.h>
177
+ * #include <stdlib.h>
178
+ * ...
179
+ * thrust::host_vector<int> v(10);
180
+ * srand(13);
181
+ * thrust::generate_n(v.begin(), 10, rand);
182
+ *
183
+ * // the elements of v are now pseudo-random numbers
184
+ * \endcode
185
+ *
186
+ * \see generate
187
+ * \see https://en.cppreference.com/w/cpp/algorithm/generate
188
+ */
189
+ template <typename OutputIterator, typename Size, typename Generator>
190
+ OutputIterator generate_n(OutputIterator first, Size n, Generator gen);
191
+
192
+ /*! \} // end transformations
193
+ */
194
+
195
+ THRUST_NAMESPACE_END
196
+
197
+ #include <thrust/detail/generate.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/inner_product.h ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 inner_product.h
18
+ * \brief Mathematical inner product between ranges
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/execution_policy.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ /*! \addtogroup reductions
37
+ * \{
38
+ * \addtogroup transformed_reductions Transformed Reductions
39
+ * \ingroup reductions
40
+ * \{
41
+ */
42
+
43
+ /*! \p inner_product calculates an inner product of the ranges
44
+ * <tt>[first1, last1)</tt> and <tt>[first2, first2 + (last1 - first1))</tt>.
45
+ *
46
+ * Specifically, this version of \p inner_product computes the sum
47
+ * <tt>init + (*first1 * *first2) + (*(first1+1) * *(first2+1)) + ... </tt>
48
+ *
49
+ * The algorithm's execution is parallelized as determined by \p exec.
50
+ *
51
+ * \param exec The execution policy to use for parallelization.
52
+ * \param first1 The beginning of the first sequence.
53
+ * \param last1 The end of the first sequence.
54
+ * \param first2 The beginning of the second sequence.
55
+ * \param init Initial value of the result.
56
+ * \return The inner product of sequences <tt>[first1, last1)</tt>
57
+ * and <tt>[first2, last2)</tt> plus \p init.
58
+ *
59
+ * \tparam DerivedPolicy The name of the derived execution policy.
60
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
61
+ * Iterator</a>, \tparam InputIterator2 is a model of <a
62
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>, \tparam OutputType is a model of
63
+ * <a href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>, and if \c x is an object of type
64
+ * \p OutputType, and \c y is an object of \p InputIterator1's \c value_type, and \c z is an object of \p
65
+ * InputIterator2's \c value_type, then <tt>x + y * z</tt> is defined and is convertible to \p OutputType.
66
+ *
67
+ * The following code demonstrates how to use \p inner_product to
68
+ * compute the dot product of two vectors using the \p thrust::host execution policy for parallelization.
69
+ *
70
+ * \code
71
+ * #include <thrust/inner_product.h>
72
+ * #include <thrust/execution_policy.h>
73
+ * ...
74
+ * float vec1[3] = {1.0f, 2.0f, 5.0f};
75
+ * float vec2[3] = {4.0f, 1.0f, 5.0f};
76
+ *
77
+ * float result = thrust::inner_product(thrust::host, vec1, vec1 + 3, vec2, 0.0f);
78
+ *
79
+ * // result == 31.0f
80
+ * \endcode
81
+ *
82
+ * \see https://en.cppreference.com/w/cpp/algorithm/inner_product
83
+ */
84
+ template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputType>
85
+ _CCCL_HOST_DEVICE OutputType inner_product(
86
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
87
+ InputIterator1 first1,
88
+ InputIterator1 last1,
89
+ InputIterator2 first2,
90
+ OutputType init);
91
+
92
+ /*! \p inner_product calculates an inner product of the ranges
93
+ * <tt>[first1, last1)</tt> and <tt>[first2, first2 + (last1 - first1))</tt>.
94
+ *
95
+ * Specifically, this version of \p inner_product computes the sum
96
+ * <tt>init + (*first1 * *first2) + (*(first1+1) * *(first2+1)) + ... </tt>
97
+ *
98
+ * Unlike the C++ Standard Template Library function <tt>std::inner_product</tt>,
99
+ * this version offers no guarantee on order of execution.
100
+ *
101
+ * \param first1 The beginning of the first sequence.
102
+ * \param last1 The end of the first sequence.
103
+ * \param first2 The beginning of the second sequence.
104
+ * \param init Initial value of the result.
105
+ * \return The inner product of sequences <tt>[first1, last1)</tt>
106
+ * and <tt>[first2, last2)</tt> plus \p init.
107
+ *
108
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
109
+ * Iterator</a>, \tparam InputIterator2 is a model of <a
110
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>, \tparam OutputType is a model of
111
+ * <a href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>, and if \c x is an object of type
112
+ * \p OutputType, and \c y is an object of \p InputIterator1's \c value_type, and \c z is an object of \p
113
+ * InputIterator2's \c value_type, then <tt>x + y * z</tt> is defined and is convertible to \p OutputType.
114
+ *
115
+ * The following code demonstrates how to use \p inner_product to
116
+ * compute the dot product of two vectors.
117
+ *
118
+ * \code
119
+ * #include <thrust/inner_product.h>
120
+ * ...
121
+ * float vec1[3] = {1.0f, 2.0f, 5.0f};
122
+ * float vec2[3] = {4.0f, 1.0f, 5.0f};
123
+ *
124
+ * float result = thrust::inner_product(vec1, vec1 + 3, vec2, 0.0f);
125
+ *
126
+ * // result == 31.0f
127
+ * \endcode
128
+ *
129
+ * \see https://en.cppreference.com/w/cpp/algorithm/inner_product
130
+ */
131
+ template <typename InputIterator1, typename InputIterator2, typename OutputType>
132
+ OutputType inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType init);
133
+
134
+ /*! \p inner_product calculates an inner product of the ranges
135
+ * <tt>[first1, last1)</tt> and <tt>[first2, first2 + (last1 - first1))</tt>.
136
+ *
137
+ * This version of \p inner_product is identical to the first, except that is uses
138
+ * two user-supplied function objects instead of \c operator+ and \c operator*.
139
+ *
140
+ * Specifically, this version of \p inner_product computes the sum
141
+ * <tt>binary_op1( init, binary_op2(*first1, *first2) ), ... </tt>
142
+ *
143
+ * The algorithm's execution is parallelized as determined by \p exec.
144
+ *
145
+ * \param exec The execution policy to use for parallelization.
146
+ * \param first1 The beginning of the first sequence.
147
+ * \param last1 The end of the first sequence.
148
+ * \param first2 The beginning of the second sequence.
149
+ * \param init Initial value of the result.
150
+ * \param binary_op1 Generalized addition operation.
151
+ * \param binary_op2 Generalized multiplication operation.
152
+ * \return The inner product of sequences <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt>.
153
+ *
154
+ * \tparam DerivedPolicy The name of the derived execution policy.
155
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
156
+ * Iterator</a>, and \p InputIterator1's \c value_type is convertible to \p BinaryFunction2's \c first_argument_type.
157
+ * \tparam InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
158
+ * Iterator</a>. and \p InputIterator2's \c value_type is convertible to \p BinaryFunction2's \c second_argument_type.
159
+ * \tparam OutputType is a model of <a
160
+ * href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>, and \p OutputType is convertible to
161
+ * \p BinaryFunction1's \c first_argument_type. \tparam BinaryFunction1 is a model of <a
162
+ * href="https://en.cppreference.com/w/cpp/utility/functional/binary_function">Binary Function</a>, and \p
163
+ * BinaryFunction1's \c return_type is convertible to \p OutputType. \tparam BinaryFunction2 is a model of <a
164
+ * href="https://en.cppreference.com/w/cpp/utility/functional/binary_function">Binary Function</a>, and \p
165
+ * BinaryFunction2's \c return_type is convertible to \p BinaryFunction1's \c second_argument_type.
166
+ *
167
+ * \code
168
+ * #include <thrust/inner_product.h>
169
+ * #include <thrust/execution_policy.h>
170
+ * ...
171
+ * float vec1[3] = {1.0f, 2.0f, 5.0f};
172
+ * float vec2[3] = {4.0f, 1.0f, 5.0f};
173
+ *
174
+ * float init = 0.0f;
175
+ * thrust::plus<float> binary_op1;
176
+ * thrust::multiplies<float> binary_op2;
177
+ *
178
+ * float result = thrust::inner_product(thrust::host, vec1, vec1 + 3, vec2, init, binary_op1, binary_op2);
179
+ *
180
+ * // result == 31.0f
181
+ * \endcode
182
+ *
183
+ * \see https://en.cppreference.com/w/cpp/algorithm/inner_product
184
+ */
185
+ template <typename DerivedPolicy,
186
+ typename InputIterator1,
187
+ typename InputIterator2,
188
+ typename OutputType,
189
+ typename BinaryFunction1,
190
+ typename BinaryFunction2>
191
+ _CCCL_HOST_DEVICE OutputType inner_product(
192
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
193
+ InputIterator1 first1,
194
+ InputIterator1 last1,
195
+ InputIterator2 first2,
196
+ OutputType init,
197
+ BinaryFunction1 binary_op1,
198
+ BinaryFunction2 binary_op2);
199
+
200
+ /*! \p inner_product calculates an inner product of the ranges
201
+ * <tt>[first1, last1)</tt> and <tt>[first2, first2 + (last1 - first1))</tt>.
202
+ *
203
+ * This version of \p inner_product is identical to the first, except that is uses
204
+ * two user-supplied function objects instead of \c operator+ and \c operator*.
205
+ *
206
+ * Specifically, this version of \p inner_product computes the sum
207
+ * <tt>binary_op1( init, binary_op2(*first1, *first2) ), ... </tt>
208
+ *
209
+ * Unlike the C++ Standard Template Library function <tt>std::inner_product</tt>,
210
+ * this version offers no guarantee on order of execution.
211
+ *
212
+ * \param first1 The beginning of the first sequence.
213
+ * \param last1 The end of the first sequence.
214
+ * \param first2 The beginning of the second sequence.
215
+ * \param init Initial value of the result.
216
+ * \param binary_op1 Generalized addition operation.
217
+ * \param binary_op2 Generalized multiplication operation.
218
+ * \return The inner product of sequences <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt>.
219
+ *
220
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
221
+ * Iterator</a>, and \p InputIterator1's \c value_type is convertible to \p BinaryFunction2's \c first_argument_type.
222
+ * \tparam InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
223
+ * Iterator</a>. and \p InputIterator2's \c value_type is convertible to \p BinaryFunction2's \c second_argument_type.
224
+ * \tparam OutputType is a model of <a
225
+ * href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>, and \p OutputType is convertible to
226
+ * \p BinaryFunction1's \c first_argument_type. \tparam BinaryFunction1 is a model of <a
227
+ * href="https://en.cppreference.com/w/cpp/utility/functional/binary_function">Binary Function</a>, and \p
228
+ * BinaryFunction1's \c return_type is convertible to \p OutputType. \tparam BinaryFunction2 is a model of <a
229
+ * href="https://en.cppreference.com/w/cpp/utility/functional/binary_function">Binary Function</a>, and \p
230
+ * BinaryFunction2's \c return_type is convertible to \p BinaryFunction1's \c second_argument_type.
231
+ *
232
+ * \code
233
+ * #include <thrust/inner_product.h>
234
+ * ...
235
+ * float vec1[3] = {1.0f, 2.0f, 5.0f};
236
+ * float vec2[3] = {4.0f, 1.0f, 5.0f};
237
+ *
238
+ * float init = 0.0f;
239
+ * thrust::plus<float> binary_op1;
240
+ * thrust::multiplies<float> binary_op2;
241
+ *
242
+ * float result = thrust::inner_product(vec1, vec1 + 3, vec2, init, binary_op1, binary_op2);
243
+ *
244
+ * // result == 31.0f
245
+ * \endcode
246
+ *
247
+ * \see https://en.cppreference.com/w/cpp/algorithm/inner_product
248
+ */
249
+ template <typename InputIterator1,
250
+ typename InputIterator2,
251
+ typename OutputType,
252
+ typename BinaryFunction1,
253
+ typename BinaryFunction2>
254
+ OutputType inner_product(
255
+ InputIterator1 first1,
256
+ InputIterator1 last1,
257
+ InputIterator2 first2,
258
+ OutputType init,
259
+ BinaryFunction1 binary_op1,
260
+ BinaryFunction2 binary_op2);
261
+
262
+ /*! \} // end transformed_reductions
263
+ * \} // end reductions
264
+ */
265
+
266
+ THRUST_NAMESPACE_END
267
+
268
+ #include <thrust/detail/inner_product.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/logical.h ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 logical.h
18
+ * \brief Logical operations on ranges
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/execution_policy.h>
33
+
34
+ THRUST_NAMESPACE_BEGIN
35
+
36
+ /*! \addtogroup reductions
37
+ * \{
38
+ * \addtogroup logical
39
+ * \ingroup reductions
40
+ * \{
41
+ */
42
+
43
+ /*! \p all_of determines whether all elements in a range satisfy a predicate.
44
+ * Specifically, \p all_of returns \c true if <tt>pred(*i)</tt> is \c true
45
+ * for every iterator \c i in the range <tt>[first, last)</tt> and
46
+ * \c false otherwise.
47
+ *
48
+ * The algorithm's execution is parallelized as determined by \p exec.
49
+ *
50
+ * \param exec The execution policy to use for parallelization.
51
+ * \param first The beginning of the sequence.
52
+ * \param last The end of the sequence.
53
+ * \param pred A predicate used to test range elements.
54
+ * \return \c true, if all elements satisfy the predicate; \c false, otherwise.
55
+ *
56
+ * \tparam DerivedPolicy The name of the derived execution policy.
57
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
58
+ * Iterator</a>, \tparam Predicate must be a model of <a
59
+ * href="https://en.cppreference.com/w/cpp/concepts/predicate">Predicate</a>.
60
+ *
61
+ * \code
62
+ * #include <thrust/logical.h>
63
+ * #include <thrust/functional.h>
64
+ * #include <thrust/execution_policy.h>
65
+ * ...
66
+ * bool A[3] = {true, true, false};
67
+ *
68
+ * thrust::all_of(thrust::host, A, A + 2, thrust::identity<bool>()); // returns true
69
+ * thrust::all_of(thrust::host, A, A + 3, thrust::identity<bool>()); // returns false
70
+ *
71
+ * // empty range
72
+ * thrust::all_of(thrust::host, A, A, thrust::identity<bool>()); // returns false
73
+ *
74
+ * \endcode
75
+ *
76
+ * \see any_of
77
+ * \see none_of
78
+ * \see transform_reduce
79
+ */
80
+ template <typename DerivedPolicy, typename InputIterator, typename Predicate>
81
+ _CCCL_HOST_DEVICE bool
82
+ all_of(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
83
+ InputIterator first,
84
+ InputIterator last,
85
+ Predicate pred);
86
+
87
+ /*! \p all_of determines whether all elements in a range satisfy a predicate.
88
+ * Specifically, \p all_of returns \c true if <tt>pred(*i)</tt> is \c true
89
+ * for every iterator \c i in the range <tt>[first, last)</tt> and
90
+ * \c false otherwise.
91
+ *
92
+ * \param first The beginning of the sequence.
93
+ * \param last The end of the sequence.
94
+ * \param pred A predicate used to test range elements.
95
+ * \return \c true, if all elements satisfy the predicate; \c false, otherwise.
96
+ *
97
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
98
+ * Iterator</a>, \tparam Predicate must be a model of <a
99
+ * href="https://en.cppreference.com/w/cpp/concepts/predicate">Predicate</a>.
100
+ *
101
+ * \code
102
+ * #include <thrust/logical.h>
103
+ * #include <thrust/functional.h>
104
+ * ...
105
+ * bool A[3] = {true, true, false};
106
+ *
107
+ * thrust::all_of(A, A + 2, thrust::identity<bool>()); // returns true
108
+ * thrust::all_of(A, A + 3, thrust::identity<bool>()); // returns false
109
+ *
110
+ * // empty range
111
+ * thrust::all_of(A, A, thrust::identity<bool>()); // returns false
112
+ *
113
+ * \endcode
114
+ *
115
+ * \see any_of
116
+ * \see none_of
117
+ * \see transform_reduce
118
+ */
119
+ template <typename InputIterator, typename Predicate>
120
+ bool all_of(InputIterator first, InputIterator last, Predicate pred);
121
+
122
+ /*! \p any_of determines whether any element in a range satisfies a predicate.
123
+ * Specifically, \p any_of returns \c true if <tt>pred(*i)</tt> is \c true
124
+ * for any iterator \c i in the range <tt>[first, last)</tt> and
125
+ * \c false otherwise.
126
+ *
127
+ * The algorithm's execution is parallelized as determined by \p exec.
128
+ *
129
+ * \param exec The execution policy to use for parallelization.
130
+ * \param first The beginning of the sequence.
131
+ * \param last The end of the sequence.
132
+ * \param pred A predicate used to test range elements.
133
+ * \return \c true, if any element satisfies the predicate; \c false, otherwise.
134
+ *
135
+ * \tparam DerivedPolicy The name of the derived execution policy.
136
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
137
+ * Iterator</a>, \tparam Predicate must be a model of <a
138
+ * href="https://en.cppreference.com/w/cpp/concepts/predicate">Predicate</a>.
139
+ *
140
+ * \code
141
+ * #include <thrust/logical.h>
142
+ * #include <thrust/functional.h>
143
+ * #include <thrust/execution_policy.h>
144
+ * ...
145
+ * bool A[3] = {true, true, false};
146
+ *
147
+ * thrust::any_of(thrust::host, A, A + 2, thrust::identity<bool>()); // returns true
148
+ * thrust::any_of(thrust::host, A, A + 3, thrust::identity<bool>()); // returns true
149
+ *
150
+ * thrust::any_of(thrust::host, A + 2, A + 3, thrust::identity<bool>()); // returns false
151
+ *
152
+ * // empty range
153
+ * thrust::any_of(thrust::host, A, A, thrust::identity<bool>()); // returns false
154
+ * \endcode
155
+ *
156
+ * \see all_of
157
+ * \see none_of
158
+ * \see transform_reduce
159
+ */
160
+ template <typename DerivedPolicy, typename InputIterator, typename Predicate>
161
+ _CCCL_HOST_DEVICE bool
162
+ any_of(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
163
+ InputIterator first,
164
+ InputIterator last,
165
+ Predicate pred);
166
+
167
+ /*! \p any_of determines whether any element in a range satisfies a predicate.
168
+ * Specifically, \p any_of returns \c true if <tt>pred(*i)</tt> is \c true
169
+ * for any iterator \c i in the range <tt>[first, last)</tt> and
170
+ * \c false otherwise.
171
+ *
172
+ * \param first The beginning of the sequence.
173
+ * \param last The end of the sequence.
174
+ * \param pred A predicate used to test range elements.
175
+ * \return \c true, if any element satisfies the predicate; \c false, otherwise.
176
+ *
177
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
178
+ * Iterator</a>, \tparam Predicate must be a model of <a
179
+ * href="https://en.cppreference.com/w/cpp/concepts/predicate">Predicate</a>.
180
+ *
181
+ * \code
182
+ * #include <thrust/logical.h>
183
+ * #include <thrust/functional.h>
184
+ * ...
185
+ * bool A[3] = {true, true, false};
186
+ *
187
+ * thrust::any_of(A, A + 2, thrust::identity<bool>()); // returns true
188
+ * thrust::any_of(A, A + 3, thrust::identity<bool>()); // returns true
189
+ *
190
+ * thrust::any_of(A + 2, A + 3, thrust::identity<bool>()); // returns false
191
+ *
192
+ * // empty range
193
+ * thrust::any_of(A, A, thrust::identity<bool>()); // returns false
194
+ * \endcode
195
+ *
196
+ * \see all_of
197
+ * \see none_of
198
+ * \see transform_reduce
199
+ */
200
+ template <typename InputIterator, typename Predicate>
201
+ bool any_of(InputIterator first, InputIterator last, Predicate pred);
202
+
203
+ /*! \p none_of determines whether no element in a range satisfies a predicate.
204
+ * Specifically, \p none_of returns \c true if there is no iterator \c i in
205
+ * the range <tt>[first, last)</tt> such that <tt>pred(*i)</tt> is \c true,
206
+ * and \c false otherwise.
207
+ *
208
+ * The algorithm's execution is parallelized as determined by \p exec.
209
+ *
210
+ * \param exec The execution policy to use for parallelization.
211
+ * \param first The beginning of the sequence.
212
+ * \param last The end of the sequence.
213
+ * \param pred A predicate used to test range elements.
214
+ * \return \c true, if no element satisfies the predicate; \c false, otherwise.
215
+ *
216
+ * \tparam DerivedPolicy The name of the derived execution policy.
217
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
218
+ * Iterator</a>, \tparam Predicate must be a model of <a
219
+ * href="https://en.cppreference.com/w/cpp/concepts/predicate">Predicate</a>.
220
+ *
221
+ * \code
222
+ * #include <thrust/logical.h>
223
+ * #include <thrust/functional.h>
224
+ * #include <thrust/execution_policy.h>
225
+ * ...
226
+ * bool A[3] = {true, true, false};
227
+ *
228
+ * thrust::none_of(thrust::host, A, A + 2, thrust::identity<bool>()); // returns false
229
+ * thrust::none_of(thrust::host, A, A + 3, thrust::identity<bool>()); // returns false
230
+ *
231
+ * thrust::none_of(thrust::host, A + 2, A + 3, thrust::identity<bool>()); // returns true
232
+ *
233
+ * // empty range
234
+ * thrust::none_of(thrust::host, A, A, thrust::identity<bool>()); // returns true
235
+ * \endcode
236
+ *
237
+ * \see all_of
238
+ * \see any_of
239
+ * \see transform_reduce
240
+ */
241
+ template <typename DerivedPolicy, typename InputIterator, typename Predicate>
242
+ _CCCL_HOST_DEVICE bool
243
+ none_of(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
244
+ InputIterator first,
245
+ InputIterator last,
246
+ Predicate pred);
247
+
248
+ /*! \p none_of determines whether no element in a range satisfies a predicate.
249
+ * Specifically, \p none_of returns \c true if there is no iterator \c i in
250
+ * the range <tt>[first, last)</tt> such that <tt>pred(*i)</tt> is \c true,
251
+ * and \c false otherwise.
252
+ *
253
+ * \param first The beginning of the sequence.
254
+ * \param last The end of the sequence.
255
+ * \param pred A predicate used to test range elements.
256
+ * \return \c true, if no element satisfies the predicate; \c false, otherwise.
257
+ *
258
+ * \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
259
+ * Iterator</a>, \tparam Predicate must be a model of <a
260
+ * href="https://en.cppreference.com/w/cpp/concepts/predicate">Predicate</a>.
261
+ *
262
+ * \code
263
+ * #include <thrust/logical.h>
264
+ * #include <thrust/functional.h>
265
+ * ...
266
+ * bool A[3] = {true, true, false};
267
+ *
268
+ * thrust::none_of(A, A + 2, thrust::identity<bool>()); // returns false
269
+ * thrust::none_of(A, A + 3, thrust::identity<bool>()); // returns false
270
+ *
271
+ * thrust::none_of(A + 2, A + 3, thrust::identity<bool>()); // returns true
272
+ *
273
+ * // empty range
274
+ * thrust::none_of(A, A, thrust::identity<bool>()); // returns true
275
+ * \endcode
276
+ *
277
+ * \see all_of
278
+ * \see any_of
279
+ * \see transform_reduce
280
+ */
281
+ template <typename InputIterator, typename Predicate>
282
+ bool none_of(InputIterator first, InputIterator last, Predicate pred);
283
+
284
+ /*! \} // end logical
285
+ * \} // end reductions
286
+ */
287
+
288
+ THRUST_NAMESPACE_END
289
+
290
+ #include <thrust/detail/logical.inl>
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/memory.h ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/memory.h
18
+ * \brief Abstractions for Thrust's memory model.
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/pointer.h>
33
+ #include <thrust/detail/raw_pointer_cast.h>
34
+ #include <thrust/detail/raw_reference_cast.h>
35
+ #include <thrust/detail/reference.h>
36
+ #include <thrust/detail/temporary_buffer.h>
37
+ #include <thrust/detail/type_traits/pointer_traits.h>
38
+
39
+ THRUST_NAMESPACE_BEGIN
40
+
41
+ /*! \addtogroup memory_management Memory Management
42
+ * \{
43
+ */
44
+
45
+ // define pointer for the purpose of Doxygenating it
46
+ // it is actually defined elsewhere
47
+ #if 0
48
+ /*! \p pointer stores a pointer to an object allocated in memory. Like \p device_ptr, this
49
+ * type ensures type safety when dispatching standard algorithms on ranges resident in memory.
50
+ *
51
+ * \p pointer generalizes \p device_ptr by relaxing the backend system associated with the \p pointer.
52
+ * Instead of the backend system specified by \p THRUST_DEVICE_SYSTEM, \p pointer's
53
+ * system is given by its second template parameter, \p Tag. For the purpose of Thrust dispatch,
54
+ * <tt>device_ptr<Element></tt> and <tt>pointer<Element,device_system_tag></tt> are considered equivalent.
55
+ *
56
+ * The raw pointer encapsulated by a \p pointer may be obtained through its <tt>get</tt> member function
57
+ * or the \p raw_pointer_cast free function.
58
+ *
59
+ * \tparam Element specifies the type of the pointed-to object.
60
+ *
61
+ * \tparam Tag specifies the system with which this \p pointer is associated. This may be any Thrust
62
+ * backend system, or a user-defined tag.
63
+ *
64
+ * \tparam Reference allows the client to specify the reference type returned upon derereference.
65
+ * By default, this type is <tt>reference<Element,pointer></tt>.
66
+ *
67
+ * \tparam Derived allows the client to specify the name of the derived type when \p pointer is used as
68
+ * a base class. This is useful to ensure that arithmetic on values of the derived type return
69
+ * values of the derived type as a result. By default, this type is <tt>pointer<Element,Tag,Reference></tt>.
70
+ *
71
+ * \note \p pointer is not a smart pointer; it is the client's responsibility to deallocate memory
72
+ * pointer to by \p pointer.
73
+ *
74
+ * \see device_ptr
75
+ * \see reference
76
+ * \see raw_pointer_cast
77
+ */
78
+ template<typename Element, typename Tag, typename Reference = thrust::use_default, typename Derived = thrust::use_default>
79
+ class pointer
80
+ {
81
+ public:
82
+ /*! The type of the raw pointer
83
+ */
84
+ using raw_pointer = typename super_t::base_type;
85
+
86
+ /*! \p pointer's default constructor initializes its encapsulated pointer to \c 0
87
+ */
88
+ _CCCL_HOST_DEVICE
89
+ pointer();
90
+
91
+ /*! This constructor allows construction of a <tt>pointer<const T, ...></tt> from a <tt>T*</tt>.
92
+ *
93
+ * \param ptr A raw pointer to copy from, presumed to point to a location in \p Tag's memory.
94
+ * \tparam OtherElement \p OtherElement shall be convertible to \p Element.
95
+ */
96
+ template<typename OtherElement>
97
+ _CCCL_HOST_DEVICE
98
+ explicit pointer(OtherElement *ptr);
99
+
100
+ /*! This constructor allows initialization from another pointer-like object.
101
+ *
102
+ * \param other The \p OtherPointer to copy.
103
+ *
104
+ * \tparam OtherPointer The tag associated with \p OtherPointer shall be convertible to \p Tag,
105
+ * and its element type shall be convertible to \p Element.
106
+ */
107
+ template<typename OtherPointer>
108
+ _CCCL_HOST_DEVICE
109
+ pointer(const OtherPointer &other,
110
+ typename thrust::detail::enable_if_pointer_is_convertible<
111
+ OtherPointer,
112
+ pointer<Element,Tag,Reference,Derived>
113
+ >::type * = 0);
114
+
115
+ /*! Assignment operator allows assigning from another pointer-like object whose element type
116
+ * is convertible to \c Element.
117
+ *
118
+ * \param other The other pointer-like object to assign from.
119
+ * \return <tt>*this</tt>
120
+ *
121
+ * \tparam OtherPointer The tag associated with \p OtherPointer shall be convertible to \p Tag,
122
+ * and its element type shall be convertible to \p Element.
123
+ */
124
+ template<typename OtherPointer>
125
+ _CCCL_HOST_DEVICE
126
+ typename thrust::detail::enable_if_pointer_is_convertible<
127
+ OtherPointer,
128
+ pointer,
129
+ derived_type &
130
+ >::type
131
+ operator=(const OtherPointer &other);
132
+
133
+ /*! \p get returns this \p pointer's encapsulated raw pointer.
134
+ * \return This \p pointer's raw pointer.
135
+ */
136
+ _CCCL_HOST_DEVICE
137
+ Element *get() const;
138
+ };
139
+ #endif
140
+
141
+ #ifndef _CCCL_DOXYGEN_INVOKED // Doxygen cannot handle both versions
142
+
143
+ /*! This version of \p malloc allocates untyped uninitialized storage associated with a given system.
144
+ *
145
+ * \param system The Thrust system with which to associate the storage.
146
+ * \param n The number of bytes of storage to allocate.
147
+ * \return If allocation succeeds, a pointer to the allocated storage; a null pointer otherwise.
148
+ * The pointer must be deallocated with \p thrust::free.
149
+ *
150
+ * \tparam DerivedPolicy The name of the derived execution policy.
151
+ *
152
+ * \pre \p DerivedPolicy must be publicly derived from <tt>thrust::execution_policy<DerivedPolicy></tt>.
153
+ *
154
+ * The following code snippet demonstrates how to use \p malloc to allocate a range of memory
155
+ * associated with Thrust's device system.
156
+ *
157
+ * \code
158
+ * #include <thrust/memory.h>
159
+ * ...
160
+ * // allocate some memory with thrust::malloc
161
+ * const int N = 100;
162
+ * thrust::device_system_tag device_sys;
163
+ * thrust::pointer<void,thrust::device_space_tag> void_ptr = thrust::malloc(device_sys, N);
164
+ *
165
+ * // manipulate memory
166
+ * ...
167
+ *
168
+ * // deallocate void_ptr with thrust::free
169
+ * thrust::free(device_sys, void_ptr);
170
+ * \endcode
171
+ *
172
+ * \see free
173
+ * \see device_malloc
174
+ */
175
+ template <typename DerivedPolicy>
176
+ _CCCL_HOST_DEVICE pointer<void, DerivedPolicy>
177
+ malloc(const thrust::detail::execution_policy_base<DerivedPolicy>& system, std::size_t n);
178
+
179
+ #endif // _CCCL_DOXYGEN_INVOKED
180
+
181
+ /*! This version of \p malloc allocates typed uninitialized storage associated with a given system.
182
+ *
183
+ * \param system The Thrust system with which to associate the storage.
184
+ * \param n The number of elements of type \c T which the storage should accommodate.
185
+ * \return If allocation succeeds, a pointer to an allocation large enough to accommodate \c n
186
+ * elements of type \c T; a null pointer otherwise.
187
+ * The pointer must be deallocated with \p thrust::free.
188
+ *
189
+ * \tparam DerivedPolicy The name of the derived execution policy.
190
+ *
191
+ * \pre \p DerivedPolicy must be publicly derived from <tt>thrust::execution_policy<DerivedPolicy></tt>.
192
+ *
193
+ * The following code snippet demonstrates how to use \p malloc to allocate a range of memory
194
+ * to accommodate integers associated with Thrust's device system.
195
+ *
196
+ * \code
197
+ * #include <thrust/memory.h>
198
+ * ...
199
+ * // allocate storage for 100 ints with thrust::malloc
200
+ * const int N = 100;
201
+ * thrust::device_system_tag device_sys;
202
+ * thrust::pointer<int,thrust::device_system_tag> ptr = thrust::malloc<int>(device_sys, N);
203
+ *
204
+ * // manipulate memory
205
+ * ...
206
+ *
207
+ * // deallocate ptr with thrust::free
208
+ * thrust::free(device_sys, ptr);
209
+ * \endcode
210
+ *
211
+ * \see free
212
+ * \see device_malloc
213
+ */
214
+ template <typename T, typename DerivedPolicy>
215
+ _CCCL_HOST_DEVICE pointer<T, DerivedPolicy>
216
+ malloc(const thrust::detail::execution_policy_base<DerivedPolicy>& system, std::size_t n);
217
+
218
+ /*! \p get_temporary_buffer returns a pointer to storage associated with a given Thrust system sufficient to store up to
219
+ * \p n objects of type \c T. If not enough storage is available to accommodate \p n objects, an implementation may
220
+ * return a smaller buffer. The number of objects the returned buffer can accommodate is also returned.
221
+ *
222
+ * Thrust uses \p get_temporary_buffer internally when allocating temporary storage required by algorithm
223
+ * implementations.
224
+ *
225
+ * The storage allocated with \p get_temporary_buffer must be returned to the system with \p return_temporary_buffer.
226
+ *
227
+ * \param system The Thrust system with which to associate the storage.
228
+ * \param n The requested number of objects of type \c T the storage should accommodate.
229
+ * \return A pair \c p such that <tt>p.first</tt> is a pointer to the allocated storage and <tt>p.second</tt> is the
230
+ * number of contiguous objects of type \c T that the storage can accommodate. If no storage can be allocated,
231
+ * <tt>p.first</tt> if no storage can be obtained. The storage must be returned to the system using \p
232
+ * return_temporary_buffer.
233
+ *
234
+ * \tparam DerivedPolicy The name of the derived execution policy.
235
+ *
236
+ * \pre \p DerivedPolicy must be publicly derived from <tt>thrust::execution_policy<DerivedPolicy></tt>.
237
+ *
238
+ * The following code snippet demonstrates how to use \p get_temporary_buffer to allocate a range of memory
239
+ * to accommodate integers associated with Thrust's device system.
240
+ *
241
+ * \code
242
+ * #include <thrust/memory.h>
243
+ * ...
244
+ * // allocate storage for 100 ints with thrust::get_temporary_buffer
245
+ * const int N = 100;
246
+ *
247
+ * using ptr_and_size_t = thrust::pair<
248
+ * thrust::pointer<int,thrust::device_system_tag>,
249
+ * std::ptrdiff_t
250
+ * >;
251
+ *
252
+ * thrust::device_system_tag device_sys;
253
+ * ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer<int>(device_sys, N);
254
+ *
255
+ * // manipulate up to 100 ints
256
+ * for(int i = 0; i < ptr_and_size.second; ++i)
257
+ * {
258
+ * *ptr_and_size.first = i;
259
+ * }
260
+ *
261
+ * // deallocate storage with thrust::return_temporary_buffer
262
+ * thrust::return_temporary_buffer(device_sys, ptr_and_size.first);
263
+ * \endcode
264
+ *
265
+ * \see malloc
266
+ * \see return_temporary_buffer
267
+ */
268
+ template <typename T, typename DerivedPolicy>
269
+ _CCCL_HOST_DEVICE
270
+ thrust::pair<thrust::pointer<T, DerivedPolicy>, typename thrust::pointer<T, DerivedPolicy>::difference_type>
271
+ get_temporary_buffer(const thrust::detail::execution_policy_base<DerivedPolicy>& system,
272
+ typename thrust::pointer<T, DerivedPolicy>::difference_type n);
273
+
274
+ /*! \p free deallocates the storage previously allocated by \p thrust::malloc.
275
+ *
276
+ * \param system The Thrust system with which the storage is associated.
277
+ * \param ptr A pointer previously returned by \p thrust::malloc. If \p ptr is null, \p free
278
+ * does nothing.
279
+ *
280
+ * \tparam DerivedPolicy The name of the derived execution policy.
281
+ *
282
+ * \pre \p ptr shall have been returned by a previous call to <tt>thrust::malloc(system, n)</tt> or
283
+ * <tt>thrust::malloc<T>(system, n)</tt> for some type \c T.
284
+ *
285
+ * The following code snippet demonstrates how to use \p free to deallocate a range of memory
286
+ * previously allocated with \p thrust::malloc.
287
+ *
288
+ * \code
289
+ * #include <thrust/memory.h>
290
+ * ...
291
+ * // allocate storage for 100 ints with thrust::malloc
292
+ * const int N = 100;
293
+ * thrust::device_system_tag device_sys;
294
+ * thrust::pointer<int,thrust::device_system_tag> ptr = thrust::malloc<int>(device_sys, N);
295
+ *
296
+ * // mainpulate memory
297
+ * ...
298
+ *
299
+ * // deallocate ptr with thrust::free
300
+ * thrust::free(device_sys, ptr);
301
+ * \endcode
302
+ */
303
+ template <typename DerivedPolicy, typename Pointer>
304
+ _CCCL_HOST_DEVICE void free(const thrust::detail::execution_policy_base<DerivedPolicy>& system, Pointer ptr);
305
+
306
+ /*! \p return_temporary_buffer deallocates storage associated with a given Thrust system previously allocated by \p
307
+ * get_temporary_buffer.
308
+ *
309
+ * Thrust uses \p return_temporary_buffer internally when deallocating temporary storage required by algorithm
310
+ * implementations.
311
+ *
312
+ * \param system The Thrust system with which the storage is associated.
313
+ * \param p A pointer previously returned by \p thrust::get_temporary_buffer. If \p ptr is null, \p
314
+ * return_temporary_buffer does nothing.
315
+ *
316
+ * \tparam DerivedPolicy The name of the derived execution policy.
317
+ *
318
+ * \pre \p p shall have been previously allocated by \p thrust::get_temporary_buffer.
319
+ *
320
+ * The following code snippet demonstrates how to use \p return_temporary_buffer to deallocate a range of memory
321
+ * previously allocated by \p get_temporary_buffer.
322
+ *
323
+ * \code
324
+ * #include <thrust/memory.h>
325
+ * ...
326
+ * // allocate storage for 100 ints with thrust::get_temporary_buffer
327
+ * const int N = 100;
328
+ *
329
+ * using ptr_and_size_t = thrust::pair<
330
+ * thrust::pointer<int,thrust::device_system_tag>,
331
+ * std::ptrdiff_t
332
+ * >;
333
+ *
334
+ * thrust::device_system_tag device_sys;
335
+ * ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer<int>(device_sys, N);
336
+ *
337
+ * // manipulate up to 100 ints
338
+ * for(int i = 0; i < ptr_and_size.second; ++i)
339
+ * {
340
+ * *ptr_and_size.first = i;
341
+ * }
342
+ *
343
+ * // deallocate storage with thrust::return_temporary_buffer
344
+ * thrust::return_temporary_buffer(device_sys, ptr_and_size.first);
345
+ * \endcode
346
+ *
347
+ * \see free
348
+ * \see get_temporary_buffer
349
+ */
350
+ template <typename DerivedPolicy, typename Pointer>
351
+ _CCCL_HOST_DEVICE void return_temporary_buffer(
352
+ const thrust::detail::execution_policy_base<DerivedPolicy>& system, Pointer p, std::ptrdiff_t n);
353
+
354
+ /*! \p raw_pointer_cast creates a "raw" pointer from a pointer-like type,
355
+ * simply returning the wrapped pointer, should it exist.
356
+ *
357
+ * \param ptr The pointer of interest.
358
+ * \return <tt>ptr.get()</tt>, if the expression is well formed; <tt>ptr</tt>, otherwise.
359
+ * \see raw_reference_cast
360
+ */
361
+ template <typename Pointer>
362
+ _CCCL_HOST_DEVICE typename thrust::detail::pointer_traits<Pointer>::raw_pointer raw_pointer_cast(Pointer ptr);
363
+
364
+ /*! \p raw_reference_cast creates a "raw" reference from a wrapped reference type,
365
+ * simply returning the underlying reference, should it exist.
366
+ *
367
+ * If the argument is not a reference wrapper, the result is a reference to the argument.
368
+ *
369
+ * \param ref The reference of interest.
370
+ * \return <tt>*thrust::raw_pointer_cast(&ref)</tt>.
371
+ * \note There are two versions of \p raw_reference_cast. One for <tt>const</tt> references,
372
+ * and one for non-<tt>const</tt>.
373
+ * \see raw_pointer_cast
374
+ */
375
+ template <typename T>
376
+ _CCCL_HOST_DEVICE typename detail::raw_reference<T>::type raw_reference_cast(T& ref);
377
+
378
+ /*! \p raw_reference_cast creates a "raw" reference from a wrapped reference type,
379
+ * simply returning the underlying reference, should it exist.
380
+ *
381
+ * If the argument is not a reference wrapper, the result is a reference to the argument.
382
+ *
383
+ * \param ref The reference of interest.
384
+ * \return <tt>*thrust::raw_pointer_cast(&ref)</tt>.
385
+ * \note There are two versions of \p raw_reference_cast. One for <tt>const</tt> references,
386
+ * and one for non-<tt>const</tt>.
387
+ * \see raw_pointer_cast
388
+ */
389
+ template <typename T>
390
+ _CCCL_HOST_DEVICE typename detail::raw_reference<const T>::type raw_reference_cast(const T& ref);
391
+
392
+ /*! \} // memory_management
393
+ */
394
+
395
+ THRUST_NAMESPACE_END
vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/merge.h ADDED
@@ -0,0 +1,725 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 merge.h
18
+ * \brief Merging sorted ranges
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/execution_policy.h>
33
+ #include <thrust/pair.h>
34
+
35
+ THRUST_NAMESPACE_BEGIN
36
+
37
+ /*! \addtogroup merging Merging
38
+ * \ingroup algorithms
39
+ * \{
40
+ */
41
+
42
+ /*! \p merge combines two sorted ranges <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt>
43
+ * into a single sorted range. That is, it copies from <tt>[first1, last1)</tt> and
44
+ * <tt>[first2, last2)</tt> into <tt>[result, result + (last1 - first1) + (last2 - first2))</tt>
45
+ * such that the resulting range is in ascending order. \p merge is stable, meaning both that the
46
+ * relative order of elements within each input range is preserved, and that for equivalent elements
47
+ * in both input ranges the element from the first range precedes the element from the second. The
48
+ * return value is <tt>result + (last1 - first1) + (last2 - first2)</tt>.
49
+ *
50
+ * This version of \p merge compares elements using \c operator<.
51
+ *
52
+ * The algorithm's execution is parallelized as determined by \p exec.
53
+ *
54
+ * \param exec The execution policy to use for parallelization.
55
+ * \param first1 The beginning of the first input range.
56
+ * \param last1 The end of the first input range.
57
+ * \param first2 The beginning of the second input range.
58
+ * \param last2 The end of the second input range.
59
+ * \param result The beginning of the merged output.
60
+ * \return The end of the output range.
61
+ *
62
+ * \tparam DerivedPolicy The name of the derived execution policy.
63
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
64
+ * Iterator</a>, \p InputIterator1 and \p InputIterator2 have the same \c value_type, \p InputIterator1's \c value_type
65
+ * is a model of <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>, the
66
+ * ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the <a
67
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a> requirements, and \p
68
+ * InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
69
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
70
+ * \p InputIterator2 and \p InputIterator1 have the same \c value_type,
71
+ * \p InputIterator2's \c value_type is a model of <a
72
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>, the ordering on \p
73
+ * InputIterator2's \c value_type is a strict weak ordering, as defined in the <a
74
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a> requirements, and \p
75
+ * InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
76
+ * OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
77
+ * Iterator</a>.
78
+ *
79
+ * \pre The ranges <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt> shall be sorted with respect to
80
+ * <tt>operator<</tt>. \pre The resulting range shall not overlap with either input range.
81
+ *
82
+ * The following code snippet demonstrates how to use
83
+ * \p merge to compute the merger of two sorted sets of integers using the \p thrust::host execution policy for
84
+ * parallelization:
85
+ *
86
+ * \code
87
+ * #include <thrust/merge.h>
88
+ * #include <thrust/execution_policy.h>
89
+ * ...
90
+ * int A1[6] = {1, 3, 5, 7, 9, 11};
91
+ * int A2[7] = {1, 1, 2, 3, 5, 8, 13};
92
+ *
93
+ * int result[13];
94
+ *
95
+ * int *result_end =
96
+ * thrust::merge(thrust::host,
97
+ * A1, A1 + 6,
98
+ * A2, A2 + 7,
99
+ * result);
100
+ * // result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13}
101
+ * \endcode
102
+ *
103
+ * \see https://en.cppreference.com/w/cpp/algorithm/merge
104
+ * \see \p set_union
105
+ * \see \p sort
106
+ * \see \p is_sorted
107
+ */
108
+ template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator>
109
+ _CCCL_HOST_DEVICE OutputIterator merge(
110
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
111
+ InputIterator1 first1,
112
+ InputIterator1 last1,
113
+ InputIterator2 first2,
114
+ InputIterator2 last2,
115
+ OutputIterator result);
116
+
117
+ /*! \p merge combines two sorted ranges <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt>
118
+ * into a single sorted range. That is, it copies from <tt>[first1, last1)</tt> and
119
+ * <tt>[first2, last2)</tt> into <tt>[result, result + (last1 - first1) + (last2 - first2))</tt>
120
+ * such that the resulting range is in ascending order. \p merge is stable, meaning both that the
121
+ * relative order of elements within each input range is preserved, and that for equivalent elements
122
+ * in both input ranges the element from the first range precedes the element from the second. The
123
+ * return value is <tt>result + (last1 - first1) + (last2 - first2)</tt>.
124
+ *
125
+ * This version of \p merge compares elements using \c operator<.
126
+ *
127
+ * \param first1 The beginning of the first input range.
128
+ * \param last1 The end of the first input range.
129
+ * \param first2 The beginning of the second input range.
130
+ * \param last2 The end of the second input range.
131
+ * \param result The beginning of the merged output.
132
+ * \return The end of the output range.
133
+ *
134
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
135
+ * Iterator</a>, \p InputIterator1 and \p InputIterator2 have the same \c value_type, \p InputIterator1's \c value_type
136
+ * is a model of <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>, the
137
+ * ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the <a
138
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a> requirements, and \p
139
+ * InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
140
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
141
+ * \p InputIterator2 and \p InputIterator1 have the same \c value_type,
142
+ * \p InputIterator2's \c value_type is a model of <a
143
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>, the ordering on \p
144
+ * InputIterator2's \c value_type is a strict weak ordering, as defined in the <a
145
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a> requirements, and \p
146
+ * InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
147
+ * OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
148
+ * Iterator</a>.
149
+ *
150
+ * \pre The ranges <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt> shall be sorted with respect to
151
+ * <tt>operator<</tt>. \pre The resulting range shall not overlap with either input range.
152
+ *
153
+ * The following code snippet demonstrates how to use
154
+ * \p merge to compute the merger of two sorted sets of integers.
155
+ *
156
+ * \code
157
+ * #include <thrust/merge.h>
158
+ * ...
159
+ * int A1[6] = {1, 3, 5, 7, 9, 11};
160
+ * int A2[7] = {1, 1, 2, 3, 5, 8, 13};
161
+ *
162
+ * int result[13];
163
+ *
164
+ * int *result_end = thrust::merge(A1, A1 + 6, A2, A2 + 7, result);
165
+ * // result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13}
166
+ * \endcode
167
+ *
168
+ * \see https://en.cppreference.com/w/cpp/algorithm/merge
169
+ * \see \p set_union
170
+ * \see \p sort
171
+ * \see \p is_sorted
172
+ */
173
+ template <typename InputIterator1, typename InputIterator2, typename OutputIterator>
174
+ OutputIterator
175
+ merge(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result);
176
+
177
+ /*! \p merge combines two sorted ranges <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt>
178
+ * into a single sorted range. That is, it copies from <tt>[first1, last1)</tt> and
179
+ * <tt>[first2, last2)</tt> into <tt>[result, result + (last1 - first1) + (last2 - first2))</tt>
180
+ * such that the resulting range is in ascending order. \p merge is stable, meaning both that the
181
+ * relative order of elements within each input range is preserved, and that for equivalent elements
182
+ * in both input ranges the element from the first range precedes the element from the second. The
183
+ * return value is <tt>result + (last1 - first1) + (last2 - first2)</tt>.
184
+ *
185
+ * This version of \p merge compares elements using a function object \p comp.
186
+ *
187
+ * The algorithm's execution is parallelized as determined by \p exec.
188
+ *
189
+ * \param exec The execution policy to use for parallelization.
190
+ * \param first1 The beginning of the first input range.
191
+ * \param last1 The end of the first input range.
192
+ * \param first2 The beginning of the second input range.
193
+ * \param last2 The end of the second input range.
194
+ * \param result The beginning of the merged output.
195
+ * \param comp Comparison operator.
196
+ * \return The end of the output range.
197
+ *
198
+ * \tparam DerivedPolicy The name of the derived execution policy.
199
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
200
+ * Iterator</a>, \p InputIterator1's \c value_type is convertible to \p StrictWeakCompare's \c first_argument_type. and
201
+ * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
202
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
203
+ * \p InputIterator2's \c value_type is convertible to \p StrictWeakCompare's \c second_argument_type.
204
+ * and \p InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types.
205
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
206
+ * Iterator</a>. \tparam StrictWeakCompare is a model of <a
207
+ * href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
208
+ *
209
+ * \pre The ranges <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt> shall be sorted with respect to \p comp.
210
+ * \pre The resulting range shall not overlap with either input range.
211
+ *
212
+ * The following code snippet demonstrates how to use
213
+ * \p merge to compute the merger of two sets of integers sorted in
214
+ * descending order using the \p thrust::host execution policy for parallelization:
215
+ *
216
+ * \code
217
+ * #include <thrust/merge.h>
218
+ * #include <thrust/functional.h>
219
+ * #include <thrust/execution_policy.h>
220
+ * ...
221
+ * int A1[6] = {11, 9, 7, 5, 3, 1};
222
+ * int A2[7] = {13, 8, 5, 3, 2, 1, 1};
223
+ *
224
+ * int result[13];
225
+ *
226
+ * int *result_end = thrust::merge(thrust::host,
227
+ * A1, A1 + 6,
228
+ * A2, A2 + 7,
229
+ * result,
230
+ * thrust::greater<int>());
231
+ * // result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1}
232
+ * \endcode
233
+ *
234
+ * \see https://en.cppreference.com/w/cpp/algorithm/merge
235
+ * \see \p sort
236
+ * \see \p is_sorted
237
+ */
238
+ template <typename DerivedPolicy,
239
+ typename InputIterator1,
240
+ typename InputIterator2,
241
+ typename OutputIterator,
242
+ typename StrictWeakCompare>
243
+ _CCCL_HOST_DEVICE OutputIterator merge(
244
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
245
+ InputIterator1 first1,
246
+ InputIterator1 last1,
247
+ InputIterator2 first2,
248
+ InputIterator2 last2,
249
+ OutputIterator result,
250
+ StrictWeakCompare comp);
251
+
252
+ /*! \p merge combines two sorted ranges <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt>
253
+ * into a single sorted range. That is, it copies from <tt>[first1, last1)</tt> and
254
+ * <tt>[first2, last2)</tt> into <tt>[result, result + (last1 - first1) + (last2 - first2))</tt>
255
+ * such that the resulting range is in ascending order. \p merge is stable, meaning both that the
256
+ * relative order of elements within each input range is preserved, and that for equivalent elements
257
+ * in both input ranges the element from the first range precedes the element from the second. The
258
+ * return value is <tt>result + (last1 - first1) + (last2 - first2)</tt>.
259
+ *
260
+ * This version of \p merge compares elements using a function object \p comp.
261
+ *
262
+ * \param first1 The beginning of the first input range.
263
+ * \param last1 The end of the first input range.
264
+ * \param first2 The beginning of the second input range.
265
+ * \param last2 The end of the second input range.
266
+ * \param result The beginning of the merged output.
267
+ * \param comp Comparison operator.
268
+ * \return The end of the output range.
269
+ *
270
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
271
+ * Iterator</a>, \p InputIterator1's \c value_type is convertible to \p StrictWeakCompare's \c first_argument_type. and
272
+ * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
273
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
274
+ * \p InputIterator2's \c value_type is convertible to \p StrictWeakCompare's \c second_argument_type.
275
+ * and \p InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types.
276
+ * \tparam OutputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output
277
+ * Iterator</a>. \tparam StrictWeakCompare is a model of <a
278
+ * href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak Ordering</a>.
279
+ *
280
+ * \pre The ranges <tt>[first1, last1)</tt> and <tt>[first2, last2)</tt> shall be sorted with respect to \p comp.
281
+ * \pre The resulting range shall not overlap with either input range.
282
+ *
283
+ * The following code snippet demonstrates how to use
284
+ * \p merge to compute the merger of two sets of integers sorted in
285
+ * descending order.
286
+ *
287
+ * \code
288
+ * #include <thrust/merge.h>
289
+ * #include <thrust/functional.h>
290
+ * ...
291
+ * int A1[6] = {11, 9, 7, 5, 3, 1};
292
+ * int A2[7] = {13, 8, 5, 3, 2, 1, 1};
293
+ *
294
+ * int result[13];
295
+ *
296
+ * int *result_end = thrust::merge(A1, A1 + 6, A2, A2 + 7, result, thrust::greater<int>());
297
+ * // result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1}
298
+ * \endcode
299
+ *
300
+ * \see https://en.cppreference.com/w/cpp/algorithm/merge
301
+ * \see \p sort
302
+ * \see \p is_sorted
303
+ */
304
+ template <typename InputIterator1, typename InputIterator2, typename OutputIterator, typename StrictWeakCompare>
305
+ OutputIterator
306
+ merge(InputIterator1 first1,
307
+ InputIterator1 last1,
308
+ InputIterator2 first2,
309
+ InputIterator2 last2,
310
+ OutputIterator result,
311
+ StrictWeakCompare comp);
312
+
313
+ /*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from
314
+ * <tt>[keys_first1, keys_last1)</tt> and <tt>[keys_first2, keys_last2)</tt> into a single range,
315
+ * <tt>[keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt> such that
316
+ * the resulting range is in ascending key order.
317
+ *
318
+ * At the same time, \p merge_by_key copies elements from the two associated ranges <tt>[values_first1 + (keys_last1 -
319
+ * keys_first1))</tt> and <tt>[values_first2 + (keys_last2 - keys_first2))</tt> into a single range, <tt>[values_result,
320
+ * values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt> such that the resulting range is in
321
+ * ascending order implied by each input element's associated key.
322
+ *
323
+ * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is
324
+ * preserved, and that for equivalent elements in all input key ranges the element from the first range
325
+ * precedes the element from the second.
326
+ *
327
+ * The return value is is <tt>(keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt>
328
+ * and <tt>(values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt>.
329
+ *
330
+ * The algorithm's execution is parallelized as determined by \p exec.
331
+ *
332
+ * \param exec The execution policy to use for parallelization.
333
+ * \param keys_first1 The beginning of the first input range of keys.
334
+ * \param keys_last1 The end of the first input range of keys.
335
+ * \param keys_first2 The beginning of the second input range of keys.
336
+ * \param keys_last2 The end of the second input range of keys.
337
+ * \param values_first1 The beginning of the first input range of values.
338
+ * \param values_first2 The beginning of the first input range of values.
339
+ * \param keys_result The beginning of the merged output range of keys.
340
+ * \param values_result The beginning of the merged output range of values.
341
+ * \return A \p pair \c p such that <tt>p.first</tt> is the end of the output range of keys,
342
+ * and such that <tt>p.second</tt> is the end of the output range of values.
343
+ *
344
+ * \tparam DerivedPolicy The name of the derived execution policy.
345
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
346
+ * Iterator</a>, \p InputIterator1 and \p InputIterator2 have the same \c value_type, \p InputIterator1's \c value_type
347
+ * is a model of <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>, the
348
+ * ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the <a
349
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a> requirements, and \p
350
+ * InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
351
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
352
+ * \p InputIterator2 and \p InputIterator1 have the same \c value_type,
353
+ * \p InputIterator2's \c value_type is a model of <a
354
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>, the ordering on \p
355
+ * InputIterator2's \c value_type is a strict weak ordering, as defined in the <a
356
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a> requirements, and \p
357
+ * InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
358
+ * InputIterator3 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
359
+ * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c
360
+ * value_types. \tparam InputIterator4 is a model of <a
361
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>, and \p InputIterator4's \c
362
+ * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam OutputIterator1 is a model
363
+ * of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. \tparam OutputIterator2
364
+ * is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>.
365
+ *
366
+ * \pre The ranges <tt>[keys_first1, keys_last1)</tt> and <tt>[keys_first2, keys_last2)</tt> shall be sorted with
367
+ * respect to <tt>operator<</tt>. \pre The resulting ranges shall not overlap with any input range.
368
+ *
369
+ * The following code snippet demonstrates how to use
370
+ * \p merge_by_key to compute the merger of two sets of integers sorted in
371
+ * ascending order using the \p thrust::host execution policy for parallelization:
372
+ *
373
+ * \code
374
+ * #include <thrust/merge.h>
375
+ * #include <thrust/functional.h>
376
+ * #include <thrust/execution_policy.h>
377
+ * ...
378
+ * int A_keys[6] = {1, 3, 5, 7, 9, 11};
379
+ * int A_vals[6] = {0, 0, 0, 0, 0, 0};
380
+ *
381
+ * int B_keys[7] = {1, 1, 2, 3, 5, 8, 13};
382
+ * int B_vals[7] = {1, 1, 1, 1, 1, 1, 1};
383
+ *
384
+ * int keys_result[13];
385
+ * int vals_result[13];
386
+ *
387
+ * thrust::pair<int*,int*> end =
388
+ * thrust::merge_by_key(thrust::host,
389
+ * A_keys, A_keys + 6,
390
+ * B_keys, B_keys + 7,
391
+ * A_vals, B_vals,
392
+ * keys_result, vals_result);
393
+ *
394
+ * // keys_result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13}
395
+ * // vals_result = {0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1}
396
+ * \endcode
397
+ *
398
+ * \see merge
399
+ * \see \p sort_by_key
400
+ * \see \p is_sorted
401
+ */
402
+ template <typename DerivedPolicy,
403
+ typename InputIterator1,
404
+ typename InputIterator2,
405
+ typename InputIterator3,
406
+ typename InputIterator4,
407
+ typename OutputIterator1,
408
+ typename OutputIterator2>
409
+ _CCCL_HOST_DEVICE thrust::pair<OutputIterator1, OutputIterator2> merge_by_key(
410
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
411
+ InputIterator1 keys_first1,
412
+ InputIterator1 keys_last1,
413
+ InputIterator2 keys_first2,
414
+ InputIterator2 keys_last2,
415
+ InputIterator3 values_first1,
416
+ InputIterator4 values_first2,
417
+ OutputIterator1 keys_result,
418
+ OutputIterator2 values_result);
419
+
420
+ /*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from
421
+ * <tt>[keys_first1, keys_last1)</tt> and <tt>[keys_first2, keys_last2)</tt> into a single range,
422
+ * <tt>[keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt> such that
423
+ * the resulting range is in ascending key order.
424
+ *
425
+ * At the same time, \p merge_by_key copies elements from the two associated ranges <tt>[values_first1 + (keys_last1 -
426
+ * keys_first1))</tt> and <tt>[values_first2 + (keys_last2 - keys_first2))</tt> into a single range, <tt>[values_result,
427
+ * values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt> such that the resulting range is in
428
+ * ascending order implied by each input element's associated key.
429
+ *
430
+ * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is
431
+ * preserved, and that for equivalent elements in all input key ranges the element from the first range
432
+ * precedes the element from the second.
433
+ *
434
+ * The return value is is <tt>(keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt>
435
+ * and <tt>(values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt>.
436
+ *
437
+ * \param keys_first1 The beginning of the first input range of keys.
438
+ * \param keys_last1 The end of the first input range of keys.
439
+ * \param keys_first2 The beginning of the second input range of keys.
440
+ * \param keys_last2 The end of the second input range of keys.
441
+ * \param values_first1 The beginning of the first input range of values.
442
+ * \param values_first2 The beginning of the first input range of values.
443
+ * \param keys_result The beginning of the merged output range of keys.
444
+ * \param values_result The beginning of the merged output range of values.
445
+ * \return A \p pair \c p such that <tt>p.first</tt> is the end of the output range of keys,
446
+ * and such that <tt>p.second</tt> is the end of the output range of values.
447
+ *
448
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
449
+ * Iterator</a>, \p InputIterator1 and \p InputIterator2 have the same \c value_type, \p InputIterator1's \c value_type
450
+ * is a model of <a href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>, the
451
+ * ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the <a
452
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a> requirements, and \p
453
+ * InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
454
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
455
+ * \p InputIterator2 and \p InputIterator1 have the same \c value_type,
456
+ * \p InputIterator2's \c value_type is a model of <a
457
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a>, the ordering on \p
458
+ * InputIterator2's \c value_type is a strict weak ordering, as defined in the <a
459
+ * href="https://en.cppreference.com/w/cpp/named_req/LessThanComparable">LessThan Comparable</a> requirements, and \p
460
+ * InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam
461
+ * InputIterator3 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
462
+ * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c
463
+ * value_types. \tparam InputIterator4 is a model of <a
464
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>, and \p InputIterator4's \c
465
+ * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam OutputIterator1 is a model
466
+ * of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. \tparam OutputIterator2
467
+ * is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>.
468
+ *
469
+ * \pre The ranges <tt>[keys_first1, keys_last1)</tt> and <tt>[keys_first2, keys_last2)</tt> shall be sorted with
470
+ * respect to <tt>operator<</tt>. \pre The resulting ranges shall not overlap with any input range.
471
+ *
472
+ * The following code snippet demonstrates how to use
473
+ * \p merge_by_key to compute the merger of two sets of integers sorted in
474
+ * ascending order.
475
+ *
476
+ * \code
477
+ * #include <thrust/merge.h>
478
+ * #include <thrust/functional.h>
479
+ * ...
480
+ * int A_keys[6] = {1, 3, 5, 7, 9, 11};
481
+ * int A_vals[6] = {0, 0, 0, 0, 0, 0};
482
+ *
483
+ * int B_keys[7] = {1, 1, 2, 3, 5, 8, 13};
484
+ * int B_vals[7] = {1, 1, 1, 1, 1, 1, 1};
485
+ *
486
+ * int keys_result[13];
487
+ * int vals_result[13];
488
+ *
489
+ * thrust::pair<int*,int*> end = thrust::merge_by_key(A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, B_vals,
490
+ * keys_result, vals_result);
491
+ *
492
+ * // keys_result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13}
493
+ * // vals_result = {0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1}
494
+ * \endcode
495
+ *
496
+ * \see merge
497
+ * \see \p sort_by_key
498
+ * \see \p is_sorted
499
+ */
500
+ template <typename InputIterator1,
501
+ typename InputIterator2,
502
+ typename InputIterator3,
503
+ typename InputIterator4,
504
+ typename OutputIterator1,
505
+ typename OutputIterator2>
506
+ thrust::pair<OutputIterator1, OutputIterator2> merge_by_key(
507
+ InputIterator1 keys_first1,
508
+ InputIterator1 keys_last1,
509
+ InputIterator2 keys_first2,
510
+ InputIterator2 keys_last2,
511
+ InputIterator3 values_first1,
512
+ InputIterator4 values_first2,
513
+ OutputIterator1 keys_result,
514
+ OutputIterator2 values_result);
515
+
516
+ /*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from
517
+ * <tt>[keys_first1, keys_last1)</tt> and <tt>[keys_first2, keys_last2)</tt> into a single range,
518
+ * <tt>[keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt> such that
519
+ * the resulting range is in ascending key order.
520
+ *
521
+ * At the same time, \p merge_by_key copies elements from the two associated ranges <tt>[values_first1 + (keys_last1 -
522
+ * keys_first1))</tt> and <tt>[values_first2 + (keys_last2 - keys_first2))</tt> into a single range, <tt>[values_result,
523
+ * values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt> such that the resulting range is in
524
+ * ascending order implied by each input element's associated key.
525
+ *
526
+ * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is
527
+ * preserved, and that for equivalent elements in all input key ranges the element from the first range
528
+ * precedes the element from the second.
529
+ *
530
+ * The return value is is <tt>(keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt>
531
+ * and <tt>(values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt>.
532
+ *
533
+ * This version of \p merge_by_key compares key elements using a function object \p comp.
534
+ *
535
+ * The algorithm's execution is parallelized using \p exec.
536
+ *
537
+ * \param exec The execution policy to use for parallelization.
538
+ * \param keys_first1 The beginning of the first input range of keys.
539
+ * \param keys_last1 The end of the first input range of keys.
540
+ * \param keys_first2 The beginning of the second input range of keys.
541
+ * \param keys_last2 The end of the second input range of keys.
542
+ * \param values_first1 The beginning of the first input range of values.
543
+ * \param values_first2 The beginning of the first input range of values.
544
+ * \param keys_result The beginning of the merged output range of keys.
545
+ * \param values_result The beginning of the merged output range of values.
546
+ * \param comp Comparison operator.
547
+ * \return A \p pair \c p such that <tt>p.first</tt> is the end of the output range of keys,
548
+ * and such that <tt>p.second</tt> is the end of the output range of values.
549
+ *
550
+ * \tparam DerivedPolicy The name of the derived execution policy.
551
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
552
+ * Iterator</a>, \p InputIterator1's \c value_type is convertible to \p StrictWeakCompare's \c first_argument_type. and
553
+ * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator1's set of \c value_types. \tparam
554
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
555
+ * \p InputIterator2's \c value_type is convertible to \p StrictWeakCompare's \c second_argument_type.
556
+ * and \p InputIterator2's \c value_type is convertible to a type in \p OutputIterator1's set of \c
557
+ * value_types. \tparam InputIterator3 is a model of <a
558
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>, and \p InputIterator3's \c
559
+ * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam InputIterator4 is a model
560
+ * of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>, and \p InputIterator4's \c
561
+ * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam OutputIterator1 is a model
562
+ * of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. \tparam OutputIterator2
563
+ * is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. \tparam
564
+ * StrictWeakCompare is a model of <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak
565
+ * Ordering</a>.
566
+ *
567
+ * \pre The ranges <tt>[keys_first1, keys_last1)</tt> and <tt>[keys_first2, keys_last2)</tt> shall be sorted with
568
+ * respect to \p comp. \pre The resulting ranges shall not overlap with any input range.
569
+ *
570
+ * The following code snippet demonstrates how to use
571
+ * \p merge_by_key to compute the merger of two sets of integers sorted in
572
+ * descending order using the \p thrust::host execution policy for parallelization:
573
+ *
574
+ * \code
575
+ * #include <thrust/merge.h>
576
+ * #include <thrust/functional.h>
577
+ * #include <thrust/execution_policy.h>
578
+ * ...
579
+ * int A_keys[6] = {11, 9, 7, 5, 3, 1};
580
+ * int A_vals[6] = { 0, 0, 0, 0, 0, 0};
581
+ *
582
+ * int B_keys[7] = {13, 8, 5, 3, 2, 1, 1};
583
+ * int B_vals[7] = { 1, 1, 1, 1, 1, 1, 1};
584
+ *
585
+ * int keys_result[13];
586
+ * int vals_result[13];
587
+ *
588
+ * thrust::pair<int*,int*> end =
589
+ * thrust::merge_by_key(thrust::host,
590
+ * A_keys, A_keys + 6,
591
+ * B_keys, B_keys + 7,
592
+ * A_vals, B_vals,
593
+ * keys_result, vals_result,
594
+ * thrust::greater<int>());
595
+ *
596
+ * // keys_result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1}
597
+ * // vals_result = { 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1}
598
+ * \endcode
599
+ *
600
+ * \see merge
601
+ * \see \p sort_by_key
602
+ * \see \p is_sorted
603
+ */
604
+ template <typename DerivedPolicy,
605
+ typename InputIterator1,
606
+ typename InputIterator2,
607
+ typename InputIterator3,
608
+ typename InputIterator4,
609
+ typename OutputIterator1,
610
+ typename OutputIterator2,
611
+ typename Compare>
612
+ _CCCL_HOST_DEVICE thrust::pair<OutputIterator1, OutputIterator2> merge_by_key(
613
+ const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
614
+ InputIterator1 keys_first1,
615
+ InputIterator1 keys_last1,
616
+ InputIterator2 keys_first2,
617
+ InputIterator2 keys_last2,
618
+ InputIterator3 values_first1,
619
+ InputIterator4 values_first2,
620
+ OutputIterator1 keys_result,
621
+ OutputIterator2 values_result,
622
+ Compare comp);
623
+
624
+ /*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from
625
+ * <tt>[keys_first1, keys_last1)</tt> and <tt>[keys_first2, keys_last2)</tt> into a single range,
626
+ * <tt>[keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt> such that
627
+ * the resulting range is in ascending key order.
628
+ *
629
+ * At the same time, \p merge_by_key copies elements from the two associated ranges <tt>[values_first1 + (keys_last1 -
630
+ * keys_first1))</tt> and <tt>[values_first2 + (keys_last2 - keys_first2))</tt> into a single range, <tt>[values_result,
631
+ * values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt> such that the resulting range is in
632
+ * ascending order implied by each input element's associated key.
633
+ *
634
+ * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is
635
+ * preserved, and that for equivalent elements in all input key ranges the element from the first range
636
+ * precedes the element from the second.
637
+ *
638
+ * The return value is is <tt>(keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt>
639
+ * and <tt>(values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2))</tt>.
640
+ *
641
+ * This version of \p merge_by_key compares key elements using a function object \p comp.
642
+ *
643
+ * \param keys_first1 The beginning of the first input range of keys.
644
+ * \param keys_last1 The end of the first input range of keys.
645
+ * \param keys_first2 The beginning of the second input range of keys.
646
+ * \param keys_last2 The end of the second input range of keys.
647
+ * \param values_first1 The beginning of the first input range of values.
648
+ * \param values_first2 The beginning of the first input range of values.
649
+ * \param keys_result The beginning of the merged output range of keys.
650
+ * \param values_result The beginning of the merged output range of values.
651
+ * \param comp Comparison operator.
652
+ * \return A \p pair \c p such that <tt>p.first</tt> is the end of the output range of keys,
653
+ * and such that <tt>p.second</tt> is the end of the output range of values.
654
+ *
655
+ * \tparam InputIterator1 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input
656
+ * Iterator</a>, \p InputIterator1's \c value_type is convertible to \p StrictWeakCompare's \c first_argument_type. and
657
+ * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator1's set of \c value_types. \tparam
658
+ * InputIterator2 is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>,
659
+ * \p InputIterator2's \c value_type is convertible to \p StrictWeakCompare's \c second_argument_type.
660
+ * and \p InputIterator2's \c value_type is convertible to a type in \p OutputIterator1's set of \c
661
+ * value_types. \tparam InputIterator3 is a model of <a
662
+ * href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>, and \p InputIterator3's \c
663
+ * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam InputIterator4 is a model
664
+ * of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator">Input Iterator</a>, and \p InputIterator4's \c
665
+ * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam OutputIterator1 is a model
666
+ * of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. \tparam OutputIterator2
667
+ * is a model of <a href="https://en.cppreference.com/w/cpp/iterator/output_iterator">Output Iterator</a>. \tparam
668
+ * StrictWeakCompare is a model of <a href="https://en.cppreference.com/w/cpp/concepts/strict_weak_order">Strict Weak
669
+ * Ordering</a>.
670
+ *
671
+ * \pre The ranges <tt>[keys_first1, keys_last1)</tt> and <tt>[keys_first2, keys_last2)</tt> shall be sorted with
672
+ * respect to \p comp. \pre The resulting ranges shall not overlap with any input range.
673
+ *
674
+ * The following code snippet demonstrates how to use
675
+ * \p merge_by_key to compute the merger of two sets of integers sorted in
676
+ * descending order.
677
+ *
678
+ * \code
679
+ * #include <thrust/merge.h>
680
+ * #include <thrust/functional.h>
681
+ * ...
682
+ * int A_keys[6] = {11, 9, 7, 5, 3, 1};
683
+ * int A_vals[6] = { 0, 0, 0, 0, 0, 0};
684
+ *
685
+ * int B_keys[7] = {13, 8, 5, 3, 2, 1, 1};
686
+ * int B_vals[7] = { 1, 1, 1, 1, 1, 1, 1};
687
+ *
688
+ * int keys_result[13];
689
+ * int vals_result[13];
690
+ *
691
+ * thrust::pair<int*,int*> end = thrust::merge_by_key(A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, B_vals,
692
+ * keys_result, vals_result, thrust::greater<int>());
693
+ *
694
+ * // keys_result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1}
695
+ * // vals_result = { 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1}
696
+ * \endcode
697
+ *
698
+ * \see merge
699
+ * \see \p sort_by_key
700
+ * \see \p is_sorted
701
+ */
702
+ template <typename InputIterator1,
703
+ typename InputIterator2,
704
+ typename InputIterator3,
705
+ typename InputIterator4,
706
+ typename OutputIterator1,
707
+ typename OutputIterator2,
708
+ typename StrictWeakCompare>
709
+ thrust::pair<OutputIterator1, OutputIterator2> merge_by_key(
710
+ InputIterator1 keys_first1,
711
+ InputIterator1 keys_last1,
712
+ InputIterator2 keys_first2,
713
+ InputIterator2 keys_last2,
714
+ InputIterator3 values_first1,
715
+ InputIterator4 values_first2,
716
+ OutputIterator1 keys_result,
717
+ OutputIterator2 values_result,
718
+ StrictWeakCompare comp);
719
+
720
+ /*! \} // merging
721
+ */
722
+
723
+ THRUST_NAMESPACE_END
724
+
725
+ #include <thrust/detail/merge.inl>