diff --git a/.gitattributes b/.gitattributes index 5958a22c6fef104f7e7a4c2149dc7d2dc6e1815c..c0b29e7f56361ff9f392272ddc0c2b490013015c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1768,3 +1768,4 @@ videollama2/lib/python3.10/site-packages/scipy.libs/libscipy_openblas-c128ec02.s vllm/lib/python3.10/site-packages/cupy/_core/flags.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text vllm/lib/python3.10/site-packages/cupy/_core/_accelerator.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text vllm/lib/python3.10/site-packages/cupy/_core/_fusion_kernel.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text +vllm/lib/libcrypto.so filter=lfs diff=lfs merge=lfs -text diff --git a/vllm/lib/libcrypto.so b/vllm/lib/libcrypto.so new file mode 100644 index 0000000000000000000000000000000000000000..536e05a1035f306531dc31c82ff16917cfeab26b --- /dev/null +++ b/vllm/lib/libcrypto.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a3a22a04cfb89e45ac9fabc0c71c3935ea24c47178c4390c492cb458dca935df +size 5172040 diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__atomic/atomic.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__atomic/atomic.h new file mode 100644 index 0000000000000000000000000000000000000000..aed52537702d6e84ff68edb8df952f213455ef7a --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__atomic/atomic.h @@ -0,0 +1,141 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA___ATOMIC_ATOMIC_H +#define _CUDA___ATOMIC_ATOMIC_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +// atomic + +template +struct atomic : public _CUDA_VSTD::__atomic_impl<_Tp, _Sco> +{ + using value_type = _Tp; + + _CCCL_HIDE_FROM_ABI constexpr atomic() noexcept = default; + + _LIBCUDACXX_HIDE_FROM_ABI constexpr atomic(_Tp __d) noexcept + : _CUDA_VSTD::__atomic_impl<_Tp, _Sco>(__d) + {} + + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + + _LIBCUDACXX_HIDE_FROM_ABI _Tp operator=(_Tp __d) volatile noexcept + { + this->store(__d); + return __d; + } + _LIBCUDACXX_HIDE_FROM_ABI _Tp operator=(_Tp __d) noexcept + { + this->store(__d); + return __d; + } + + _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_max(const _Tp& __op, memory_order __m = memory_order_seq_cst) noexcept + { + return _CUDA_VSTD::__atomic_fetch_max_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{}); + } + _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_max(const _Tp& __op, memory_order __m = memory_order_seq_cst) volatile noexcept + { + return _CUDA_VSTD::__atomic_fetch_max_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{}); + } + + _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_min(const _Tp& __op, memory_order __m = memory_order_seq_cst) noexcept + { + return _CUDA_VSTD::__atomic_fetch_min_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{}); + } + _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_min(const _Tp& __op, memory_order __m = memory_order_seq_cst) volatile noexcept + { + return _CUDA_VSTD::__atomic_fetch_min_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{}); + } +}; + +// atomic_ref + +template +struct atomic_ref : public _CUDA_VSTD::__atomic_ref_impl<_Tp, _Sco> +{ + using value_type = _Tp; + + static constexpr size_t required_alignment = sizeof(_Tp); + + static constexpr bool is_always_lock_free = sizeof(_Tp) <= 8; + + _LIBCUDACXX_HIDE_FROM_ABI explicit constexpr atomic_ref(_Tp& __ref) + : _CUDA_VSTD::__atomic_ref_impl<_Tp, _Sco>(__ref) + {} + + _LIBCUDACXX_HIDE_FROM_ABI _Tp operator=(_Tp __v) const noexcept + { + this->store(__v); + return __v; + } + + _CCCL_HIDE_FROM_ABI atomic_ref(const atomic_ref&) noexcept = default; + atomic_ref& operator=(const atomic_ref&) = delete; + atomic_ref& operator=(const atomic_ref&) const = delete; + + _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_max(const _Tp& __op, memory_order __m = memory_order_seq_cst) const noexcept + { + return _CUDA_VSTD::__atomic_fetch_max_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{}); + } + + _LIBCUDACXX_HIDE_FROM_ABI _Tp fetch_min(const _Tp& __op, memory_order __m = memory_order_seq_cst) const noexcept + { + return _CUDA_VSTD::__atomic_fetch_min_dispatch(&this->__a, __op, __m, _CUDA_VSTD::__scope_to_tag<_Sco>{}); + } +}; + +inline _CCCL_HOST_DEVICE void +atomic_thread_fence(memory_order __m, thread_scope _Scope = thread_scope::thread_scope_system) +{ + NV_DISPATCH_TARGET( + NV_IS_DEVICE, + (switch (_Scope) { + case thread_scope::thread_scope_system: + _CUDA_VSTD::__atomic_thread_fence_cuda((int) __m, __thread_scope_system_tag{}); + break; + case thread_scope::thread_scope_device: + _CUDA_VSTD::__atomic_thread_fence_cuda((int) __m, __thread_scope_device_tag{}); + break; + case thread_scope::thread_scope_block: + _CUDA_VSTD::__atomic_thread_fence_cuda((int) __m, __thread_scope_block_tag{}); + break; + // Atomics scoped to themselves do not require fencing + case thread_scope::thread_scope_thread: + break; + }), + NV_IS_HOST, + ((void) _Scope; _CUDA_VSTD::atomic_thread_fence(__m);)) +} + +inline _CCCL_HOST_DEVICE void atomic_signal_fence(memory_order __m) +{ + _CUDA_VSTD::atomic_signal_fence(__m); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA___ATOMIC_ATOMIC_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__cmath/ceil_div.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__cmath/ceil_div.h new file mode 100644 index 0000000000000000000000000000000000000000..7e67503bdd5f0320fc25b834a378d87f35da97b6 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__cmath/ceil_div.h @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA___CMATH_CEIL_DIV_H +#define _CUDA___CMATH_CEIL_DIV_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include +#include +#include +#include +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +//! @brief Divides two numbers \p __a and \p __b, rounding up if there is a remainder +//! @param __a The dividend +//! @param __b The divisor +//! @pre \p __a must be non-negative +//! @pre \p __b must be positive +template = 0, + _CUDA_VSTD::enable_if_t<_CCCL_TRAIT(_CUDA_VSTD::is_integral, _Up), int> = 0> +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX14 _Tp ceil_div(const _Tp __a, const _Up __b) noexcept +{ + _CCCL_ASSERT(__b > _Up(0), "cuda::ceil_div: b must be positive"); + using _UCommon = _CUDA_VSTD::make_unsigned_t<_CUDA_VSTD::common_type_t<_Tp, _Up>>; + const auto __res = static_cast<_UCommon>(__a) / static_cast<_UCommon>(__b); + return static_cast<_Tp>(__res + (__res * static_cast<_UCommon>(__b) != static_cast<_UCommon>(__a))); +} + +//! @brief Divides two numbers \p __a and \p __b, rounding up if there is a remainder +//! @param __a The dividend +//! @param __b The divisor +//! @pre \p __a must be non-negative +//! @pre \p __b must be positive +template = 0, + _CUDA_VSTD::enable_if_t<_CCCL_TRAIT(_CUDA_VSTD::is_integral, _Up), int> = 0> +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX14 _Tp ceil_div(const _Tp __a, const _Up __b) noexcept +{ + _CCCL_ASSERT(__a >= _Tp(0), "cuda::ceil_div: a must be non negative"); + _CCCL_ASSERT(__b > _Up(0), "cuda::ceil_div: b must be positive"); + using _UCommon = _CUDA_VSTD::make_unsigned_t<_CUDA_VSTD::common_type_t<_Tp, _Up>>; + // Due to the precondition `__a >= 0` we can safely cast to unsigned without danger of overflowing + return static_cast<_Tp>((static_cast<_UCommon>(__a) + static_cast<_UCommon>(__b) - 1) / static_cast<_UCommon>(__b)); +} + +//! @brief Divides two numbers \p __a and \p __b, rounding up if there is a remainder, \p __b is an enum +//! @param __a The dividend +//! @param __b The divisor +//! @pre \p __a must be non-negative +//! @pre \p __b must be positive +template = 0, + _CUDA_VSTD::enable_if_t<_CCCL_TRAIT(_CUDA_VSTD::is_enum, _Up), int> = 0> +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI _CCCL_CONSTEXPR_CXX14 _Tp ceil_div(const _Tp __a, const _Up __b) noexcept +{ + return ::cuda::ceil_div(__a, static_cast<_CUDA_VSTD::underlying_type_t<_Up>>(__b)); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA___CMATH_CEIL_DIV_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__latch/latch.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__latch/latch.h new file mode 100644 index 0000000000000000000000000000000000000000..84389022dc1ba5eec97edc9203e780c4de9e4f39 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__latch/latch.h @@ -0,0 +1,40 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef __CUDA__LATCH_LATCH_H +#define __CUDA__LATCH_LATCH_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +template +class latch : public _CUDA_VSTD::__latch_base<_Sco> +{ +public: + _LIBCUDACXX_HIDE_FROM_ABI constexpr latch(_CUDA_VSTD::ptrdiff_t __count) + : _CUDA_VSTD::__latch_base<_Sco>(__count) + {} +}; + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // __CUDA__LATCH_LATCH_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/completion_mechanism.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/completion_mechanism.h new file mode 100644 index 0000000000000000000000000000000000000000..1564e00a092f8e43c97425ac47c2ceb15b2d8241 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/completion_mechanism.h @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA___BARRIER_COMPLETION_MECHANISM_H +#define _CUDA___BARRIER_COMPLETION_MECHANISM_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +//! @brief __completion_mechanism allows memcpy_async to report back what completion +//! mechanism it used. This is necessary to determine in which way to synchronize +//! the memcpy_async with a sync object (barrier or pipeline). +// +//! In addition, we use this enum to create bit flags so that calling functions +//! can specify which completion mechanisms can be used (__sync is always +//! allowed). +enum class __completion_mechanism +{ + __sync = 0, + __mbarrier_complete_tx = 1 << 0, // Use powers of two here to support the + __async_group = 1 << 1, // bit flag use case + __async_bulk_group = 1 << 2, +}; + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA___BARRIER_COMPLETION_MECHANISM_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_bulk_shared_global.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_bulk_shared_global.h new file mode 100644 index 0000000000000000000000000000000000000000..8a6cc2232bb844d6933e34d9e5d36647b2ec1f1e --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_bulk_shared_global.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_BULK_SHARED_GLOBAL_H_ +#define _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_BULK_SHARED_GLOBAL_H_ + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if _CCCL_HAS_CUDA_COMPILER +# if __cccl_ptx_isa >= 800 + +# include +# include +# include +# include + +# include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +extern "C" _CCCL_DEVICE void __cuda_ptx_cp_async_bulk_shared_global_is_not_supported_before_SM_90__(); +template +inline __device__ void __cp_async_bulk_shared_global( + const _Group& __g, char* __dest, const char* __src, _CUDA_VSTD::size_t __size, _CUDA_VSTD::uint64_t* __bar_handle) +{ + // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async-bulk + NV_IF_ELSE_TARGET(NV_PROVIDES_SM_90, + (if (__g.thread_rank() == 0) { + _CUDA_VPTX::cp_async_bulk( + _CUDA_VPTX::space_cluster, _CUDA_VPTX::space_global, __dest, __src, __size, __bar_handle); + }), + (__cuda_ptx_cp_async_bulk_shared_global_is_not_supported_before_SM_90__();)); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +# endif // __cccl_ptx_isa >= 800 +#endif // _CCCL_CUDA_COMPILER + +#endif // _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_BULK_SHARED_GLOBAL_H_ diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_fallback.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_fallback.h new file mode 100644 index 0000000000000000000000000000000000000000..43c21f5cba6fa07ea0cd4ff840dac9701aeb2839 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_fallback.h @@ -0,0 +1,68 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_FALLBACK_H_ +#define _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_FALLBACK_H_ + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include + +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +template <_CUDA_VSTD::size_t _Copy_size> +struct __copy_chunk +{ + _CCCL_ALIGNAS(_Copy_size) char data[_Copy_size]; +}; + +template <_CUDA_VSTD::size_t _Alignment, typename _Group> +inline _CCCL_HOST_DEVICE void +__cp_async_fallback_mechanism(_Group __g, char* __dest, const char* __src, _CUDA_VSTD::size_t __size) +{ + // Maximal copy size is 16 bytes + constexpr _CUDA_VSTD::size_t __copy_size = (_Alignment > 16) ? 16 : _Alignment; + + using __chunk_t = __copy_chunk<__copy_size>; + + // "Group"-strided loop over memory + const _CUDA_VSTD::size_t __stride = __g.size() * __copy_size; + + // An unroll factor of 64 ought to be enough for anybody. This unroll pragma + // is mainly intended to place an upper bound on loop unrolling. The number + // is more than high enough for the intended use case: an unroll factor of + // 64 allows moving 4 * 64 * 256 = 64kb in one unrolled loop with 256 + // threads (copying ints). On the other hand, in the unfortunate case that + // we have to move 1024 bytes / thread with char width, then we prevent + // fully unrolling the loop to 1024 copy instructions. This prevents the + // compile times from increasing unreasonably, and also has negligible + // impact on runtime performance. + _LIBCUDACXX_PRAGMA_UNROLL(64) + for (_CUDA_VSTD::size_t __offset = __g.thread_rank() * __copy_size; __offset < __size; __offset += __stride) + { + __chunk_t tmp = *reinterpret_cast(__src + __offset); + *reinterpret_cast<__chunk_t*>(__dest + __offset) = tmp; + } +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_FALLBACK_H_ diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_shared_global.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_shared_global.h new file mode 100644 index 0000000000000000000000000000000000000000..867dad16111282324f59f1afa528d662a5fbae78 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/cp_async_shared_global.h @@ -0,0 +1,102 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_SHARED_GLOBAL_H_ +#define _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_SHARED_GLOBAL_H_ + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if _CCCL_HAS_CUDA_COMPILER + +# include +# include +# include + +# include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +extern "C" _CCCL_DEVICE void __cuda_ptx_cp_async_shared_global_is_not_supported_before_SM_80__(); +template +inline __device__ void __cp_async_shared_global(char* __dest, const char* __src) +{ + // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async + + // If `if constexpr` is not available, this function gets instantiated even + // if is not called. Do not static_assert in that case. +# if _CCCL_STD_VER >= 2017 + static_assert(_Copy_size == 4 || _Copy_size == 8 || _Copy_size == 16, + "cp.async.shared.global requires a copy size of 4, 8, or 16."); +# endif // _CCCL_STD_VER >= 2017 + + NV_IF_ELSE_TARGET( + NV_PROVIDES_SM_80, + (asm volatile("cp.async.ca.shared.global [%0], [%1], %2, %2;" + : + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__dest))), + "l"(static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__src))), + "n"(_Copy_size) + : "memory");), + (__cuda_ptx_cp_async_shared_global_is_not_supported_before_SM_80__();)); +} + +template <> +inline __device__ void __cp_async_shared_global<16>(char* __dest, const char* __src) +{ + // https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cp-async + // When copying 16 bytes, it is possible to skip L1 cache (.cg). + NV_IF_ELSE_TARGET( + NV_PROVIDES_SM_80, + (asm volatile("cp.async.cg.shared.global [%0], [%1], %2, %2;" + : + : "r"(static_cast<_CUDA_VSTD::uint32_t>(__cvta_generic_to_shared(__dest))), + "l"(static_cast<_CUDA_VSTD::uint64_t>(__cvta_generic_to_global(__src))), + "n"(16) + : "memory");), + (__cuda_ptx_cp_async_shared_global_is_not_supported_before_SM_80__();)); +} + +template +inline __device__ void +__cp_async_shared_global_mechanism(_Group __g, char* __dest, const char* __src, _CUDA_VSTD::size_t __size) +{ + // If `if constexpr` is not available, this function gets instantiated even + // if is not called. Do not static_assert in that case. +# if _CCCL_STD_VER >= 2017 + static_assert(4 <= _Alignment, "cp.async requires at least 4-byte alignment"); +# endif // _CCCL_STD_VER >= 2017 + + // Maximal copy size is 16. + constexpr int __copy_size = (_Alignment > 16) ? 16 : _Alignment; + // We use an int offset here, because we are copying to shared memory, + // which is easily addressable using int. + const int __group_size = __g.size(); + const int __group_rank = __g.thread_rank(); + const int __stride = __group_size * __copy_size; + for (int __offset = __group_rank * __copy_size; __offset < static_cast(__size); __offset += __stride) + { + __cp_async_shared_global<__copy_size>(__dest + __offset, __src + __offset); + } +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CCCL_CUDA_COMPILER + +#endif // _CUDA_PTX__MEMCPY_ASYNC_CP_ASYNC_SHARED_GLOBAL_H_ diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/dispatch_memcpy_async.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/dispatch_memcpy_async.h new file mode 100644 index 0000000000000000000000000000000000000000..cb8fcb690836b5af91c9fdc7414f86d7ed5bfae2 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/dispatch_memcpy_async.h @@ -0,0 +1,157 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_PTX__MEMCPY_ASYNC_DISPATCH_MEMCPY_ASYNC_H_ +#define _CUDA_PTX__MEMCPY_ASYNC_DISPATCH_MEMCPY_ASYNC_H_ + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include +#include +#include +#include +#include + +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +/*********************************************************************** + * cuda::memcpy_async dispatch + * + * The dispatch mechanism takes all the arguments and dispatches to the + * fastest asynchronous copy mechanism available. + * + * It returns a __completion_mechanism that indicates which completion mechanism + * was used by the copy mechanism. This value can be used by the sync object to + * further synchronize if necessary. + * + ***********************************************************************/ + +template <_CUDA_VSTD::size_t _Align, typename _Group> +_CCCL_NODISCARD _CCCL_DEVICE inline __completion_mechanism __dispatch_memcpy_async_any_to_any( + _Group const& __group, + char* __dest_char, + char const* __src_char, + _CUDA_VSTD::size_t __size, + _CUDA_VSTD::uint32_t __allowed_completions, + _CUDA_VSTD::uint64_t* __bar_handle) +{ + __cp_async_fallback_mechanism<_Align>(__group, __dest_char, __src_char, __size); + return __completion_mechanism::__sync; +} + +template <_CUDA_VSTD::size_t _Align, typename _Group> +_CCCL_NODISCARD _CCCL_DEVICE inline __completion_mechanism __dispatch_memcpy_async_global_to_shared( + _Group const& __group, + char* __dest_char, + char const* __src_char, + _CUDA_VSTD::size_t __size, + _CUDA_VSTD::uint32_t __allowed_completions, + _CUDA_VSTD::uint64_t* __bar_handle) +{ +#if __cccl_ptx_isa >= 800 + NV_IF_TARGET( + NV_PROVIDES_SM_90, + (const bool __can_use_complete_tx = __allowed_completions & uint32_t(__completion_mechanism::__mbarrier_complete_tx); + (void) __can_use_complete_tx; + _CCCL_ASSERT(__can_use_complete_tx == (nullptr != __bar_handle), + "Pass non-null bar_handle if and only if can_use_complete_tx."); + _CCCL_IF_CONSTEXPR (_Align >= 16) { + if (__can_use_complete_tx && __isShared(__bar_handle)) + { + __cp_async_bulk_shared_global(__group, __dest_char, __src_char, __size, __bar_handle); + return __completion_mechanism::__mbarrier_complete_tx; + } + } + // Fallthrough to SM 80.. + )); +#endif // __cccl_ptx_isa >= 800 + + NV_IF_TARGET( + NV_PROVIDES_SM_80, + (_CCCL_IF_CONSTEXPR (_Align >= 4) { + const bool __can_use_async_group = __allowed_completions & uint32_t(__completion_mechanism::__async_group); + if (__can_use_async_group) + { + __cp_async_shared_global_mechanism<_Align>(__group, __dest_char, __src_char, __size); + return __completion_mechanism::__async_group; + } + } + // Fallthrough.. + )); + + __cp_async_fallback_mechanism<_Align>(__group, __dest_char, __src_char, __size); + return __completion_mechanism::__sync; +} + +// __dispatch_memcpy_async is the internal entry point for dispatching to the correct memcpy_async implementation. +template <_CUDA_VSTD::size_t _Align, typename _Group> +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI __completion_mechanism __dispatch_memcpy_async( + _Group const& __group, + char* __dest_char, + char const* __src_char, + _CUDA_VSTD::size_t __size, + _CUDA_VSTD::uint32_t __allowed_completions, + _CUDA_VSTD::uint64_t* __bar_handle) +{ + NV_IF_ELSE_TARGET( + NV_IS_DEVICE, + ( + // Dispatch based on direction of the copy: global to shared, shared to + // global, etc. + + // CUDA compilers <= 12.2 may not propagate assumptions about the state space + // of pointers correctly. Therefore, we + // 1) put the code for each copy direction in a separate function, and + // 2) make sure none of the code paths can reach each other by "falling through". + // + // See nvbug 4074679 and also PR #478. + if (__isGlobal(__src_char) && __isShared(__dest_char)) { + return __dispatch_memcpy_async_global_to_shared<_Align>( + __group, __dest_char, __src_char, __size, __allowed_completions, __bar_handle); + } else { + return __dispatch_memcpy_async_any_to_any<_Align>( + __group, __dest_char, __src_char, __size, __allowed_completions, __bar_handle); + }), + ( + // Host code path: + if (__group.thread_rank() == 0) { + memcpy(__dest_char, __src_char, __size); + } return __completion_mechanism::__sync;)); +} + +template <_CUDA_VSTD::size_t _Align, typename _Group> +_CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI __completion_mechanism __dispatch_memcpy_async( + _Group const& __group, + char* __dest_char, + char const* __src_char, + _CUDA_VSTD::size_t __size, + _CUDA_VSTD::uint32_t __allowed_completions) +{ + _CCCL_ASSERT(!(__allowed_completions & uint32_t(__completion_mechanism::__mbarrier_complete_tx)), + "Cannot allow mbarrier_complete_tx completion mechanism when not passing a barrier. "); + return __dispatch_memcpy_async<_Align>(__group, __dest_char, __src_char, __size, __allowed_completions, nullptr); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA_PTX__MEMCPY_ASYNC_DISPATCH_MEMCPY_ASYNC_H_ diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/is_local_smem_barrier.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/is_local_smem_barrier.h new file mode 100644 index 0000000000000000000000000000000000000000..c130d8c6736c6d7150871d9467b1628bd38ba3fa --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/is_local_smem_barrier.h @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA___BARRIER_IS_LOCAL_SMEM_BARRIER_H +#define _CUDA___BARRIER_IS_LOCAL_SMEM_BARRIER_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include +#include + +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +//! @brief __is_local_smem_barrier returns true if barrier is (1) block-scoped and (2) located in shared memory. +template +_LIBCUDACXX_HIDE_FROM_ABI bool __is_local_smem_barrier(barrier<_Sco, _CompF>& __barrier) +{ + NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return _Is_mbarrier && __isShared(&__barrier);), (return false;)); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA___BARRIER_IS_LOCAL_SMEM_BARRIER_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async.h new file mode 100644 index 0000000000000000000000000000000000000000..8afd043027f279bc1e4c29b2b0f61771f9d4824e --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async.h @@ -0,0 +1,166 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_H_ +#define _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_H_ + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if _CCCL_HAS_CUDA_COMPILER + +# include +# include +# include +# include +# include +# include +# include +# include +# include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +/*********************************************************************** + * memcpy_async code: + * + * A call to cuda::memcpy_async(dest, src, size, barrier) can dispatch to any of + * these PTX instructions: + * + * 1. normal synchronous copy (fallback) + * 2. cp.async: shared <- global + * 3. cp.async.bulk: shared <- global + * 4. TODO: cp.async.bulk: global <- shared + * 5. TODO: cp.async.bulk: cluster <- shared + * + * Which of these options is chosen, depends on: + * + * 1. The alignment of dest, src, and size; + * 2. The direction of the copy + * 3. The current compute capability + * 4. The requested completion mechanism + * + * PTX has 3 asynchronous completion mechanisms: + * + * 1. Async group - local to a thread. Used by cp.async + * 2. Bulk async group - local to a thread. Used by cp.async.bulk (shared -> global) + * 3. mbarrier::complete_tx - shared memory barier. Used by cp.async.bulk (other directions) + * + * The code is organized as follows: + * + * 1. Asynchronous copy mechanisms that wrap the PTX instructions + * + * 2. Device memcpy_async implementation per copy direction (global to shared, + * shared to global, etc). Dispatches to fastest mechanism based on requested + * completion mechanism(s), pointer alignment, and architecture. + * + * 3. Host and device memcpy_async implementations. Host implementation is + * basically a memcpy wrapper; device implementation dispatches based on the + * direction of the copy. + * + * 4. __memcpy_async_barrier: + * a) Sets the allowed completion mechanisms based on the barrier location + * b) Calls the host or device memcpy_async implementation + * c) If necessary, synchronizes with the barrier based on the returned + * completion mechanism. + * + * 5. The public memcpy_async function overloads. Call into + * __memcpy_async_barrier. + * + ***********************************************************************/ + +/*********************************************************************** + * Asynchronous copy mechanisms: + * + * 1. cp.async.bulk: shared <- global + * 2. TODO: cp.async.bulk: cluster <- shared + * 3. TODO: cp.async.bulk: global <- shared + * 4. cp.async: shared <- global + * 5. normal synchronous copy (fallback) + ***********************************************************************/ + +template +_LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment memcpy_async( + _Group const& __group, + _Tp* __destination, + _Tp const* __source, + aligned_size_t<_Alignment> __size, + barrier<_Sco, _CompF>& __barrier) +{ + return __memcpy_async_barrier(__group, __destination, __source, __size, __barrier); +} + +template +_LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment +memcpy_async(_Tp* __destination, _Tp const* __source, _Size __size, barrier<_Sco, _CompF>& __barrier) +{ + return __memcpy_async_barrier(__single_thread_group{}, __destination, __source, __size, __barrier); +} + +template +_LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment memcpy_async( + _Group const& __group, + _Tp* __destination, + _Tp const* __source, + _CUDA_VSTD::size_t __size, + barrier<_Sco, _CompF>& __barrier) +{ + return __memcpy_async_barrier(__group, __destination, __source, __size, __barrier); +} + +template +_LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment memcpy_async( + _Group const& __group, + void* __destination, + void const* __source, + _CUDA_VSTD::size_t __size, + barrier<_Sco, _CompF>& __barrier) +{ + return __memcpy_async_barrier( + __group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __barrier); +} + +template +_LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment memcpy_async( + _Group const& __group, + void* __destination, + void const* __source, + aligned_size_t<_Alignment> __size, + barrier<_Sco, _CompF>& __barrier) +{ + return __memcpy_async_barrier( + __group, reinterpret_cast(__destination), reinterpret_cast(__source), __size, __barrier); +} + +template +_LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment +memcpy_async(void* __destination, void const* __source, _Size __size, barrier<_Sco, _CompF>& __barrier) +{ + return __memcpy_async_barrier( + __single_thread_group{}, + reinterpret_cast(__destination), + reinterpret_cast(__source), + __size, + __barrier); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CCCL_CUDA_COMPILER + +#endif // _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_H_ diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_barrier.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_barrier.h new file mode 100644 index 0000000000000000000000000000000000000000..ed9c68ad5a34633f836f6473aaa14581acfb3153 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_barrier.h @@ -0,0 +1,118 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_BARRIER_H_ +#define _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_BARRIER_H_ + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +/*********************************************************************** + * cuda::memcpy_async dispatch helper functions + * + * - __get_size_align struct to determine the alignment from a size type. + ***********************************************************************/ + +// The __get_size_align struct provides a way to query the guaranteed +// "alignment" of a provided size. In this case, an n-byte aligned size means +// that the size is a multiple of n. +// +// Use as follows: +// static_assert(__get_size_align::align == 1) +// static_assert(__get_size_align>::align == n) + +// Default impl: always returns 1. +template +struct __get_size_align +{ + static constexpr int align = 1; +}; + +// aligned_size_t overload: return n. +template +struct __get_size_align> +{ + static constexpr int align = T::align; +}; + +//////////////////////////////////////////////////////////////////////////////// + +struct __single_thread_group +{ + _LIBCUDACXX_HIDE_FROM_ABI void sync() const {} + _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _CUDA_VSTD::size_t size() const + { + return 1; + }; + _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI constexpr _CUDA_VSTD::size_t thread_rank() const + { + return 0; + }; +}; + +template +_LIBCUDACXX_HIDE_FROM_ABI async_contract_fulfillment __memcpy_async_barrier( + _Group const& __group, _Tp* __destination, _Tp const* __source, _Size __size, barrier<_Sco, _CompF>& __barrier) +{ + static_assert(_CCCL_TRAIT(_CUDA_VSTD::is_trivially_copyable, _Tp), "memcpy_async requires a trivially copyable type"); + + // 1. Determine which completion mechanisms can be used with the current + // barrier. A local shared memory barrier, i.e., block-scope barrier in local + // shared memory, supports the mbarrier_complete_tx mechanism in addition to + // the async group mechanism. + _CUDA_VSTD::uint32_t __allowed_completions = + __is_local_smem_barrier(__barrier) + ? (_CUDA_VSTD::uint32_t(__completion_mechanism::__async_group) + | _CUDA_VSTD::uint32_t(__completion_mechanism::__mbarrier_complete_tx)) + : _CUDA_VSTD::uint32_t(__completion_mechanism::__async_group); + + // Alignment: Use the maximum of the alignment of _Tp and that of a possible cuda::aligned_size_t. + constexpr _CUDA_VSTD::size_t __size_align = __get_size_align<_Size>::align; + constexpr _CUDA_VSTD::size_t __align = (alignof(_Tp) < __size_align) ? __size_align : alignof(_Tp); + // Cast to char pointers. We don't need the type for alignment anymore and + // erasing the types reduces the number of instantiations of down-stream + // functions. + char* __dest_char = reinterpret_cast(__destination); + char const* __src_char = reinterpret_cast(__source); + + // 2. Issue actual copy instructions. + auto __bh = __try_get_barrier_handle(__barrier); + auto __cm = __dispatch_memcpy_async<__align>(__group, __dest_char, __src_char, __size, __allowed_completions, __bh); + + // 3. Synchronize barrier with copy instructions. + return __memcpy_completion_impl::__defer(__cm, __group, __size, __barrier); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_BARRIER_H_ diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_tx.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_tx.h new file mode 100644 index 0000000000000000000000000000000000000000..b7924a7721b112d79d62c6f518e7e96a806d3f80 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_async_tx.h @@ -0,0 +1,90 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_TX_H_ +#define _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_TX_H_ + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if _CCCL_HAS_CUDA_COMPILER +# if __cccl_ptx_isa >= 800 + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_DEVICE + +extern "C" _CCCL_DEVICE void __cuda_ptx_memcpy_async_tx_is_not_supported_before_SM_90__(); +template +_CCCL_DEVICE inline async_contract_fulfillment memcpy_async_tx( + _Tp* __dest, + const _Tp* __src, + ::cuda::aligned_size_t<_Alignment> __size, + ::cuda::barrier<::cuda::thread_scope_block>& __b) +{ + // When compiling with NVCC and GCC 4.8, certain user defined types that _are_ trivially copyable are + // incorrectly classified as not trivially copyable. Remove this assertion to allow for their usage with + // memcpy_async when compiling with GCC 4.8. + // FIXME: remove the #if once GCC 4.8 is no longer supported. +# if !_CCCL_COMPILER(GCC) || _CCCL_COMPILER(GCC, >, 4, 8) + static_assert(_CUDA_VSTD::is_trivially_copyable<_Tp>::value, "memcpy_async_tx requires a trivially copyable type"); +# endif + static_assert(16 <= _Alignment, "mempcy_async_tx expects arguments to be at least 16 byte aligned."); + + _CCCL_ASSERT(__isShared(barrier_native_handle(__b)), "Barrier must be located in local shared memory."); + _CCCL_ASSERT(__isShared(__dest), "dest must point to shared memory."); + _CCCL_ASSERT(__isGlobal(__src), "src must point to global memory."); + + NV_IF_ELSE_TARGET( + NV_PROVIDES_SM_90, + ( + if (__isShared(__dest) && __isGlobal(__src)) { + _CUDA_VPTX::cp_async_bulk( + _CUDA_VPTX::space_cluster, + _CUDA_VPTX::space_global, + __dest, + __src, + static_cast(__size), + barrier_native_handle(__b)); + } else { + // memcpy_async_tx only supports copying from global to shared + // or from shared to remote cluster dsmem. To copy to remote + // dsmem, we need to arrive on a cluster-scoped barrier, which + // is not yet implemented. So we trap in this case as well. + _CCCL_UNREACHABLE(); + }), + (__cuda_ptx_memcpy_async_tx_is_not_supported_before_SM_90__();)); + + return async_contract_fulfillment::async; +} + +_LIBCUDACXX_END_NAMESPACE_CUDA_DEVICE + +# endif // __cccl_ptx_isa >= 800 +#endif // _CCCL_CUDA_COMPILER + +#endif // _CUDA_PTX__MEMCPY_ASYNC_MEMCPY_ASYNC_TX_H_ diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_completion.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_completion.h new file mode 100644 index 0000000000000000000000000000000000000000..182357d591a317bedc32c9eaad42fb68ab3cac7e --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/memcpy_completion.h @@ -0,0 +1,168 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA___MEMCPY_ASYNC_MEMCPY_COMPLETION_H +#define _CUDA___MEMCPY_ASYNC_MEMCPY_COMPLETION_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if _CCCL_HAS_CUDA_COMPILER +# include +# include +#endif // _CCCL_CUDA_COMPILER + +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +// This struct contains functions to defer the completion of a barrier phase +// or pipeline stage until a specific memcpy_async operation *initiated by +// this thread* has completed. + +// The user is still responsible for arriving and waiting on (or otherwise +// synchronizing with) the barrier or pipeline barrier to see the results of +// copies from other threads participating in the synchronization object. +struct __memcpy_completion_impl +{ + template + _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI static async_contract_fulfillment + __defer(__completion_mechanism __cm, + _Group const& __group, + _CUDA_VSTD::size_t __size, + barrier<::cuda::thread_scope_block>& __barrier) + { + // In principle, this is the overload for shared memory barriers. However, a + // block-scope barrier may also be located in global memory. Therefore, we + // check if the barrier is a non-smem barrier and handle that separately. + if (!__is_local_smem_barrier(__barrier)) + { + return __defer_non_smem_barrier(__cm, __group, __size, __barrier); + } + + switch (__cm) + { + case __completion_mechanism::__async_group: + // Pre-SM80, the async_group mechanism is not available. + NV_IF_TARGET( + NV_PROVIDES_SM_80, + ( + // Non-Blocking: unbalance barrier by 1, barrier will be + // rebalanced when all thread-local cp.async instructions + // have completed writing to shared memory. + _CUDA_VSTD::uint64_t* __bh = __try_get_barrier_handle(__barrier); + + asm volatile("cp.async.mbarrier.arrive.shared.b64 [%0];" ::"r"(static_cast<_CUDA_VSTD::uint32_t>( + __cvta_generic_to_shared(__bh))) + : "memory");)); + return async_contract_fulfillment::async; + case __completion_mechanism::__async_bulk_group: + // This completion mechanism should not be used with a shared + // memory barrier. Or at least, we do not currently envision + // bulk group to be used with shared memory barriers. + _CCCL_UNREACHABLE(); + case __completion_mechanism::__mbarrier_complete_tx: +#if __cccl_ptx_isa >= 800 + // Pre-sm90, the mbarrier_complete_tx completion mechanism is not available. + NV_IF_TARGET(NV_PROVIDES_SM_90, + ( + // Only perform the expect_tx operation with the leader thread + if (__group.thread_rank() == 0) { ::cuda::device::barrier_expect_tx(__barrier, __size); })); +#endif // __cccl_ptx_isa >= 800 + return async_contract_fulfillment::async; + case __completion_mechanism::__sync: + // sync: In this case, we do not need to do anything. The user will have + // to issue `bar.arrive_wait();` to see the effect of the transaction. + return async_contract_fulfillment::none; + default: + // Get rid of "control reaches end of non-void function": + _CCCL_UNREACHABLE(); + } + } + + template + _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI static async_contract_fulfillment __defer( + __completion_mechanism __cm, _Group const& __group, _CUDA_VSTD::size_t __size, barrier<_Sco, _CompF>& __barrier) + { + return __defer_non_smem_barrier(__cm, __group, __size, __barrier); + } + + template + _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI static async_contract_fulfillment __defer_non_smem_barrier( + __completion_mechanism __cm, _Group const& __group, _CUDA_VSTD::size_t __size, barrier<_Sco, _CompF>& __barrier) + { + // Overload for non-smem barriers. + switch (__cm) + { + case __completion_mechanism::__async_group: + // Pre-SM80, the async_group mechanism is not available. + NV_IF_TARGET(NV_PROVIDES_SM_80, + ( + // Blocking: wait for all thread-local cp.async instructions to have + // completed writing to shared memory. + asm volatile("cp.async.wait_all;" :: + : "memory");)); + return async_contract_fulfillment::async; + case __completion_mechanism::__mbarrier_complete_tx: + // Non-smem barriers do not have an mbarrier_complete_tx mechanism.. + _CCCL_UNREACHABLE(); + case __completion_mechanism::__async_bulk_group: + // This completion mechanism is currently not expected to be used with barriers. + _CCCL_UNREACHABLE(); + case __completion_mechanism::__sync: + // sync: In this case, we do not need to do anything. + return async_contract_fulfillment::none; + default: + // Get rid of "control reaches end of non-void function": + _CCCL_UNREACHABLE(); + } + } + + template + _CCCL_NODISCARD _LIBCUDACXX_HIDE_FROM_ABI static async_contract_fulfillment + __defer(__completion_mechanism __cm, _Group const&, _CUDA_VSTD::size_t, pipeline<_Sco>&) + { + switch (__cm) + { + case __completion_mechanism::__async_group: + return async_contract_fulfillment::async; + case __completion_mechanism::__async_bulk_group: + return async_contract_fulfillment::async; + case __completion_mechanism::__mbarrier_complete_tx: + return async_contract_fulfillment::async; + case __completion_mechanism::__sync: + return async_contract_fulfillment::none; + default: + // Get rid of "control reaches end of non-void function": + _CCCL_UNREACHABLE(); + } + } +}; + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA___MEMCPY_ASYNC_MEMCPY_COMPLETION_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/try_get_barrier_handle.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/try_get_barrier_handle.h new file mode 100644 index 0000000000000000000000000000000000000000..cb55695031ba8578626af4d50bdb260da61dc70d --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memcpy_async/try_get_barrier_handle.h @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA___BARRIER_TRY_GET_BARRIER_HANDLE_H +#define _CUDA___BARRIER_TRY_GET_BARRIER_HANDLE_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include +#include +#include +#include +#include + +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +//! @brief __try_get_barrier_handle returns barrier handle of block-scoped barriers and a nullptr otherwise. +template +_LIBCUDACXX_HIDE_FROM_ABI _CUDA_VSTD::uint64_t* __try_get_barrier_handle(barrier<_Sco, _CompF>& __barrier) +{ + return nullptr; +} + +template <> +_LIBCUDACXX_HIDE_FROM_ABI _CUDA_VSTD::uint64_t* +__try_get_barrier_handle<::cuda::thread_scope_block, _CUDA_VSTD::__empty_completion>( + barrier& __barrier) +{ + (void) __barrier; + NV_DISPATCH_TARGET( + NV_IS_DEVICE, (return ::cuda::device::barrier_native_handle(__barrier);), NV_ANY_TARGET, (return nullptr;)); +} + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // _CUDA___BARRIER_TRY_GET_BARRIER_HANDLE_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource.h new file mode 100644 index 0000000000000000000000000000000000000000..733a8fdde8ba3d4b88daeb812e3d2fc35ecdde51 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource.h @@ -0,0 +1,129 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA__MEMORY_RESOURCE_RESOURCE_H +#define _CUDA__MEMORY_RESOURCE_RESOURCE_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if !_CCCL_COMPILER(MSVC2017) && defined(LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE) + +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# if _CCCL_STD_VER >= 2014 + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_MR + +//! @brief The \c resource concept verifies that a type Resource satisfies the basic requirements of a memory +//! resource +//! @rst +//! We require that a resource supports the following interface +//! +//! - ``allocate(size_t bytes, size_t alignment)`` +//! - ``deallocate(void* ptr, size_t bytes, size_t alignment)`` +//! - ``T() == T()`` +//! - ``T() != T()`` +//! +//! @endrst +//! @tparam _Resource The type that should implement the resource concept +template +_CCCL_CONCEPT resource = + _CCCL_REQUIRES_EXPR((_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment)( + _Same_as(void*) __res.allocate(__bytes, __alignment), // + _Same_as(void) __res.deallocate(__ptr, __bytes, __alignment), + requires(_CUDA_VSTD::equality_comparable<_Resource>)); + +//! @brief The \c async_resource concept verifies that a type Resource satisfies the basic requirements of a +//! memory resource and additionally supports stream ordered allocations +//! @rst +//! We require that an async resource supports the following interface +//! +//! - ``allocate(size_t bytes, size_t alignment)`` +//! - ``deallocate(void* ptr, size_t bytes, size_t alignment)`` +//! - ``T() == T()`` +//! - ``T() != T()`` +//! +//! - ``allocate_async(size_t bytes, size_t alignment, cuda::stream_ref stream)`` +//! - ``deallocate_async(void* ptr, size_t bytes, size_t alignment, cuda::stream_ref stream)`` +//! +//! @endrst +//! @tparam _Resource The type that should implement the async resource concept +template +_CCCL_CONCEPT async_resource = _CCCL_REQUIRES_EXPR( + (_Resource), _Resource& __res, void* __ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream)( + _Same_as(void*) __res.allocate_async(__bytes, __alignment, __stream), + _Same_as(void) __res.deallocate_async(__ptr, __bytes, __alignment, __stream), + requires(resource<_Resource>)); + +//! @brief The \c resource_with concept verifies that a type Resource satisfies the `resource` concept and +//! also satisfies all the provided Properties +//! @tparam _Resource +//! @tparam _Properties +// We cannot use fold expressions here due to a nvcc bug +template +_CCCL_CONCEPT resource_with = _CCCL_REQUIRES_EXPR((_Resource, variadic _Properties))( + requires(resource<_Resource>), requires(_CUDA_VSTD::__all...>::value)); + +//! @brief The \c async_resource_with concept verifies that a type Resource satisfies the `async_resource` +//! concept and also satisfies all the provided Properties +//! @tparam _Resource +//! @tparam _Properties +// We cannot use fold expressions here due to a nvcc bug +template +_CCCL_CONCEPT async_resource_with = _CCCL_REQUIRES_EXPR((_Resource, variadic _Properties))( + requires(async_resource<_Resource>), requires(_CUDA_VSTD::__all...>::value)); + +template +struct __different_resource__ +{ + template + static constexpr bool __value(_OtherResource*) noexcept + { + return resource<_OtherResource>; + } +}; + +template <> +struct __different_resource__ +{ + static constexpr bool __value(void*) noexcept + { + return false; + } +}; + +template +_CCCL_CONCEPT __different_resource = + __different_resource__<_CUDA_VSTD::convertible_to<_OtherResource const&, _Resource const&>>::__value( + static_cast<_OtherResource*>(nullptr)); + +_LIBCUDACXX_END_NAMESPACE_CUDA_MR + +# endif // _CCCL_STD_VER >= 2014 + +#endif // !_CCCL_COMPILER(MSVC2017) && LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE + +#endif //_CUDA__MEMORY_RESOURCE_RESOURCE_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource_ref.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource_ref.h new file mode 100644 index 0000000000000000000000000000000000000000..24f0298ac56724c50a250b61d7b4ca83eb8dd117 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__memory_resource/resource_ref.h @@ -0,0 +1,653 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _CUDA__MEMORY_RESOURCE_RESOURCE_REF_H +#define _CUDA__MEMORY_RESOURCE_RESOURCE_REF_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#if !_CCCL_COMPILER(MSVC2017) && defined(LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE) + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# if _CCCL_STD_VER >= 2014 + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA_MR + +union _AnyResourceStorage +{ + _LIBCUDACXX_HIDE_FROM_ABI constexpr _AnyResourceStorage(void* __ptr = nullptr) noexcept + : __ptr_(__ptr) + {} + + void* __ptr_; + char __buf_[3 * sizeof(void*)]; +}; + +template +constexpr bool _IsSmall() noexcept +{ + return (sizeof(_Resource) <= sizeof(_AnyResourceStorage)) // + && (alignof(_AnyResourceStorage) % alignof(_Resource) == 0) + && _CCCL_TRAIT(_CUDA_VSTD::is_nothrow_move_constructible, _Resource); +} + +template +constexpr _Resource* _Any_resource_cast(_AnyResourceStorage* __object) noexcept +{ + return static_cast<_Resource*>(_IsSmall<_Resource>() ? __object->__buf_ : __object->__ptr_); +} + +template +constexpr const _Resource* _Any_resource_cast(const _AnyResourceStorage* __object) noexcept +{ + return static_cast(_IsSmall<_Resource>() ? __object->__buf_ : __object->__ptr_); +} + +enum class _WrapperType +{ + _Reference, + _Owning +}; + +enum class _AllocType +{ + _Default, + _Async, +}; + +struct _Alloc_vtable +{ + using _AllocFn = void* (*) (void*, size_t, size_t); + using _DeallocFn = void (*)(void*, void*, size_t, size_t) _CCCL_FUNCTION_TYPE_NOEXCEPT; + using _EqualFn = bool (*)(void*, void*); + using _DestroyFn = void (*)(_AnyResourceStorage*) _CCCL_FUNCTION_TYPE_NOEXCEPT; + using _MoveFn = void (*)(_AnyResourceStorage*, _AnyResourceStorage*) _CCCL_FUNCTION_TYPE_NOEXCEPT; + using _CopyFn = void (*)(_AnyResourceStorage*, const _AnyResourceStorage*); + + bool __is_small; + _AllocFn __alloc_fn; + _DeallocFn __dealloc_fn; + _EqualFn __equal_fn; + _DestroyFn __destroy_fn; + _MoveFn __move_fn; + _CopyFn __copy_fn; + + constexpr _Alloc_vtable( + bool __is_small_, + _AllocFn __alloc_fn_, + _DeallocFn __dealloc_fn_, + _EqualFn __equal_fn_, + _DestroyFn __destroy_fn_, + _MoveFn __move_fn_, + _CopyFn __copy_fn_) noexcept + : __is_small(__is_small_) + , __alloc_fn(__alloc_fn_) + , __dealloc_fn(__dealloc_fn_) + , __equal_fn(__equal_fn_) + , __destroy_fn(__destroy_fn_) + , __move_fn(__move_fn_) + , __copy_fn(__copy_fn_) + {} +}; + +struct _Async_alloc_vtable : public _Alloc_vtable +{ + using _AsyncAllocFn = void* (*) (void*, size_t, size_t, ::cuda::stream_ref); + using _AsyncDeallocFn = void (*)(void*, void*, size_t, size_t, ::cuda::stream_ref); + + _AsyncAllocFn __async_alloc_fn; + _AsyncDeallocFn __async_dealloc_fn; + + constexpr _Async_alloc_vtable( + bool __is_small_, + _Alloc_vtable::_AllocFn __alloc_fn_, + _Alloc_vtable::_DeallocFn __dealloc_fn_, + _Alloc_vtable::_EqualFn __equal_fn_, + _Alloc_vtable::_DestroyFn __destroy_fn_, + _Alloc_vtable::_MoveFn __move_fn_, + _Alloc_vtable::_CopyFn __copy_fn_, + _AsyncAllocFn __async_alloc_fn_, + _AsyncDeallocFn __async_dealloc_fn_) noexcept + : _Alloc_vtable(__is_small_, __alloc_fn_, __dealloc_fn_, __equal_fn_, __destroy_fn_, __move_fn_, __copy_fn_) + , __async_alloc_fn(__async_alloc_fn_) + , __async_dealloc_fn(__async_dealloc_fn_) + {} +}; + +struct _Resource_vtable_builder +{ + template <_WrapperType _Wrapper_type> + using __wrapper_type = _CUDA_VSTD::integral_constant<_WrapperType, _Wrapper_type>; + + template + static __property_value_t<_Property> _Get_property(const void* __res) noexcept + { + return get_property(*static_cast(__res), _Property{}); + } + + template + static void* _Alloc(void* __object, size_t __bytes, size_t __alignment) + { + return static_cast<_Resource*>(__object)->allocate(__bytes, __alignment); + } + + template + static void _Dealloc(void* __object, void* __ptr, size_t __bytes, size_t __alignment) noexcept + { + // TODO: this breaks RMM because their memory resources do not declare their + // deallocate functions to be noexcept. Comment out the check for now until + // we can fix RMM. + // static_assert(noexcept(static_cast<_Resource*>(__object)->deallocate(__ptr, __bytes, __alignment))); + return static_cast<_Resource*>(__object)->deallocate(__ptr, __bytes, __alignment); + } + + template + static void* _Alloc_async(void* __object, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream) + { + return static_cast<_Resource*>(__object)->allocate_async(__bytes, __alignment, __stream); + } + + template + static void + _Dealloc_async(void* __object, void* __ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream) + { + return static_cast<_Resource*>(__object)->deallocate_async(__ptr, __bytes, __alignment, __stream); + } + + template + static bool _Equal(void* __left, void* __rhs) + { + return *static_cast<_Resource*>(__left) == *static_cast<_Resource*>(__rhs); + } + + template + static void _Destroy_impl(_AnyResourceStorage* __object_, __wrapper_type<_WrapperType::_Owning>) noexcept + { + _Resource* __object = _Any_resource_cast<_Resource>(__object_); + _CCCL_IF_CONSTEXPR (_IsSmall<_Resource>()) + { + __object->~_Resource(); + } + else + { + delete __object; + } + } + + template + static void _Destroy_impl(_AnyResourceStorage*, __wrapper_type<_WrapperType::_Reference>) noexcept + {} + + template + static void _Destroy(_AnyResourceStorage* __object) noexcept + { + _Destroy_impl<_Resource>(__object, __wrapper_type<_Wrapper_type>{}); + } + + template + static void _Move_impl( + _AnyResourceStorage* __object, _AnyResourceStorage* __other_, __wrapper_type<_WrapperType::_Owning>) noexcept + { + _CCCL_IF_CONSTEXPR (_IsSmall<_Resource>()) + { + _Resource* __other = _Any_resource_cast<_Resource>(__other_); + ::new (static_cast(__object->__buf_)) _Resource(_CUDA_VSTD::move(*__other)); + __other->~_Resource(); + } + else + { + __object->__ptr_ = _CUDA_VSTD::exchange(__other_->__ptr_, nullptr); + } + } + + template + static void _Move_impl(_AnyResourceStorage*, _AnyResourceStorage*, __wrapper_type<_WrapperType::_Reference>) noexcept + {} + + template + static void _Move(_AnyResourceStorage* __object, _AnyResourceStorage* __other) noexcept + { + _Move_impl<_Resource>(__object, __other, __wrapper_type<_Wrapper_type>{}); + } + + template + static void _Copy_impl( + _AnyResourceStorage* __object, const _AnyResourceStorage* __other, __wrapper_type<_WrapperType::_Owning>) noexcept + { + _CCCL_IF_CONSTEXPR (_IsSmall<_Resource>()) + { + ::new (static_cast(__object->__buf_)) _Resource(*_Any_resource_cast<_Resource>(__other)); + } + else + { + __object->__ptr_ = new _Resource(*_Any_resource_cast<_Resource>(__other)); + } + } + + template + static void + _Copy_impl(_AnyResourceStorage*, const _AnyResourceStorage*, __wrapper_type<_WrapperType::_Reference>) noexcept + {} + + template + static void _Copy(_AnyResourceStorage* __object, const _AnyResourceStorage* __other) + { + _Copy_impl<_Resource>(__object, __other, __wrapper_type<_Wrapper_type>{}); + } + + _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type, _WrapperType _Wrapper_type) + _CCCL_REQUIRES((_Alloc_type == _AllocType::_Default)) + static constexpr _Alloc_vtable _Create() noexcept + { + return {_IsSmall<_Resource>(), + &_Resource_vtable_builder::_Alloc<_Resource>, + &_Resource_vtable_builder::_Dealloc<_Resource>, + &_Resource_vtable_builder::_Equal<_Resource>, + &_Resource_vtable_builder::_Destroy<_Resource, _Wrapper_type>, + &_Resource_vtable_builder::_Move<_Resource, _Wrapper_type>, + &_Resource_vtable_builder::_Copy<_Resource, _Wrapper_type>}; + } + + _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type, _WrapperType _Wrapper_type) + _CCCL_REQUIRES((_Alloc_type == _AllocType::_Async)) + static constexpr _Async_alloc_vtable _Create() noexcept + { + return {_IsSmall<_Resource>(), + &_Resource_vtable_builder::_Alloc<_Resource>, + &_Resource_vtable_builder::_Dealloc<_Resource>, + &_Resource_vtable_builder::_Equal<_Resource>, + &_Resource_vtable_builder::_Destroy<_Resource, _Wrapper_type>, + &_Resource_vtable_builder::_Move<_Resource, _Wrapper_type>, + &_Resource_vtable_builder::_Copy<_Resource, _Wrapper_type>, + &_Resource_vtable_builder::_Alloc_async<_Resource>, + &_Resource_vtable_builder::_Dealloc_async<_Resource>}; + } +}; + +template +using __property_fn_t = __property_value_t<_Property> (*)(const void*); + +template +struct _Property_vtable +{ + __property_fn_t<_Property> __property_fn = nullptr; + + constexpr _Property_vtable(__property_fn_t<_Property> __property_fn_) noexcept + : __property_fn(__property_fn_) + {} +}; + +template <_AllocType _Alloc_type, class... _Properties> +class basic_resource_ref; + +template +struct _Resource_vtable : public _Property_vtable<_Properties>... +{ + constexpr _Resource_vtable(__property_fn_t<_Properties>... __property_fn_) noexcept + : _Property_vtable<_Properties>(__property_fn_)... + {} + + template + constexpr _Resource_vtable(const _Resource_vtable<_OtherProperties...>& __other) noexcept + : _Property_vtable<_Properties>(__other._Property_vtable<_Properties>::__property_fn)... + {} + + template + static constexpr _Resource_vtable _Create() noexcept + { + return {&_Resource_vtable_builder::_Get_property<_Resource, _Properties>...}; + } +}; + +template +struct _Filtered; + +template +struct _Property_filter +{ + template + using _Filtered_properties = + typename _Filtered<_Properties...>::_Filtered_vtable::template _Append_property<_Property>; +}; + +template <> +struct _Property_filter +{ + template + using _Filtered_properties = typename _Filtered<_Properties...>::_Filtered_vtable; +}; + +template +struct _Filtered<_Property, _Properties...> +{ + using _Filtered_vtable = typename _Property_filter< + property_with_value<_Property> && !_CUDA_VSTD::__is_included_in_v<_Property, _Properties...>>:: + template _Filtered_properties<_Property, _Properties...>; + + template + using _Append_property = _Filtered<_OtherPropery, _Property, _Properties...>; + + using _Vtable = _Resource_vtable<_Property, _Properties...>; +}; + +template <> +struct _Filtered<> +{ + using _Filtered_vtable = _Filtered<>; + + template + using _Append_property = _Filtered<_OtherPropery>; + + using _Vtable = _Resource_vtable<>; +}; + +template +using _Filtered_vtable = typename _Filtered<_Properties...>::_Filtered_vtable::_Vtable; + +template <_WrapperType _Wrapper_type> +using __alloc_object_storage_t = _CUDA_VSTD::_If<_Wrapper_type == _WrapperType::_Reference, void*, _AnyResourceStorage>; + +struct _Resource_ref_base +{}; + +template +struct _CCCL_DECLSPEC_EMPTY_BASES _Alloc_base : _Resource_ref_base +{ + static_assert(_CUDA_VSTD::is_base_of_v<_Alloc_vtable, _Vtable>, ""); + + _Alloc_base(void* __object_, const _Vtable* __static_vtabl_) noexcept + : __object(__object_) + , __static_vtable(__static_vtabl_) + {} + + _CCCL_NODISCARD void* allocate(size_t __bytes, size_t __alignment = alignof(_CUDA_VSTD::max_align_t)) + { + return __static_vtable->__alloc_fn(_Get_object(), __bytes, __alignment); + } + + void deallocate(void* _Ptr, size_t __bytes, size_t __alignment = alignof(_CUDA_VSTD::max_align_t)) noexcept + { + __static_vtable->__dealloc_fn(_Get_object(), _Ptr, __bytes, __alignment); + } + +protected: + static _CCCL_FORCEINLINE void* _Get_object_(bool, void* __object) noexcept + { + return __object; + } + + static _CCCL_FORCEINLINE void* _Get_object_(const bool __is_small, const _AnyResourceStorage& __object) noexcept + { + const void* __pv = __is_small ? __object.__buf_ : __object.__ptr_; + return const_cast(__pv); + } + + void* _Get_object() const noexcept + { + return _Get_object_(__static_vtable->__is_small, this->__object); + } + + __alloc_object_storage_t<_Wrapper_type> __object{}; + const _Vtable* __static_vtable = nullptr; +}; + +template +struct _Async_alloc_base : public _Alloc_base<_Vtable, _Wrapper_type> +{ + static_assert(_CUDA_VSTD::is_base_of_v<_Async_alloc_vtable, _Vtable>, ""); + + _Async_alloc_base(void* __object_, const _Vtable* __static_vtabl_) noexcept + : _Alloc_base<_Vtable, _Wrapper_type>(__object_, __static_vtabl_) + {} + + _CCCL_NODISCARD void* allocate_async(size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream) + { + return this->__static_vtable->__async_alloc_fn(this->_Get_object(), __bytes, __alignment, __stream); + } + + _CCCL_NODISCARD void* allocate_async(size_t __bytes, ::cuda::stream_ref __stream) + { + return this->__static_vtable->__async_alloc_fn(this->_Get_object(), __bytes, alignof(max_align_t), __stream); + } + + void deallocate_async(void* _Ptr, size_t __bytes, ::cuda::stream_ref __stream) + { + this->__static_vtable->__async_dealloc_fn(this->_Get_object(), _Ptr, __bytes, alignof(max_align_t), __stream); + } + + void deallocate_async(void* _Ptr, size_t __bytes, size_t __alignment, ::cuda::stream_ref __stream) + { + this->__static_vtable->__async_dealloc_fn(this->_Get_object(), _Ptr, __bytes, __alignment, __stream); + } +}; + +template +_CCCL_CONCEPT _Is_resource_ref = _CUDA_VSTD::convertible_to<_Resource&, _Resource_ref_base>; + +template <_AllocType _Alloc_type, _WrapperType _Wrapper_type> +using _Resource_base = + _CUDA_VSTD::_If<_Alloc_type == _AllocType::_Default, + _Alloc_base<_Alloc_vtable, _Wrapper_type>, + _Async_alloc_base<_Async_alloc_vtable, _Wrapper_type>>; + +template <_AllocType _Alloc_type> +using _Vtable_store = _CUDA_VSTD::_If<_Alloc_type == _AllocType::_Default, _Alloc_vtable, _Async_alloc_vtable>; + +template <_AllocType _Alloc_type, _WrapperType _Wrapper_type, class _Resource> +_CCCL_INLINE_VAR constexpr _Vtable_store<_Alloc_type> __alloc_vtable = + _Resource_vtable_builder::template _Create<_Resource, _Alloc_type, _Wrapper_type>(); + +struct _Resource_ref_helper +{ + //! This is used from \c basic_any_resource to make it convertible to a \c basic_resource_ref + template <_AllocType _Alloc_type, class... _Properties> + static basic_resource_ref<_Alloc_type, _Properties...> + _Construct(void* __object, + const _Vtable_store<_Alloc_type>* __static_vtable, + _Filtered_vtable<_Properties...> __properties) noexcept + { + return basic_resource_ref<_Alloc_type, _Properties...>(__object, __static_vtable, __properties); + } +}; + +template <_AllocType _Alloc_type, class... _Properties> +class basic_resource_ref + : public _Resource_base<_Alloc_type, _WrapperType::_Reference> + , private _Filtered_vtable<_Properties...> +{ +private: + static_assert(__contains_execution_space_property<_Properties...>, + "The properties of cuda::mr::basic_resource_ref must contain at least one execution space property!"); + + template <_AllocType, class...> + friend class basic_resource_ref; + + template + friend struct _Resource_vtable; + + friend struct _Resource_ref_helper; + + using __vtable = _Filtered_vtable<_Properties...>; + + //! @brief Checks whether \c _OtherProperties is a true superset of \c _Properties, accounting for host_accessible + template + static constexpr bool __properties_match = + _CUDA_VSTD::__type_set_contains_v<_CUDA_VSTD::__make_type_set<_OtherProperties...>, _Properties...>; + + //! @brief Constructs a \c basic_resource_ref from a void*, a resource vtable ptr, and a vtable + //! for the properties. This is used to create a \c basic_resource_ref from a \c basic_any_resource. + explicit basic_resource_ref( + void* __object_, const _Vtable_store<_Alloc_type>* __static_vtable, __vtable __properties) noexcept + : _Resource_base<_Alloc_type, _WrapperType::_Reference>(__object_, __static_vtable) + , __vtable(__properties) + {} + +public: + //! @brief Constructs a \c basic_resource_ref from a type that satisfies the \c resource or \c async_resource concept + //! as well as all properties + //! @param __res The resource to be wrapped within the \c basic_resource_ref + _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type2 = _Alloc_type) + _CCCL_REQUIRES((!_Is_resource_ref<_Resource>) _CCCL_AND(_Alloc_type2 == _AllocType::_Default) + _CCCL_AND resource_with<_Resource, _Properties...>) + basic_resource_ref(_Resource& __res) noexcept + : _Resource_base<_Alloc_type, _WrapperType::_Reference>( + _CUDA_VSTD::addressof(__res), &__alloc_vtable<_Alloc_type, _WrapperType::_Reference, _Resource>) + , __vtable(__vtable::template _Create<_Resource>()) + {} + + //! @brief Constructs a \c resource_ref from a type that satisfies the \c async_resource concept as well as all + //! properties. This ignores the async interface of the passed in resource + //! @param __res The resource to be wrapped within the \c resource_ref + _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type2 = _Alloc_type) + _CCCL_REQUIRES((!_Is_resource_ref<_Resource>) _CCCL_AND(_Alloc_type2 == _AllocType::_Async) + _CCCL_AND async_resource_with<_Resource, _Properties...>) + basic_resource_ref(_Resource& __res) noexcept + : _Resource_base<_Alloc_type, _WrapperType::_Reference>( + _CUDA_VSTD::addressof(__res), &__alloc_vtable<_Alloc_type, _WrapperType::_Reference, _Resource>) + , __vtable(__vtable::template _Create<_Resource>()) + {} + + //! @brief Constructs a \c basic_resource_ref from a type that satisfies the \c resource or \c async_resource concept + //! as well as all properties + //! @param __res Pointer to a resource to be wrapped within the \c basic_resource_ref + _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type2 = _Alloc_type) + _CCCL_REQUIRES((!_Is_resource_ref<_Resource>) _CCCL_AND(_Alloc_type2 == _AllocType::_Default) + _CCCL_AND resource_with<_Resource, _Properties...>) + basic_resource_ref(_Resource* __res) noexcept + : _Resource_base<_Alloc_type, _WrapperType::_Reference>( + __res, &__alloc_vtable<_Alloc_type, _WrapperType::_Reference, _Resource>) + , __vtable(__vtable::template _Create<_Resource>()) + {} + + //! @brief Constructs a \c resource_ref from a type that satisfies the \c async_resource concept as well as all + //! properties. This ignores the async interface of the passed in resource + //! @param __res Pointer to a resource to be wrapped within the \c resource_ref + _CCCL_TEMPLATE(class _Resource, _AllocType _Alloc_type2 = _Alloc_type) + _CCCL_REQUIRES((!_Is_resource_ref<_Resource>) _CCCL_AND(_Alloc_type2 == _AllocType::_Async) + _CCCL_AND async_resource_with<_Resource, _Properties...>) + basic_resource_ref(_Resource* __res) noexcept + : _Resource_base<_Alloc_type, _WrapperType::_Reference>( + __res, &__alloc_vtable<_Alloc_type, _WrapperType::_Reference, _Resource>) + , __vtable(__vtable::template _Create<_Resource>()) + {} + + //! @brief Conversion from a \c basic_resource_ref with the same set of properties but in a different order + //! @param __ref The other \c basic_resource_ref + _CCCL_TEMPLATE(class... _OtherProperties) + _CCCL_REQUIRES(__properties_match<_OtherProperties...>) + basic_resource_ref(basic_resource_ref<_Alloc_type, _OtherProperties...> __ref) noexcept + : _Resource_base<_Alloc_type, _WrapperType::_Reference>(__ref.__object, __ref.__static_vtable) + , __vtable(static_cast&>(__ref)) + {} + + //! @brief Conversion from a \c async_resource_ref with the same set of properties but in a different order to a + //! \c resource_ref + //! @param __ref The other \c async_resource_ref + _CCCL_TEMPLATE(_AllocType _OtherAllocType, class... _OtherProperties) + _CCCL_REQUIRES((_OtherAllocType == _AllocType::_Async) _CCCL_AND(_OtherAllocType != _Alloc_type) + _CCCL_AND __properties_match<_OtherProperties...>) + basic_resource_ref(basic_resource_ref<_OtherAllocType, _OtherProperties...> __ref) noexcept + : _Resource_base<_Alloc_type, _WrapperType::_Reference>(__ref.__object, __ref.__static_vtable) + , __vtable(static_cast&>(__ref)) + {} + + //! @brief Equality comparison between two \c basic_resource_ref + //! @param __lhs The first \c basic_resource_ref + //! @param __rhs The second \c basic_resource_ref + //! @return Checks whether both resources have the same equality function stored in their vtable and if so returns + //! the result of that equality comparison. Otherwise returns false. + _CCCL_NODISCARD_FRIEND bool operator==(const basic_resource_ref& __lhs, const basic_resource_ref& __rhs) + { + // BUGBUG: comparing function pointers like this can lead to false negatives: + return (__lhs.__static_vtable->__equal_fn == __rhs.__static_vtable->__equal_fn) + && __lhs.__static_vtable->__equal_fn(__lhs.__object, __rhs.__object); + } + + //! @overload + _CCCL_TEMPLATE(class... _OtherProperties) + _CCCL_REQUIRES((sizeof...(_Properties) == sizeof...(_OtherProperties)) + _CCCL_AND __properties_match<_OtherProperties...>) + _CCCL_NODISCARD bool operator==(const basic_resource_ref<_Alloc_type, _OtherProperties...>& __rhs) const + { + // BUGBUG: comparing function pointers like this can lead to false negatives: + return (this->__static_vtable->__equal_fn == __rhs.__static_vtable->__equal_fn) + && this->__static_vtable->__equal_fn(this->__object, __rhs.__object); + } + + //! @brief Inequality comparison between two \c basic_resource_ref + //! @param __lhs The first \c basic_resource_ref + //! @param __rhs The second \c basic_resource_ref + //! @return Checks whether both resources have the same equality function stored in their vtable and if so returns + //! the inverse result of that equality comparison. Otherwise returns true. + _CCCL_NODISCARD_FRIEND bool operator!=(const basic_resource_ref& __lhs, const basic_resource_ref& __rhs) + { + return !(__lhs == __rhs); + } + + //! @overload + _CCCL_TEMPLATE(class... _OtherProperties) + _CCCL_REQUIRES((sizeof...(_Properties) == sizeof...(_OtherProperties)) + _CCCL_AND __properties_match<_OtherProperties...>) + _CCCL_NODISCARD bool operator!=(const basic_resource_ref<_Alloc_type, _OtherProperties...>& __rhs) const + { + return !(*this == __rhs); + } + + //! @brief Forwards the stateless properties + _CCCL_TEMPLATE(class _Property) + _CCCL_REQUIRES((!property_with_value<_Property>) _CCCL_AND _CUDA_VSTD::__is_included_in_v<_Property, _Properties...>) + friend void get_property(const basic_resource_ref&, _Property) noexcept {} + + //! @brief Forwards the stateful properties + _CCCL_TEMPLATE(class _Property) + _CCCL_REQUIRES(property_with_value<_Property> _CCCL_AND _CUDA_VSTD::__is_included_in_v<_Property, _Properties...>) + _CCCL_NODISCARD_FRIEND __property_value_t<_Property> get_property(const basic_resource_ref& __res, _Property) noexcept + { + return __res._Property_vtable<_Property>::__property_fn(__res.__object); + } +}; + +//! @brief Type erased wrapper around a `resource` that satisfies \tparam _Properties +//! @tparam _Properties The properties that any resource wrapped within the `resource_ref` needs to satisfy +template +using resource_ref = basic_resource_ref<_AllocType::_Default, _Properties...>; + +//! @brief Type erased wrapper around a `async_resource` that satisfies \tparam _Properties +//! @tparam _Properties The properties that any async resource wrapped within the `async_resource_ref` needs to satisfy +template +using async_resource_ref = basic_resource_ref<_AllocType::_Async, _Properties...>; + +_LIBCUDACXX_END_NAMESPACE_CUDA_MR + +# endif // _CCCL_STD_VER >= 2014 + +#endif // !_CCCL_COMPILER(MSVC2017) && LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE + +#endif //_CUDA__MEMORY_RESOURCE_RESOURCE_REF_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__type_traits/is_floating_point.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__type_traits/is_floating_point.h new file mode 100644 index 0000000000000000000000000000000000000000..e253315a67227a463fc493053b8b50a5f93d003e --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/__type_traits/is_floating_point.h @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef __CUDA__TYPE_TRAITS_IS_FLOATING_POINT_H +#define __CUDA__TYPE_TRAITS_IS_FLOATING_POINT_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA + +template +struct _CCCL_TYPE_VISIBILITY_DEFAULT is_floating_point + : _CUDA_VSTD::bool_constant<_CUDA_VSTD::is_floating_point<_CUDA_VSTD::remove_cv_t<_Tp>>::value + || _CUDA_VSTD::__is_extended_floating_point<_CUDA_VSTD::remove_cv_t<_Tp>>::value> +{}; + +#if !defined(_CCCL_NO_VARIABLE_TEMPLATES) +template +_CCCL_INLINE_VAR constexpr bool is_floating_point_v = + _CUDA_VSTD::is_floating_point_v<_CUDA_VSTD::remove_cv_t<_Tp>> + || _CUDA_VSTD::__is_extended_floating_point_v<_CUDA_VSTD::remove_cv_t<_Tp>>; +#endif // !_CCCL_NO_VARIABLE_TEMPLATES + +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif // __CUDA__TYPE_TRAITS_IS_FLOATING_POINT_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/std/__memory/temporary_buffer.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/std/__memory/temporary_buffer.h new file mode 100644 index 0000000000000000000000000000000000000000..232003ab1ed978f5fc4c7784048c790b889ff9a8 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/cuda/std/__memory/temporary_buffer.h @@ -0,0 +1,89 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___MEMORY_TEMPORARY_BUFFER_H +#define _LIBCUDACXX___MEMORY_TEMPORARY_BUFFER_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_CCCL_NODISCARD _LIBCUDACXX_NO_CFI _LIBCUDACXX_HIDE_FROM_ABI pair<_Tp*, ptrdiff_t> +get_temporary_buffer(ptrdiff_t __n) noexcept +{ + pair<_Tp*, ptrdiff_t> __r(0, 0); + const ptrdiff_t __m = + (~ptrdiff_t(0) ^ ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) / sizeof(_Tp); + if (__n > __m) + { + __n = __m; + } + while (__n > 0) + { +#if !defined(_LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION) + if (__is_overaligned_for_new(_LIBCUDACXX_ALIGNOF(_Tp))) + { + _CUDA_VSTD::align_val_t __al = _CUDA_VSTD::align_val_t(_CUDA_VSTD::alignment_of<_Tp>::value); + __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al)); + } + else + { + __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); + } +#else // ^^^ !_LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION ^^^ / vvv _LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION vvv + if (__is_overaligned_for_new(_LIBCUDACXX_ALIGNOF(_Tp))) + { + // Since aligned operator new is unavailable, return an empty + // buffer rather than one with invalid alignment. + return __r; + } + + __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); +#endif // _LIBCUDACXX_HAS_NO_ALIGNED_ALLOCATION + + if (__r.first) + { + __r.second = __n; + break; + } + __n /= 2; + } + return __r; +} + +template +_LIBCUDACXX_HIDE_FROM_ABI void return_temporary_buffer(_Tp* __p) noexcept +{ + _CUDA_VSTD::__cccl_deallocate_unsized((void*) __p, _LIBCUDACXX_ALIGNOF(_Tp)); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___MEMORY_TEMPORARY_BUFFER_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__preprocessor b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__preprocessor new file mode 100644 index 0000000000000000000000000000000000000000..15fe84eabd7193c9284373193d7f41f8e5a24668 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__preprocessor @@ -0,0 +1,176 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#if defined(__GNUC__) +# pragma GCC system_header +#endif + +// For all compilers and dialects this header defines: +// _NV_EVAL +// _NV_IF +// _NV_CONCAT_EVAL +// For C++11 and up it defines: +// _NV_STRIP_PAREN +// _NV_DISPATCH_N_ARY +// _NV_FIRST_ARG +// _NV_REMOVE_PAREN + +#if defined(_NV_TARGET_CPP11) +# define _NV_EVAL1(...) __VA_ARGS__ +# define _NV_EVAL(...) _NV_EVAL1(__VA_ARGS__) +#else +# define _NV_EVAL1(x) x +# define _NV_EVAL(x) _NV_EVAL1(x) +#endif // C++11 + +#define _NV_CONCAT_EVAL1(l, r) _NV_EVAL(l##r) +#define _NV_CONCAT_EVAL(l, r) _NV_CONCAT_EVAL1(l, r) + +#define _NV_IF_0(t, f) f +#define _NV_IF_1(t, f) t + +#define _NV_IF_BIT(b) _NV_EVAL(_NV_IF_##b) +#define _NV_IF__EVAL(fn, t, f) _NV_EVAL(fn(t, f)) +#define _NV_IF_EVAL(cond, t, f) _NV_IF__EVAL(_NV_IF_BIT(cond), t, f) + +#define _NV_IF1(cond, t, f) _NV_IF_EVAL(cond, t, f) +#define _NV_IF(cond, t, f) _NV_IF1(_NV_EVAL(cond), _NV_EVAL(t), _NV_EVAL(f)) + +#if defined(_NV_TARGET_CPP11) + +// The below mechanisms were derived from: https://gustedt.wordpress.com/2010/06/08/detect-empty-macro-arguments/ + +# define _NV_ARG32(...) _NV_EVAL(_NV_ARG32_0(__VA_ARGS__)) +# define _NV_ARG32_0( \ + _0, \ + _1, \ + _2, \ + _3, \ + _4, \ + _5, \ + _6, \ + _7, \ + _8, \ + _9, \ + _10, \ + _11, \ + _12, \ + _13, \ + _14, \ + _15, \ + _16, \ + _17, \ + _18, \ + _19, \ + _20, \ + _21, \ + _22, \ + _23, \ + _24, \ + _25, \ + _26, \ + _27, \ + _28, \ + _29, \ + _30, \ + _31, \ + ...) \ + _31 + +# define _NV_HAS_COMMA(...) \ + _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) + +# define _NV_TRIGGER_PARENTHESIS_(...) , + +# define _NV_ISEMPTY(...) \ + _NV_ISEMPTY0(/* test if there is just one argument, eventually an empty \ + one */ \ + _NV_EVAL(_NV_HAS_COMMA(__VA_ARGS__)), /* test if _TRIGGER_PARENTHESIS_ together with the argument \ + adds a comma */ \ + _NV_EVAL(_NV_HAS_COMMA(_NV_TRIGGER_PARENTHESIS_ __VA_ARGS__)), /* test if the argument together with \ + a parenthesis adds a comma */ \ + _NV_EVAL(_NV_HAS_COMMA(__VA_ARGS__(/*empty*/))), /* test if placing it between _TRIGGER_PARENTHESIS_ \ + and the parenthesis adds a comma */ \ + _NV_EVAL(_NV_HAS_COMMA(_NV_TRIGGER_PARENTHESIS_ __VA_ARGS__(/*empty*/)))) + +# define _NV_PASTE5(_0, _1, _2, _3, _4) _0##_1##_2##_3##_4 +# define _NV_ISEMPTY0(_0, _1, _2, _3) _NV_HAS_COMMA(_NV_PASTE5(_NV_IS_EMPTY_CASE_, _0, _1, _2, _3)) +# define _NV_IS_EMPTY_CASE_0001 , + +# define _NV_REMOVE_PAREN(...) _NV_REMOVE_PAREN1(__VA_ARGS__) +# define _NV_REMOVE_PAREN1(...) \ + _NV_STRIP_PAREN(_NV_IF(_NV_TEST_PAREN(__VA_ARGS__), (_NV_STRIP_PAREN(__VA_ARGS__)), (__VA_ARGS__))) + +# define _NV_STRIP_PAREN2(...) __VA_ARGS__ +# define _NV_STRIP_PAREN1(...) _NV_STRIP_PAREN2 __VA_ARGS__ +# define _NV_STRIP_PAREN(...) _NV_STRIP_PAREN1(__VA_ARGS__) + +# define _NV_TEST_PAREN(...) _NV_TEST_PAREN1(__VA_ARGS__) +# define _NV_TEST_PAREN1(...) _NV_TEST_PAREN2(_NV_TEST_PAREN_DUMMY __VA_ARGS__) +# define _NV_TEST_PAREN2(...) _NV_TEST_PAREN3(_NV_CONCAT_EVAL(_, __VA_ARGS__)) +# define _NV_TEST_PAREN3(...) _NV_EVAL(_NV_FIRST_ARG(__VA_ARGS__)) + +# define __NV_PAREN_YES 1 +# define __NV_PAREN_NO 0 + +# define _NV_TEST_PAREN_DUMMY(...) _NV_PAREN_YES +# define __NV_TEST_PAREN_DUMMY __NV_PAREN_NO, + +# define _NV_FIRST_ARG1(x, ...) x +# define _NV_FIRST_ARG(x, ...) _NV_FIRST_ARG1(x) + +# define _NV_REMOVE_FIRST_ARGS1(...) __VA_ARGS__ +# define _NV_REMOVE_FIRST_ARGS(x, ...) _NV_REMOVE_FIRST_ARGS1(__VA_ARGS__) + +# define _NV_NUM_ARGS(...) _NV_NUM_ARGS0(__VA_ARGS__) +# define _NV_NUM_ARGS0(...) _NV_EVAL(_NV_NUM_ARGS1(__VA_ARGS__)) +# define _NV_NUM_ARGS1(...) _NV_IF(_NV_ISEMPTY(__VA_ARGS__), 0, _NV_NUM_ARGS2(__VA_ARGS__)) +# define _NV_NUM_ARGS2(...) \ + _NV_ARG32( \ + __VA_ARGS__, \ + 31, \ + 30, \ + 29, \ + 28, \ + 27, \ + 26, \ + 25, \ + 24, \ + 23, \ + 22, \ + 21, \ + 20, \ + 19, \ + 18, \ + 17, \ + 16, \ + 15, \ + 14, \ + 13, \ + 12, \ + 11, \ + 10, \ + 9, \ + 8, \ + 7, \ + 6, \ + 5, \ + 4, \ + 3, \ + 2, \ + 1, \ + 0) + +# define _NV_DISPATCH_N_IMPL1(name, ...) _NV_EVAL(name(__VA_ARGS__)) +# define _NV_DISPATCH_N_IMPL0(depth, name, ...) _NV_DISPATCH_N_IMPL1(_NV_CONCAT_EVAL(name, depth), __VA_ARGS__) +# define _NV_DISPATCH_N_IMPL(name, ...) _NV_DISPATCH_N_IMPL0(_NV_NUM_ARGS(__VA_ARGS__), name, __VA_ARGS__) +# define _NV_DISPATCH_N_ARY(name, ...) _NV_DISPATCH_N_IMPL(name, __VA_ARGS__) + +#endif // C++11 diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__target_macros b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__target_macros new file mode 100644 index 0000000000000000000000000000000000000000..2de10fc8ec477b476b8bcb61aaf8cf8956a20864 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/libcudacxx/nv/detail/__target_macros @@ -0,0 +1,610 @@ +//===----------------------------------------------------------------------===// +// +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +#ifndef _NV__TARGET_MACROS +#define _NV__TARGET_MACROS + +#include + +#if defined(__GNUC__) +# pragma GCC system_header +#endif + +#define _NV_TARGET_ARCH_TO_SELECTOR_350 nv::target::sm_35 +#define _NV_TARGET_ARCH_TO_SELECTOR_370 nv::target::sm_37 +#define _NV_TARGET_ARCH_TO_SELECTOR_500 nv::target::sm_50 +#define _NV_TARGET_ARCH_TO_SELECTOR_520 nv::target::sm_52 +#define _NV_TARGET_ARCH_TO_SELECTOR_530 nv::target::sm_53 +#define _NV_TARGET_ARCH_TO_SELECTOR_600 nv::target::sm_60 +#define _NV_TARGET_ARCH_TO_SELECTOR_610 nv::target::sm_61 +#define _NV_TARGET_ARCH_TO_SELECTOR_620 nv::target::sm_62 +#define _NV_TARGET_ARCH_TO_SELECTOR_700 nv::target::sm_70 +#define _NV_TARGET_ARCH_TO_SELECTOR_720 nv::target::sm_72 +#define _NV_TARGET_ARCH_TO_SELECTOR_750 nv::target::sm_75 +#define _NV_TARGET_ARCH_TO_SELECTOR_800 nv::target::sm_80 +#define _NV_TARGET_ARCH_TO_SELECTOR_860 nv::target::sm_86 +#define _NV_TARGET_ARCH_TO_SELECTOR_870 nv::target::sm_87 +#define _NV_TARGET_ARCH_TO_SELECTOR_890 nv::target::sm_89 +#define _NV_TARGET_ARCH_TO_SELECTOR_900 nv::target::sm_90 +#define _NV_TARGET_ARCH_TO_SELECTOR_1000 nv::target::sm_100 +#define _NV_TARGET_ARCH_TO_SELECTOR_1010 nv::target::sm_101 +#define _NV_TARGET_ARCH_TO_SELECTOR_1200 nv::target::sm_120 + +#define _NV_TARGET_ARCH_TO_SM_350 35 +#define _NV_TARGET_ARCH_TO_SM_370 37 +#define _NV_TARGET_ARCH_TO_SM_500 50 +#define _NV_TARGET_ARCH_TO_SM_520 52 +#define _NV_TARGET_ARCH_TO_SM_530 53 +#define _NV_TARGET_ARCH_TO_SM_600 60 +#define _NV_TARGET_ARCH_TO_SM_610 61 +#define _NV_TARGET_ARCH_TO_SM_620 62 +#define _NV_TARGET_ARCH_TO_SM_700 70 +#define _NV_TARGET_ARCH_TO_SM_720 72 +#define _NV_TARGET_ARCH_TO_SM_750 75 +#define _NV_TARGET_ARCH_TO_SM_800 80 +#define _NV_TARGET_ARCH_TO_SM_860 86 +#define _NV_TARGET_ARCH_TO_SM_870 87 +#define _NV_TARGET_ARCH_TO_SM_890 89 +#define _NV_TARGET_ARCH_TO_SM_900 90 +#define _NV_TARGET_ARCH_TO_SM_1000 100 +#define _NV_TARGET_ARCH_TO_SM_1010 101 +#define _NV_TARGET_ARCH_TO_SM_1200 120 + +// Only enable when compiling for CUDA/stdpar +#if defined(_NV_COMPILER_NVCXX) && defined(_NVHPC_CUDA) + +# define _NV_TARGET_VAL_SM_35 nv::target::sm_35 +# define _NV_TARGET_VAL_SM_37 nv::target::sm_37 +# define _NV_TARGET_VAL_SM_50 nv::target::sm_50 +# define _NV_TARGET_VAL_SM_52 nv::target::sm_52 +# define _NV_TARGET_VAL_SM_53 nv::target::sm_53 +# define _NV_TARGET_VAL_SM_60 nv::target::sm_60 +# define _NV_TARGET_VAL_SM_61 nv::target::sm_61 +# define _NV_TARGET_VAL_SM_62 nv::target::sm_62 +# define _NV_TARGET_VAL_SM_70 nv::target::sm_70 +# define _NV_TARGET_VAL_SM_72 nv::target::sm_72 +# define _NV_TARGET_VAL_SM_75 nv::target::sm_75 +# define _NV_TARGET_VAL_SM_80 nv::target::sm_80 +# define _NV_TARGET_VAL_SM_86 nv::target::sm_86 +# define _NV_TARGET_VAL_SM_87 nv::target::sm_87 +# define _NV_TARGET_VAL_SM_89 nv::target::sm_89 +# define _NV_TARGET_VAL_SM_90 nv::target::sm_90 +# define _NV_TARGET_VAL_SM_100 nv::target::sm_100 +# define _NV_TARGET_VAL_SM_101 nv::target::sm_101 +# define _NV_TARGET_VAL_SM_120 nv::target::sm_120 + +# define _NV_TARGET___NV_IS_HOST nv::target::is_host +# define _NV_TARGET___NV_IS_DEVICE nv::target::is_device + +# define _NV_TARGET___NV_ANY_TARGET (nv::target::any_target) +# define _NV_TARGET___NV_NO_TARGET (nv::target::no_target) + +# if defined(NV_TARGET_SM_INTEGER_LIST) +# define NV_TARGET_MINIMUM_SM_SELECTOR _NV_FIRST_ARG(NV_TARGET_SM_SELECTOR_LIST) +# define NV_TARGET_MINIMUM_SM_INTEGER _NV_FIRST_ARG(NV_TARGET_SM_INTEGER_LIST) +# define __CUDA_MINIMUM_ARCH__ _NV_CONCAT_EVAL(_NV_FIRST_ARG(NV_TARGET_SM_INTEGER_LIST), 0) +# endif + +# define _NV_TARGET_PROVIDES(q) nv::target::provides(q) +# define _NV_TARGET_IS_EXACTLY(q) nv::target::is_exactly(q) + +#elif defined(_NV_COMPILER_NVCC) || defined(_NV_COMPILER_CLANG_CUDA) + +# define _NV_TARGET_VAL_SM_35 350 +# define _NV_TARGET_VAL_SM_37 370 +# define _NV_TARGET_VAL_SM_50 500 +# define _NV_TARGET_VAL_SM_52 520 +# define _NV_TARGET_VAL_SM_53 530 +# define _NV_TARGET_VAL_SM_60 600 +# define _NV_TARGET_VAL_SM_61 610 +# define _NV_TARGET_VAL_SM_62 620 +# define _NV_TARGET_VAL_SM_70 700 +# define _NV_TARGET_VAL_SM_72 720 +# define _NV_TARGET_VAL_SM_75 750 +# define _NV_TARGET_VAL_SM_80 800 +# define _NV_TARGET_VAL_SM_86 860 +# define _NV_TARGET_VAL_SM_87 870 +# define _NV_TARGET_VAL_SM_89 890 +# define _NV_TARGET_VAL_SM_90 900 +# define _NV_TARGET_VAL_SM_100 1000 +# define _NV_TARGET_VAL_SM_101 1010 +# define _NV_TARGET_VAL_SM_120 1200 + +# if defined(__CUDA_ARCH__) +# define _NV_TARGET_VAL __CUDA_ARCH__ +# define NV_TARGET_MINIMUM_SM_SELECTOR _NV_CONCAT_EVAL(_NV_TARGET_ARCH_TO_SELECTOR_, __CUDA_ARCH__) +# define NV_TARGET_MINIMUM_SM_INTEGER _NV_CONCAT_EVAL(_NV_TARGET_ARCH_TO_SM_, __CUDA_ARCH__) +# define __CUDA_MINIMUM_ARCH__ __CUDA_ARCH__ +# endif + +# if defined(__CUDA_ARCH__) +# define _NV_TARGET_IS_HOST 0 +# define _NV_TARGET_IS_DEVICE 1 +# else +# define _NV_TARGET_IS_HOST 1 +# define _NV_TARGET_IS_DEVICE 0 +# endif + +# if defined(_NV_TARGET_VAL) +# define _NV_DEVICE_CHECK(q) (q) +# else +# define _NV_DEVICE_CHECK(q) (0) +# endif + +# define _NV_TARGET_PROVIDES(q) _NV_DEVICE_CHECK(_NV_TARGET_VAL >= q) +# define _NV_TARGET_IS_EXACTLY(q) _NV_DEVICE_CHECK(_NV_TARGET_VAL == q) + +// NVCC/NVCXX not being used, only host dispatches allowed +#else + +# define _NV_COMPILER_NVCC + +# define _NV_TARGET_VAL_SM_35 350 +# define _NV_TARGET_VAL_SM_37 370 +# define _NV_TARGET_VAL_SM_50 500 +# define _NV_TARGET_VAL_SM_52 520 +# define _NV_TARGET_VAL_SM_53 530 +# define _NV_TARGET_VAL_SM_60 600 +# define _NV_TARGET_VAL_SM_61 610 +# define _NV_TARGET_VAL_SM_62 620 +# define _NV_TARGET_VAL_SM_70 700 +# define _NV_TARGET_VAL_SM_72 720 +# define _NV_TARGET_VAL_SM_75 750 +# define _NV_TARGET_VAL_SM_80 800 +# define _NV_TARGET_VAL_SM_86 860 +# define _NV_TARGET_VAL_SM_87 870 +# define _NV_TARGET_VAL_SM_89 890 +# define _NV_TARGET_VAL_SM_90 900 +# define _NV_TARGET_VAL_SM_100 1000 +# define _NV_TARGET_VAL_SM_101 1010 +# define _NV_TARGET_VAL_SM_120 1200 + +# define _NV_TARGET_VAL 0 + +# define _NV_TARGET_IS_HOST 1 +# define _NV_TARGET_IS_DEVICE 0 + +# define _NV_DEVICE_CHECK(q) (false) + +# define _NV_TARGET_PROVIDES(q) _NV_DEVICE_CHECK(_NV_TARGET_VAL >= q) +# define _NV_TARGET_IS_EXACTLY(q) _NV_DEVICE_CHECK(_NV_TARGET_VAL == q) + +#endif + +#define _NV_TARGET___NV_PROVIDES_SM_35 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_35)) +#define _NV_TARGET___NV_PROVIDES_SM_37 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_37)) +#define _NV_TARGET___NV_PROVIDES_SM_50 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_50)) +#define _NV_TARGET___NV_PROVIDES_SM_52 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_52)) +#define _NV_TARGET___NV_PROVIDES_SM_53 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_53)) +#define _NV_TARGET___NV_PROVIDES_SM_60 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_60)) +#define _NV_TARGET___NV_PROVIDES_SM_61 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_61)) +#define _NV_TARGET___NV_PROVIDES_SM_62 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_62)) +#define _NV_TARGET___NV_PROVIDES_SM_70 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_70)) +#define _NV_TARGET___NV_PROVIDES_SM_72 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_72)) +#define _NV_TARGET___NV_PROVIDES_SM_75 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_75)) +#define _NV_TARGET___NV_PROVIDES_SM_80 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_80)) +#define _NV_TARGET___NV_PROVIDES_SM_86 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_86)) +#define _NV_TARGET___NV_PROVIDES_SM_87 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_87)) +#define _NV_TARGET___NV_PROVIDES_SM_89 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_89)) +#define _NV_TARGET___NV_PROVIDES_SM_90 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_90)) +#define _NV_TARGET___NV_PROVIDES_SM_100 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_100)) +#define _NV_TARGET___NV_PROVIDES_SM_101 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_101)) +#define _NV_TARGET___NV_PROVIDES_SM_120 (_NV_TARGET_PROVIDES(_NV_TARGET_VAL_SM_120)) + +#define _NV_TARGET___NV_IS_EXACTLY_SM_35 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_35)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_37 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_37)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_50 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_50)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_52 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_52)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_53 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_53)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_60 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_60)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_61 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_61)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_62 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_62)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_70 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_70)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_72 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_72)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_75 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_75)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_80 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_80)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_86 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_86)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_87 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_87)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_89 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_89)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_90 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_90)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_100 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_100)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_101 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_101)) +#define _NV_TARGET___NV_IS_EXACTLY_SM_120 (_NV_TARGET_IS_EXACTLY(_NV_TARGET_VAL_SM_120)) + +#define NV_PROVIDES_SM_35 __NV_PROVIDES_SM_35 +#define NV_PROVIDES_SM_37 __NV_PROVIDES_SM_37 +#define NV_PROVIDES_SM_50 __NV_PROVIDES_SM_50 +#define NV_PROVIDES_SM_52 __NV_PROVIDES_SM_52 +#define NV_PROVIDES_SM_53 __NV_PROVIDES_SM_53 +#define NV_PROVIDES_SM_60 __NV_PROVIDES_SM_60 +#define NV_PROVIDES_SM_61 __NV_PROVIDES_SM_61 +#define NV_PROVIDES_SM_62 __NV_PROVIDES_SM_62 +#define NV_PROVIDES_SM_70 __NV_PROVIDES_SM_70 +#define NV_PROVIDES_SM_72 __NV_PROVIDES_SM_72 +#define NV_PROVIDES_SM_75 __NV_PROVIDES_SM_75 +#define NV_PROVIDES_SM_80 __NV_PROVIDES_SM_80 +#define NV_PROVIDES_SM_86 __NV_PROVIDES_SM_86 +#define NV_PROVIDES_SM_87 __NV_PROVIDES_SM_87 +#define NV_PROVIDES_SM_89 __NV_PROVIDES_SM_89 +#define NV_PROVIDES_SM_90 __NV_PROVIDES_SM_90 +#define NV_PROVIDES_SM_100 __NV_PROVIDES_SM_100 +#define NV_PROVIDES_SM_101 __NV_PROVIDES_SM_101 +#define NV_PROVIDES_SM_120 __NV_PROVIDES_SM_120 + +#define NV_IS_EXACTLY_SM_35 __NV_IS_EXACTLY_SM_35 +#define NV_IS_EXACTLY_SM_37 __NV_IS_EXACTLY_SM_37 +#define NV_IS_EXACTLY_SM_50 __NV_IS_EXACTLY_SM_50 +#define NV_IS_EXACTLY_SM_52 __NV_IS_EXACTLY_SM_52 +#define NV_IS_EXACTLY_SM_53 __NV_IS_EXACTLY_SM_53 +#define NV_IS_EXACTLY_SM_60 __NV_IS_EXACTLY_SM_60 +#define NV_IS_EXACTLY_SM_61 __NV_IS_EXACTLY_SM_61 +#define NV_IS_EXACTLY_SM_62 __NV_IS_EXACTLY_SM_62 +#define NV_IS_EXACTLY_SM_70 __NV_IS_EXACTLY_SM_70 +#define NV_IS_EXACTLY_SM_72 __NV_IS_EXACTLY_SM_72 +#define NV_IS_EXACTLY_SM_75 __NV_IS_EXACTLY_SM_75 +#define NV_IS_EXACTLY_SM_80 __NV_IS_EXACTLY_SM_80 +#define NV_IS_EXACTLY_SM_86 __NV_IS_EXACTLY_SM_86 +#define NV_IS_EXACTLY_SM_87 __NV_IS_EXACTLY_SM_87 +#define NV_IS_EXACTLY_SM_89 __NV_IS_EXACTLY_SM_89 +#define NV_IS_EXACTLY_SM_90 __NV_IS_EXACTLY_SM_90 +#define NV_IS_EXACTLY_SM_100 __NV_IS_EXACTLY_SM_100 +#define NV_IS_EXACTLY_SM_101 __NV_IS_EXACTLY_SM_101 +#define NV_IS_EXACTLY_SM_120 __NV_IS_EXACTLY_SM_120 + +// Disable SM_90a support on non-supporting compilers. +// Will re-enable for nvcc below. +#define NV_HAS_FEATURE_SM_90a NV_NO_TARGET +#define NV_HAS_FEATURE_SM_100a NV_NO_TARGET +#define NV_HAS_FEATURE_SM_101a NV_NO_TARGET + +#define NV_IS_HOST __NV_IS_HOST +#define NV_IS_DEVICE __NV_IS_DEVICE + +#define NV_ANY_TARGET __NV_ANY_TARGET +#define NV_NO_TARGET __NV_NO_TARGET + +// Platform invoke mechanisms +#if defined(_NV_COMPILER_NVCXX) && defined(_NVHPC_CUDA) + +# define _NV_ARCH_COND(q) (_NV_TARGET_##q) + +# define _NV_BLOCK_EXPAND(...) _NV_REMOVE_PAREN(__VA_ARGS__) + +# define _NV_TARGET_IF(cond, t, ...) \ + (if target _NV_ARCH_COND(cond) { _NV_BLOCK_EXPAND(t) } else {_NV_BLOCK_EXPAND(__VA_ARGS__)}) + +#elif defined(_NV_COMPILER_NVCC) || defined(_NV_COMPILER_CLANG_CUDA) + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_35) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_35 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_35 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_37) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_37 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_37 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_50) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_50 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_50 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_52) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_52 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_52 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_53) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_53 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_53 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_60) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_60 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_60 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_61) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_61 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_61 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_62) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_62 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_62 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_70) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_70 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_70 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_72) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_72 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_72 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_75) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_75 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_75 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_80) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_80 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_80 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_86) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_86 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_86 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_87) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_87 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_87 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_89) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_89 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_89 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_90) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_90 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_90 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_100) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_100 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_100 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_101) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_101 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_101 0 +# endif + +# if (_NV_TARGET___NV_IS_EXACTLY_SM_120) +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_120 1 +# else +# define _NV_TARGET_BOOL___NV_IS_EXACTLY_SM_120 0 +# endif + +// Re-enable sm_90a support in nvcc. +# undef NV_HAS_FEATURE_SM_90a +# define NV_HAS_FEATURE_SM_90a __NV_HAS_FEATURE_SM_90a +# if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 900) && defined(__CUDA_ARCH_FEAT_SM90_ALL)) +# define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_90a 1 +# else +# define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_90a 0 +# endif + +// Re-enable sm_100a support in nvcc. +# undef NV_HAS_FEATURE_SM_100a +# define NV_HAS_FEATURE_SM_100a __NV_HAS_FEATURE_SM_100a +# if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 1000) && defined(__CUDA_ARCH_FEAT_SM100_ALL)) +# define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_100a 1 +# else +# define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_100a 0 +# endif + +// Re-enable sm_101a support in nvcc. +# undef NV_HAS_FEATURE_SM_101a +# define NV_HAS_FEATURE_SM_101a __NV_HAS_FEATURE_SM_101a +# if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 1010) && defined(__CUDA_ARCH_FEAT_SM101_ALL)) +# define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_101a 1 +# else +# define _NV_TARGET_BOOL___NV_HAS_FEATURE_SM_101a 0 +# endif + +# if (_NV_TARGET_IS_HOST) +# define _NV_TARGET_BOOL___NV_IS_HOST 1 +# define _NV_TARGET_BOOL___NV_IS_DEVICE 0 +# else +# define _NV_TARGET_BOOL___NV_IS_HOST 0 +# define _NV_TARGET_BOOL___NV_IS_DEVICE 1 +# endif + +# define _NV_TARGET_BOOL___NV_ANY_TARGET 1 +# define _NV_TARGET_BOOL___NV_NO_TARGET 0 + +// NVCC Greater than stuff + +# if (_NV_TARGET___NV_PROVIDES_SM_35) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_35 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_35 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_37) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_37 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_37 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_50) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_50 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_50 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_52) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_52 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_52 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_53) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_53 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_53 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_60) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_60 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_60 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_61) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_61 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_61 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_62) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_62 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_62 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_70) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_70 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_70 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_72) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_72 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_72 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_75) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_75 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_75 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_80) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_80 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_80 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_86) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_86 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_86 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_87) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_87 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_87 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_89) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_89 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_89 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_90) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_90 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_90 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_100) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_100 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_100 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_101) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_101 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_101 0 +# endif + +# if (_NV_TARGET___NV_PROVIDES_SM_120) +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_120 1 +# else +# define _NV_TARGET_BOOL___NV_PROVIDES_SM_120 0 +# endif + +# define _NV_ARCH_COND_CAT1(cond) _NV_TARGET_BOOL_##cond +# define _NV_ARCH_COND_CAT(cond) _NV_EVAL(_NV_ARCH_COND_CAT1(cond)) + +# define _NV_TARGET_EMPTY_PARAM ; + +# if defined(_NV_TARGET_CPP11) + +# define _NV_BLOCK_EXPAND(...) {_NV_REMOVE_PAREN(__VA_ARGS__)} +# define _NV_TARGET_IF(cond, t, ...) _NV_IF(_NV_ARCH_COND_CAT(cond), t, __VA_ARGS__) + +# else // = 201103L +# define _NV_COMPILER_NVCXX +#elif defined(__clang__) && defined(__CUDA__) && defined(__CUDA_ARCH__) +// clang compiling CUDA code, device mode. +# define _NV_COMPILER_CLANG_CUDA +#endif + +#if ((defined(__cplusplus) && __cplusplus >= 201103L) || (defined(_MSC_VER) && _MSVC_LANG >= 201103L)) +# define _NV_TARGET_CPP11 +#endif + +// Hide `if target` support from NVRTC +#if defined(_NV_TARGET_CPP11) && !defined(__CUDACC_RTC__) + +# if defined(_NV_COMPILER_NVCXX) +# define _NV_BITSET_ATTRIBUTE [[nv::__target_bitset]] +# else +# define _NV_BITSET_ATTRIBUTE +# endif + +namespace nv +{ +namespace target +{ +namespace detail +{ + +typedef unsigned long long base_int_t; + +// No host specialization +constexpr base_int_t all_hosts = 1; + +// NVIDIA GPUs +constexpr base_int_t sm_35_bit = 1 << 1; +constexpr base_int_t sm_37_bit = 1 << 2; +constexpr base_int_t sm_50_bit = 1 << 3; +constexpr base_int_t sm_52_bit = 1 << 4; +constexpr base_int_t sm_53_bit = 1 << 5; +constexpr base_int_t sm_60_bit = 1 << 6; +constexpr base_int_t sm_61_bit = 1 << 7; +constexpr base_int_t sm_62_bit = 1 << 8; +constexpr base_int_t sm_70_bit = 1 << 9; +constexpr base_int_t sm_72_bit = 1 << 10; +constexpr base_int_t sm_75_bit = 1 << 11; +constexpr base_int_t sm_80_bit = 1 << 12; +constexpr base_int_t sm_86_bit = 1 << 13; +constexpr base_int_t sm_87_bit = 1 << 14; +constexpr base_int_t sm_89_bit = 1 << 15; +constexpr base_int_t sm_90_bit = 1 << 16; +constexpr base_int_t sm_100_bit = 1 << 17; +constexpr base_int_t sm_101_bit = 1 << 18; +constexpr base_int_t sm_120_bit = 1 << 19; +constexpr base_int_t all_devices = + 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 + | 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; + +// Store a set of targets as a set of bits +struct _NV_BITSET_ATTRIBUTE target_description +{ + base_int_t targets; + + constexpr target_description(base_int_t a) + : targets(a) + {} +}; + +// The type of the user-visible names of the NVIDIA GPU targets +enum class sm_selector : base_int_t +{ + sm_35 = 35, + sm_37 = 37, + sm_50 = 50, + sm_52 = 52, + sm_53 = 53, + sm_60 = 60, + sm_61 = 61, + sm_62 = 62, + sm_70 = 70, + sm_72 = 72, + sm_75 = 75, + sm_80 = 80, + sm_86 = 86, + sm_87 = 87, + sm_89 = 89, + sm_90 = 90, + sm_100 = 100, + sm_101 = 101, + sm_120 = 120, +}; + +constexpr base_int_t toint(sm_selector a) +{ + return static_cast(a); +} + +constexpr base_int_t bitexact(sm_selector a) +{ + return toint(a) == 35 ? sm_35_bit + : toint(a) == 37 ? sm_37_bit + : toint(a) == 50 ? sm_50_bit + : toint(a) == 52 ? sm_52_bit + : toint(a) == 53 ? sm_53_bit + : toint(a) == 60 ? sm_60_bit + : toint(a) == 61 ? sm_61_bit + : toint(a) == 62 ? sm_62_bit + : toint(a) == 70 ? sm_70_bit + : toint(a) == 72 ? sm_72_bit + : toint(a) == 75 ? sm_75_bit + : toint(a) == 80 ? sm_80_bit + : toint(a) == 86 ? sm_86_bit + : toint(a) == 87 ? sm_87_bit + : toint(a) == 89 ? sm_89_bit + : toint(a) == 90 ? sm_90_bit + : toint(a) == 100 ? sm_100_bit + : toint(a) == 101 ? sm_101_bit + : toint(a) == 120 ? sm_120_bit + : 0; +} + +constexpr base_int_t bitrounddown(sm_selector a) +{ + return toint(a) >= 120 ? sm_120_bit + : toint(a) >= 101 ? sm_101_bit + : toint(a) >= 100 ? sm_100_bit + : toint(a) >= 90 ? sm_90_bit + : toint(a) >= 89 ? sm_89_bit + : toint(a) >= 87 ? sm_87_bit + : toint(a) >= 86 ? sm_86_bit + : toint(a) >= 80 ? sm_80_bit + : toint(a) >= 75 ? sm_75_bit + : toint(a) >= 72 ? sm_72_bit + : toint(a) >= 70 ? sm_70_bit + : toint(a) >= 62 ? sm_62_bit + : toint(a) >= 61 ? sm_61_bit + : toint(a) >= 60 ? sm_60_bit + : toint(a) >= 53 ? sm_53_bit + : toint(a) >= 52 ? sm_52_bit + : toint(a) >= 50 ? sm_50_bit + : toint(a) >= 37 ? sm_37_bit + : toint(a) >= 35 ? sm_35_bit + : 0; +} + +// Public API for NVIDIA GPUs + +constexpr target_description is_exactly(sm_selector a) +{ + return target_description(bitexact(a)); +} + +constexpr target_description provides(sm_selector a) +{ + return target_description(~(bitrounddown(a) - 1) & all_devices); +} + +// Boolean operations on target sets + +constexpr target_description operator&&(target_description a, target_description b) +{ + return target_description(a.targets & b.targets); +} + +constexpr target_description operator||(target_description a, target_description b) +{ + return target_description(a.targets | b.targets); +} + +constexpr target_description operator!(target_description a) +{ + return target_description(~a.targets & (all_devices | all_hosts)); +} +} // namespace detail + +using detail::sm_selector; +using detail::target_description; + +// The predicates for basic host/device selection +constexpr target_description is_host = target_description(detail::all_hosts); +constexpr target_description is_device = target_description(detail::all_devices); +constexpr target_description any_target = target_description(detail::all_hosts | detail::all_devices); +constexpr target_description no_target = target_description(0); + +// The public names for NVIDIA GPU architectures +constexpr sm_selector sm_35 = sm_selector::sm_35; +constexpr sm_selector sm_37 = sm_selector::sm_37; +constexpr sm_selector sm_50 = sm_selector::sm_50; +constexpr sm_selector sm_52 = sm_selector::sm_52; +constexpr sm_selector sm_53 = sm_selector::sm_53; +constexpr sm_selector sm_60 = sm_selector::sm_60; +constexpr sm_selector sm_61 = sm_selector::sm_61; +constexpr sm_selector sm_62 = sm_selector::sm_62; +constexpr sm_selector sm_70 = sm_selector::sm_70; +constexpr sm_selector sm_72 = sm_selector::sm_72; +constexpr sm_selector sm_75 = sm_selector::sm_75; +constexpr sm_selector sm_80 = sm_selector::sm_80; +constexpr sm_selector sm_86 = sm_selector::sm_86; +constexpr sm_selector sm_87 = sm_selector::sm_87; +constexpr sm_selector sm_89 = sm_selector::sm_89; +constexpr sm_selector sm_90 = sm_selector::sm_90; +constexpr sm_selector sm_100 = sm_selector::sm_100; +constexpr sm_selector sm_101 = sm_selector::sm_101; +constexpr sm_selector sm_120 = sm_selector::sm_120; + +using detail::is_exactly; +using detail::provides; +} // namespace target +} // namespace nv + +#endif // C++11 && !defined(__CUDACC_RTC__) + +#include + +#endif // __NV_TARGET_H diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/adjacent_difference.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/adjacent_difference.h new file mode 100644 index 0000000000000000000000000000000000000000..756b42937fee4a4b08aaf47e50037088e32b3a2b --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/adjacent_difference.h @@ -0,0 +1,251 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file adjacent_difference.h + * \brief Compute difference between consecutive elements of a range + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup transformations Transformations + * \{ + */ + +/*! \p adjacent_difference calculates the differences of adjacent elements in the + * range [first, last). That is, \*first is assigned to + * \*result, and, for each iterator \p i in the range + * [first + 1, last), the difference of \*i and *(i - 1) + * is assigned to \*(result + (i - first)). + * + * This version of \p adjacent_difference uses operator- to calculate + * differences. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param result The beginning of the output range. + * \return The iterator result + (last - first) + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \c x and \c y are objects of \p InputIterator's \c value_type, then \c x - \c is defined, and \p + * InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, and the return + * type of x - y is convertible to a type in \p OutputIterator's set of \c value_types. \tparam OutputIterator + * is a model of Output Iterator. + * + * \remark Note that \p result is permitted to be the same iterator as \p first. This is + * useful for computing differences "in place". + * + * The following code snippet demonstrates how to use \p adjacent_difference to compute + * the difference between adjacent elements of a range using the \p thrust::device execution policy: + * + * \code + * #include + * #include + * #include + * ... + * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; + * thrust::device_vector d_data(h_data, h_data + 8); + * thrust::device_vector d_result(8); + * + * thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin()); + * + * // d_result is now [1, 1, -1, 1, -1, 1, -1, 1] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/adjacent_difference + * \see inclusive_scan + */ +template +_CCCL_HOST_DEVICE OutputIterator adjacent_difference( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result); + +/*! \p adjacent_difference calculates the differences of adjacent elements in the + * range [first, last). That is, *first is assigned to + * \*result, and, for each iterator \p i in the range + * [first + 1, last), binary_op(\*i, \*(i - 1)) is assigned to + * \*(result + (i - first)). + * + * This version of \p adjacent_difference uses the binary function \p binary_op to + * calculate differences. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param result The beginning of the output range. + * \param binary_op The binary function used to compute differences. + * \return The iterator result + (last - first) + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p BinaryFunction's \c first_argument_type and + * \c second_argument_type, and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of + * \c value_types. \tparam OutputIterator is a model of Output Iterator. \tparam BinaryFunction's \c + * result_type is convertible to a type in \p OutputIterator's set of \c value_types. + * + * \remark Note that \p result is permitted to be the same iterator as \p first. This is + * useful for computing differences "in place". + * + * The following code snippet demonstrates how to use \p adjacent_difference to compute + * the sum between adjacent elements of a range using the \p thrust::device execution policy: + * + * \code + * #include + * #include + * #include + * #include + * ... + * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; + * thrust::device_vector d_data(h_data, h_data + 8); + * thrust::device_vector d_result(8); + * + * thrust::adjacent_difference(thrust::device, d_data.begin(), d_data.end(), d_result.begin(), thrust::plus()); + * + * // d_result is now [1, 3, 3, 3, 3, 3, 3, 3] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/adjacent_difference + * \see inclusive_scan + */ +template +_CCCL_HOST_DEVICE OutputIterator adjacent_difference( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + BinaryFunction binary_op); + +/*! \p adjacent_difference calculates the differences of adjacent elements in the + * range [first, last). That is, \*first is assigned to + * \*result, and, for each iterator \p i in the range + * [first + 1, last), the difference of \*i and *(i - 1) + * is assigned to \*(result + (i - first)). + * + * This version of \p adjacent_difference uses operator- to calculate + * differences. + * + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param result The beginning of the output range. + * \return The iterator result + (last - first) + * + * \tparam InputIterator is a model of Input + * Iterator, and \c x and \c y are objects of \p InputIterator's \c value_type, then \c x - \c is defined, and \p + * InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, and the return + * type of x - y is convertible to a type in \p OutputIterator's set of \c value_types. \tparam OutputIterator + * is a model of Output Iterator. + * + * \remark Note that \p result is permitted to be the same iterator as \p first. This is + * useful for computing differences "in place". + * + * The following code snippet demonstrates how to use \p adjacent_difference to compute + * the difference between adjacent elements of a range. + * + * \code + * #include + * #include + * ... + * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; + * thrust::device_vector d_data(h_data, h_data + 8); + * thrust::device_vector d_result(8); + * + * thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin()); + * + * // d_result is now [1, 1, -1, 1, -1, 1, -1, 1] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/adjacent_difference + * \see inclusive_scan + */ +template +OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); + +/*! \p adjacent_difference calculates the differences of adjacent elements in the + * range [first, last). That is, *first is assigned to + * \*result, and, for each iterator \p i in the range + * [first + 1, last), binary_op(\*i, \*(i - 1)) is assigned to + * \*(result + (i - first)). + * + * This version of \p adjacent_difference uses the binary function \p binary_op to + * calculate differences. + * + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param result The beginning of the output range. + * \param binary_op The binary function used to compute differences. + * \return The iterator result + (last - first) + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p BinaryFunction's \c first_argument_type and + * \c second_argument_type, and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of + * \c value_types. \tparam OutputIterator is a model of Output Iterator. \tparam BinaryFunction's \c + * result_type is convertible to a type in \p OutputIterator's set of \c value_types. + * + * \remark Note that \p result is permitted to be the same iterator as \p first. This is + * useful for computing differences "in place". + * + * The following code snippet demonstrates how to use \p adjacent_difference to compute + * the sum between adjacent elements of a range. + * + * \code + * #include + * #include + * #include + * ... + * int h_data[8] = {1, 2, 1, 2, 1, 2, 1, 2}; + * thrust::device_vector d_data(h_data, h_data + 8); + * thrust::device_vector d_result(8); + * + * thrust::adjacent_difference(d_data.begin(), d_data.end(), d_result.begin(), thrust::plus()); + * + * // d_result is now [1, 3, 3, 3, 3, 3, 3, 3] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/adjacent_difference + * \see inclusive_scan + */ +template +OutputIterator +adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryFunction binary_op); + +/*! \} + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/advance.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/advance.h new file mode 100644 index 0000000000000000000000000000000000000000..801568b6e0005dbbf37482ccfcf18e4690881a69 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/advance.h @@ -0,0 +1,147 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file advance.h + * \brief Advance an iterator by a given distance. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup iterators + * \{ + */ + +/*! \p advance(i, n) increments the iterator \p i by the distance \p n. + * If n > 0 it is equivalent to executing ++i \p n + * times, and if n < 0 it is equivalent to executing --i + * \p n times. If n == 0, the call has no effect. + * + * \param i The iterator to be advanced. + * \param n The distance by which to advance the iterator. + * + * \tparam InputIterator is a model of Input + * Iterator. \tparam Distance is an integral type that is convertible to \p InputIterator's distance type. + * + * \pre \p n shall be negative only for bidirectional and random access iterators. + * + * The following code snippet demonstrates how to use \p advance to increment + * an iterator a given number of times. + * + * \code + * #include + * #include + * ... + * thrust::device_vector vec(13); + * thrust::device_vector::iterator iter = vec.begin(); + * + * thrust::advance(iter, 7); + * + * // iter - vec.begin() == 7 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/iterator/advance + */ +template +_CCCL_HOST_DEVICE void advance(InputIterator& i, Distance n); + +/*! \p next(i, n) returns the \p n th successor of the iterator \p i. + * + * \param i An iterator. + * \param n The number of elements to advance. + * + * \tparam InputIterator must meet the InputIterator. + * + * \pre \p n shall be negative only for bidirectional and random access iterators. + * + * The following code snippet demonstrates how to use \p next. + * + * \code + * #include + * #include + * ... + * thrust::device_vector vec(13); + * thrust::device_vector::iterator i0 = vec.begin(); + * + * auto i1 = thrust::next(i0); + * + * // i0 - vec.begin() == 0 + * // i1 - vec.begin() == 1 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/iterator/next + */ +#if 0 // Doxygen only +template +_CCCL_HOST_DEVICE +InputIterator next( + InputIterator i +, typename iterator_traits::difference_type n = 1 +); +#endif + +/*! \p prev(i, n) returns the \p n th predecessor of the iterator \p i. + * + * \param i An iterator. + * \param n The number of elements to descend. + * + * \tparam BidirectionalIterator must meet the BidirectionalIterator. + * + * The following code snippet demonstrates how to use \p prev. + * + * \code + * #include + * #include + * ... + * thrust::device_vector vec(13); + * thrust::device_vector::iterator i0 = vec.end(); + * + * auto i1 = thrust::prev(i0); + * + * // vec.end() - i0 == 0 + * // vec.end() - i1 == 1 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/iterator/prev + */ +#if 0 // Doxygen only +template +_CCCL_HOST_DEVICE +BidirectionalIterator prev( + BidirectionalIterator i +, typename iterator_traits::difference_type n = 1 +); +#endif + +/*! \} // end iterators + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/allocate_unique.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/allocate_unique.h new file mode 100644 index 0000000000000000000000000000000000000000..1ec032acdda9d09e90fcff0184d5938511215a0c --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/allocate_unique.h @@ -0,0 +1,350 @@ +// Copyright (c) 2018 NVIDIA Corporation +// Author: Bryce Adelstein Lelbach +// +// Distributed under the Boost Software License v1.0 (boost.org/LICENSE_1_0.txt) + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include + +#include + +THRUST_NAMESPACE_BEGIN + +// wg21.link/p0316r0 + +/////////////////////////////////////////////////////////////////////////////// + +namespace detail +{ + +template +void allocator_delete_impl(Allocator const& alloc, Pointer p, std::false_type) +{ + using traits = + typename detail::allocator_traits::type>::type>; + + typename traits::allocator_type alloc_T(alloc); + + if (nullptr != pointer_traits::get(p)) + { + traits::destroy(alloc_T, thrust::raw_pointer_cast(p)); + traits::deallocate(alloc_T, p, 1); + } +} + +template +void allocator_delete_impl(Allocator const& alloc, Pointer p, std::true_type) +{ + using traits = + typename detail::allocator_traits::type>::type>; + + typename traits::allocator_type alloc_T(alloc); + + if (nullptr != pointer_traits::get(p)) + { + traits::deallocate(alloc_T, p, 1); + } +} + +} // namespace detail + +template +struct allocator_delete final +{ + using allocator_type = + typename std::remove_cv::type>::type::template rebind::other; + using pointer = typename detail::allocator_traits::pointer; + + template + allocator_delete(UAllocator&& other) noexcept + : alloc_(THRUST_FWD(other)) + {} + + template + allocator_delete(allocator_delete const& other) noexcept + : alloc_(other.get_allocator()) + {} + template + allocator_delete(allocator_delete&& other) noexcept + : alloc_(std::move(other.get_allocator())) + {} + + template + allocator_delete& operator=(allocator_delete const& other) noexcept + { + alloc_ = other.get_allocator(); + return *this; + } + template + allocator_delete& operator=(allocator_delete&& other) noexcept + { + alloc_ = std::move(other.get_allocator()); + return *this; + } + + void operator()(pointer p) + { + std::integral_constant ic; + + detail::allocator_delete_impl(get_allocator(), p, ic); + } + + allocator_type& get_allocator() noexcept + { + return alloc_; + } + allocator_type const& get_allocator() const noexcept + { + return alloc_; + } + + void swap(allocator_delete& other) noexcept + { + using ::cuda::std::swap; + swap(alloc_, other.alloc_); + } + +private: + allocator_type alloc_; +}; + +template +using uninitialized_allocator_delete = allocator_delete; + +namespace detail +{ + +template +void array_allocator_delete_impl(Allocator const& alloc, Pointer p, Size count, std::false_type) +{ + using traits = + typename detail::allocator_traits::type>::type>; + + typename traits::allocator_type alloc_T(alloc); + + if (nullptr != pointer_traits::get(p)) + { + destroy_n(alloc_T, p, count); + traits::deallocate(alloc_T, p, count); + } +} + +template +void array_allocator_delete_impl(Allocator const& alloc, Pointer p, Size count, std::true_type) +{ + using traits = + typename detail::allocator_traits::type>::type>; + + typename traits::allocator_type alloc_T(alloc); + + if (nullptr != pointer_traits::get(p)) + { + traits::deallocate(alloc_T, p, count); + } +} + +} // namespace detail + +template +struct array_allocator_delete final +{ + using allocator_type = + typename std::remove_cv::type>::type::template rebind::other; + using pointer = typename detail::allocator_traits::pointer; + + template + array_allocator_delete(UAllocator&& other, std::size_t n) noexcept + : alloc_(THRUST_FWD(other)) + , count_(n) + {} + + template + array_allocator_delete(array_allocator_delete const& other) noexcept + : alloc_(other.get_allocator()) + , count_(other.count_) + {} + template + array_allocator_delete(array_allocator_delete&& other) noexcept + : alloc_(std::move(other.get_allocator())) + , count_(other.count_) + {} + + template + array_allocator_delete& operator=(array_allocator_delete const& other) noexcept + { + alloc_ = other.get_allocator(); + count_ = other.count_; + return *this; + } + template + array_allocator_delete& operator=(array_allocator_delete&& other) noexcept + { + alloc_ = std::move(other.get_allocator()); + count_ = other.count_; + return *this; + } + + void operator()(pointer p) + { + std::integral_constant ic; + + detail::array_allocator_delete_impl(get_allocator(), p, count_, ic); + } + + allocator_type& get_allocator() noexcept + { + return alloc_; + } + allocator_type const& get_allocator() const noexcept + { + return alloc_; + } + + void swap(array_allocator_delete& other) noexcept + { + using ::cuda::std::swap; + swap(alloc_, other.alloc_); + swap(count_, other.count_); + } + +private: + allocator_type alloc_; + std::size_t count_; +}; + +template +using uninitialized_array_allocator_delete = array_allocator_delete; + +/////////////////////////////////////////////////////////////////////////////// + +template +struct tagged_deleter : Lambda +{ + _CCCL_HOST_DEVICE tagged_deleter(Lambda&& l) + : Lambda(THRUST_FWD(l)) + {} + + using pointer = Pointer; +}; + +template +_CCCL_HOST_DEVICE tagged_deleter make_tagged_deleter(Lambda&& l) +{ + return tagged_deleter(THRUST_FWD(l)); +} + +/////////////////////////////////////////////////////////////////////////////// + +template +_CCCL_HOST std::unique_ptr< + T, + allocator_delete::type>::type>::template rebind_traits::allocator_type>> +allocate_unique(Allocator const& alloc, Args&&... args) +{ + using traits = typename detail::allocator_traits< + typename std::remove_cv::type>::type>::template rebind_traits; + + typename traits::allocator_type alloc_T(alloc); + + auto hold_deleter = make_tagged_deleter([&alloc_T](typename traits::pointer p) { + traits::deallocate(alloc_T, p, 1); + }); + using hold_t = std::unique_ptr; + auto hold = hold_t(traits::allocate(alloc_T, 1), hold_deleter); + + traits::construct(alloc_T, thrust::raw_pointer_cast(hold.get()), THRUST_FWD(args)...); + auto deleter = allocator_delete(alloc); + return std::unique_ptr(hold.release(), std::move(deleter)); +} + +template +_CCCL_HOST +std::unique_ptr::type>::type>::template rebind_traits::allocator_type>> +uninitialized_allocate_unique(Allocator const& alloc) +{ + using traits = typename detail::allocator_traits< + typename std::remove_cv::type>::type>::template rebind_traits; + + typename traits::allocator_type alloc_T(alloc); + + auto hold_deleter = make_tagged_deleter([&alloc_T](typename traits::pointer p) { + traits::deallocate(alloc_T, p, 1); + }); + using hold_t = std::unique_ptr; + auto hold = hold_t(traits::allocate(alloc_T, 1), hold_deleter); + + auto deleter = uninitialized_allocator_delete(alloc_T); + return std::unique_ptr(hold.release(), std::move(deleter)); +} + +template +_CCCL_HOST std::unique_ptr< + T[], + array_allocator_delete::type>::type>::template rebind_traits::allocator_type>> +allocate_unique_n(Allocator const& alloc, Size n, Args&&... args) +{ + using traits = typename detail::allocator_traits< + typename std::remove_cv::type>::type>::template rebind_traits; + + typename traits::allocator_type alloc_T(alloc); + + auto hold_deleter = make_tagged_deleter([n, &alloc_T](typename traits::pointer p) { + traits::deallocate(alloc_T, p, n); + }); + using hold_t = std::unique_ptr; + auto hold = hold_t(traits::allocate(alloc_T, n), hold_deleter); + + uninitialized_construct_n_with_allocator(alloc_T, hold.get(), n, THRUST_FWD(args)...); + auto deleter = array_allocator_delete(alloc_T, n); + return std::unique_ptr(hold.release(), std::move(deleter)); +} + +template +_CCCL_HOST +std::unique_ptr::type>::type>::template rebind_traits::allocator_type>> +uninitialized_allocate_unique_n(Allocator const& alloc, Size n) +{ + using traits = typename detail::allocator_traits< + typename std::remove_cv::type>::type>::template rebind_traits; + + typename traits::allocator_type alloc_T(alloc); + + auto hold_deleter = make_tagged_deleter([n, &alloc_T](typename traits::pointer p) { + traits::deallocate(alloc_T, p, n); + }); + using hold_t = std::unique_ptr; + auto hold = hold_t(traits::allocate(alloc_T, n), hold_deleter); + + auto deleter = uninitialized_array_allocator_delete(alloc_T, n); + return std::unique_ptr(hold.release(), std::move(deleter)); +} + +/////////////////////////////////////////////////////////////////////////////// + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/binary_search.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/binary_search.h new file mode 100644 index 0000000000000000000000000000000000000000..d370fe37f959b70457220d7a019c754f4f4fdfb6 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/binary_search.h @@ -0,0 +1,1887 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file binary_search.h + * \brief Search for values in sorted ranges. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup algorithms + */ + +/*! \addtogroup searching + * \ingroup algorithms + * \{ + */ + +/*! \addtogroup binary_search Binary Search + * \ingroup searching + * \{ + */ + +////////////////////// +// Scalar Functions // +////////////////////// + +/*! \p lower_bound is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * Specifically, it returns the first position where value could be + * inserted without violating the ordering. This version of + * \p lower_bound uses operator< for comparison and returns + * the furthermost iterator \c i in [first, last) such that, + * for every iterator \c j in [first, i), *j < value. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \return The furthermost iterator \c i, such that *i < value. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam LessThanComparable is a model of LessThanComparable. + * + * The following code snippet demonstrates how to use \p lower_bound + * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::lower_bound(thrust::device, input.begin(), input.end(), 0); // returns input.begin() + * thrust::lower_bound(thrust::device, input.begin(), input.end(), 1); // returns input.begin() + 1 + * thrust::lower_bound(thrust::device, input.begin(), input.end(), 2); // returns input.begin() + 1 + * thrust::lower_bound(thrust::device, input.begin(), input.end(), 3); // returns input.begin() + 2 + * thrust::lower_bound(thrust::device, input.begin(), input.end(), 8); // returns input.begin() + 4 + * thrust::lower_bound(thrust::device, input.begin(), input.end(), 9); // returns input.end() + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE ForwardIterator lower_bound( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const LessThanComparable& value); + +/*! \p lower_bound is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * Specifically, it returns the first position where value could be + * inserted without violating the ordering. This version of + * \p lower_bound uses operator< for comparison and returns + * the furthermost iterator \c i in [first, last) such that, + * for every iterator \c j in [first, i), *j < value. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \return The furthermost iterator \c i, such that *i < value. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam LessThanComparable is a model of LessThanComparable. + * + * The following code snippet demonstrates how to use \p lower_bound + * to search for values in a ordered range. + * + * \code + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::lower_bound(input.begin(), input.end(), 0); // returns input.begin() + * thrust::lower_bound(input.begin(), input.end(), 1); // returns input.begin() + 1 + * thrust::lower_bound(input.begin(), input.end(), 2); // returns input.begin() + 1 + * thrust::lower_bound(input.begin(), input.end(), 3); // returns input.begin() + 2 + * thrust::lower_bound(input.begin(), input.end(), 8); // returns input.begin() + 4 + * thrust::lower_bound(input.begin(), input.end(), 9); // returns input.end() + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const LessThanComparable& value); + +/*! \p lower_bound is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * Specifically, it returns the first position where value could be + * inserted without violating the ordering. This version of + * \p lower_bound uses function object \c comp for comparison + * and returns the furthermost iterator \c i in [first, last) + * such that, for every iterator \c j in [first, i), + * comp(*j, value) is \c true. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \param comp The comparison operator. + * \return The furthermost iterator \c i, such that comp(*i, value) is \c true. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p lower_bound + * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::lower_bound(input.begin(), input.end(), 0, thrust::less()); // returns input.begin() + * thrust::lower_bound(input.begin(), input.end(), 1, thrust::less()); // returns input.begin() + 1 + * thrust::lower_bound(input.begin(), input.end(), 2, thrust::less()); // returns input.begin() + 1 + * thrust::lower_bound(input.begin(), input.end(), 3, thrust::less()); // returns input.begin() + 2 + * thrust::lower_bound(input.begin(), input.end(), 8, thrust::less()); // returns input.begin() + 4 + * thrust::lower_bound(input.begin(), input.end(), 9, thrust::less()); // returns input.end() + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE ForwardIterator lower_bound( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const T& value, + StrictWeakOrdering comp); + +/*! \p lower_bound is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * Specifically, it returns the first position where value could be + * inserted without violating the ordering. This version of + * \p lower_bound uses function object \c comp for comparison + * and returns the furthermost iterator \c i in [first, last) + * such that, for every iterator \c j in [first, i), + * comp(*j, value) is \c true. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \param comp The comparison operator. + * \return The furthermost iterator \c i, such that comp(*i, value) is \c true. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p lower_bound + * to search for values in a ordered range. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::lower_bound(input.begin(), input.end(), 0, thrust::less()); // returns input.begin() + * thrust::lower_bound(input.begin(), input.end(), 1, thrust::less()); // returns input.begin() + 1 + * thrust::lower_bound(input.begin(), input.end(), 2, thrust::less()); // returns input.begin() + 1 + * thrust::lower_bound(input.begin(), input.end(), 3, thrust::less()); // returns input.begin() + 2 + * thrust::lower_bound(input.begin(), input.end(), 8, thrust::less()); // returns input.begin() + 4 + * thrust::lower_bound(input.begin(), input.end(), 9, thrust::less()); // returns input.end() + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp); + +/*! \p upper_bound is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * Specifically, it returns the last position where value could be + * inserted without violating the ordering. This version of + * \p upper_bound uses operator< for comparison and returns + * the furthermost iterator \c i in [first, last) such that, + * for every iterator \c j in [first, i), value < *j + * is \c false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \return The furthermost iterator \c i, such that value < *i is \c false. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam LessThanComparable is a model of LessThanComparable. + * + * The following code snippet demonstrates how to use \p upper_bound + * to search for values in a ordered range using the \p thrust::device execution policy for parallelism: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::upper_bound(thrust::device, input.begin(), input.end(), 0); // returns input.begin() + 1 + * thrust::upper_bound(thrust::device, input.begin(), input.end(), 1); // returns input.begin() + 1 + * thrust::upper_bound(thrust::device, input.begin(), input.end(), 2); // returns input.begin() + 2 + * thrust::upper_bound(thrust::device, input.begin(), input.end(), 3); // returns input.begin() + 2 + * thrust::upper_bound(thrust::device, input.begin(), input.end(), 8); // returns input.end() + * thrust::upper_bound(thrust::device, input.begin(), input.end(), 9); // returns input.end() + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound + * \see \p lower_bound + * \see \p equal_range + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE ForwardIterator upper_bound( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const LessThanComparable& value); + +/*! \p upper_bound is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * Specifically, it returns the last position where value could be + * inserted without violating the ordering. This version of + * \p upper_bound uses operator< for comparison and returns + * the furthermost iterator \c i in [first, last) such that, + * for every iterator \c j in [first, i), value < *j + * is \c false. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \return The furthermost iterator \c i, such that value < *i is \c false. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam LessThanComparable is a model of LessThanComparable. + * + * The following code snippet demonstrates how to use \p upper_bound + * to search for values in a ordered range. + * + * \code + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::upper_bound(input.begin(), input.end(), 0); // returns input.begin() + 1 + * thrust::upper_bound(input.begin(), input.end(), 1); // returns input.begin() + 1 + * thrust::upper_bound(input.begin(), input.end(), 2); // returns input.begin() + 2 + * thrust::upper_bound(input.begin(), input.end(), 3); // returns input.begin() + 2 + * thrust::upper_bound(input.begin(), input.end(), 8); // returns input.end() + * thrust::upper_bound(input.begin(), input.end(), 9); // returns input.end() + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound + * \see \p lower_bound + * \see \p equal_range + * \see \p binary_search + */ +template +ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const LessThanComparable& value); + +/*! \p upper_bound is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * Specifically, it returns the last position where value could be + * inserted without violating the ordering. This version of + * \p upper_bound uses function object \c comp for comparison and returns + * the furthermost iterator \c i in [first, last) such that, + * for every iterator \c j in [first, i), comp(value, *j) + * is \c false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \param comp The comparison operator. + * \return The furthermost iterator \c i, such that comp(value, *i) is \c false. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p upper_bound + * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::upper_bound(thrust::device, input.begin(), input.end(), 0, thrust::less()); // returns input.begin() + + * 1 thrust::upper_bound(thrust::device, input.begin(), input.end(), 1, thrust::less()); // returns input.begin() + + * 1 thrust::upper_bound(thrust::device, input.begin(), input.end(), 2, thrust::less()); // returns input.begin() + + * 2 thrust::upper_bound(thrust::device, input.begin(), input.end(), 3, thrust::less()); // returns input.begin() + + * 2 thrust::upper_bound(thrust::device, input.begin(), input.end(), 8, thrust::less()); // returns input.end() + * thrust::upper_bound(thrust::device, input.begin(), input.end(), 9, thrust::less()); // returns input.end() + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound + * \see \p lower_bound + * \see \p equal_range + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE ForwardIterator upper_bound( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const T& value, + StrictWeakOrdering comp); + +/*! \p upper_bound is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * Specifically, it returns the last position where value could be + * inserted without violating the ordering. This version of + * \p upper_bound uses function object \c comp for comparison and returns + * the furthermost iterator \c i in [first, last) such that, + * for every iterator \c j in [first, i), comp(value, *j) + * is \c false. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \param comp The comparison operator. + * \return The furthermost iterator \c i, such that comp(value, *i) is \c false. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p upper_bound + * to search for values in a ordered range. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::upper_bound(input.begin(), input.end(), 0, thrust::less()); // returns input.begin() + 1 + * thrust::upper_bound(input.begin(), input.end(), 1, thrust::less()); // returns input.begin() + 1 + * thrust::upper_bound(input.begin(), input.end(), 2, thrust::less()); // returns input.begin() + 2 + * thrust::upper_bound(input.begin(), input.end(), 3, thrust::less()); // returns input.begin() + 2 + * thrust::upper_bound(input.begin(), input.end(), 8, thrust::less()); // returns input.end() + * thrust::upper_bound(input.begin(), input.end(), 9, thrust::less()); // returns input.end() + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound + * \see \p lower_bound + * \see \p equal_range + * \see \p binary_search + */ +template +ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp); + +/*! \p binary_search is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * It returns \c true if an element that is equivalent to \c value + * is present in [first, last) and \c false if no such element + * exists. Specifically, this version returns \c true if and only if + * there exists an iterator \c i in [first, last) such that + * *i < value and value < *i are both \c false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \return \c true if an equivalent element exists in [first, last), otherwise \c false. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam LessThanComparable is a model of LessThanComparable. + * + * The following code snippet demonstrates how to use \p binary_search + * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::binary_search(thrust::device, input.begin(), input.end(), 0); // returns true + * thrust::binary_search(thrust::device, input.begin(), input.end(), 1); // returns false + * thrust::binary_search(thrust::device, input.begin(), input.end(), 2); // returns true + * thrust::binary_search(thrust::device, input.begin(), input.end(), 3); // returns false + * thrust::binary_search(thrust::device, input.begin(), input.end(), 8); // returns true + * thrust::binary_search(thrust::device, input.begin(), input.end(), 9); // returns false + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/binary_search + * \see \p lower_bound + * \see \p upper_bound + * \see \p equal_range + */ +template +_CCCL_HOST_DEVICE bool binary_search( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const LessThanComparable& value); + +/*! \p binary_search is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * It returns \c true if an element that is equivalent to \c value + * is present in [first, last) and \c false if no such element + * exists. Specifically, this version returns \c true if and only if + * there exists an iterator \c i in [first, last) such that + * *i < value and value < *i are both \c false. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \return \c true if an equivalent element exists in [first, last), otherwise \c false. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam LessThanComparable is a model of LessThanComparable. + * + * The following code snippet demonstrates how to use \p binary_search + * to search for values in a ordered range. + * + * \code + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::binary_search(input.begin(), input.end(), 0); // returns true + * thrust::binary_search(input.begin(), input.end(), 1); // returns false + * thrust::binary_search(input.begin(), input.end(), 2); // returns true + * thrust::binary_search(input.begin(), input.end(), 3); // returns false + * thrust::binary_search(input.begin(), input.end(), 8); // returns true + * thrust::binary_search(input.begin(), input.end(), 9); // returns false + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/binary_search + * \see \p lower_bound + * \see \p upper_bound + * \see \p equal_range + */ +template +bool binary_search(ForwardIterator first, ForwardIterator last, const LessThanComparable& value); + +/*! \p binary_search is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * It returns \c true if an element that is equivalent to \c value + * is present in [first, last) and \c false if no such element + * exists. Specifically, this version returns \c true if and only if + * there exists an iterator \c i in [first, last) such that + * comp(*i, value) and comp(value, *i) are both \c false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \param comp The comparison operator. + * \return \c true if an equivalent element exists in [first, last), otherwise \c false. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p binary_search + * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::binary_search(thrust::device, input.begin(), input.end(), 0, thrust::less()); // returns true + * thrust::binary_search(thrust::device, input.begin(), input.end(), 1, thrust::less()); // returns false + * thrust::binary_search(thrust::device, input.begin(), input.end(), 2, thrust::less()); // returns true + * thrust::binary_search(thrust::device, input.begin(), input.end(), 3, thrust::less()); // returns false + * thrust::binary_search(thrust::device, input.begin(), input.end(), 8, thrust::less()); // returns true + * thrust::binary_search(thrust::device, input.begin(), input.end(), 9, thrust::less()); // returns false + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/binary_search + * \see \p lower_bound + * \see \p upper_bound + * \see \p equal_range + */ +template +_CCCL_HOST_DEVICE bool binary_search( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const T& value, + StrictWeakOrdering comp); + +/*! \p binary_search is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). + * It returns \c true if an element that is equivalent to \c value + * is present in [first, last) and \c false if no such element + * exists. Specifically, this version returns \c true if and only if + * there exists an iterator \c i in [first, last) such that + * comp(*i, value) and comp(value, *i) are both \c false. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \param comp The comparison operator. + * \return \c true if an equivalent element exists in [first, last), otherwise \c false. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p binary_search + * to search for values in a ordered range. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::binary_search(input.begin(), input.end(), 0, thrust::less()); // returns true + * thrust::binary_search(input.begin(), input.end(), 1, thrust::less()); // returns false + * thrust::binary_search(input.begin(), input.end(), 2, thrust::less()); // returns true + * thrust::binary_search(input.begin(), input.end(), 3, thrust::less()); // returns false + * thrust::binary_search(input.begin(), input.end(), 8, thrust::less()); // returns true + * thrust::binary_search(input.begin(), input.end(), 9, thrust::less()); // returns false + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/binary_search + * \see \p lower_bound + * \see \p upper_bound + * \see \p equal_range + */ +template +bool binary_search(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp); + +/*! \p equal_range is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). The + * value returned by \p equal_range is essentially a combination of + * the values returned by \p lower_bound and \p upper_bound: it returns + * a \p pair of iterators \c i and \c j such that \c i is the first + * position where value could be inserted without violating the + * ordering and \c j is the last position where value could be inserted + * without violating the ordering. It follows that every element in the + * range [i, j) is equivalent to value, and that + * [i, j) is the largest subrange of [first, last) that + * has this property. + * + * This version of \p equal_range returns a \p pair of iterators + * [i, j), where \c i is the furthermost iterator in + * [first, last) such that, for every iterator \c k in + * [first, i), *k < value. \c j is the furthermost + * iterator in [first, last) such that, for every iterator + * \c k in [first, j), value < *k is \c false. + * For every iterator \c k in [i, j), neither + * value < *k nor *k < value is \c true. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \return A \p pair of iterators [i, j) that define the range of equivalent elements. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam LessThanComparable is a model of LessThanComparable. + * + * The following code snippet demonstrates how to use \p equal_range + * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::equal_range(thrust::device, input.begin(), input.end(), 0); // returns [input.begin(), input.begin() + 1) + * thrust::equal_range(thrust::device, input.begin(), input.end(), 1); // returns [input.begin() + 1, input.begin() + + * 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 2); // returns [input.begin() + 1, input.begin() + + * 2) thrust::equal_range(thrust::device, input.begin(), input.end(), 3); // returns [input.begin() + 2, input.begin() + + * 2) thrust::equal_range(thrust::device, input.begin(), input.end(), 8); // returns [input.begin() + 4, input.end()) + * thrust::equal_range(thrust::device, input.begin(), input.end(), 9); // returns [input.end(), input.end()) + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/equal_range + * \see \p lower_bound + * \see \p upper_bound + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE thrust::pair equal_range( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const LessThanComparable& value); + +/*! \p equal_range is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). The + * value returned by \p equal_range is essentially a combination of + * the values returned by \p lower_bound and \p upper_bound: it returns + * a \p pair of iterators \c i and \c j such that \c i is the first + * position where value could be inserted without violating the + * ordering and \c j is the last position where value could be inserted + * without violating the ordering. It follows that every element in the + * range [i, j) is equivalent to value, and that + * [i, j) is the largest subrange of [first, last) that + * has this property. + * + * This version of \p equal_range returns a \p pair of iterators + * [i, j), where \c i is the furthermost iterator in + * [first, last) such that, for every iterator \c k in + * [first, i), *k < value. \c j is the furthermost + * iterator in [first, last) such that, for every iterator + * \c k in [first, j), value < *k is \c false. + * For every iterator \c k in [i, j), neither + * value < *k nor *k < value is \c true. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \return A \p pair of iterators [i, j) that define the range of equivalent elements. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam LessThanComparable is a model of LessThanComparable. + * + * The following code snippet demonstrates how to use \p equal_range + * to search for values in a ordered range. + * + * \code + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::equal_range(input.begin(), input.end(), 0); // returns [input.begin(), input.begin() + 1) + * thrust::equal_range(input.begin(), input.end(), 1); // returns [input.begin() + 1, input.begin() + 1) + * thrust::equal_range(input.begin(), input.end(), 2); // returns [input.begin() + 1, input.begin() + 2) + * thrust::equal_range(input.begin(), input.end(), 3); // returns [input.begin() + 2, input.begin() + 2) + * thrust::equal_range(input.begin(), input.end(), 8); // returns [input.begin() + 4, input.end()) + * thrust::equal_range(input.begin(), input.end(), 9); // returns [input.end(), input.end()) + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/equal_range + * \see \p lower_bound + * \see \p upper_bound + * \see \p binary_search + */ +template +thrust::pair +equal_range(ForwardIterator first, ForwardIterator last, const LessThanComparable& value); + +/*! \p equal_range is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). The + * value returned by \p equal_range is essentially a combination of + * the values returned by \p lower_bound and \p upper_bound: it returns + * a \p pair of iterators \c i and \c j such that \c i is the first + * position where value could be inserted without violating the + * ordering and \c j is the last position where value could be inserted + * without violating the ordering. It follows that every element in the + * range [i, j) is equivalent to value, and that + * [i, j) is the largest subrange of [first, last) that + * has this property. + * + * This version of \p equal_range returns a \p pair of iterators + * [i, j). \c i is the furthermost iterator in + * [first, last) such that, for every iterator \c k in + * [first, i), comp(*k, value) is \c true. + * \c j is the furthermost iterator in [first, last) such + * that, for every iterator \c k in [first, last), + * comp(value, *k) is \c false. For every iterator \c k + * in [i, j), neither comp(value, *k) nor + * comp(*k, value) is \c true. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \param comp The comparison operator. + * \return A \p pair of iterators [i, j) that define the range of equivalent elements. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p equal_range + * to search for values in a ordered range using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::equal_range(thrust::device, input.begin(), input.end(), 0, thrust::less()); // returns [input.begin(), + * input.begin() + 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 1, thrust::less()); // + * returns [input.begin() + 1, input.begin() + 1) thrust::equal_range(thrust::device, input.begin(), input.end(), 2, + * thrust::less()); // returns [input.begin() + 1, input.begin() + 2) thrust::equal_range(thrust::device, + * input.begin(), input.end(), 3, thrust::less()); // returns [input.begin() + 2, input.begin() + 2) + * thrust::equal_range(thrust::device, input.begin(), input.end(), 8, thrust::less()); // returns [input.begin() + + * 4, input.end()) thrust::equal_range(thrust::device, input.begin(), input.end(), 9, thrust::less()); // returns + * [input.end(), input.end()) \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/equal_range + * \see \p lower_bound + * \see \p upper_bound + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE thrust::pair equal_range( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const T& value, + StrictWeakOrdering comp); + +/*! \p equal_range is a version of binary search: it attempts to find + * the element value in an ordered range [first, last). The + * value returned by \p equal_range is essentially a combination of + * the values returned by \p lower_bound and \p upper_bound: it returns + * a \p pair of iterators \c i and \c j such that \c i is the first + * position where value could be inserted without violating the + * ordering and \c j is the last position where value could be inserted + * without violating the ordering. It follows that every element in the + * range [i, j) is equivalent to value, and that + * [i, j) is the largest subrange of [first, last) that + * has this property. + * + * This version of \p equal_range returns a \p pair of iterators + * [i, j). \c i is the furthermost iterator in + * [first, last) such that, for every iterator \c k in + * [first, i), comp(*k, value) is \c true. + * \c j is the furthermost iterator in [first, last) such + * that, for every iterator \c k in [first, last), + * comp(value, *k) is \c false. For every iterator \c k + * in [i, j), neither comp(value, *k) nor + * comp(*k, value) is \c true. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param value The value to be searched. + * \param comp The comparison operator. + * \return A \p pair of iterators [i, j) that define the range of equivalent elements. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam T is comparable to \p ForwardIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p equal_range + * to search for values in a ordered range. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::equal_range(input.begin(), input.end(), 0, thrust::less()); // returns [input.begin(), input.begin() + + * 1) thrust::equal_range(input.begin(), input.end(), 1, thrust::less()); // returns [input.begin() + 1, + * input.begin() + 1) thrust::equal_range(input.begin(), input.end(), 2, thrust::less()); // returns [input.begin() + * + 1, input.begin() + 2) thrust::equal_range(input.begin(), input.end(), 3, thrust::less()); // returns + * [input.begin() + 2, input.begin() + 2) thrust::equal_range(input.begin(), input.end(), 8, thrust::less()); // + * returns [input.begin() + 4, input.end()) thrust::equal_range(input.begin(), input.end(), 9, thrust::less()); // + * returns [input.end(), input.end()) \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/equal_range + * \see \p lower_bound + * \see \p upper_bound + * \see \p binary_search + */ +template +thrust::pair +equal_range(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp); + +/*! \addtogroup vectorized_binary_search Vectorized Searches + * \ingroup binary_search + * \{ + */ + +////////////////////// +// Vector Functions // +////////////////////// + +/*! \p lower_bound is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * Specifically, it returns the index of first position where value could + * be inserted without violating the ordering. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is LessThanComparable. + * \tparam OutputIterator is a model of Output + * Iterator. and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p lower_bound + * to search for multiple values in a ordered range using the \p thrust::device execution policy for + * parallelization: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::lower_bound(thrust::device, + * input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin()); + * + * // output is now [0, 1, 1, 2, 4, 5] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE OutputIterator lower_bound( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result); + +/*! \p lower_bound is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * Specifically, it returns the index of first position where value could + * be inserted without violating the ordering. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is LessThanComparable. + * \tparam OutputIterator is a model of Output + * Iterator. and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p lower_bound + * to search for multiple values in a ordered range. + * + * \code + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::lower_bound(input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin()); + * + * // output is now [0, 1, 1, 2, 4, 5] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +OutputIterator lower_bound( + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result); + +/*! \p lower_bound is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * Specifically, it returns the index of first position where value could + * be inserted without violating the ordering. This version of + * \p lower_bound uses function object \c comp for comparison. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * \param comp The comparison operator. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is comparable to \p ForwardIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator. and \c ForwardIterator's + * difference_type is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p lower_bound + * to search for multiple values in a ordered range. + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::lower_bound(input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin(), + * thrust::less()); + * + * // output is now [0, 1, 1, 2, 4, 5] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE OutputIterator lower_bound( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result, + StrictWeakOrdering comp); + +/*! \p lower_bound is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * Specifically, it returns the index of first position where value could + * be inserted without violating the ordering. This version of + * \p lower_bound uses function object \c comp for comparison. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * \param comp The comparison operator. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is comparable to \p ForwardIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator. and \c ForwardIterator's + * difference_type is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p lower_bound + * to search for multiple values in a ordered range. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::lower_bound(input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin(), + * thrust::less()); + * + * // output is now [0, 1, 1, 2, 4, 5] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/lower_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +OutputIterator lower_bound( + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result, + StrictWeakOrdering comp); + +/*! \p upper_bound is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * Specifically, it returns the index of last position where value could + * be inserted without violating the ordering. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is LessThanComparable. + * \tparam OutputIterator is a model of Output + * Iterator. and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p upper_bound + * to search for multiple values in a ordered range using the \p thrust::device execution policy for + * parallelization: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::upper_bound(thrust::device, + * input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin()); + * + * // output is now [1, 1, 2, 2, 5, 5] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE OutputIterator upper_bound( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result); + +/*! \p upper_bound is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * Specifically, it returns the index of last position where value could + * be inserted without violating the ordering. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is LessThanComparable. + * \tparam OutputIterator is a model of Output + * Iterator. and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p upper_bound + * to search for multiple values in a ordered range. + * + * \code + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::upper_bound(input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin()); + * + * // output is now [1, 1, 2, 2, 5, 5] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound + * \see \p upper_bound + * \see \p equal_range + * \see \p binary_search + */ +template +OutputIterator upper_bound( + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result); + +/*! \p upper_bound is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * Specifically, it returns the index of first position where value could + * be inserted without violating the ordering. This version of + * \p upper_bound uses function object \c comp for comparison. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * \param comp The comparison operator. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is comparable to \p ForwardIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator. and \c ForwardIterator's + * difference_type is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p upper_bound + * to search for multiple values in a ordered range using the \p thrust::device execution policy for + * parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::upper_bound(thrust::device, + * input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin(), + * thrust::less()); + * + * // output is now [1, 1, 2, 2, 5, 5] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound + * \see \p lower_bound + * \see \p equal_range + * \see \p binary_search + */ +template +_CCCL_HOST_DEVICE OutputIterator upper_bound( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result, + StrictWeakOrdering comp); + +/*! \p upper_bound is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * Specifically, it returns the index of first position where value could + * be inserted without violating the ordering. This version of + * \p upper_bound uses function object \c comp for comparison. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * \param comp The comparison operator. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is comparable to \p ForwardIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator. and \c ForwardIterator's + * difference_type is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p upper_bound + * to search for multiple values in a ordered range. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::upper_bound(input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin(), + * thrust::less()); + * + * // output is now [1, 1, 2, 2, 5, 5] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/upper_bound + * \see \p lower_bound + * \see \p equal_range + * \see \p binary_search + */ +template +OutputIterator upper_bound( + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result, + StrictWeakOrdering comp); + +/*! \p binary_search is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * It returns \c true if an element that is equivalent to \c value + * is present in [first, last) and \c false if no such element + * exists. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is LessThanComparable. + * \tparam OutputIterator is a model of Output + * Iterator. and bool is convertible to \c OutputIterator's \c value_type. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p binary_search + * to search for multiple values in a ordered range using the \p thrust::device execution policy for + * parallelization: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::binary_search(thrust::device, + * input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin()); + * + * // output is now [true, false, true, false, true, false] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/binary_search + * \see \p lower_bound + * \see \p upper_bound + * \see \p equal_range + */ +template +_CCCL_HOST_DEVICE OutputIterator binary_search( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result); + +/*! \p binary_search is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * It returns \c true if an element that is equivalent to \c value + * is present in [first, last) and \c false if no such element + * exists. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is LessThanComparable. + * \tparam OutputIterator is a model of Output + * Iterator. and bool is convertible to \c OutputIterator's \c value_type. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p binary_search + * to search for multiple values in a ordered range. + * + * \code + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::binary_search(input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin()); + * + * // output is now [true, false, true, false, true, false] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/binary_search + * \see \p lower_bound + * \see \p upper_bound + * \see \p equal_range + */ +template +OutputIterator binary_search( + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result); + +/*! \p binary_search is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * It returns \c true if an element that is equivalent to \c value + * is present in [first, last) and \c false if no such element + * exists. This version of \p binary_search uses function object + * \c comp for comparison. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * \param comp The comparison operator. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is LessThanComparable. + * \tparam OutputIterator is a model of Output + * Iterator. and bool is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p binary_search + * to search for multiple values in a ordered range using the \p thrust::device execution policy for + * parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::binary_search(thrust::device, + * input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin(), + * thrust::less()); + * + * // output is now [true, false, true, false, true, false] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/binary_search + * \see \p lower_bound + * \see \p upper_bound + * \see \p equal_range + */ +template +_CCCL_HOST_DEVICE OutputIterator binary_search( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result, + StrictWeakOrdering comp); + +/*! \p binary_search is a vectorized version of binary search: for each + * iterator \c v in [values_first, values_last) it attempts to + * find the value *v in an ordered range [first, last). + * It returns \c true if an element that is equivalent to \c value + * is present in [first, last) and \c false if no such element + * exists. This version of \p binary_search uses function object + * \c comp for comparison. + * + * \param first The beginning of the ordered sequence. + * \param last The end of the ordered sequence. + * \param values_first The beginning of the search values sequence. + * \param values_last The end of the search values sequence. + * \param result The beginning of the output sequence. + * \param comp The comparison operator. + * + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam InputIterator is a model of Input Iterator. and \c InputIterator's \c + * value_type is LessThanComparable. + * \tparam OutputIterator is a model of Output + * Iterator. and bool is convertible to \c OutputIterator's \c value_type. \tparam StrictWeakOrdering is a model of + * Strict Weak Ordering. + * + * \pre The ranges [first,last) and [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p binary_search + * to search for multiple values in a ordered range. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector input(5); + * + * input[0] = 0; + * input[1] = 2; + * input[2] = 5; + * input[3] = 7; + * input[4] = 8; + * + * thrust::device_vector values(6); + * values[0] = 0; + * values[1] = 1; + * values[2] = 2; + * values[3] = 3; + * values[4] = 8; + * values[5] = 9; + * + * thrust::device_vector output(6); + * + * thrust::binary_search(input.begin(), input.end(), + * values.begin(), values.end(), + * output.begin(), + * thrust::less()); + * + * // output is now [true, false, true, false, true, false] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/binary_search + * \see \p lower_bound + * \see \p upper_bound + * \see \p equal_range + */ +template +OutputIterator binary_search( + ForwardIterator first, + ForwardIterator last, + InputIterator values_first, + InputIterator values_last, + OutputIterator result, + StrictWeakOrdering comp); + +/*! \} // end vectorized_binary_search + */ + +/*! \} // end binary_search + */ + +/*! \} // end searching + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/complex.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/complex.h new file mode 100644 index 0000000000000000000000000000000000000000..1cca771fa455796e91eac51462f942d43c26e879 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/complex.h @@ -0,0 +1,854 @@ +/* + * Copyright 2008-2019 NVIDIA Corporation + * Copyright 2013 Filipe RNC Maia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file complex.h + * \brief Complex numbers + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include + +#include +#include +#include + +#define THRUST_STD_COMPLEX_REAL(z) \ + reinterpret_cast::value_type(&)[2]>(z)[0] +#define THRUST_STD_COMPLEX_IMAG(z) \ + reinterpret_cast::value_type(&)[2]>(z)[1] +#define THRUST_STD_COMPLEX_DEVICE _CCCL_DEVICE + +THRUST_NAMESPACE_BEGIN + +/* + * Calls to the standard math library from inside the thrust namespace + * with real arguments require explicit scope otherwise they will fail + * to resolve as it will find the equivalent complex function but then + * fail to match the template, and give up looking for other scopes. + */ + +/*! \addtogroup numerics + * \{ + */ + +/*! \addtogroup complex_numbers Complex Numbers + * \{ + */ + +/*! \p complex is the Thrust equivalent to std::complex. It is + * functionally identical to it, but can also be used in device code which + * std::complex currently cannot. + * + * \tparam T The type used to hold the real and imaginary parts. Should be + * float or double. Others types are not supported. + * + */ +template +struct complex +{ +public: + /*! \p value_type is the type of \p complex's real and imaginary parts. + */ + using value_type = T; + + /* --- Constructors --- */ + + /*! Construct a complex number with an imaginary part of 0. + * + * \param re The real part of the number. + */ + _CCCL_HOST_DEVICE complex(const T& re); + + /*! Construct a complex number from its real and imaginary parts. + * + * \param re The real part of the number. + * \param im The imaginary part of the number. + */ + _CCCL_HOST_DEVICE complex(const T& re, const T& im); + + /*! Default construct a complex number. + */ + complex() = default; + + /*! This copy constructor copies from a \p complex with a type that is + * convertible to this \p complex's \c value_type. + * + * \param z The \p complex to copy from. + */ + complex(const complex& z) = default; + + /*! This converting copy constructor copies from a \p complex with a type + * that is convertible to this \p complex's \c value_type. + * + * \param z The \p complex to copy from. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex(const complex& z); + + /*! This converting copy constructor copies from a std::complex with + * a type that is convertible to this \p complex's \c value_type. + * + * \param z The \p complex to copy from. + */ + _CCCL_HOST THRUST_STD_COMPLEX_DEVICE complex(const std::complex& z); + + /*! This converting copy constructor copies from a std::complex with + * a type that is convertible to this \p complex's \c value_type. + * + * \param z The \p complex to copy from. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST THRUST_STD_COMPLEX_DEVICE complex(const std::complex& z); + + /* --- Assignment Operators --- */ + + /*! Assign `re` to the real part of this \p complex and set the imaginary part + * to 0. + * + * \param re The real part of the number. + */ + _CCCL_HOST_DEVICE complex& operator=(const T& re); + + /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this + * \p complex respectively. + * + * \param z The \p complex to copy from. + */ + complex& operator=(const complex& z) = default; + + /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this + * \p complex respectively. + * + * \param z The \p complex to copy from. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex& operator=(const complex& z); + + /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this + * \p complex respectively. + * + * \param z The \p complex to copy from. + */ + _CCCL_HOST THRUST_STD_COMPLEX_DEVICE complex& operator=(const std::complex& z); + + /*! Assign `z.real()` and `z.imag()` to the real and imaginary parts of this + * \p complex respectively. + * + * \param z The \p complex to copy from. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST THRUST_STD_COMPLEX_DEVICE complex& operator=(const std::complex& z); + + /* --- Compound Assignment Operators --- */ + + /*! Adds a \p complex to this \p complex and assigns the result to this + * \p complex. + * + * \param z The \p complex to be added. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex& operator+=(const complex& z); + + /*! Subtracts a \p complex from this \p complex and assigns the result to + * this \p complex. + * + * \param z The \p complex to be subtracted. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex& operator-=(const complex& z); + + /*! Multiplies this \p complex by another \p complex and assigns the result + * to this \p complex. + * + * \param z The \p complex to be multiplied. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex& operator*=(const complex& z); + + /*! Divides this \p complex by another \p complex and assigns the result to + * this \p complex. + * + * \param z The \p complex to be divided. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex& operator/=(const complex& z); + + /*! Adds a scalar to this \p complex and assigns the result to this + * \p complex. + * + * \param z The \p complex to be added. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex& operator+=(const U& z); + + /*! Subtracts a scalar from this \p complex and assigns the result to + * this \p complex. + * + * \param z The scalar to be subtracted. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex& operator-=(const U& z); + + /*! Multiplies this \p complex by a scalar and assigns the result + * to this \p complex. + * + * \param z The scalar to be multiplied. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex& operator*=(const U& z); + + /*! Divides this \p complex by a scalar and assigns the result to + * this \p complex. + * + * \param z The scalar to be divided. + * + * \tparam U is convertible to \c value_type. + */ + template + _CCCL_HOST_DEVICE complex& operator/=(const U& z); + + /* --- Getter functions --- + * The volatile ones are there to help for example + * with certain reductions optimizations + */ + + /*! Returns the real part of this \p complex. + */ + _CCCL_HOST_DEVICE T real() const volatile + { + return data.x; + } + + /*! Returns the imaginary part of this \p complex. + */ + _CCCL_HOST_DEVICE T imag() const volatile + { + return data.y; + } + + /*! Returns the real part of this \p complex. + */ + _CCCL_HOST_DEVICE T real() const + { + return data.x; + } + + /*! Returns the imaginary part of this \p complex. + */ + _CCCL_HOST_DEVICE T imag() const + { + return data.y; + } + + /* --- Setter functions --- + * The volatile ones are there to help for example + * with certain reductions optimizations + */ + + /*! Sets the real part of this \p complex. + * + * \param re The new real part of this \p complex. + */ + _CCCL_HOST_DEVICE void real(T re) volatile + { + data.x = re; + } + + /*! Sets the imaginary part of this \p complex. + * + * \param im The new imaginary part of this \p complex.e + */ + _CCCL_HOST_DEVICE void imag(T im) volatile + { + data.y = im; + } + + /*! Sets the real part of this \p complex. + * + * \param re The new real part of this \p complex. + */ + _CCCL_HOST_DEVICE void real(T re) + { + data.x = re; + } + + /*! Sets the imaginary part of this \p complex. + * + * \param im The new imaginary part of this \p complex. + */ + _CCCL_HOST_DEVICE void imag(T im) + { + data.y = im; + } + + /* --- Casting functions --- */ + + /*! Casts this \p complex to a std::complex of the same type. + */ + _CCCL_HOST operator std::complex() const + { + return std::complex(real(), imag()); + } + +private: +#if _CCCL_CUDA_COMPILER(NVCC, <, 11, 7) + struct __align__(sizeof(T) * 2) storage +#elif _CCCL_COMPILER(ICC) + struct storage +#else // !(_CCCL_COMPILER(ICC) || _CCCL_CUDA_COMPILER(NVCC, <, 11, 7)) + struct alignas(sizeof(T) * 2) storage +#endif // !(_CCCL_COMPILER(ICC) || _CCCL_CUDA_COMPILER(NVCC, <, 11, 7)) + { + T x; + T y; + } +#if _CCCL_COMPILER(ICC) + __attribute__((aligned(sizeof(T) * 2))) +#endif // _CCCL_COMPILER(ICC) + ; + storage data; +}; + +/* --- General Functions --- */ + +/*! Returns the magnitude (also known as absolute value) of a \p complex. + * + * \param z The \p complex from which to calculate the absolute value. + */ +template +_CCCL_HOST_DEVICE T abs(const complex& z); + +/*! Returns the phase angle (also known as argument) in radians of a \p complex. + * + * \param z The \p complex from which to calculate the phase angle. + */ +template +_CCCL_HOST_DEVICE T arg(const complex& z); + +/*! Returns the square of the magnitude of a \p complex. + * + * \param z The \p complex from which to calculate the norm. + */ +template +_CCCL_HOST_DEVICE T norm(const complex& z); + +/*! Returns the complex conjugate of a \p complex. + * + * \param z The \p complex from which to calculate the complex conjugate. + */ +template +_CCCL_HOST_DEVICE complex conj(const complex& z); + +/*! Returns a \p complex with the specified magnitude and phase. + * + * \param m The magnitude of the returned \p complex. + * \param theta The phase of the returned \p complex in radians. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> polar(const T0& m, const T1& theta = T1()); + +/*! Returns the projection of a \p complex on the Riemann sphere. + * For all finite \p complex it returns the argument. For \p complexs + * with a non finite part returns (INFINITY,+/-0) where the sign of + * the zero matches the sign of the imaginary part of the argument. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex proj(const T& z); + +/* --- Binary Arithmetic operators --- */ + +/*! Adds two \p complex numbers. + * + * The value types of the two \p complex types should be compatible and the + * type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The first \p complex. + * \param y The second \p complex. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator+(const complex& x, const complex& y); + +/*! Adds a scalar to a \p complex number. + * + * The value type of the \p complex should be compatible with the scalar and + * the type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The \p complex. + * \param y The scalar. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator+(const complex& x, const T1& y); + +/*! Adds a \p complex number to a scalar. + * + * The value type of the \p complex should be compatible with the scalar and + * the type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The scalar. + * \param y The \p complex. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator+(const T0& x, const complex& y); + +/*! Subtracts two \p complex numbers. + * + * The value types of the two \p complex types should be compatible and the + * type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The first \p complex (minuend). + * \param y The second \p complex (subtrahend). + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator-(const complex& x, const complex& y); + +/*! Subtracts a scalar from a \p complex number. + * + * The value type of the \p complex should be compatible with the scalar and + * the type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The \p complex (minuend). + * \param y The scalar (subtrahend). + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator-(const complex& x, const T1& y); + +/*! Subtracts a \p complex number from a scalar. + * + * The value type of the \p complex should be compatible with the scalar and + * the type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The scalar (minuend). + * \param y The \p complex (subtrahend). + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator-(const T0& x, const complex& y); + +/*! Multiplies two \p complex numbers. + * + * The value types of the two \p complex types should be compatible and the + * type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The first \p complex. + * \param y The second \p complex. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator*(const complex& x, const complex& y); + +/*! Multiplies a \p complex number by a scalar. + * + * \param x The \p complex. + * \param y The scalar. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator*(const complex& x, const T1& y); + +/*! Multiplies a scalar by a \p complex number. + * + * The value type of the \p complex should be compatible with the scalar and + * the type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The scalar. + * \param y The \p complex. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator*(const T0& x, const complex& y); + +/*! Divides two \p complex numbers. + * + * The value types of the two \p complex types should be compatible and the + * type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The numerator (dividend). + * \param y The denomimator (divisor). + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator/(const complex& x, const complex& y); + +/*! Divides a \p complex number by a scalar. + * + * The value type of the \p complex should be compatible with the scalar and + * the type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The complex numerator (dividend). + * \param y The scalar denomimator (divisor). + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator/(const complex& x, const T1& y); + +/*! Divides a scalar by a \p complex number. + * + * The value type of the \p complex should be compatible with the scalar and + * the type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The scalar numerator (dividend). + * \param y The complex denomimator (divisor). + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> operator/(const T0& x, const complex& y); + +/* --- Unary Arithmetic operators --- */ + +/*! Unary plus, returns its \p complex argument. + * + * \param y The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex operator+(const complex& y); + +/*! Unary minus, returns the additive inverse (negation) of its \p complex + * argument. + * + * \param y The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex operator-(const complex& y); + +/* --- Exponential Functions --- */ + +/*! Returns the complex exponential of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex exp(const complex& z); + +/*! Returns the complex natural logarithm of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex log(const complex& z); + +/*! Returns the complex base 10 logarithm of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex log10(const complex& z); + +/* --- Power Functions --- */ + +/*! Returns a \p complex number raised to another. + * + * The value types of the two \p complex types should be compatible and the + * type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The base. + * \param y The exponent. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> pow(const complex& x, const complex& y); + +/*! Returns a \p complex number raised to a scalar. + * + * The value type of the \p complex should be compatible with the scalar and + * the type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The base. + * \param y The exponent. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> pow(const complex& x, const T1& y); + +/*! Returns a scalar raised to a \p complex number. + * + * The value type of the \p complex should be compatible with the scalar and + * the type of the returned \p complex is the promoted type of the two arguments. + * + * \param x The base. + * \param y The exponent. + */ +template +_CCCL_HOST_DEVICE complex<::cuda::std::common_type_t> pow(const T0& x, const complex& y); + +/*! Returns the complex square root of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex sqrt(const complex& z); + +/* --- Trigonometric Functions --- */ + +/*! Returns the complex cosine of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex cos(const complex& z); + +/*! Returns the complex sine of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex sin(const complex& z); + +/*! Returns the complex tangent of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex tan(const complex& z); + +/* --- Hyperbolic Functions --- */ + +/*! Returns the complex hyperbolic cosine of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex cosh(const complex& z); + +/*! Returns the complex hyperbolic sine of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex sinh(const complex& z); + +/*! Returns the complex hyperbolic tangent of a \p complex number. + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex tanh(const complex& z); + +/* --- Inverse Trigonometric Functions --- */ + +/*! Returns the complex arc cosine of a \p complex number. + * + * The range of the real part of the result is [0, Pi] and + * the range of the imaginary part is [-inf, +inf] + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex acos(const complex& z); + +/*! Returns the complex arc sine of a \p complex number. + * + * The range of the real part of the result is [-Pi/2, Pi/2] and + * the range of the imaginary part is [-inf, +inf] + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex asin(const complex& z); + +/*! Returns the complex arc tangent of a \p complex number. + * + * The range of the real part of the result is [-Pi/2, Pi/2] and + * the range of the imaginary part is [-inf, +inf] + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex atan(const complex& z); + +/* --- Inverse Hyperbolic Functions --- */ + +/*! Returns the complex inverse hyperbolic cosine of a \p complex number. + * + * The range of the real part of the result is [0, +inf] and + * the range of the imaginary part is [-Pi, Pi] + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex acosh(const complex& z); + +/*! Returns the complex inverse hyperbolic sine of a \p complex number. + * + * The range of the real part of the result is [-inf, +inf] and + * the range of the imaginary part is [-Pi/2, Pi/2] + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex asinh(const complex& z); + +/*! Returns the complex inverse hyperbolic tangent of a \p complex number. + * + * The range of the real part of the result is [-inf, +inf] and + * the range of the imaginary part is [-Pi/2, Pi/2] + * + * \param z The \p complex argument. + */ +template +_CCCL_HOST_DEVICE complex atanh(const complex& z); + +/* --- Stream Operators --- */ + +/*! Writes to an output stream a \p complex number in the form (real, imaginary). + * + * \param os The output stream. + * \param z The \p complex number to output. + */ +template +std::basic_ostream& operator<<(std::basic_ostream& os, const complex& z); + +/*! Reads a \p complex number from an input stream. + * + * The recognized formats are: + * - real + * - (real) + * - (real, imaginary) + * + * The values read must be convertible to the \p complex's \c value_type + * + * \param is The input stream. + * \param z The \p complex number to set. + */ +template +_CCCL_HOST std::basic_istream& operator>>(std::basic_istream& is, complex& z); + +/* --- Equality Operators --- */ + +/*! Returns true if two \p complex numbers are equal and false otherwise. + * + * \param x The first \p complex. + * \param y The second \p complex. + */ +template +_CCCL_HOST_DEVICE bool operator==(const complex& x, const complex& y); + +/*! Returns true if two \p complex numbers are equal and false otherwise. + * + * \param x The first \p complex. + * \param y The second \p complex. + */ +template +_CCCL_HOST THRUST_STD_COMPLEX_DEVICE bool operator==(const complex& x, const std::complex& y); + +/*! Returns true if two \p complex numbers are equal and false otherwise. + * + * \param x The first \p complex. + * \param y The second \p complex. + */ +template +_CCCL_HOST THRUST_STD_COMPLEX_DEVICE bool operator==(const std::complex& x, const complex& y); + +/*! Returns true if the imaginary part of the \p complex number is zero and + * the real part is equal to the scalar. Returns false otherwise. + * + * \param x The scalar. + * \param y The \p complex. + */ +template +_CCCL_HOST_DEVICE bool operator==(const T0& x, const complex& y); + +/*! Returns true if the imaginary part of the \p complex number is zero and + * the real part is equal to the scalar. Returns false otherwise. + * + * \param x The \p complex. + * \param y The scalar. + */ +template +_CCCL_HOST_DEVICE bool operator==(const complex& x, const T1& y); + +/*! Returns true if two \p complex numbers are different and false otherwise. + * + * \param x The first \p complex. + * \param y The second \p complex. + */ +template +_CCCL_HOST_DEVICE bool operator!=(const complex& x, const complex& y); + +/*! Returns true if two \p complex numbers are different and false otherwise. + * + * \param x The first \p complex. + * \param y The second \p complex. + */ +template +_CCCL_HOST THRUST_STD_COMPLEX_DEVICE bool operator!=(const complex& x, const std::complex& y); + +/*! Returns true if two \p complex numbers are different and false otherwise. + * + * \param x The first \p complex. + * \param y The second \p complex. + */ +template +_CCCL_HOST THRUST_STD_COMPLEX_DEVICE bool operator!=(const std::complex& x, const complex& y); + +/*! Returns true if the imaginary part of the \p complex number is not zero or + * the real part is different from the scalar. Returns false otherwise. + * + * \param x The scalar. + * \param y The \p complex. + */ +template +_CCCL_HOST_DEVICE bool operator!=(const T0& x, const complex& y); + +/*! Returns true if the imaginary part of the \p complex number is not zero or + * the real part is different from the scalar. Returns false otherwise. + * + * \param x The \p complex. + * \param y The scalar. + */ +template +_CCCL_HOST_DEVICE bool operator!=(const complex& x, const T1& y); + +THRUST_NAMESPACE_END + +#include + +#undef THRUST_STD_COMPLEX_REAL +#undef THRUST_STD_COMPLEX_IMAG +#undef THRUST_STD_COMPLEX_DEVICE + +/*! \} // complex_numbers + */ + +/*! \} // numerics + */ diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/count.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/count.h new file mode 100644 index 0000000000000000000000000000000000000000..8febab3399591b07eb5aae5247ba87b7072526a3 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/count.h @@ -0,0 +1,246 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file count.h + * \brief Counting elements in a range + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup algorithms + */ + +/*! \addtogroup reductions + * \ingroup algorithms + * \{ + */ + +/*! \addtogroup counting + * \ingroup reductions + * \{ + */ + +/*! \p count finds the number of elements in [first,last) that are equal + * to \p value. More precisely, \p count returns the number of iterators \c i in + * [first, last) such that *i == value. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param value The value to be counted. + * \return The number of elements equal to \p value. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator must be a model of Input + * Iterator and \c InputIterator's \c value_type must be a model of must be a model of Equality Comparable. \tparam + * EqualityComparable must be a model of Equality Comparable and can be compared for + * equality with \c InputIterator's \c value_type + * + * The following code snippet demonstrates how to use \p count to + * count the number of instances in a range of a value of interest using the \p thrust::device execution policy: + * + * \code + * #include + * #include + * #include + * ... + * // put 3 1s in a device_vector + * thrust::device_vector vec(5,0); + * vec[1] = 1; + * vec[3] = 1; + * vec[4] = 1; + * + * // count the 1s + * int result = thrust::count(thrust::device, vec.begin(), vec.end(), 1); + * // result == 3 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/count + */ +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +count(const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + const EqualityComparable& value); + +/*! \p count finds the number of elements in [first,last) that are equal + * to \p value. More precisely, \p count returns the number of iterators \c i in + * [first, last) such that *i == value. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param value The value to be counted. + * \return The number of elements equal to \p value. + * + * \tparam InputIterator must be a model of Input + * Iterator and \c InputIterator's \c value_type must be a model of must be a model of Equality Comparable. \tparam + * EqualityComparable must be a model of Equality Comparable and can be compared for + * equality with \c InputIterator's \c value_type + * + * The following code snippet demonstrates how to use \p count to + * count the number of instances in a range of a value of interest. + * \code + * #include + * #include + * ... + * // put 3 1s in a device_vector + * thrust::device_vector vec(5,0); + * vec[1] = 1; + * vec[3] = 1; + * vec[4] = 1; + * + * // count the 1s + * int result = thrust::count(vec.begin(), vec.end(), 1); + * // result == 3 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/count + */ +template +typename thrust::iterator_traits::difference_type +count(InputIterator first, InputIterator last, const EqualityComparable& value); + +/*! \p count_if finds the number of elements in [first,last) for which + * a predicate is \c true. More precisely, \p count_if returns the number of iterators + * \c i in [first, last) such that pred(*i) == true. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param pred The predicate. + * \return The number of elements where \p pred is \c true. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator must be a model of Input + * Iterator and \c InputIterator's \c value_type must be convertible to \c Predicate's \c argument_type. \tparam + * Predicate must be a model of Predicate. + * + * The following code snippet demonstrates how to use \p count to + * count the number of odd numbers in a range using the \p thrust::device execution policy: + * + * \code + * #include + * #include + * #include + * ... + * struct is_odd + * { + * __host__ __device__ + * bool operator()(int &x) + * { + * return x & 1; + * } + * }; + * ... + * // fill a device_vector with even & odd numbers + * thrust::device_vector vec(5); + * vec[0] = 0; + * vec[1] = 1; + * vec[2] = 2; + * vec[3] = 3; + * vec[4] = 4; + * + * // count the odd elements in vec + * int result = thrust::count_if(thrust::device, vec.begin(), vec.end(), is_odd()); + * // result == 2 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/count + */ +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +count_if(const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + Predicate pred); + +/*! \p count_if finds the number of elements in [first,last) for which + * a predicate is \c true. More precisely, \p count_if returns the number of iterators + * \c i in [first, last) such that pred(*i) == true. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param pred The predicate. + * \return The number of elements where \p pred is \c true. + * + * \tparam InputIterator must be a model of Input + * Iterator and \c InputIterator's \c value_type must be convertible to \c Predicate's \c argument_type. \tparam + * Predicate must be a model of Predicate. + * + * The following code snippet demonstrates how to use \p count to + * count the number of odd numbers in a range. + * \code + * #include + * #include + * ... + * struct is_odd + * { + * __host__ __device__ + * bool operator()(int &x) + * { + * return x & 1; + * } + * }; + * ... + * // fill a device_vector with even & odd numbers + * thrust::device_vector vec(5); + * vec[0] = 0; + * vec[1] = 1; + * vec[2] = 2; + * vec[3] = 3; + * vec[4] = 4; + * + * // count the odd elements in vec + * int result = thrust::count_if(vec.begin(), vec.end(), is_odd()); + * // result == 2 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/count + */ +template +typename thrust::iterator_traits::difference_type +count_if(InputIterator first, InputIterator last, Predicate pred); + +/*! \} // end counting + * \} // end reductions + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_delete.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_delete.h new file mode 100644 index 0000000000000000000000000000000000000000..bfc8d398d09d5cd2f772c2a4a1f390374f942138 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_delete.h @@ -0,0 +1,59 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file + * \brief Deletes variables in device memory. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup memory_management Memory Management + * \{ + */ + +/*! \p device_delete deletes a \p device_ptr allocated with + * \p device_new. + * + * \param ptr The \p device_ptr to delete, assumed to have + * been allocated with \p device_new. + * \param n The number of objects to destroy at \p ptr. Defaults to \c 1 + * similar to \p device_new. + * + * \see device_ptr + * \see device_new + */ +template +inline void device_delete(thrust::device_ptr ptr, const size_t n = 1); + +/*! \} // memory_management + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_free.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_free.h new file mode 100644 index 0000000000000000000000000000000000000000..4269a82694b2688bf839508423e235e81327783d --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_free.h @@ -0,0 +1,72 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file + * \brief Deallocates storage allocated by \p device_malloc. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup memory_management Memory Management + * \{ + */ + +/*! \p device_free deallocates memory allocated by the function \p device_malloc. + * + * \param ptr A \p device_ptr pointing to memory to be deallocated. + * + * The following code snippet demonstrates how to use \p device_free to + * deallocate memory allocated by \p device_malloc. + * + * \code + * #include + * #include + * ... + * // allocate some integers with device_malloc + * const int N = 100; + * thrust::device_ptr int_array = thrust::device_malloc(N); + * + * // manipulate integers + * ... + * + * // deallocate with device_free + * thrust::device_free(int_array); + * \endcode + * + * \see device_ptr + * \see device_malloc + */ +inline void device_free(thrust::device_ptr ptr); + +/*! \} // memory_management + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_make_unique.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_make_unique.h new file mode 100644 index 0000000000000000000000000000000000000000..133552d46da66950fdf52a128e5288b94c9eb673 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_make_unique.h @@ -0,0 +1,56 @@ +/* + * Copyright 2008-2018 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file device_make_unique.h + * \brief A factory function for creating `unique_ptr`s to device objects. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// + +template +_CCCL_HOST auto device_make_unique(Args&&... args) + -> decltype(uninitialized_allocate_unique(::cuda::std::declval>())) +{ + // FIXME: This is crude - we construct an unnecessary T on the host for + // `device_new`. We need a proper dispatched `construct` algorithm to + // do this properly. + auto p = uninitialized_allocate_unique(device_allocator()); + device_new(p.get(), T(THRUST_FWD(args)...)); + return p; +} + +/////////////////////////////////////////////////////////////////////////////// + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc.h new file mode 100644 index 0000000000000000000000000000000000000000..be07dca52f65a856dc4bb688bda74b0525315dfd --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc.h @@ -0,0 +1,108 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file + * \brief Allocates storage in device memory. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +#include // for std::size_t + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup memory_management Memory Management + * \{ + */ + +/*! This version of \p device_malloc allocates sequential device storage + * for bytes. + * + * \param n The number of bytes to allocate sequentially + * in device memory. + * \return A \p device_ptr to the newly allocated memory. + * + * The following code snippet demonstrates how to use \p device_malloc to + * allocate a range of device memory. + * + * \code + * #include + * #include + * ... + * // allocate some memory with device_malloc + * const int N = 100; + * thrust::device_ptr void_ptr = thrust::device_malloc(N); + * + * // manipulate memory + * ... + * + * // deallocate with device_free + * thrust::device_free(void_ptr); + * \endcode + * + * \see device_ptr + * \see device_free + */ +inline thrust::device_ptr device_malloc(const std::size_t n); + +/*! This version of \p device_malloc allocates sequential device storage for + * new objects of the given type. + * + * \param n The number of objects of type T to allocate + * sequentially in device memory. + * \return A \p device_ptr to the newly allocated memory. + * + * The following code snippet demonstrates how to use \p device_malloc to + * allocate a range of device memory. + * + * \code + * #include + * #include + * ... + * // allocate some integers with device_malloc + * const int N = 100; + * thrust::device_ptr int_array = thrust::device_malloc(N); + * + * // manipulate integers + * ... + * + * // deallocate with device_free + * thrust::device_free(int_array); + * \endcode + * + * \see device_ptr + * \see device_free + */ +template +inline thrust::device_ptr device_malloc(const std::size_t n); + +/*! \} // memory_management + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc_allocator.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc_allocator.h new file mode 100644 index 0000000000000000000000000000000000000000..c9de52a8404f13d787dc04142d60f8382c2d155c --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_malloc_allocator.h @@ -0,0 +1,193 @@ +/* + * Copyright 2008-2018 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file + * \brief An allocator which allocates storage with \p device_malloc. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include + +#include +#include + +THRUST_NAMESPACE_BEGIN + +// forward declarations to WAR circular #includes +#ifndef _CCCL_DOXYGEN_INVOKED // Do not document +template +class device_ptr; +template +device_ptr device_malloc(const std::size_t n); +#endif // _CCCL_DOXYGEN_INVOKED + +/*! \addtogroup allocators Allocators + * \ingroup memory_management + * \{ + */ + +/*! \p device_malloc_allocator is a device memory allocator that employs the + * \p device_malloc function for allocation. + * + * \p device_malloc_allocator is deprecated in favor of thrust::mr + * memory resource-based allocators. + * + * \see device_malloc + * \see device_ptr + * \see device_allocator + * \see https://en.cppreference.com/w/cpp/memory/allocator + */ +template +class device_malloc_allocator +{ +public: + /*! Type of element allocated, \c T. */ + using value_type = T; + + /*! Pointer to allocation, \c device_ptr. */ + using pointer = device_ptr; + + /*! \c const pointer to allocation, \c device_ptr. */ + using const_pointer = device_ptr; + + /*! Reference to allocated element, \c device_reference. */ + using reference = device_reference; + + /*! \c const reference to allocated element, \c device_reference. */ + using const_reference = device_reference; + + /*! Type of allocation size, \c std::size_t. */ + using size_type = std::size_t; + + /*! Type of allocation difference, \c pointer::difference_type. */ + using difference_type = typename pointer::difference_type; + + /*! The \p rebind metafunction provides the type of a \p device_malloc_allocator + * instantiated with another type. + * + * \tparam U The other type to use for instantiation. + */ + template + struct rebind + { + /*! The alias \p other gives the type of the rebound \p device_malloc_allocator. + */ + using other = device_malloc_allocator; + }; // end rebind + + /*! No-argument constructor has no effect. */ + _CCCL_HOST_DEVICE inline device_malloc_allocator() {} + + /*! No-argument destructor has no effect. */ + _CCCL_HOST_DEVICE inline ~device_malloc_allocator() {} + + /*! Copy constructor has no effect. */ + _CCCL_HOST_DEVICE inline device_malloc_allocator(device_malloc_allocator const&) {} + + /*! Constructor from other \p device_malloc_allocator has no effect. */ + template + _CCCL_HOST_DEVICE inline device_malloc_allocator(device_malloc_allocator const&) + {} + + device_malloc_allocator& operator=(const device_malloc_allocator&) = default; + + /*! Returns the address of an allocated object. + * \return &r. + */ + _CCCL_HOST_DEVICE inline pointer address(reference r) + { + return &r; + } + + /*! Returns the address an allocated object. + * \return &r. + */ + _CCCL_HOST_DEVICE inline const_pointer address(const_reference r) + { + return &r; + } + + /*! Allocates storage for \p cnt objects. + * \param cnt The number of objects to allocate. + * \return A \p pointer to uninitialized storage for \p cnt objects. + * \note Memory allocated by this function must be deallocated with \p deallocate. + */ + _CCCL_HOST inline pointer allocate(size_type cnt, const_pointer = const_pointer(static_cast(0))) + { + if (cnt > this->max_size()) + { + throw std::bad_alloc(); + } // end if + + return pointer(device_malloc(cnt)); + } // end allocate() + + /*! Deallocates storage for objects allocated with \p allocate. + * \param p A \p pointer to the storage to deallocate. + * \param cnt The size of the previous allocation. + * \note Memory deallocated by this function must previously have been + * allocated with \p allocate. + */ + _CCCL_HOST inline void deallocate(pointer p, size_type cnt) noexcept + { + // silence unused parameter warning while still leaving the parameter name for Doxygen + (void) (cnt); + + device_free(p); + } // end deallocate() + + /*! Returns the largest value \c n for which allocate(n) might succeed. + * \return The largest value \c n for which allocate(n) might succeed. + */ + inline size_type max_size() const + { + return (std::numeric_limits::max)() / sizeof(T); + } // end max_size() + + /*! Compares against another \p device_malloc_allocator for equality. + * \return \c true + */ + _CCCL_HOST_DEVICE inline bool operator==(device_malloc_allocator const&) const + { + return true; + } + + /*! Compares against another \p device_malloc_allocator for inequality. + * \return \c false + */ + _CCCL_HOST_DEVICE inline bool operator!=(device_malloc_allocator const& a) const + { + return !operator==(a); + } +}; // end device_malloc_allocator + +/*! \} // allocators + */ + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new.h new file mode 100644 index 0000000000000000000000000000000000000000..dc1dd19054e295093ad82b24d280d61460257907 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new.h @@ -0,0 +1,91 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file device_new.h + * \brief Constructs new elements in device memory + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// #include this for size_t +#include + +#include + +THRUST_NAMESPACE_BEGIN + +/*! + * \addtogroup memory_management Memory Management + * \{ + */ + +/*! \p device_new implements the placement \c new operator for types + * resident in device memory. \p device_new calls T's null + * constructor on a array of objects in device memory. + * No memory is allocated by this function. + * + * \param p A \p device_ptr to a region of device memory into which + * to construct one or many Ts. + * \param n The number of objects to construct at \p p. + * \return p, casted to T's type. + * + * \see device_ptr + */ +template +device_ptr device_new(device_ptr p, const size_t n = 1); + +/*! \p device_new implements the placement new operator for types + * resident in device memory. \p device_new calls T's copy + * constructor on a array of objects in device memory. No memory is + * allocated by this function. + * + * \param p A \p device_ptr to a region of device memory into which to + * construct one or many Ts. + * \param exemplar The value from which to copy. + * \param n The number of objects to construct at \p p. + * \return p, casted to T's type. + * + * \see device_ptr + * \see fill + */ +template +device_ptr device_new(device_ptr p, const T& exemplar, const size_t n = 1); + +/*! \p device_new implements the new operator for types resident in device memory. + * It allocates device memory large enough to hold \p n new objects of type \c T. + * + * \param n The number of objects to allocate. Defaults to \c 1. + * \return A \p device_ptr to the newly allocated region of device memory. + */ +template +device_ptr device_new(const size_t n = 1); + +/*! \} // memory_management + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new_allocator.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new_allocator.h new file mode 100644 index 0000000000000000000000000000000000000000..f9052a0dcfbb1e7495d56b7fffc3a245bc4c45c0 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_new_allocator.h @@ -0,0 +1,181 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file + * \brief An allocator which allocates storage with \p device_new. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include + +#include +#include + +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup allocators Allocators + * \ingroup memory_management + * \{ + */ + +/*! \p device_new_allocator is a device memory allocator that employs the + * \p device_new function for allocation. + * + * \see device_new + * \see device_ptr + * \see https://en.cppreference.com/w/cpp/memory/allocator + */ +template +class device_new_allocator +{ +public: + /*! Type of element allocated, \c T. */ + using value_type = T; + + /*! Pointer to allocation, \c device_ptr. */ + using pointer = device_ptr; + + /*! \c const pointer to allocation, \c device_ptr. */ + using const_pointer = device_ptr; + + /*! Reference to allocated element, \c device_reference. */ + using reference = device_reference; + + /*! \c const reference to allocated element, \c device_reference. */ + using const_reference = device_reference; + + /*! Type of allocation size, \c ::cuda::std::size_t. */ + using size_type = ::cuda::std::size_t; + + /*! Type of allocation difference, \c pointer::difference_type. */ + using difference_type = typename pointer::difference_type; + + /*! The \p rebind metafunction provides the type of a \p device_new_allocator + * instantiated with another type. + * + * \tparam U The other type to use for instantiation. + */ + template + struct rebind + { + /*! The alias \p other gives the type of the rebound \p device_new_allocator. + */ + using other = device_new_allocator; + }; // end rebind + + /*! No-argument constructor has no effect. */ + _CCCL_HOST_DEVICE inline device_new_allocator() {} + + /*! No-argument destructor has no effect. */ + _CCCL_HOST_DEVICE inline ~device_new_allocator() {} + + /*! Copy constructor has no effect. */ + _CCCL_HOST_DEVICE inline device_new_allocator(device_new_allocator const&) {} + + /*! Constructor from other \p device_malloc_allocator has no effect. */ + template + _CCCL_HOST_DEVICE inline device_new_allocator(device_new_allocator const&) + {} + + /*! Returns the address of an allocated object. + * \return &r. + */ + _CCCL_HOST_DEVICE inline pointer address(reference r) + { + return &r; + } + + /*! Returns the address an allocated object. + * \return &r. + */ + _CCCL_HOST_DEVICE inline const_pointer address(const_reference r) + { + return &r; + } + + /*! Allocates storage for \p cnt objects. + * \param cnt The number of objects to allocate. + * \return A \p pointer to uninitialized storage for \p cnt objects. + * \note Memory allocated by this function must be deallocated with \p deallocate. + */ + _CCCL_HOST inline pointer allocate(size_type cnt, const_pointer = const_pointer(static_cast(0))) + { + if (cnt > this->max_size()) + { + throw std::bad_alloc(); + } // end if + + // use "::operator new" rather than keyword new + return pointer(device_new(cnt)); + } // end allocate() + + /*! Deallocates storage for objects allocated with \p allocate. + * \param p A \p pointer to the storage to deallocate. + * \param cnt The size of the previous allocation. + * \note Memory deallocated by this function must previously have been + * allocated with \p allocate. + */ + _CCCL_HOST inline void deallocate(pointer p, size_type cnt) noexcept + { + // use "::operator delete" rather than keyword delete + (void) cnt; + device_delete(p); + } // end deallocate() + + /*! Returns the largest value \c n for which allocate(n) might succeed. + * \return The largest value \c n for which allocate(n) might succeed. + */ + _CCCL_HOST_DEVICE inline size_type max_size() const + { + return ::cuda::std::numeric_limits::max THRUST_PREVENT_MACRO_SUBSTITUTION() / sizeof(T); + } // end max_size() + + /*! Compares against another \p device_malloc_allocator for equality. + * \return \c true + */ + _CCCL_HOST_DEVICE inline bool operator==(device_new_allocator const&) + { + return true; + } + + /*! Compares against another \p device_malloc_allocator for inequality. + * \return \c false + */ + _CCCL_HOST_DEVICE inline bool operator!=(device_new_allocator const& a) + { + return !operator==(a); + } +}; // end device_new_allocator + +/*! \} // allocators + */ + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_reference.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_reference.h new file mode 100644 index 0000000000000000000000000000000000000000..7d457b20bfa496472a0e3588b35394e404f8076f --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_reference.h @@ -0,0 +1,977 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file + * \brief A reference to an object which resides in memory associated with the + * device system. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup memory_management Memory Management + * \{ + */ + +/*! \p device_reference acts as a reference-like object to an object stored in device memory. + * \p device_reference is not intended to be used directly; rather, this type + * is the result of dereferencing a \p device_ptr. Similarly, taking the address of + * a \p device_reference yields a \p device_ptr. + * + * \p device_reference may often be used from host code in place of operations defined on + * its associated \c value_type. For example, when \p device_reference refers to an + * arithmetic type, arithmetic operations on it are legal: + * + * \code + * #include + * + * int main() + * { + * thrust::device_vector vec(1, 13); + * + * thrust::device_reference ref_to_thirteen = vec[0]; + * + * int x = ref_to_thirteen + 1; + * + * // x is 14 + * + * return 0; + * } + * \endcode + * + * Similarly, we can print the value of \c ref_to_thirteen in the above code by using an + * \c iostream: + * + * \code + * #include + * #include + * + * int main() + * { + * thrust::device_vector vec(1, 13); + * + * thrust::device_reference ref_to_thirteen = vec[0]; + * + * std::cout << ref_to_thirteen << std::endl; + * + * // 13 is printed + * + * return 0; + * } + * \endcode + * + * Of course, we needn't explicitly create a \p device_reference in the previous + * example, because one is returned by \p device_vector's bracket operator. A more natural + * way to print the value of a \p device_vector element might be: + * + * \code + * #include + * #include + * + * int main() + * { + * thrust::device_vector vec(1, 13); + * + * std::cout << vec[0] << std::endl; + * + * // 13 is printed + * + * return 0; + * } + * \endcode + * + * These kinds of operations should be used sparingly in performance-critical code, because + * they imply a potentially expensive copy between host and device space. + * + * Some operations which are possible with regular objects are impossible with their + * corresponding \p device_reference objects due to the requirements of the C++ language. For + * example, because the member access operator cannot be overloaded, member variables and functions + * of a referent object cannot be directly accessed through its \p device_reference. + * + * The following code, which generates a compiler error, illustrates: + * + * \code + * #include + * + * struct foo + * { + * int x; + * }; + * + * int main() + * { + * thrust::device_vector foo_vec(1); + * + * thrust::device_reference foo_ref = foo_vec[0]; + * + * foo_ref.x = 13; // ERROR: x cannot be accessed through foo_ref + * + * return 0; + * } + * \endcode + * + * Instead, a host space copy must be created to access \c foo's \c x member: + * + * \code + * #include + * + * struct foo + * { + * int x; + * }; + * + * int main() + * { + * thrust::device_vector foo_vec(1); + * + * // create a local host-side foo object + * foo host_foo; + * host_foo.x = 13; + * + * thrust::device_reference foo_ref = foo_vec[0]; + * + * foo_ref = host_foo; + * + * // foo_ref's x member is 13 + * + * return 0; + * } + * \endcode + * + * Another common case where a \p device_reference cannot directly be used in place of + * its referent object occurs when passing them as parameters to functions like \c printf + * which have varargs parameters. Because varargs parameters must be Plain Old Data, a + * \p device_reference to a POD type requires a cast when passed to \c printf: + * + * \code + * #include + * #include + * + * int main() + * { + * thrust::device_vector vec(1,13); + * + * // vec[0] must be cast to int when passing to printf + * printf("%d\n", (int) vec[0]); + * + * return 0; + * } + * \endcode + * + * \see device_ptr + * \see device_vector + */ +template +class device_reference : public thrust::reference, thrust::device_reference> +{ +private: + using super_t = thrust::reference, thrust::device_reference>; + +public: + /*! The type of the value referenced by this type of \p device_reference. + */ + using value_type = typename super_t::value_type; + + /*! The type of the expression &ref, where ref is a \p device_reference. + */ + using pointer = typename super_t::pointer; + + /*! This copy constructor accepts a const reference to another + * \p device_reference. After this \p device_reference is constructed, + * it shall refer to the same object as \p other. + * + * \param other A \p device_reference to copy from. + * + * The following code snippet demonstrates the semantics of this + * copy constructor. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,0); + * thrust::device_reference ref = v[0]; + * + * // ref equals the object at v[0] + * assert(ref == v[0]); + * + * // the address of ref equals the address of v[0] + * assert(&ref == &v[0]); + * + * // modifying v[0] modifies ref + * v[0] = 13; + * assert(ref == 13); + * \endcode + * + * \note This constructor is templated primarily to allow initialization of + * device_reference from device_reference. + */ + template + _CCCL_HOST_DEVICE + device_reference(const device_reference& other, + thrust::detail::enable_if_convertible_t::pointer, pointer>* = 0) + : super_t(other) + {} + + /*! This copy constructor initializes this \p device_reference + * to refer to an object pointed to by the given \p device_ptr. After + * this \p device_reference is constructed, it shall refer to the + * object pointed to by \p ptr. + * + * \param ptr A \p device_ptr to copy from. + * + * The following code snippet demonstrates the semantic of this + * copy constructor. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,0); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals the object pointed to by ptr + * assert(ref == *ptr); + * + * // the address of ref equals ptr + * assert(&ref == ptr); + * + * // modifying *ptr modifies ref + * *ptr = 13; + * assert(ref == 13); + * \endcode + */ + _CCCL_HOST_DEVICE explicit device_reference(const pointer& ptr) + : super_t(ptr) + {} + + /*! This assignment operator assigns the value of the object referenced by + * the given \p device_reference to the object referenced by this + * \p device_reference. + * + * \param other The \p device_reference to assign from. + * \return *this + */ + template + _CCCL_HOST_DEVICE device_reference& operator=(const device_reference& other) + { + return super_t::operator=(other); + } + + /*! Assignment operator assigns the value of the given value to the + * value referenced by this \p device_reference. + * + * \param x The value to assign from. + * \return *this + */ + _CCCL_HOST_DEVICE device_reference& operator=(const value_type& x) + { + return super_t::operator=(x); + } + +// declare these members for the purpose of Doxygenating them +// they actually exist in a base class +#if 0 + /*! Address-of operator returns a \p device_ptr pointing to the object + * referenced by this \p device_reference. It does not return the + * address of this \p device_reference. + * + * \return A \p device_ptr pointing to the object this + * \p device_reference references. + */ + _CCCL_HOST_DEVICE + pointer operator&(void) const; + + /*! Conversion operator converts this \p device_reference to T + * by returning a copy of the object referenced by this + * \p device_reference. + * + * \return A copy of the object referenced by this \p device_reference. + */ + _CCCL_HOST_DEVICE + operator value_type (void) const; + + /*! swaps the value this \p device_reference references with another. + * \p other The other \p device_reference with which to swap. + */ + _CCCL_HOST_DEVICE + void swap(device_reference &other); + + /*! Prefix increment operator increments the object referenced by this + * \p device_reference. + * + * \return *this + * + * The following code snippet demonstrates the semantics of + * \p device_reference's prefix increment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,0); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * + * // increment ref + * ++ref; + * + * // ref equals 1 + * assert(ref == 1); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * \endcode + * + * \note The increment executes as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator++(void); + + /*! Postfix increment operator copies the object referenced by this + * \p device_reference, increments the object referenced by this + * \p device_reference, and returns the copy. + * + * \return A copy of the object referenced by this \p device_reference + * before being incremented. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's postfix increment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,0); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 0 + * assert(*ptr == 0); + * + * // v[0] equals 0 + * assert(v[0] == 0); + * + * // increment ref + * int x = ref++; + * + * // x equals 0 + * assert(x == 0) + * + * // ref equals 1 + * assert(ref == 1); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * \endcode + * + * \note The increment executes as if it were executed on the host. + * This may change in a later version. + */ + value_type operator++(int); + + /*! Addition assignment operator add-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the add-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's addition assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,0); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 0 + * assert(*ptr == 0); + * + * // v[0] equals 0 + * assert(v[0] == 0); + * + * // add-assign ref + * ref += 5; + * + * // ref equals 5 + * assert(ref == 5); + * + * // the object pointed to by ptr equals 5 + * assert(*ptr == 5); + * + * // v[0] equals 5 + * assert(v[0] == 5); + * \endcode + * + * \note The add-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator+=(const T &rhs); + + /*! Prefix decrement operator decrements the object referenced by this + * \p device_reference. + * + * \return *this + * + * The following code snippet demonstrates the semantics of + * \p device_reference's prefix decrement operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,0); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 0 + * assert(*ptr == 0); + * + * // v[0] equals 0 + * assert(v[0] == 0); + * + * // decrement ref + * --ref; + * + * // ref equals -1 + * assert(ref == -1); + * + * // the object pointed to by ptr equals -1 + * assert(*ptr == -1); + * + * // v[0] equals -1 + * assert(v[0] == -1); + * \endcode + * + * \note The decrement executes as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator--(void); + + /*! Postfix decrement operator copies the object referenced by this + * \p device_reference, decrements the object referenced by this + * \p device_reference, and returns the copy. + * + * \return A copy of the object referenced by this \p device_reference + * before being decremented. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's postfix decrement operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,0); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 0 + * assert(*ptr == 0); + * + * // v[0] equals 0 + * assert(v[0] == 0); + * + * // decrement ref + * int x = ref--; + * + * // x equals 0 + * assert(x == 0) + * + * // ref equals -1 + * assert(ref == -1); + * + * // the object pointed to by ptr equals -1 + * assert(*ptr == -1); + * + * // v[0] equals -1 + * assert(v[0] == -1); + * \endcode + * + * \note The decrement executes as if it were executed on the host. + * This may change in a later version. + */ + value_type operator--(int); + + /*! Subtraction assignment operator subtract-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the subtraction-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's addition assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,0); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 0 + * assert(*ptr == 0); + * + * // v[0] equals 0 + * assert(v[0] == 0); + * + * // subtract-assign ref + * ref -= 5; + * + * // ref equals -5 + * assert(ref == -5); + * + * // the object pointed to by ptr equals -5 + * assert(*ptr == -5); + * + * // v[0] equals -5 + * assert(v[0] == -5); + * \endcode + * + * \note The subtract-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator-=(const T &rhs); + + /*! Multiplication assignment operator multiply-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the multiply-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's multiply assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,1); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 1 + * assert(ref == 1); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * + * // multiply-assign ref + * ref *= 5; + * + * // ref equals 5 + * assert(ref == 5); + * + * // the object pointed to by ptr equals 5 + * assert(*ptr == 5); + * + * // v[0] equals 5 + * assert(v[0] == 5); + * \endcode + * + * \note The multiply-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator*=(const T &rhs); + + /*! Division assignment operator divide-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the divide-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's divide assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,5); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 5 + * assert(ref == 5); + * + * // the object pointed to by ptr equals 5 + * assert(*ptr == 5); + * + * // v[0] equals 5 + * assert(v[0] == 5); + * + * // divide-assign ref + * ref /= 5; + * + * // ref equals 1 + * assert(ref == 1); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * \endcode + * + * \note The divide-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator/=(const T &rhs); + + /*! Modulation assignment operator modulus-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the divide-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's divide assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,5); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 5 + * assert(ref == 5); + * + * // the object pointed to by ptr equals 5 + * assert(*ptr == 5); + * + * // v[0] equals 5 + * assert(v[0] == 5); + * + * // modulus-assign ref + * ref %= 5; + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 0 + * assert(*ptr == 0); + * + * // v[0] equals 0 + * assert(v[0] == 0); + * \endcode + * + * \note The modulus-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator%=(const T &rhs); + + /*! Bitwise left shift assignment operator left shift-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the left shift-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's left shift assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,1); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 1 + * assert(ref == 1); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * + * // left shift-assign ref + * ref <<= 1; + * + * // ref equals 2 + * assert(ref == 2); + * + * // the object pointed to by ptr equals 2 + * assert(*ptr == 2); + * + * // v[0] equals 2 + * assert(v[0] == 2); + * \endcode + * + * \note The left shift-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator<<=(const T &rhs); + + /*! Bitwise right shift assignment operator right shift-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the right shift-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's right shift assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,2); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 2 + * assert(ref == 2); + * + * // the object pointed to by ptr equals 2 + * assert(*ptr == 2); + * + * // v[0] equals 2 + * assert(v[0] == 2); + * + * // right shift-assign ref + * ref >>= 1; + * + * // ref equals 1 + * assert(ref == 1); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * \endcode + * + * \note The right shift-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator>>=(const T &rhs); + + /*! Bitwise AND assignment operator AND-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the AND-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's AND assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,1); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 1 + * assert(ref == 1); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * + * // right AND-assign ref + * ref &= 0; + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 0 + * assert(*ptr == 0); + * + * // v[0] equals 0 + * assert(v[0] == 0); + * \endcode + * + * \note The AND-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator&=(const T &rhs); + + /*! Bitwise OR assignment operator OR-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the OR-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's OR assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,0); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 0 + * assert(*ptr == 0); + * + * // v[0] equals 0 + * assert(v[0] == 0); + * + * // right OR-assign ref + * ref |= 1; + * + * // ref equals 1 + * assert(ref == 1); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * \endcode + * + * \note The OR-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator|=(const T &rhs); + + /*! Bitwise XOR assignment operator XOR-assigns the object referenced by this + * \p device_reference and returns this \p device_reference. + * + * \param rhs The right hand side of the XOR-assignment. + * \return *this. + * + * The following code snippet demonstrates the semantics of + * \p device_reference's XOR assignment operator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(1,1); + * thrust::device_ptr ptr = &v[0]; + * thrust::device_reference ref(ptr); + * + * // ref equals 1 + * assert(ref == 1); + * + * // the object pointed to by ptr equals 1 + * assert(*ptr == 1); + * + * // v[0] equals 1 + * assert(v[0] == 1); + * + * // right XOR-assign ref + * ref ^= 1; + * + * // ref equals 0 + * assert(ref == 0); + * + * // the object pointed to by ptr equals 0 + * assert(*ptr == 0); + * + * // v[0] equals 0 + * assert(v[0] == 0); + * \endcode + * + * \note The XOR-assignment executes as as if it were executed on the host. + * This may change in a later version. + */ + device_reference &operator^=(const T &rhs); +#endif // end doxygen-only members + + /*! swaps the value of one \p device_reference with another. + * \p x The first \p device_reference of interest. + * \p y The second \p device_reference of interest. + */ + _CCCL_HOST_DEVICE friend void swap(device_reference& x, device_reference& y) noexcept(noexcept(x.swap(y))) + { + x.swap(y); + } +}; // end device_reference + +// declare these methods for the purpose of Doxygenating them +// they actually are defined for a base class +#ifdef _CCCL_DOXYGEN_INVOKED +/*! Writes to an output stream the value of a \p device_reference. + * + * \param os The output stream. + * \param y The \p device_reference to output. + * \return os. + */ +template +std::basic_ostream& operator<<(std::basic_ostream& os, const device_reference& y); +#endif + +/*! \} // memory_management + */ + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_vector.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_vector.h new file mode 100644 index 0000000000000000000000000000000000000000..d9d5916a244baf0637e6f1af0cdde07d87221184 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/device_vector.h @@ -0,0 +1,547 @@ +/* + * Copyright 2008-2018 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file + * \brief A dynamically-sizable array of elements which resides in memory + * accessible to devices. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +#include +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup containers Containers + * \{ + */ + +/*! A \p device_vector is a container that supports random access to elements, + * constant time removal of elements at the end, and linear time insertion + * and removal of elements at the beginning or in the middle. The number of + * elements in a \p device_vector may vary dynamically; memory management is + * automatic. The memory associated with a \p device_vector resides in the + * memory accessible to devices. + * + * \see https://en.cppreference.com/w/cpp/container/vector + * \see device_allocator + * \see host_vector + * \see universal_vector + */ +template > +class device_vector : public detail::vector_base +{ +private: + using Parent = detail::vector_base; + +public: + /*! \cond + */ + using size_type = typename Parent::size_type; + using value_type = typename Parent::value_type; + /*! \endcond + */ + + /*! This constructor creates an empty \p device_vector. + */ + device_vector() + : Parent() + {} + + /*! This constructor creates an empty \p device_vector. + * \param alloc The allocator to use by this device_vector. + */ + device_vector(const Alloc& alloc) + : Parent(alloc) + {} + + /*! The destructor erases the elements. + */ + // Define an empty destructor to explicitly specify + // its execution space qualifier, as a workaround for nvcc warning + ~device_vector() {} + + /*! This constructor creates a \p device_vector with the given + * size. + * \param n The number of elements to initially create. + */ + explicit device_vector(size_type n) + : Parent(n) + {} + + /*! This constructor creates a \p device_vector with the given + * size. + * \param n The number of elements to initially create. + * \param alloc The allocator to use by this device_vector. + */ + explicit device_vector(size_type n, const Alloc& alloc) + : Parent(n, alloc) + {} + + /*! This constructor creates a \p device_vector with copies + * of an exemplar element. + * \param n The number of elements to initially create. + * \param value An element to copy. + */ + explicit device_vector(size_type n, const value_type& value) + : Parent(n, value) + {} + + /*! This constructor creates a \p device_vector with copies + * of an exemplar element. + * \param n The number of elements to initially create. + * \param value An element to copy. + * \param alloc The allocator to use by this device_vector. + */ + explicit device_vector(size_type n, const value_type& value, const Alloc& alloc) + : Parent(n, value, alloc) + {} + + /*! Copy constructor copies from an exemplar \p device_vector. + * \param v The \p device_vector to copy. + */ + device_vector(const device_vector& v) + : Parent(v) + {} + + /*! Copy constructor copies from an exemplar \p device_vector. + * \param v The \p device_vector to copy. + * \param alloc The allocator to use by this device_vector. + */ + device_vector(const device_vector& v, const Alloc& alloc) + : Parent(v, alloc) + {} + + /*! Move constructor moves from another \p device_vector. + * \param v The device_vector to move. + */ + device_vector(device_vector&& v) + : Parent(std::move(v)) + {} + + /*! Move constructor moves from another \p device_vector. + * \param v The device_vector to move. + * \param alloc The allocator to use by this device_vector. + */ + device_vector(device_vector&& v, const Alloc& alloc) + : Parent(std::move(v), alloc) + {} + + /*! Copy assign operator copies another \p device_vector with the same type. + * \param v The \p device_vector to copy. + */ + device_vector& operator=(const device_vector& v) + { + Parent::operator=(v); + return *this; + } + + /*! Move assign operator moves from another \p device_vector. + * \param v The device_vector to move. + */ + device_vector& operator=(device_vector&& v) + { + Parent::operator=(std::move(v)); + return *this; + } + + /*! Copy constructor copies from an exemplar \p device_vector with different type. + * \param v The \p device_vector to copy. + */ + template + explicit device_vector(const device_vector& v) + : Parent(v) + {} + + /*! Assign operator copies from an exemplar \p device_vector with different type. + * \param v The \p device_vector to copy. + */ + template + device_vector& operator=(const device_vector& v) + { + Parent::operator=(v); + return *this; + } + + /*! Copy constructor copies from an exemplar \c std::vector. + * \param v The std::vector to copy. + */ + template + device_vector(const std::vector& v) + : Parent(v) + {} + + /*! Assign operator copies from an exemplar std::vector. + * \param v The std::vector to copy. + */ + template + device_vector& operator=(const std::vector& v) + { + Parent::operator=(v); + return *this; + } + + /*! Copy construct from a \p vector_base whose element type is convertible + * to \c T. + * + * \param v The \p vector_base to copy. + */ + template + device_vector(const detail::vector_base& v) + : Parent(v) + {} + + /*! Assign a \p vector_base whose element type is convertible to \c T. + * \param v The \p vector_base to copy. + */ + template + device_vector& operator=(const detail::vector_base& v) + { + Parent::operator=(v); + return *this; + } + + /*! This constructor builds a \p device_vector from an intializer_list. + * \param il The intializer_list. + */ + device_vector(std::initializer_list il) + : Parent(il) + {} + + /*! This constructor builds a \p device_vector from an intializer_list. + * \param il The intializer_list. + * \param alloc The allocator to use by this device_vector. + */ + device_vector(std::initializer_list il, const Alloc& alloc) + : Parent(il, alloc) + {} + + /*! Assign an \p intializer_list with a matching element type + * \param il The intializer_list. + */ + device_vector& operator=(std::initializer_list il) + { + Parent::operator=(il); + return *this; + } + + /*! This constructor builds a \p device_vector from a range. + * \param first The beginning of the range. + * \param last The end of the range. + */ + template + device_vector(InputIterator first, InputIterator last) + : Parent(first, last) + {} + + /*! This constructor builds a \p device_vector from a range. + * \param first The beginning of the range. + * \param last The end of the range. + * \param alloc The allocator to use by this device_vector. + */ + template + device_vector(InputIterator first, InputIterator last, const Alloc& alloc) + : Parent(first, last, alloc) + {} + + /*! Exchanges the values of two vectors. + * \p x The first \p device_vector of interest. + * \p y The second \p device_vector of interest. + */ + friend void swap(device_vector& a, device_vector& b) noexcept(noexcept(a.swap(b))) + { + a.swap(b); + } + +// declare these members for the purpose of Doxygenating them +// they actually exist in a base class +#if 0 + /*! \brief Resizes this vector to the specified number of elements. + * \param new_size Number of elements this vector should contain. + * \param x Data with which new elements should be populated. + * \throw std::length_error If n exceeds max_size(). + * + * This method will resize this vector to the specified number of + * elements. If the number is smaller than this vector's current + * size this vector is truncated, otherwise this vector is + * extended and new elements are populated with given data. + */ + void resize(size_type new_size, const value_type &x = value_type()); + + /*! Returns the number of elements in this vector. + */ + size_type size() const; + + /*! Returns the size() of the largest possible vector. + * \return The largest possible return value of size(). + */ + size_type max_size() const; + + /*! \brief If n is less than or equal to capacity(), this call has no effect. + * Otherwise, this method is a request for allocation of additional memory. If + * the request is successful, then capacity() is greater than or equal to + * n; otherwise, capacity() is unchanged. In either case, size() is unchanged. + * \throw std::length_error If n exceeds max_size(). + */ + void reserve(size_type n); + + /*! Returns the number of elements which have been reserved in this + * vector. + */ + size_type capacity() const; + + /*! This method shrinks the capacity of this vector to exactly + * fit its elements. + */ + void shrink_to_fit(); + + /*! \brief Subscript access to the data contained in this vector_dev. + * \param n The index of the element for which data should be accessed. + * \return Read/write reference to data. + * + * This operator allows for easy, array-style, data access. + * Note that data access with this operator is unchecked and + * out_of_range lookups are not defined. + */ + reference operator[](size_type n); + + /*! \brief Subscript read access to the data contained in this vector_dev. + * \param n The index of the element for which data should be accessed. + * \return Read reference to data. + * + * This operator allows for easy, array-style, data access. + * Note that data access with this operator is unchecked and + * out_of_range lookups are not defined. + */ + const_reference operator[](size_type n) const; + + /*! This method returns an iterator pointing to the beginning of + * this vector. + * \return mStart + */ + iterator begin(); + + /*! This method returns a const_iterator pointing to the beginning + * of this vector. + * \return mStart + */ + const_iterator begin() const; + + /*! This method returns a const_iterator pointing to the beginning + * of this vector. + * \return mStart + */ + const_iterator cbegin() const; + + /*! This method returns a reverse_iterator pointing to the beginning of + * this vector's reversed sequence. + * \return A reverse_iterator pointing to the beginning of this + * vector's reversed sequence. + */ + reverse_iterator rbegin(); + + /*! This method returns a const_reverse_iterator pointing to the beginning of + * this vector's reversed sequence. + * \return A const_reverse_iterator pointing to the beginning of this + * vector's reversed sequence. + */ + const_reverse_iterator rbegin() const; + + /*! This method returns a const_reverse_iterator pointing to the beginning of + * this vector's reversed sequence. + * \return A const_reverse_iterator pointing to the beginning of this + * vector's reversed sequence. + */ + const_reverse_iterator crbegin() const; + + /*! This method returns an iterator pointing to one element past the + * last of this vector. + * \return begin() + size(). + */ + iterator end(); + + /*! This method returns a const_iterator pointing to one element past the + * last of this vector. + * \return begin() + size(). + */ + const_iterator end() const; + + /*! This method returns a const_iterator pointing to one element past the + * last of this vector. + * \return begin() + size(). + */ + const_iterator cend() const; + + /*! This method returns a reverse_iterator pointing to one element past the + * last of this vector's reversed sequence. + * \return rbegin() + size(). + */ + reverse_iterator rend(); + + /*! This method returns a const_reverse_iterator pointing to one element past the + * last of this vector's reversed sequence. + * \return rbegin() + size(). + */ + const_reverse_iterator rend() const; + + /*! This method returns a const_reverse_iterator pointing to one element past the + * last of this vector's reversed sequence. + * \return rbegin() + size(). + */ + const_reverse_iterator crend() const; + + /*! This method returns a const_reference referring to the first element of this + * vector. + * \return The first element of this vector. + */ + const_reference front() const; + + /*! This method returns a reference pointing to the first element of this + * vector. + * \return The first element of this vector. + */ + reference front(); + + /*! This method returns a const reference pointing to the last element of + * this vector. + * \return The last element of this vector. + */ + const_reference back() const; + + /*! This method returns a reference referring to the last element of + * this vector_dev. + * \return The last element of this vector. + */ + reference back(); + + /*! This method returns a pointer to this vector's first element. + * \return A pointer to the first element of this vector. + */ + pointer data(); + + /*! This method returns a const_pointer to this vector's first element. + * \return a const_pointer to the first element of this vector. + */ + const_pointer data() const; + + /*! This method resizes this vector to 0. + */ + void clear(); + + /*! This method returns true iff size() == 0. + * \return true if size() == 0; false, otherwise. + */ + bool empty() const; + + /*! This method appends the given element to the end of this vector. + * \param x The element to append. + */ + void push_back(const value_type &x); + + /*! This method erases the last element of this vector, invalidating + * all iterators and references to it. + */ + void pop_back(); + + /*! This method swaps the contents of this device_vector with another vector. + * \param v The vector with which to swap. + */ + void swap(device_vector &v); + + /*! This method removes the element at position pos. + * \param pos The position of the element of interest. + * \return An iterator pointing to the new location of the element that followed the element + * at position pos. + */ + iterator erase(iterator pos); + + /*! This method removes the range of elements [first,last) from this vector. + * \param first The beginning of the range of elements to remove. + * \param last The end of the range of elements to remove. + * \return An iterator pointing to the new location of the element that followed the last + * element in the sequence [first,last). + */ + iterator erase(iterator first, iterator last); + + /*! This method inserts a single copy of a given exemplar value at the + * specified position in this vector. + * \param position The insertion position. + * \param x The exemplar element to copy & insert. + * \return An iterator pointing to the newly inserted element. + */ + iterator insert(iterator position, const T &x); + + /*! This method inserts a copy of an exemplar value to a range at the + * specified position in this vector. + * \param position The insertion position + * \param n The number of insertions to perform. + * \param x The value to replicate and insert. + */ + void insert(iterator position, size_type n, const T &x); + + /*! This method inserts a copy of an input range at the specified position + * in this vector. + * \param position The insertion position. + * \param first The beginning of the range to copy. + * \param last The end of the range to copy. + * + * \tparam InputIterator is a model of Assignable. + */ + template + void insert(iterator position, InputIterator first, InputIterator last); + + /*! This version of \p assign replicates a given exemplar + * \p n times into this vector. + * \param n The number of times to copy \p x. + * \param x The exemplar element to replicate. + */ + void assign(size_type n, const T &x); + + /*! This version of \p assign makes this vector a copy of a given input range. + * \param first The beginning of the range to copy. + * \param last The end of the range to copy. + * + * \tparam InputIterator is a model of Input Iterator. + */ + template + void assign(InputIterator first, InputIterator last); + + /*! This method returns a copy of this vector's allocator. + * \return A copy of the allocator used by this vector. + */ + allocator_type get_allocator() const; +#endif // end doxygen-only members +}; + +/*! \} // containres + */ + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/equal.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/equal.h new file mode 100644 index 0000000000000000000000000000000000000000..dc22aeb16b1818d66ba3a1dbfa49b15f390f5257 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/equal.h @@ -0,0 +1,247 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file equal.h + * \brief Equality between ranges + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup reductions + * \{ + * \addtogroup comparisons + * \ingroup reductions + * \{ + */ + +/*! \p equal returns \c true if the two ranges [first1, last1) + * and [first2, first2 + (last1 - first1)) are identical when + * compared element-by-element, and otherwise returns \c false. + * + * This version of \p equal returns \c true if and only if for every + * iterator \c i in [first1, last1), *i == *(first2 + (i - first1)). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \return \c true, if the sequences are equal; \c false, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator1's \c value_type is a model of Equality Comparable, and \p + * InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type. \tparam + * InputIterator2 is a model of Input Iterator, + * and \p InputIterator2's \c value_type is a model of Equality Comparable, and \p + * InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type. + * + * The following code snippet demonstrates how to use \p equal to test + * two ranges for equality using the \p thrust::host execution policy: + * + * \code + * #include + * #include + * ... + * int A1[7] = {3, 1, 4, 1, 5, 9, 3}; + * int A2[7] = {3, 1, 4, 2, 8, 5, 7}; + * ... + * bool result = thrust::equal(thrust::host, A1, A1 + 7, A2); + * + * // result == false + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/equal + */ +template +_CCCL_HOST_DEVICE bool +equal(const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2); + +/*! \p equal returns \c true if the two ranges [first1, last1) + * and [first2, first2 + (last1 - first1)) are identical when + * compared element-by-element, and otherwise returns \c false. + * + * This version of \p equal returns \c true if and only if for every + * iterator \c i in [first1, last1), *i == *(first2 + (i - first1)). + * + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \return \c true, if the sequences are equal; \c false, otherwise. + * + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator1's \c value_type is a model of Equality Comparable, and \p + * InputIterator1's \c value_type can be compared for equality with \c InputIterator2's \c value_type. \tparam + * InputIterator2 is a model of Input Iterator, + * and \p InputIterator2's \c value_type is a model of Equality Comparable, and \p + * InputIterator2's \c value_type can be compared for equality with \c InputIterator1's \c value_type. + * + * The following code snippet demonstrates how to use \p equal to test + * two ranges for equality. + * + * \code + * #include + * ... + * int A1[7] = {3, 1, 4, 1, 5, 9, 3}; + * int A2[7] = {3, 1, 4, 2, 8, 5, 7}; + * ... + * bool result = thrust::equal(A1, A1 + 7, A2); + * + * // result == false + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/equal + */ +template +bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); + +/*! \p equal returns \c true if the two ranges [first1, last1) + * and [first2, first2 + (last1 - first1)) are identical when + * compared element-by-element, and otherwise returns \c false. + * + * This version of \p equal returns \c true if and only if for every + * iterator \c i in [first1, last1), + * binary_pred(*i, *(first2 + (i - first1))) is \c true. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \param binary_pred Binary predicate used to test element equality. + * \return \c true, if the sequences are equal; \c false, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type. + * \tparam InputIterator2 is a model of Input + * Iterator, and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type. + * \tparam BinaryPredicate is a model of Binary + * Predicate. + * + * The following code snippet demonstrates how to use \p equal to compare the + * elements in two ranges modulo 2 using the \p thrust::host execution policy. + * + * \code + * #include + * #include + * ... + * + * struct compare_modulo_two + * { + * __host__ __device__ + * bool operator()(int x, int y) const + * { + * return (x % 2) == (y % 2); + * } + * }; + * ... + * int x[6] = {0, 2, 4, 6, 8, 10}; + * int y[6] = {1, 3, 5, 7, 9, 11}; + * + * bool result = thrust::equal(x, x + 6, y, compare_modulo_two()); + * + * // result is false + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/equal + */ +template +_CCCL_HOST_DEVICE bool +equal(const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + BinaryPredicate binary_pred); + +/*! \p equal returns \c true if the two ranges [first1, last1) + * and [first2, first2 + (last1 - first1)) are identical when + * compared element-by-element, and otherwise returns \c false. + * + * This version of \p equal returns \c true if and only if for every + * iterator \c i in [first1, last1), + * binary_pred(*i, *(first2 + (i - first1))) is \c true. + * + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \param binary_pred Binary predicate used to test element equality. + * \return \c true, if the sequences are equal; \c false, otherwise. + * + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator1's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type. + * \tparam InputIterator2 is a model of Input + * Iterator, and \p InputIterator2's \c value_type is convertible to \p BinaryPredicate's \c second_argument_type. + * \tparam BinaryPredicate is a model of Binary + * Predicate. + * + * The following code snippet demonstrates how to use \p equal to compare the + * elements in two ranges modulo 2. + * + * \code + * #include + * + * struct compare_modulo_two + * { + * __host__ __device__ + * bool operator()(int x, int y) const + * { + * return (x % 2) == (y % 2); + * } + * }; + * ... + * int x[6] = {0, 2, 4, 6, 8, 10}; + * int y[6] = {1, 3, 5, 7, 9, 11}; + * + * bool result = thrust::equal(x, x + 5, y, compare_modulo_two()); + * + * // result is true + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/equal + */ +template +bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred); + +/*! \} // end comparisons + * \} // end reductions + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/event.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/event.h new file mode 100644 index 0000000000000000000000000000000000000000..edd42be6c5e1c9c8e469a5533d4e3c607df78c66 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/event.h @@ -0,0 +1,35 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file thrust/event.h + * \brief `thrust::event`, an asynchronous handle type. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include + +// TODO: Actually separate `` into two headers. diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/execution_policy.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/execution_policy.h new file mode 100644 index 0000000000000000000000000000000000000000..8f733215e9afb7ec7864c297a66371835a5568cc --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/execution_policy.h @@ -0,0 +1,384 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file thrust/execution_policy.h + * \brief Thrust execution policies. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include + +//! \cond + +// #include the host system's execution_policy header +#define __THRUST_HOST_SYSTEM_EXECUTION_POLICY_HEADER <__THRUST_HOST_SYSTEM_ROOT/execution_policy.h> +#include __THRUST_HOST_SYSTEM_EXECUTION_POLICY_HEADER +#undef __THRUST_HOST_SYSTEM_EXECUTION_POLICY_HEADER + +// #include the device system's execution_policy.h header +#define __THRUST_DEVICE_SYSTEM_EXECUTION_POLICY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/execution_policy.h> +#include __THRUST_DEVICE_SYSTEM_EXECUTION_POLICY_HEADER +#undef __THRUST_DEVICE_SYSTEM_EXECUTION_POLICY_HEADER + +//! \endcond + +THRUST_NAMESPACE_BEGIN + +/*! \cond + */ + +namespace detail +{ + +using host_t = thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::detail::par_t; + +using device_t = thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::detail::par_t; + +} // namespace detail + +/*! \endcond + */ + +/*! \addtogroup execution_policies Parallel Execution Policies + * \{ + */ + +// define execution_policy for the purpose of Doxygenating it +// it is actually defined elsewhere +#if 0 +/*! \p execution_policy is the base class for all Thrust parallel execution policies + * like \p thrust::host, \p thrust::device, and each backend system's tag type. + * + * Custom user-defined backends should derive a policy from this type in order to + * interoperate with Thrust algorithm dispatch. + * + * The following code snippet demonstrates how to derive a standalone custom execution policy + * from \p thrust::execution_policy to implement a backend which only implements \p for_each: + * + * \code + * #include + * #include + * + * // define a type derived from thrust::execution_policy to distinguish our custom execution policy: + * struct my_policy : thrust::execution_policy {}; + * + * // overload for_each on my_policy + * template + * Iterator for_each(my_policy, Iterator first, Iterator last, Function f) + * { + * std::cout << "Hello, world from for_each(my_policy)!" << std::endl; + * + * for(; first < last; ++first) + * { + * f(*first); + * } + * + * return first; + * } + * + * struct ignore_argument + * { + * void operator()(int) {} + * }; + * + * int main() + * { + * int data[4]; + * + * // dispatch thrust::for_each using our custom policy: + * my_policy exec; + * thrust::for_each(exec, data, data + 4, ignore_argument()); + * + * // can't dispatch thrust::transform because no overload exists for my_policy: + * //thrust::transform(exec, data, data, + 4, data, thrust::identity()); // error! + * + * return 0; + * } + * \endcode + * + * \see host_execution_policy + * \see device_execution_policy + */ +template +struct execution_policy : thrust::detail::execution_policy_base +{}; +#endif + +/*! \p host_execution_policy is the base class for all Thrust parallel execution policies + * which are derived from Thrust's default host backend system configured with the \p THRUST_HOST_SYSTEM + * macro. + * + * Custom user-defined backends which wish to inherit the functionality of Thrust's host backend system + * should derive a policy from this type in order to interoperate with Thrust algorithm dispatch. + * + * The following code snippet demonstrates how to derive a standalone custom execution policy from + * \p thrust::host_execution_policy to implement a backend which specializes \p for_each while inheriting + * the behavior of every other algorithm from the host system: + * + * \code + * #include + * #include + * + * // define a type derived from thrust::host_execution_policy to distinguish our custom execution policy: + * struct my_policy : thrust::host_execution_policy {}; + * + * // overload for_each on my_policy + * template + * Iterator for_each(my_policy, Iterator first, Iterator last, Function f) + * { + * std::cout << "Hello, world from for_each(my_policy)!" << std::endl; + * + * for(; first < last; ++first) + * { + * f(*first); + * } + * + * return first; + * } + * + * struct ignore_argument + * { + * void operator()(int) {} + * }; + * + * int main() + * { + * int data[4]; + * + * // dispatch thrust::for_each using our custom policy: + * my_policy exec; + * thrust::for_each(exec, data, data + 4, ignore_argument()); + * + * // dispatch thrust::transform whose behavior our policy inherits + * thrust::transform(exec, data, data, + 4, data, thrust::identity()); + * + * return 0; + * } + * \endcode + * + * \see execution_policy + * \see device_execution_policy + */ +template +struct host_execution_policy : thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::execution_policy +{}; + +/*! \p device_execution_policy is the base class for all Thrust parallel execution policies + * which are derived from Thrust's default device backend system configured with the \p THRUST_DEVICE_SYSTEM + * macro. + * + * Custom user-defined backends which wish to inherit the functionality of Thrust's device backend system + * should derive a policy from this type in order to interoperate with Thrust algorithm dispatch. + * + * The following code snippet demonstrates how to derive a standalone custom execution policy from + * \p thrust::device_execution_policy to implement a backend which specializes \p for_each while inheriting + * the behavior of every other algorithm from the device system: + * + * \code + * #include + * #include + * + * // define a type derived from thrust::device_execution_policy to distinguish our custom execution policy: + * struct my_policy : thrust::device_execution_policy {}; + * + * // overload for_each on my_policy + * template + * Iterator for_each(my_policy, Iterator first, Iterator last, Function f) + * { + * std::cout << "Hello, world from for_each(my_policy)!" << std::endl; + * + * for(; first < last; ++first) + * { + * f(*first); + * } + * + * return first; + * } + * + * struct ignore_argument + * { + * void operator()(int) {} + * }; + * + * int main() + * { + * int data[4]; + * + * // dispatch thrust::for_each using our custom policy: + * my_policy exec; + * thrust::for_each(exec, data, data + 4, ignore_argument()); + * + * // dispatch thrust::transform whose behavior our policy inherits + * thrust::transform(exec, data, data, + 4, data, thrust::identity()); + * + * return 0; + * } + * \endcode + * + * \see execution_policy + * \see host_execution_policy + */ +template +struct device_execution_policy : thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::execution_policy +{}; + +/*! \p thrust::host is the default parallel execution policy associated with Thrust's host backend system + * configured by the \p THRUST_HOST_SYSTEM macro. + * + * Instead of relying on implicit algorithm dispatch through iterator system tags, users may directly target + * algorithm dispatch at Thrust's host system by providing \p thrust::host as an algorithm parameter. + * + * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such as + * \p thrust::host_vector. + * + * Note that even though \p thrust::host targets the host CPU, it is a parallel execution policy. That is, + * the order that an algorithm invokes functors or dereferences iterators is not defined. + * + * The type of \p thrust::host is implementation-defined. + * + * The following code snippet demonstrates how to use \p thrust::host to explicitly dispatch an invocation + * of \p thrust::for_each to the host backend system: + * + * \code + * #include + * #include + * #include + * + * struct printf_functor + * { + * __host__ __device__ + * void operator()(int x) + * { + * printf("%d\n", x); + * } + * }; + * ... + * int vec[] = { 0, 1, 2 }; + * + * thrust::for_each(thrust::host, vec, vec + 3, printf_functor()); + * + * // 0 1 2 is printed to standard output in some unspecified order + * \endcode + * + * \see host_execution_policy + * \see thrust::device + */ +static const detail::host_t host; + +/*! \p thrust::device is the default parallel execution policy associated with Thrust's device backend system + * configured by the \p THRUST_DEVICE_SYSTEM macro. + * + * Instead of relying on implicit algorithm dispatch through iterator system tags, users may directly target + * algorithm dispatch at Thrust's device system by providing \p thrust::device as an algorithm parameter. + * + * Explicit dispatch can be useful in avoiding the introduction of data copies into containers such as + * \p thrust::device_vector or to avoid wrapping e.g. raw pointers allocated by the CUDA API with types + * such as \p thrust::device_ptr. + * + * The user must take care to guarantee that the iterators provided to an algorithm are compatible with + * the device backend system. For example, raw pointers allocated by std::malloc typically + * cannot be dereferenced by a GPU. For this reason, raw pointers allocated by host APIs should not be mixed + * with a \p thrust::device algorithm invocation when the device backend is CUDA. + * + * The type of \p thrust::device is implementation-defined. + * + * The following code snippet demonstrates how to use \p thrust::device to explicitly dispatch an invocation + * of \p thrust::for_each to the device backend system: + * + * \code + * #include + * #include + * #include + * #include + * + * struct printf_functor + * { + * __host__ __device__ + * void operator()(int x) + * { + * printf("%d\n", x); + * } + * }; + * ... + * thrust::device_vector vec(3); + * vec[0] = 0; vec[1] = 1; vec[2] = 2; + * + * thrust::for_each(thrust::device, vec.begin(), vec.end(), printf_functor()); + * + * // 0 1 2 is printed to standard output in some unspecified order + * \endcode + * + * \see host_execution_policy + * \see thrust::device + */ +_CCCL_GLOBAL_CONSTANT detail::device_t device; + +// define seq for the purpose of Doxygenating it +// it is actually defined elsewhere +#if 0 +/*! \p thrust::seq is an execution policy which requires an algorithm invocation to execute sequentially + * in the current thread. It can not be configured by a compile-time macro. + * + * The type of \p thrust::seq is implementation-defined. + * + * The following code snippet demonstrates how to use \p thrust::seq to explicitly execute an invocation + * of \p thrust::for_each sequentially: + * + * \code + * #include + * #include + * #include + * #include + * + * struct printf_functor + * { + * __host__ __device__ + * void operator()(int x) + * { + * printf("%d\n", x); + * } + * }; + * ... + * std::vector vec(3); + * vec[0] = 0; vec[1] = 1; vec[2] = 2; + * + * thrust::for_each(thrust::seq, vec.begin(), vec.end(), printf_functor()); + * + * // 0 1 2 is printed to standard output in sequential order + * \endcode + * + * \see thrust::host + * \see thrust::device + */ +static const detail::seq_t seq; +#endif + +/*! \} + */ + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/extrema.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/extrema.h new file mode 100644 index 0000000000000000000000000000000000000000..9011468e3ed5bf5a17907e653e2d806660feeca8 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/extrema.h @@ -0,0 +1,800 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file extrema.h + * \brief Functions for computing computing extremal values + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! This version of \p min returns the smaller of two values, given a comparison operation. + * \param lhs The first value to compare. + * \param rhs The second value to compare. + * \param comp A comparison operation. + * \return The smaller element. + * + * \tparam T is convertible to \p BinaryPredicate's first argument type and to its second argument type. + * \tparam BinaryPredicate is a model of BinaryPredicate. + * + * The following code snippet demonstrates how to use \p min to compute the smaller of two + * key-value objects. + * + * \code + * #include + * ... + * struct key_value + * { + * int key; + * int value; + * }; + * + * struct compare_key_value + * { + * __host__ __device__ + * bool operator()(key_value lhs, key_value rhs) + * { + * return lhs.key < rhs.key; + * } + * }; + * + * ... + * key_value a = {13, 0}; + * key_value b = { 7, 1); + * + * key_value smaller = thrust::min(a, b, compare_key_value()); + * + * // smaller is {7, 1} + * \endcode + * + * \note Returns the first argument when the arguments are equivalent. + * \see max + */ +template +_CCCL_HOST_DEVICE T min THRUST_PREVENT_MACRO_SUBSTITUTION(const T& lhs, const T& rhs, BinaryPredicate comp); + +/*! This version of \p min returns the smaller of two values. + * \param lhs The first value to compare. + * \param rhs The second value to compare. + * \return The smaller element. + * + * \tparam T is a model of LessThan + * Comparable. + * + * The following code snippet demonstrates how to use \p min to compute the smaller of two + * integers. + * + * \code + * #include + * ... + * int a = 13; + * int b = 7; + * + * int smaller = thrust::min(a, b); + * + * // smaller is 7 + * \endcode + * + * \note Returns the first argument when the arguments are equivalent. + * \see max + */ +template +_CCCL_HOST_DEVICE T min THRUST_PREVENT_MACRO_SUBSTITUTION(const T& lhs, const T& rhs); + +/*! This version of \p max returns the larger of two values, given a comparison operation. + * \param lhs The first value to compare. + * \param rhs The second value to compare. + * \param comp A comparison operation. + * \return The larger element. + * + * \tparam T is convertible to \p BinaryPredicate's first argument type and to its second argument type. + * \tparam BinaryPredicate is a model of BinaryPredicate. + * + * The following code snippet demonstrates how to use \p max to compute the larger of two + * key-value objects. + * + * \code + * #include + * ... + * struct key_value + * { + * int key; + * int value; + * }; + * + * struct compare_key_value + * { + * __host__ __device__ + * bool operator()(key_value lhs, key_value rhs) + * { + * return lhs.key < rhs.key; + * } + * }; + * + * ... + * key_value a = {13, 0}; + * key_value b = { 7, 1); + * + * key_value larger = thrust::max(a, b, compare_key_value()); + * + * // larger is {13, 0} + * \endcode + * + * \note Returns the first argument when the arguments are equivalent. + * \see min + */ +template +_CCCL_HOST_DEVICE T max THRUST_PREVENT_MACRO_SUBSTITUTION(const T& lhs, const T& rhs, BinaryPredicate comp); + +/*! This version of \p max returns the larger of two values. + * \param lhs The first value to compare. + * \param rhs The second value to compare. + * \return The larger element. + * + * \tparam T is a model of LessThan + * Comparable. + * + * The following code snippet demonstrates how to use \p max to compute the larger of two + * integers. + * + * \code + * #include + * ... + * int a = 13; + * int b = 7; + * + * int larger = thrust::min(a, b); + * + * // larger is 13 + * \endcode + * + * \note Returns the first argument when the arguments are equivalent. + * \see min + */ +template +_CCCL_HOST_DEVICE T max THRUST_PREVENT_MACRO_SUBSTITUTION(const T& lhs, const T& rhs); + +/*! \addtogroup reductions + * \{ + * \addtogroup extrema + * \ingroup reductions + * \{ + */ + +/*! \p min_element finds the smallest element in the range [first, last). + * It returns the first iterator \c i in [first, last) + * such that no other iterator in [first, last) points to a value smaller + * than \c *i. The return value is \p last if and only if [first, last) is an + * empty range. + * + * The two versions of \p min_element differ in how they define whether one element is + * less than another. This version compares objects using \c operator<. Specifically, + * this version of \p min_element returns the first iterator \c i in [first, last) + * such that, for every iterator \c j in [first, last), *j < *i is + * \c false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \return An iterator pointing to the smallest element of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \c ForwardIterator's \c value_type is a model of LessThan Comparable. + * + * \code + * #include + * #include + * ... + * int data[6] = {1, 0, 2, 2, 1, 3}; + * int *result = thrust::min_element(thrust::host, data, data + 6); + * + * // result is data + 1 + * // *result is 0 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/min_element + */ +template +_CCCL_HOST_DEVICE ForwardIterator min_element( + const thrust::detail::execution_policy_base& exec, ForwardIterator first, ForwardIterator last); + +/*! \p min_element finds the smallest element in the range [first, last). + * It returns the first iterator \c i in [first, last) + * such that no other iterator in [first, last) points to a value smaller + * than \c *i. The return value is \p last if and only if [first, last) is an + * empty range. + * + * The two versions of \p min_element differ in how they define whether one element is + * less than another. This version compares objects using \c operator<. Specifically, + * this version of \p min_element returns the first iterator \c i in [first, last) + * such that, for every iterator \c j in [first, last), *j < *i is + * \c false. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \return An iterator pointing to the smallest element of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \c ForwardIterator's \c value_type is a model of LessThan Comparable. + * + * \code + * #include + * ... + * int data[6] = {1, 0, 2, 2, 1, 3}; + * int *result = thrust::min_element(data, data + 6); + * + * // result is data + 1 + * // *result is 0 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/min_element + */ +template +ForwardIterator min_element(ForwardIterator first, ForwardIterator last); + +/*! \p min_element finds the smallest element in the range [first, last). + * It returns the first iterator \c i in [first, last) + * such that no other iterator in [first, last) points to a value smaller + * than \c *i. The return value is \p last if and only if [first, last) is an + * empty range. + * + * The two versions of \p min_element differ in how they define whether one element is + * less than another. This version compares objects using a function object \p comp. + * Specifically, this version of \p min_element returns the first iterator \c i in [first, last) + * such that, for every iterator \c j in [first, last), comp(*j, *i) is + * \c false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp A binary predicate used for comparison. + * \return An iterator pointing to the smallest element of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c + * second_argument_type. \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p min_element to find the smallest element + * of a collection of key-value pairs using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * + * struct key_value + * { + * int key; + * int value; + * }; + * + * struct compare_key_value + * { + * __host__ __device__ + * bool operator()(key_value lhs, key_value rhs) + * { + * return lhs.key < rhs.key; + * } + * }; + * + * ... + * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; + * + * key_value *smallest = thrust::min_element(thrust::host, data, data + 4, compare_key_value()); + * + * // smallest == data + 1 + * // *smallest == {0,7} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/min_element + */ +template +_CCCL_HOST_DEVICE ForwardIterator min_element( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + BinaryPredicate comp); + +/*! \p min_element finds the smallest element in the range [first, last). + * It returns the first iterator \c i in [first, last) + * such that no other iterator in [first, last) points to a value smaller + * than \c *i. The return value is \p last if and only if [first, last) is an + * empty range. + * + * The two versions of \p min_element differ in how they define whether one element is + * less than another. This version compares objects using a function object \p comp. + * Specifically, this version of \p min_element returns the first iterator \c i in [first, last) + * such that, for every iterator \c j in [first, last), comp(*j, *i) is + * \c false. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp A binary predicate used for comparison. + * \return An iterator pointing to the smallest element of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c + * second_argument_type. \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p min_element to find the smallest element + * of a collection of key-value pairs. + * + * \code + * #include + * + * struct key_value + * { + * int key; + * int value; + * }; + * + * struct compare_key_value + * { + * __host__ __device__ + * bool operator()(key_value lhs, key_value rhs) + * { + * return lhs.key < rhs.key; + * } + * }; + * + * ... + * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; + * + * key_value *smallest = thrust::min_element(data, data + 4, compare_key_value()); + * + * // smallest == data + 1 + * // *smallest == {0,7} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/min_element + */ +template +ForwardIterator min_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp); + +/*! \p max_element finds the largest element in the range [first, last). + * It returns the first iterator \c i in [first, last) + * such that no other iterator in [first, last) points to a value larger + * than \c *i. The return value is \p last if and only if [first, last) is an + * empty range. + * + * The two versions of \p max_element differ in how they define whether one element is + * greater than another. This version compares objects using \c operator<. Specifically, + * this version of \p max_element returns the first iterator \c i in [first, last) + * such that, for every iterator \c j in [first, last), *i < *j is + * \c false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \return An iterator pointing to the largest element of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam A Thrust backend system. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \c ForwardIterator's \c value_type is a model of LessThan Comparable. + * + * \code + * #include + * #include + * ... + * int data[6] = {1, 0, 2, 2, 1, 3}; + * int *result = thrust::max_element(thrust::host, data, data + 6); + * + * // *result == 3 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/max_element + */ +template +_CCCL_HOST_DEVICE ForwardIterator max_element( + const thrust::detail::execution_policy_base& exec, ForwardIterator first, ForwardIterator last); + +/*! \p max_element finds the largest element in the range [first, last). + * It returns the first iterator \c i in [first, last) + * such that no other iterator in [first, last) points to a value larger + * than \c *i. The return value is \p last if and only if [first, last) is an + * empty range. + * + * The two versions of \p max_element differ in how they define whether one element is + * greater than another. This version compares objects using \c operator<. Specifically, + * this version of \p max_element returns the first iterator \c i in [first, last) + * such that, for every iterator \c j in [first, last), *i < *j is + * \c false. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \return An iterator pointing to the largest element of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \c ForwardIterator's \c value_type is a model of LessThan Comparable. + * + * \code + * #include + * ... + * int data[6] = {1, 0, 2, 2, 1, 3}; + * int *result = thrust::max_element(data, data + 6); + * + * // *result == 3 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/max_element + */ +template +ForwardIterator max_element(ForwardIterator first, ForwardIterator last); + +/*! \p max_element finds the largest element in the range [first, last). + * It returns the first iterator \c i in [first, last) + * such that no other iterator in [first, last) points to a value larger + * than \c *i. The return value is \p last if and only if [first, last) is an + * empty range. + * + * The two versions of \p max_element differ in how they define whether one element is + * less than another. This version compares objects using a function object \p comp. + * Specifically, this version of \p max_element returns the first iterator \c i in [first, last) + * such that, for every iterator \c j in [first, last), comp(*i, *j) is + * \c false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp A binary predicate used for comparison. + * \return An iterator pointing to the largest element of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c + * second_argument_type. \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p max_element to find the largest element + * of a collection of key-value pairs using the \p thrust::host execution policy for parallelization. + * + * \code + * #include + * #include + * ... + * + * struct key_value + * { + * int key; + * int value; + * }; + * + * struct compare_key_value + * { + * __host__ __device__ + * bool operator()(key_value lhs, key_value rhs) + * { + * return lhs.key < rhs.key; + * } + * }; + * + * ... + * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; + * + * key_value *largest = thrust::max_element(thrust::host, data, data + 4, compare_key_value()); + * + * // largest == data + 3 + * // *largest == {6,1} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/max_element + */ +template +_CCCL_HOST_DEVICE ForwardIterator max_element( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + BinaryPredicate comp); + +/*! \p max_element finds the largest element in the range [first, last). + * It returns the first iterator \c i in [first, last) + * such that no other iterator in [first, last) points to a value larger + * than \c *i. The return value is \p last if and only if [first, last) is an + * empty range. + * + * The two versions of \p max_element differ in how they define whether one element is + * less than another. This version compares objects using a function object \p comp. + * Specifically, this version of \p max_element returns the first iterator \c i in [first, last) + * such that, for every iterator \c j in [first, last), comp(*i, *j) is + * \c false. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp A binary predicate used for comparison. + * \return An iterator pointing to the largest element of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c + * second_argument_type. \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p max_element to find the largest element + * of a collection of key-value pairs. + * + * \code + * #include + * + * struct key_value + * { + * int key; + * int value; + * }; + * + * struct compare_key_value + * { + * __host__ __device__ + * bool operator()(key_value lhs, key_value rhs) + * { + * return lhs.key < rhs.key; + * } + * }; + * + * ... + * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; + * + * key_value *largest = thrust::max_element(data, data + 4, compare_key_value()); + * + * // largest == data + 3 + * // *largest == {6,1} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/max_element + */ +template +ForwardIterator max_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp); + +/*! \p minmax_element finds the smallest and largest elements in the range [first, last). + * It returns a pair of iterators (imin, imax) where \c imin is the same iterator + * returned by \p min_element and \c imax is the same iterator returned by \p max_element. + * This function is potentially more efficient than separate calls to \p min_element and \p max_element. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \return A pair of iterator pointing to the smallest and largest elements of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \c ForwardIterator's \c value_type is a model of LessThan Comparable. + * + * \code + * #include + * #include + * ... + * int data[6] = {1, 0, 2, 2, 1, 3}; + * thrust::pair result = thrust::minmax_element(thrust::host, data, data + 6); + * + * // result.first is data + 1 + * // result.second is data + 5 + * // *result.first is 0 + * // *result.second is 3 + * \endcode + * + * \see min_element + * \see max_element + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf + */ +template +_CCCL_HOST_DEVICE thrust::pair minmax_element( + const thrust::detail::execution_policy_base& exec, ForwardIterator first, ForwardIterator last); + +/*! \p minmax_element finds the smallest and largest elements in the range [first, last). + * It returns a pair of iterators (imin, imax) where \c imin is the same iterator + * returned by \p min_element and \c imax is the same iterator returned by \p max_element. + * This function is potentially more efficient than separate calls to \p min_element and \p max_element. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \return A pair of iterator pointing to the smallest and largest elements of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \c ForwardIterator's \c value_type is a model of LessThan Comparable. + * + * \code + * #include + * ... + * int data[6] = {1, 0, 2, 2, 1, 3}; + * thrust::pair result = thrust::minmax_element(data, data + 6); + * + * // result.first is data + 1 + * // result.second is data + 5 + * // *result.first is 0 + * // *result.second is 3 + * \endcode + * + * \see min_element + * \see max_element + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf + */ +template +thrust::pair minmax_element(ForwardIterator first, ForwardIterator last); + +/*! \p minmax_element finds the smallest and largest elements in the range [first, last). + * It returns a pair of iterators (imin, imax) where \c imin is the same iterator + * returned by \p min_element and \c imax is the same iterator returned by \p max_element. + * This function is potentially more efficient than separate calls to \p min_element and \p max_element. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp A binary predicate used for comparison. + * \return A pair of iterator pointing to the smallest and largest elements of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c + * second_argument_type. \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p minmax_element to find the smallest and largest elements + * of a collection of key-value pairs using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * struct key_value + * { + * int key; + * int value; + * }; + * + * struct compare_key_value + * { + * __host__ __device__ + * bool operator()(key_value lhs, key_value rhs) + * { + * return lhs.key < rhs.key; + * } + * }; + * + * ... + * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; + * + * thrust::pair extrema = thrust::minmax_element(thrust::host, data, data + 4, + * compare_key_value()); + * + * // extrema.first == data + 1 + * // *extrema.first == {0,7} + * // extrema.second == data + 3 + * // *extrema.second == {6,1} + * \endcode + * + * \see min_element + * \see max_element + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf + */ +template +_CCCL_HOST_DEVICE thrust::pair minmax_element( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + BinaryPredicate comp); + +/*! \p minmax_element finds the smallest and largest elements in the range [first, last). + * It returns a pair of iterators (imin, imax) where \c imin is the same iterator + * returned by \p min_element and \c imax is the same iterator returned by \p max_element. + * This function is potentially more efficient than separate calls to \p min_element and \p max_element. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp A binary predicate used for comparison. + * \return A pair of iterator pointing to the smallest and largest elements of the range [first, last), + * if it is not an empty range; \p last, otherwise. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to both \p comp's \c first_argument_type and \c + * second_argument_type. \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p minmax_element to find the smallest and largest elements + * of a collection of key-value pairs. + * + * \code + * #include + * #include + * + * struct key_value + * { + * int key; + * int value; + * }; + * + * struct compare_key_value + * { + * __host__ __device__ + * bool operator()(key_value lhs, key_value rhs) + * { + * return lhs.key < rhs.key; + * } + * }; + * + * ... + * key_value data[4] = { {4,5}, {0,7}, {2,3}, {6,1} }; + * + * thrust::pair extrema = thrust::minmax_element(data, data + 4, compare_key_value()); + * + * // extrema.first == data + 1 + * // *extrema.first == {0,7} + * // extrema.second == data + 3 + * // *extrema.second == {6,1} + * \endcode + * + * \see min_element + * \see max_element + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1840.pdf + */ +template +thrust::pair +minmax_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp); + +/*! \} // end extrema + * \} // end reductions + */ + +THRUST_NAMESPACE_END + +#include +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/fill.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/fill.h new file mode 100644 index 0000000000000000000000000000000000000000..c7c1c72389e37fbfe5655a5ca7d7e717af0fab78 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/fill.h @@ -0,0 +1,201 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file fill.h + * \brief Fills a range with a constant value + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup transformations + * \addtogroup filling + * \ingroup transformations + * \{ + */ + +/*! \p fill assigns the value \p value to every element in + * the range [first, last). That is, for every + * iterator \c i in [first, last), it performs + * the assignment *i = value. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param value The value to be copied. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam T is a model of Assignable, and \p T's \c value_type is + * convertible to \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's + * elements to a given value using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector v(4); + * thrust::fill(thrust::device, v.begin(), v.end(), 137); + * + * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/fill + * \see \c fill_n + * \see \c uninitialized_fill + */ +template +_CCCL_HOST_DEVICE void +fill(const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const T& value); + +/*! \p fill assigns the value \p value to every element in + * the range [first, last). That is, for every + * iterator \c i in [first, last), it performs + * the assignment *i = value. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param value The value to be copied. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam T is a model of Assignable, and \p T's \c value_type is + * convertible to \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's + * elements to a given value. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(4); + * thrust::fill(v.begin(), v.end(), 137); + * + * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/fill + * \see \c fill_n + * \see \c uninitialized_fill + */ +template +_CCCL_HOST_DEVICE void fill(ForwardIterator first, ForwardIterator last, const T& value); + +/*! \p fill_n assigns the value \p value to every element in + * the range [first, first+n). That is, for every + * iterator \c i in [first, first+n), it performs + * the assignment *i = value. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param n The size of the sequence. + * \param value The value to be copied. + * \return first + n + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam OutputIterator is a model of Output + * Iterator. \tparam T is a model of Assignable, and \p T's \c value_type is + * convertible to a type in \p OutputIterator's set of \c value_type. + * + * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's + * elements to a given value using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector v(4); + * thrust::fill_n(thrust::device, v.begin(), v.size(), 137); + * + * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/fill_n + * \see \c fill + * \see \c uninitialized_fill_n + */ +template +_CCCL_HOST_DEVICE OutputIterator +fill_n(const thrust::detail::execution_policy_base& exec, OutputIterator first, Size n, const T& value); + +/*! \p fill_n assigns the value \p value to every element in + * the range [first, first+n). That is, for every + * iterator \c i in [first, first+n), it performs + * the assignment *i = value. + * + * \param first The beginning of the sequence. + * \param n The size of the sequence. + * \param value The value to be copied. + * \return first + n + * + * \tparam OutputIterator is a model of Output + * Iterator. \tparam T is a model of Assignable, and \p T's \c value_type is + * convertible to a type in \p OutputIterator's set of \c value_type. + * + * The following code snippet demonstrates how to use \p fill to set a thrust::device_vector's + * elements to a given value. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v(4); + * thrust::fill_n(v.begin(), v.size(), 137); + * + * // v[0] == 137, v[1] == 137, v[2] == 137, v[3] == 137 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/fill_n + * \see \c fill + * \see \c uninitialized_fill_n + */ +template +_CCCL_HOST_DEVICE OutputIterator fill_n(OutputIterator first, Size n, const T& value); + +/*! \} // end filling + * \} // transformations + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/for_each.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/for_each.h new file mode 100644 index 0000000000000000000000000000000000000000..0bd28d8b10bc46b84379c86d2f88207d1cc94bc5 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/for_each.h @@ -0,0 +1,266 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file thrust/for_each.h + * \brief Applies a function to each element in a range + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup modifying + * \ingroup transformations + * \{ + */ + +/*! \p for_each applies the function object \p f to each element + * in the range [first, last); \p f's return value, if any, + * is ignored. Unlike the C++ Standard Template Library function + * std::for_each, this version offers no guarantee on + * order of execution. For this reason, this version of \p for_each + * does not return a copy of the function object. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param f The function object to apply to the range [first, last). + * \return last + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam + * UnaryFunction is a model of Unary + * Function, and \p UnaryFunction does not apply any non-constant operation through its argument. + * + * The following code snippet demonstrates how to use \p for_each to print the elements + * of a \p thrust::device_vector using the \p thrust::device parallelization policy: + * + * \code + * #include + * #include + * #include + * #include + * ... + * + * struct printf_functor + * { + * __host__ __device__ + * void operator()(int x) + * { + * // note that using printf in a __device__ function requires + * // code compiled for a GPU with compute capability 2.0 or + * // higher (nvcc --arch=sm_20) + * printf("%d\n", x); + * } + * }; + * ... + * thrust::device_vector d_vec(3); + * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2; + * + * thrust::for_each(thrust::device, d_vec.begin(), d_vec.end(), printf_functor()); + * + * // 0 1 2 is printed to standard output in some unspecified order + * \endcode + * + * \see for_each_n + * \see https://en.cppreference.com/w/cpp/algorithm/for_each + */ +template +_CCCL_HOST_DEVICE InputIterator for_each( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + UnaryFunction f); + +/*! \p for_each_n applies the function object \p f to each element + * in the range [first, first + n); \p f's return value, if any, + * is ignored. Unlike the C++ Standard Template Library function + * std::for_each, this version offers no guarantee on + * order of execution. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param n The size of the input sequence. + * \param f The function object to apply to the range [first, first + n). + * \return first + n + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam + * Size is an integral type. \tparam UnaryFunction is a model of Unary Function, and \p UnaryFunction + * does not apply any non-constant operation through its argument. + * + * The following code snippet demonstrates how to use \p for_each_n to print the elements + * of a \p device_vector using the \p thrust::device parallelization policy. + * + * \code + * #include + * #include + * #include + * #include + * + * struct printf_functor + * { + * __host__ __device__ + * void operator()(int x) + * { + * // note that using printf in a __device__ function requires + * // code compiled for a GPU with compute capability 2.0 or + * // higher (nvcc --arch=sm_20) + * printf("%d\n", x); + * } + * }; + * ... + * thrust::device_vector d_vec(3); + * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2; + * + * thrust::for_each_n(thrust::device, d_vec.begin(), d_vec.size(), printf_functor()); + * + * // 0 1 2 is printed to standard output in some unspecified order + * \endcode + * + * \see for_each + * \see https://en.cppreference.com/w/cpp/algorithm/for_each + */ +template +_CCCL_HOST_DEVICE InputIterator for_each_n( + const thrust::detail::execution_policy_base& exec, InputIterator first, Size n, UnaryFunction f); + +/*! \p for_each applies the function object \p f to each element + * in the range [first, last); \p f's return value, if any, + * is ignored. Unlike the C++ Standard Template Library function + * std::for_each, this version offers no guarantee on + * order of execution. For this reason, this version of \p for_each + * does not return a copy of the function object. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param f The function object to apply to the range [first, last). + * \return last + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam + * UnaryFunction is a model of Unary + * Function, and \p UnaryFunction does not apply any non-constant operation through its argument. + * + * The following code snippet demonstrates how to use \p for_each to print the elements + * of a \p device_vector. + * + * \code + * #include + * #include + * #include + * + * struct printf_functor + * { + * __host__ __device__ + * void operator()(int x) + * { + * // note that using printf in a __device__ function requires + * // code compiled for a GPU with compute capability 2.0 or + * // higher (nvcc --arch=sm_20) + * printf("%d\n", x); + * } + * }; + * ... + * thrust::device_vector d_vec(3); + * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2; + * + * thrust::for_each(d_vec.begin(), d_vec.end(), printf_functor()); + * + * // 0 1 2 is printed to standard output in some unspecified order + * \endcode + * + * \see for_each_n + * \see https://en.cppreference.com/w/cpp/algorithm/for_each + */ +template +InputIterator for_each(InputIterator first, InputIterator last, UnaryFunction f); + +/*! \p for_each_n applies the function object \p f to each element + * in the range [first, first + n); \p f's return value, if any, + * is ignored. Unlike the C++ Standard Template Library function + * std::for_each, this version offers no guarantee on + * order of execution. + * + * \param first The beginning of the sequence. + * \param n The size of the input sequence. + * \param f The function object to apply to the range [first, first + n). + * \return first + n + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam + * Size is an integral type. \tparam UnaryFunction is a model of Unary Function, and \p UnaryFunction + * does not apply any non-constant operation through its argument. + * + * The following code snippet demonstrates how to use \p for_each_n to print the elements + * of a \p device_vector. + * + * \code + * #include + * #include + * #include + * + * struct printf_functor + * { + * __host__ __device__ + * void operator()(int x) + * { + * // note that using printf in a __device__ function requires + * // code compiled for a GPU with compute capability 2.0 or + * // higher (nvcc --arch=sm_20) + * printf("%d\n", x); + * } + * }; + * ... + * thrust::device_vector d_vec(3); + * d_vec[0] = 0; d_vec[1] = 1; d_vec[2] = 2; + * + * thrust::for_each_n(d_vec.begin(), d_vec.size(), printf_functor()); + * + * // 0 1 2 is printed to standard output in some unspecified order + * \endcode + * + * \see for_each + * \see https://en.cppreference.com/w/cpp/algorithm/for_each + */ +template +InputIterator for_each_n(InputIterator first, Size n, UnaryFunction f); + +/*! \} // end modifying + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/future.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/future.h new file mode 100644 index 0000000000000000000000000000000000000000..977ba2a32a38202731912bcd29aeb2be19652fb6 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/future.h @@ -0,0 +1,183 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file thrust/future.h + * \brief `thrust::future`, an asynchronous value type. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +#if _CCCL_STD_VER >= 2014 + +# include +# include + +# include + +/* +// #include the host system's pointer.h header. +#define __THRUST_HOST_SYSTEM_POINTER_HEADER <__THRUST_HOST_SYSTEM_ROOT/pointer.h> + #include __THRUST_HOST_SYSTEM_POINTER_HEADER +#undef __THRUST_HOST_SYSTEM_POINTER_HEADER +*/ + +// #include the device system's pointer.h header. +# define __THRUST_DEVICE_SYSTEM_POINTER_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/pointer.h> +# include __THRUST_DEVICE_SYSTEM_POINTER_HEADER +# undef __THRUST_DEVICE_SYSTEM_POINTER_HEADER + +/* +// #include the host system's future.h header. +#define __THRUST_HOST_SYSTEM_FUTURE_HEADER <__THRUST_HOST_SYSTEM_ROOT/future.h> + #include __THRUST_HOST_SYSTEM_FUTURE_HEADER +#undef __THRUST_HOST_SYSTEM_FUTURE_HEADER +*/ + +// #include the device system's future.h header. +# define __THRUST_DEVICE_SYSTEM_FUTURE_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/future.h> +# include __THRUST_DEVICE_SYSTEM_FUTURE_HEADER +# undef __THRUST_DEVICE_SYSTEM_FUTURE_HEADER + +_CCCL_SUPPRESS_DEPRECATED_PUSH +THRUST_NAMESPACE_BEGIN + +/////////////////////////////////////////////////////////////////////////////// + +// `select_unique_(future|event)_type` is a hook for choosing the +// `unique_eager_event`/`unique_eager_future` type for a system. `decltype` is +// used to determine the return type of an ADL call to +// `select_unique_eager_(future|event)_type(system)`; that return type should +// be the correct event/future type for `system`. Overloads should only be +// declared, not defined. + +namespace unimplemented +{ + +struct CCCL_DEPRECATED no_unique_eager_event_type_found +{}; + +CCCL_DEPRECATED _CCCL_HOST inline no_unique_eager_event_type_found unique_eager_event_type(...) noexcept; + +struct CCCL_DEPRECATED no_unique_eager_future_type_found +{}; + +template +CCCL_DEPRECATED _CCCL_HOST no_unique_eager_future_type_found unique_eager_future_type(...) noexcept; + +} // namespace unimplemented + +namespace unique_eager_event_type_detail +{ + +using unimplemented::unique_eager_event_type; + +template +using select CCCL_DEPRECATED = decltype(unique_eager_event_type(std::declval())); + +} // namespace unique_eager_event_type_detail + +namespace unique_eager_future_type_detail +{ + +using unimplemented::unique_eager_future_type; + +template +using select CCCL_DEPRECATED = decltype(unique_eager_future_type(std::declval())); + +} // namespace unique_eager_future_type_detail + +/////////////////////////////////////////////////////////////////////////////// + +template +using unique_eager_event CCCL_DEPRECATED = unique_eager_event_type_detail::select; + +template +using event CCCL_DEPRECATED = unique_eager_event; + +/////////////////////////////////////////////////////////////////////////////// + +template +using unique_eager_future CCCL_DEPRECATED = unique_eager_future_type_detail::select; + +template +using future CCCL_DEPRECATED = unique_eager_future; + +/* +/////////////////////////////////////////////////////////////////////////////// + +using host_unique_eager_event = unique_eager_event_type_detail::select< + thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::tag +>; +using host_event = host_unique_eager_event; + +/////////////////////////////////////////////////////////////////////////////// + +template +using host_unique_eager_future = unique_eager_future_type_detail::select< + thrust::system::__THRUST_HOST_SYSTEM_NAMESPACE::tag, T +>; +template +using host_future = host_unique_eager_future; +*/ + +/////////////////////////////////////////////////////////////////////////////// + +using device_unique_eager_event CCCL_DEPRECATED = + unique_eager_event_type_detail::select; + +using device_event CCCL_DEPRECATED = device_unique_eager_event; + +/////////////////////////////////////////////////////////////////////////////// + +template +using device_unique_eager_future CCCL_DEPRECATED = + unique_eager_future_type_detail::select; + +template +using device_future CCCL_DEPRECATED = device_unique_eager_future; + +/////////////////////////////////////////////////////////////////////////////// + +struct CCCL_DEPRECATED new_stream_t final +{}; + +# ifndef CCCL_HEADER_MACRO_CHECK +// when building header tests, we get a deprecation warning from cudafe1.stub.c if we deprecate a global variable +CCCL_DEPRECATED +# endif +_CCCL_GLOBAL_CONSTANT new_stream_t new_stream{}; + +/////////////////////////////////////////////////////////////////////////////// + +using thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::when_all; + +/////////////////////////////////////////////////////////////////////////////// + +_CCCL_SUPPRESS_DEPRECATED_POP +THRUST_NAMESPACE_END + +#endif diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/generate.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/generate.h new file mode 100644 index 0000000000000000000000000000000000000000..20f5090bea497ec6657a98d81620df638a15fb5c --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/generate.h @@ -0,0 +1,197 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file generate.h + * \brief Fills a range with values "generated" from a function of no arguments + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup transformations + * \{ + */ + +/*! \p generate assigns the result of invoking \p gen, a function object that takes no arguments, + * to each element in the range [first,last). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element in the range of interest. + * \param last The last element in the range of interest. + * \param gen A function argument, taking no parameters, used to generate values to assign to + * elements in the range [first,last). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam Generator is a model of Generator, and \p Generator's \c result_type is + * convertible to \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to fill a \c host_vector with random numbers, + * using the standard C library function \c rand using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::host_vector v(10); + * srand(13); + * thrust::generate(thrust::host, v.begin(), v.end(), rand); + * + * // the elements of v are now pseudo-random numbers + * \endcode + * + * \see generate_n + * \see https://en.cppreference.com/w/cpp/algorithm/generate + */ +template +_CCCL_HOST_DEVICE void +generate(const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + Generator gen); + +/*! \p generate assigns the result of invoking \p gen, a function object that takes no arguments, + * to each element in the range [first,last). + * + * \param first The first element in the range of interest. + * \param last The last element in the range of interest. + * \param gen A function argument, taking no parameters, used to generate values to assign to + * elements in the range [first,last). + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam Generator is a model of Generator, and \p Generator's \c result_type is + * convertible to \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to fill a \c host_vector with random numbers, + * using the standard C library function \c rand. + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::host_vector v(10); + * srand(13); + * thrust::generate(v.begin(), v.end(), rand); + * + * // the elements of v are now pseudo-random numbers + * \endcode + * + * \see generate_n + * \see https://en.cppreference.com/w/cpp/algorithm/generate + */ +template +void generate(ForwardIterator first, ForwardIterator last, Generator gen); + +/*! \p generate_n assigns the result of invoking \p gen, a function object that takes no arguments, + * to each element in the range [first,first + n). The return value is first + n. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element in the range of interest. + * \param n The size of the range of interest. + * \param gen A function argument, taking no parameters, used to generate values to assign to + * elements in the range [first,first + n). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam OutputIterator is a model of Output + * Iterator. \tparam Size is an integral type (either signed or unsigned). \tparam Generator is a model of Generator, and \p Generator's \c result_type is + * convertible to a type in \p OutputIterator's set of \c value_types. + * + * The following code snippet demonstrates how to fill a \c host_vector with random numbers, + * using the standard C library function \c rand using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::host_vector v(10); + * srand(13); + * thrust::generate_n(thrust::host, v.begin(), 10, rand); + * + * // the elements of v are now pseudo-random numbers + * \endcode + * + * \see generate + * \see https://en.cppreference.com/w/cpp/algorithm/generate + */ +template +_CCCL_HOST_DEVICE OutputIterator generate_n( + const thrust::detail::execution_policy_base& exec, OutputIterator first, Size n, Generator gen); + +/*! \p generate_n assigns the result of invoking \p gen, a function object that takes no arguments, + * to each element in the range [first,first + n). The return value is first + n. + * + * \param first The first element in the range of interest. + * \param n The size of the range of interest. + * \param gen A function argument, taking no parameters, used to generate values to assign to + * elements in the range [first,first + n). + * + * \tparam OutputIterator is a model of Output + * Iterator. \tparam Size is an integral type (either signed or unsigned). \tparam Generator is a model of Generator, and \p Generator's \c result_type is + * convertible to a type in \p OutputIterator's set of \c value_types. + * + * The following code snippet demonstrates how to fill a \c host_vector with random numbers, + * using the standard C library function \c rand. + * + * \code + * #include + * #include + * #include + * ... + * thrust::host_vector v(10); + * srand(13); + * thrust::generate_n(v.begin(), 10, rand); + * + * // the elements of v are now pseudo-random numbers + * \endcode + * + * \see generate + * \see https://en.cppreference.com/w/cpp/algorithm/generate + */ +template +OutputIterator generate_n(OutputIterator first, Size n, Generator gen); + +/*! \} // end transformations + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/inner_product.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/inner_product.h new file mode 100644 index 0000000000000000000000000000000000000000..7f31482a17c87e61142a6609998d9d946942823c --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/inner_product.h @@ -0,0 +1,268 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file inner_product.h + * \brief Mathematical inner product between ranges + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup reductions + * \{ + * \addtogroup transformed_reductions Transformed Reductions + * \ingroup reductions + * \{ + */ + +/*! \p inner_product calculates an inner product of the ranges + * [first1, last1) and [first2, first2 + (last1 - first1)). + * + * Specifically, this version of \p inner_product computes the sum + * init + (*first1 * *first2) + (*(first1+1) * *(first2+1)) + ... + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \param init Initial value of the result. + * \return The inner product of sequences [first1, last1) + * and [first2, last2) plus \p init. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, \tparam InputIterator2 is a model of Input Iterator, \tparam OutputType is a model of + * Assignable, and if \c x is an object of type + * \p OutputType, and \c y is an object of \p InputIterator1's \c value_type, and \c z is an object of \p + * InputIterator2's \c value_type, then x + y * z is defined and is convertible to \p OutputType. + * + * The following code demonstrates how to use \p inner_product to + * compute the dot product of two vectors using the \p thrust::host execution policy for parallelization. + * + * \code + * #include + * #include + * ... + * float vec1[3] = {1.0f, 2.0f, 5.0f}; + * float vec2[3] = {4.0f, 1.0f, 5.0f}; + * + * float result = thrust::inner_product(thrust::host, vec1, vec1 + 3, vec2, 0.0f); + * + * // result == 31.0f + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/inner_product + */ +template +_CCCL_HOST_DEVICE OutputType inner_product( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputType init); + +/*! \p inner_product calculates an inner product of the ranges + * [first1, last1) and [first2, first2 + (last1 - first1)). + * + * Specifically, this version of \p inner_product computes the sum + * init + (*first1 * *first2) + (*(first1+1) * *(first2+1)) + ... + * + * Unlike the C++ Standard Template Library function std::inner_product, + * this version offers no guarantee on order of execution. + * + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \param init Initial value of the result. + * \return The inner product of sequences [first1, last1) + * and [first2, last2) plus \p init. + * + * \tparam InputIterator1 is a model of Input + * Iterator, \tparam InputIterator2 is a model of Input Iterator, \tparam OutputType is a model of + * Assignable, and if \c x is an object of type + * \p OutputType, and \c y is an object of \p InputIterator1's \c value_type, and \c z is an object of \p + * InputIterator2's \c value_type, then x + y * z is defined and is convertible to \p OutputType. + * + * The following code demonstrates how to use \p inner_product to + * compute the dot product of two vectors. + * + * \code + * #include + * ... + * float vec1[3] = {1.0f, 2.0f, 5.0f}; + * float vec2[3] = {4.0f, 1.0f, 5.0f}; + * + * float result = thrust::inner_product(vec1, vec1 + 3, vec2, 0.0f); + * + * // result == 31.0f + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/inner_product + */ +template +OutputType inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType init); + +/*! \p inner_product calculates an inner product of the ranges + * [first1, last1) and [first2, first2 + (last1 - first1)). + * + * This version of \p inner_product is identical to the first, except that is uses + * two user-supplied function objects instead of \c operator+ and \c operator*. + * + * Specifically, this version of \p inner_product computes the sum + * binary_op1( init, binary_op2(*first1, *first2) ), ... + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \param init Initial value of the result. + * \param binary_op1 Generalized addition operation. + * \param binary_op2 Generalized multiplication operation. + * \return The inner product of sequences [first1, last1) and [first2, last2). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator1's \c value_type is convertible to \p BinaryFunction2's \c first_argument_type. + * \tparam InputIterator2 is a model of Input + * Iterator. and \p InputIterator2's \c value_type is convertible to \p BinaryFunction2's \c second_argument_type. + * \tparam OutputType is a model of Assignable, and \p OutputType is convertible to + * \p BinaryFunction1's \c first_argument_type. \tparam BinaryFunction1 is a model of Binary Function, and \p + * BinaryFunction1's \c return_type is convertible to \p OutputType. \tparam BinaryFunction2 is a model of Binary Function, and \p + * BinaryFunction2's \c return_type is convertible to \p BinaryFunction1's \c second_argument_type. + * + * \code + * #include + * #include + * ... + * float vec1[3] = {1.0f, 2.0f, 5.0f}; + * float vec2[3] = {4.0f, 1.0f, 5.0f}; + * + * float init = 0.0f; + * thrust::plus binary_op1; + * thrust::multiplies binary_op2; + * + * float result = thrust::inner_product(thrust::host, vec1, vec1 + 3, vec2, init, binary_op1, binary_op2); + * + * // result == 31.0f + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/inner_product + */ +template +_CCCL_HOST_DEVICE OutputType inner_product( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputType init, + BinaryFunction1 binary_op1, + BinaryFunction2 binary_op2); + +/*! \p inner_product calculates an inner product of the ranges + * [first1, last1) and [first2, first2 + (last1 - first1)). + * + * This version of \p inner_product is identical to the first, except that is uses + * two user-supplied function objects instead of \c operator+ and \c operator*. + * + * Specifically, this version of \p inner_product computes the sum + * binary_op1( init, binary_op2(*first1, *first2) ), ... + * + * Unlike the C++ Standard Template Library function std::inner_product, + * this version offers no guarantee on order of execution. + * + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \param init Initial value of the result. + * \param binary_op1 Generalized addition operation. + * \param binary_op2 Generalized multiplication operation. + * \return The inner product of sequences [first1, last1) and [first2, last2). + * + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator1's \c value_type is convertible to \p BinaryFunction2's \c first_argument_type. + * \tparam InputIterator2 is a model of Input + * Iterator. and \p InputIterator2's \c value_type is convertible to \p BinaryFunction2's \c second_argument_type. + * \tparam OutputType is a model of Assignable, and \p OutputType is convertible to + * \p BinaryFunction1's \c first_argument_type. \tparam BinaryFunction1 is a model of Binary Function, and \p + * BinaryFunction1's \c return_type is convertible to \p OutputType. \tparam BinaryFunction2 is a model of Binary Function, and \p + * BinaryFunction2's \c return_type is convertible to \p BinaryFunction1's \c second_argument_type. + * + * \code + * #include + * ... + * float vec1[3] = {1.0f, 2.0f, 5.0f}; + * float vec2[3] = {4.0f, 1.0f, 5.0f}; + * + * float init = 0.0f; + * thrust::plus binary_op1; + * thrust::multiplies binary_op2; + * + * float result = thrust::inner_product(vec1, vec1 + 3, vec2, init, binary_op1, binary_op2); + * + * // result == 31.0f + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/inner_product + */ +template +OutputType inner_product( + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputType init, + BinaryFunction1 binary_op1, + BinaryFunction2 binary_op2); + +/*! \} // end transformed_reductions + * \} // end reductions + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/logical.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/logical.h new file mode 100644 index 0000000000000000000000000000000000000000..747af38554ead2c5c3d9de2b134770eba9614656 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/logical.h @@ -0,0 +1,290 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file logical.h + * \brief Logical operations on ranges + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup reductions + * \{ + * \addtogroup logical + * \ingroup reductions + * \{ + */ + +/*! \p all_of determines whether all elements in a range satisfy a predicate. + * Specifically, \p all_of returns \c true if pred(*i) is \c true + * for every iterator \c i in the range [first, last) and + * \c false otherwise. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param pred A predicate used to test range elements. + * \return \c true, if all elements satisfy the predicate; \c false, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, \tparam Predicate must be a model of Predicate. + * + * \code + * #include + * #include + * #include + * ... + * bool A[3] = {true, true, false}; + * + * thrust::all_of(thrust::host, A, A + 2, thrust::identity()); // returns true + * thrust::all_of(thrust::host, A, A + 3, thrust::identity()); // returns false + * + * // empty range + * thrust::all_of(thrust::host, A, A, thrust::identity()); // returns false + * + * \endcode + * + * \see any_of + * \see none_of + * \see transform_reduce + */ +template +_CCCL_HOST_DEVICE bool +all_of(const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + Predicate pred); + +/*! \p all_of determines whether all elements in a range satisfy a predicate. + * Specifically, \p all_of returns \c true if pred(*i) is \c true + * for every iterator \c i in the range [first, last) and + * \c false otherwise. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param pred A predicate used to test range elements. + * \return \c true, if all elements satisfy the predicate; \c false, otherwise. + * + * \tparam InputIterator is a model of Input + * Iterator, \tparam Predicate must be a model of Predicate. + * + * \code + * #include + * #include + * ... + * bool A[3] = {true, true, false}; + * + * thrust::all_of(A, A + 2, thrust::identity()); // returns true + * thrust::all_of(A, A + 3, thrust::identity()); // returns false + * + * // empty range + * thrust::all_of(A, A, thrust::identity()); // returns false + * + * \endcode + * + * \see any_of + * \see none_of + * \see transform_reduce + */ +template +bool all_of(InputIterator first, InputIterator last, Predicate pred); + +/*! \p any_of determines whether any element in a range satisfies a predicate. + * Specifically, \p any_of returns \c true if pred(*i) is \c true + * for any iterator \c i in the range [first, last) and + * \c false otherwise. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param pred A predicate used to test range elements. + * \return \c true, if any element satisfies the predicate; \c false, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, \tparam Predicate must be a model of Predicate. + * + * \code + * #include + * #include + * #include + * ... + * bool A[3] = {true, true, false}; + * + * thrust::any_of(thrust::host, A, A + 2, thrust::identity()); // returns true + * thrust::any_of(thrust::host, A, A + 3, thrust::identity()); // returns true + * + * thrust::any_of(thrust::host, A + 2, A + 3, thrust::identity()); // returns false + * + * // empty range + * thrust::any_of(thrust::host, A, A, thrust::identity()); // returns false + * \endcode + * + * \see all_of + * \see none_of + * \see transform_reduce + */ +template +_CCCL_HOST_DEVICE bool +any_of(const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + Predicate pred); + +/*! \p any_of determines whether any element in a range satisfies a predicate. + * Specifically, \p any_of returns \c true if pred(*i) is \c true + * for any iterator \c i in the range [first, last) and + * \c false otherwise. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param pred A predicate used to test range elements. + * \return \c true, if any element satisfies the predicate; \c false, otherwise. + * + * \tparam InputIterator is a model of Input + * Iterator, \tparam Predicate must be a model of Predicate. + * + * \code + * #include + * #include + * ... + * bool A[3] = {true, true, false}; + * + * thrust::any_of(A, A + 2, thrust::identity()); // returns true + * thrust::any_of(A, A + 3, thrust::identity()); // returns true + * + * thrust::any_of(A + 2, A + 3, thrust::identity()); // returns false + * + * // empty range + * thrust::any_of(A, A, thrust::identity()); // returns false + * \endcode + * + * \see all_of + * \see none_of + * \see transform_reduce + */ +template +bool any_of(InputIterator first, InputIterator last, Predicate pred); + +/*! \p none_of determines whether no element in a range satisfies a predicate. + * Specifically, \p none_of returns \c true if there is no iterator \c i in + * the range [first, last) such that pred(*i) is \c true, + * and \c false otherwise. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param pred A predicate used to test range elements. + * \return \c true, if no element satisfies the predicate; \c false, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, \tparam Predicate must be a model of Predicate. + * + * \code + * #include + * #include + * #include + * ... + * bool A[3] = {true, true, false}; + * + * thrust::none_of(thrust::host, A, A + 2, thrust::identity()); // returns false + * thrust::none_of(thrust::host, A, A + 3, thrust::identity()); // returns false + * + * thrust::none_of(thrust::host, A + 2, A + 3, thrust::identity()); // returns true + * + * // empty range + * thrust::none_of(thrust::host, A, A, thrust::identity()); // returns true + * \endcode + * + * \see all_of + * \see any_of + * \see transform_reduce + */ +template +_CCCL_HOST_DEVICE bool +none_of(const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + Predicate pred); + +/*! \p none_of determines whether no element in a range satisfies a predicate. + * Specifically, \p none_of returns \c true if there is no iterator \c i in + * the range [first, last) such that pred(*i) is \c true, + * and \c false otherwise. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param pred A predicate used to test range elements. + * \return \c true, if no element satisfies the predicate; \c false, otherwise. + * + * \tparam InputIterator is a model of Input + * Iterator, \tparam Predicate must be a model of Predicate. + * + * \code + * #include + * #include + * ... + * bool A[3] = {true, true, false}; + * + * thrust::none_of(A, A + 2, thrust::identity()); // returns false + * thrust::none_of(A, A + 3, thrust::identity()); // returns false + * + * thrust::none_of(A + 2, A + 3, thrust::identity()); // returns true + * + * // empty range + * thrust::none_of(A, A, thrust::identity()); // returns true + * \endcode + * + * \see all_of + * \see any_of + * \see transform_reduce + */ +template +bool none_of(InputIterator first, InputIterator last, Predicate pred); + +/*! \} // end logical + * \} // end reductions + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/memory.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/memory.h new file mode 100644 index 0000000000000000000000000000000000000000..9b7d7ab3e503a7d5cb873bd045bd50ec92bb971b --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/memory.h @@ -0,0 +1,395 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file thrust/memory.h + * \brief Abstractions for Thrust's memory model. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup memory_management Memory Management + * \{ + */ + +// define pointer for the purpose of Doxygenating it +// it is actually defined elsewhere +#if 0 +/*! \p pointer stores a pointer to an object allocated in memory. Like \p device_ptr, this + * type ensures type safety when dispatching standard algorithms on ranges resident in memory. + * + * \p pointer generalizes \p device_ptr by relaxing the backend system associated with the \p pointer. + * Instead of the backend system specified by \p THRUST_DEVICE_SYSTEM, \p pointer's + * system is given by its second template parameter, \p Tag. For the purpose of Thrust dispatch, + * device_ptr and pointer are considered equivalent. + * + * The raw pointer encapsulated by a \p pointer may be obtained through its get member function + * or the \p raw_pointer_cast free function. + * + * \tparam Element specifies the type of the pointed-to object. + * + * \tparam Tag specifies the system with which this \p pointer is associated. This may be any Thrust + * backend system, or a user-defined tag. + * + * \tparam Reference allows the client to specify the reference type returned upon derereference. + * By default, this type is reference. + * + * \tparam Derived allows the client to specify the name of the derived type when \p pointer is used as + * a base class. This is useful to ensure that arithmetic on values of the derived type return + * values of the derived type as a result. By default, this type is pointer. + * + * \note \p pointer is not a smart pointer; it is the client's responsibility to deallocate memory + * pointer to by \p pointer. + * + * \see device_ptr + * \see reference + * \see raw_pointer_cast + */ +template + class pointer +{ + public: + /*! The type of the raw pointer + */ + using raw_pointer = typename super_t::base_type; + + /*! \p pointer's default constructor initializes its encapsulated pointer to \c 0 + */ + _CCCL_HOST_DEVICE + pointer(); + + /*! This constructor allows construction of a pointer from a T*. + * + * \param ptr A raw pointer to copy from, presumed to point to a location in \p Tag's memory. + * \tparam OtherElement \p OtherElement shall be convertible to \p Element. + */ + template + _CCCL_HOST_DEVICE + explicit pointer(OtherElement *ptr); + + /*! This constructor allows initialization from another pointer-like object. + * + * \param other The \p OtherPointer to copy. + * + * \tparam OtherPointer The tag associated with \p OtherPointer shall be convertible to \p Tag, + * and its element type shall be convertible to \p Element. + */ + template + _CCCL_HOST_DEVICE + pointer(const OtherPointer &other, + typename thrust::detail::enable_if_pointer_is_convertible< + OtherPointer, + pointer + >::type * = 0); + + /*! Assignment operator allows assigning from another pointer-like object whose element type + * is convertible to \c Element. + * + * \param other The other pointer-like object to assign from. + * \return *this + * + * \tparam OtherPointer The tag associated with \p OtherPointer shall be convertible to \p Tag, + * and its element type shall be convertible to \p Element. + */ + template + _CCCL_HOST_DEVICE + typename thrust::detail::enable_if_pointer_is_convertible< + OtherPointer, + pointer, + derived_type & + >::type + operator=(const OtherPointer &other); + + /*! \p get returns this \p pointer's encapsulated raw pointer. + * \return This \p pointer's raw pointer. + */ + _CCCL_HOST_DEVICE + Element *get() const; +}; +#endif + +#ifndef _CCCL_DOXYGEN_INVOKED // Doxygen cannot handle both versions + +/*! This version of \p malloc allocates untyped uninitialized storage associated with a given system. + * + * \param system The Thrust system with which to associate the storage. + * \param n The number of bytes of storage to allocate. + * \return If allocation succeeds, a pointer to the allocated storage; a null pointer otherwise. + * The pointer must be deallocated with \p thrust::free. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * + * \pre \p DerivedPolicy must be publicly derived from thrust::execution_policy. + * + * The following code snippet demonstrates how to use \p malloc to allocate a range of memory + * associated with Thrust's device system. + * + * \code + * #include + * ... + * // allocate some memory with thrust::malloc + * const int N = 100; + * thrust::device_system_tag device_sys; + * thrust::pointer void_ptr = thrust::malloc(device_sys, N); + * + * // manipulate memory + * ... + * + * // deallocate void_ptr with thrust::free + * thrust::free(device_sys, void_ptr); + * \endcode + * + * \see free + * \see device_malloc + */ +template +_CCCL_HOST_DEVICE pointer +malloc(const thrust::detail::execution_policy_base& system, std::size_t n); + +#endif // _CCCL_DOXYGEN_INVOKED + +/*! This version of \p malloc allocates typed uninitialized storage associated with a given system. + * + * \param system The Thrust system with which to associate the storage. + * \param n The number of elements of type \c T which the storage should accommodate. + * \return If allocation succeeds, a pointer to an allocation large enough to accommodate \c n + * elements of type \c T; a null pointer otherwise. + * The pointer must be deallocated with \p thrust::free. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * + * \pre \p DerivedPolicy must be publicly derived from thrust::execution_policy. + * + * The following code snippet demonstrates how to use \p malloc to allocate a range of memory + * to accommodate integers associated with Thrust's device system. + * + * \code + * #include + * ... + * // allocate storage for 100 ints with thrust::malloc + * const int N = 100; + * thrust::device_system_tag device_sys; + * thrust::pointer ptr = thrust::malloc(device_sys, N); + * + * // manipulate memory + * ... + * + * // deallocate ptr with thrust::free + * thrust::free(device_sys, ptr); + * \endcode + * + * \see free + * \see device_malloc + */ +template +_CCCL_HOST_DEVICE pointer +malloc(const thrust::detail::execution_policy_base& system, std::size_t n); + +/*! \p get_temporary_buffer returns a pointer to storage associated with a given Thrust system sufficient to store up to + * \p n objects of type \c T. If not enough storage is available to accommodate \p n objects, an implementation may + * return a smaller buffer. The number of objects the returned buffer can accommodate is also returned. + * + * Thrust uses \p get_temporary_buffer internally when allocating temporary storage required by algorithm + * implementations. + * + * The storage allocated with \p get_temporary_buffer must be returned to the system with \p return_temporary_buffer. + * + * \param system The Thrust system with which to associate the storage. + * \param n The requested number of objects of type \c T the storage should accommodate. + * \return A pair \c p such that p.first is a pointer to the allocated storage and p.second is the + * number of contiguous objects of type \c T that the storage can accommodate. If no storage can be allocated, + * p.first if no storage can be obtained. The storage must be returned to the system using \p + * return_temporary_buffer. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * + * \pre \p DerivedPolicy must be publicly derived from thrust::execution_policy. + * + * The following code snippet demonstrates how to use \p get_temporary_buffer to allocate a range of memory + * to accommodate integers associated with Thrust's device system. + * + * \code + * #include + * ... + * // allocate storage for 100 ints with thrust::get_temporary_buffer + * const int N = 100; + * + * using ptr_and_size_t = thrust::pair< + * thrust::pointer, + * std::ptrdiff_t + * >; + * + * thrust::device_system_tag device_sys; + * ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer(device_sys, N); + * + * // manipulate up to 100 ints + * for(int i = 0; i < ptr_and_size.second; ++i) + * { + * *ptr_and_size.first = i; + * } + * + * // deallocate storage with thrust::return_temporary_buffer + * thrust::return_temporary_buffer(device_sys, ptr_and_size.first); + * \endcode + * + * \see malloc + * \see return_temporary_buffer + */ +template +_CCCL_HOST_DEVICE +thrust::pair, typename thrust::pointer::difference_type> +get_temporary_buffer(const thrust::detail::execution_policy_base& system, + typename thrust::pointer::difference_type n); + +/*! \p free deallocates the storage previously allocated by \p thrust::malloc. + * + * \param system The Thrust system with which the storage is associated. + * \param ptr A pointer previously returned by \p thrust::malloc. If \p ptr is null, \p free + * does nothing. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * + * \pre \p ptr shall have been returned by a previous call to thrust::malloc(system, n) or + * thrust::malloc(system, n) for some type \c T. + * + * The following code snippet demonstrates how to use \p free to deallocate a range of memory + * previously allocated with \p thrust::malloc. + * + * \code + * #include + * ... + * // allocate storage for 100 ints with thrust::malloc + * const int N = 100; + * thrust::device_system_tag device_sys; + * thrust::pointer ptr = thrust::malloc(device_sys, N); + * + * // mainpulate memory + * ... + * + * // deallocate ptr with thrust::free + * thrust::free(device_sys, ptr); + * \endcode + */ +template +_CCCL_HOST_DEVICE void free(const thrust::detail::execution_policy_base& system, Pointer ptr); + +/*! \p return_temporary_buffer deallocates storage associated with a given Thrust system previously allocated by \p + * get_temporary_buffer. + * + * Thrust uses \p return_temporary_buffer internally when deallocating temporary storage required by algorithm + * implementations. + * + * \param system The Thrust system with which the storage is associated. + * \param p A pointer previously returned by \p thrust::get_temporary_buffer. If \p ptr is null, \p + * return_temporary_buffer does nothing. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * + * \pre \p p shall have been previously allocated by \p thrust::get_temporary_buffer. + * + * The following code snippet demonstrates how to use \p return_temporary_buffer to deallocate a range of memory + * previously allocated by \p get_temporary_buffer. + * + * \code + * #include + * ... + * // allocate storage for 100 ints with thrust::get_temporary_buffer + * const int N = 100; + * + * using ptr_and_size_t = thrust::pair< + * thrust::pointer, + * std::ptrdiff_t + * >; + * + * thrust::device_system_tag device_sys; + * ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer(device_sys, N); + * + * // manipulate up to 100 ints + * for(int i = 0; i < ptr_and_size.second; ++i) + * { + * *ptr_and_size.first = i; + * } + * + * // deallocate storage with thrust::return_temporary_buffer + * thrust::return_temporary_buffer(device_sys, ptr_and_size.first); + * \endcode + * + * \see free + * \see get_temporary_buffer + */ +template +_CCCL_HOST_DEVICE void return_temporary_buffer( + const thrust::detail::execution_policy_base& system, Pointer p, std::ptrdiff_t n); + +/*! \p raw_pointer_cast creates a "raw" pointer from a pointer-like type, + * simply returning the wrapped pointer, should it exist. + * + * \param ptr The pointer of interest. + * \return ptr.get(), if the expression is well formed; ptr, otherwise. + * \see raw_reference_cast + */ +template +_CCCL_HOST_DEVICE typename thrust::detail::pointer_traits::raw_pointer raw_pointer_cast(Pointer ptr); + +/*! \p raw_reference_cast creates a "raw" reference from a wrapped reference type, + * simply returning the underlying reference, should it exist. + * + * If the argument is not a reference wrapper, the result is a reference to the argument. + * + * \param ref The reference of interest. + * \return *thrust::raw_pointer_cast(&ref). + * \note There are two versions of \p raw_reference_cast. One for const references, + * and one for non-const. + * \see raw_pointer_cast + */ +template +_CCCL_HOST_DEVICE typename detail::raw_reference::type raw_reference_cast(T& ref); + +/*! \p raw_reference_cast creates a "raw" reference from a wrapped reference type, + * simply returning the underlying reference, should it exist. + * + * If the argument is not a reference wrapper, the result is a reference to the argument. + * + * \param ref The reference of interest. + * \return *thrust::raw_pointer_cast(&ref). + * \note There are two versions of \p raw_reference_cast. One for const references, + * and one for non-const. + * \see raw_pointer_cast + */ +template +_CCCL_HOST_DEVICE typename detail::raw_reference::type raw_reference_cast(const T& ref); + +/*! \} // memory_management + */ + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/merge.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/merge.h new file mode 100644 index 0000000000000000000000000000000000000000..baf5fc6d7b303441a5d5fd1593f7156ccb358fea --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/merge.h @@ -0,0 +1,725 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file merge.h + * \brief Merging sorted ranges + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup merging Merging + * \ingroup algorithms + * \{ + */ + +/*! \p merge combines two sorted ranges [first1, last1) and [first2, last2) + * into a single sorted range. That is, it copies from [first1, last1) and + * [first2, last2) into [result, result + (last1 - first1) + (last2 - first2)) + * such that the resulting range is in ascending order. \p merge is stable, meaning both that the + * relative order of elements within each input range is preserved, and that for equivalent elements + * in both input ranges the element from the first range precedes the element from the second. The + * return value is result + (last1 - first1) + (last2 - first2). + * + * This version of \p merge compares elements using \c operator<. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first input range. + * \param last1 The end of the first input range. + * \param first2 The beginning of the second input range. + * \param last2 The end of the second input range. + * \param result The beginning of the merged output. + * \return The end of the output range. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1 and \p InputIterator2 have the same \c value_type, \p InputIterator1's \c value_type + * is a model of LessThan Comparable, the + * ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and \p + * InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * InputIterator2 is a model of Input Iterator, + * \p InputIterator2 and \p InputIterator1 have the same \c value_type, + * \p InputIterator2's \c value_type is a model of LessThan Comparable, the ordering on \p + * InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and \p + * InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * OutputIterator is a model of Output + * Iterator. + * + * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to + * operator<. \pre The resulting range shall not overlap with either input range. + * + * The following code snippet demonstrates how to use + * \p merge to compute the merger of two sorted sets of integers using the \p thrust::host execution policy for + * parallelization: + * + * \code + * #include + * #include + * ... + * int A1[6] = {1, 3, 5, 7, 9, 11}; + * int A2[7] = {1, 1, 2, 3, 5, 8, 13}; + * + * int result[13]; + * + * int *result_end = + * thrust::merge(thrust::host, + * A1, A1 + 6, + * A2, A2 + 7, + * result); + * // result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/merge + * \see \p set_union + * \see \p sort + * \see \p is_sorted + */ +template +_CCCL_HOST_DEVICE OutputIterator merge( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result); + +/*! \p merge combines two sorted ranges [first1, last1) and [first2, last2) + * into a single sorted range. That is, it copies from [first1, last1) and + * [first2, last2) into [result, result + (last1 - first1) + (last2 - first2)) + * such that the resulting range is in ascending order. \p merge is stable, meaning both that the + * relative order of elements within each input range is preserved, and that for equivalent elements + * in both input ranges the element from the first range precedes the element from the second. The + * return value is result + (last1 - first1) + (last2 - first2). + * + * This version of \p merge compares elements using \c operator<. + * + * \param first1 The beginning of the first input range. + * \param last1 The end of the first input range. + * \param first2 The beginning of the second input range. + * \param last2 The end of the second input range. + * \param result The beginning of the merged output. + * \return The end of the output range. + * + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1 and \p InputIterator2 have the same \c value_type, \p InputIterator1's \c value_type + * is a model of LessThan Comparable, the + * ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and \p + * InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * InputIterator2 is a model of Input Iterator, + * \p InputIterator2 and \p InputIterator1 have the same \c value_type, + * \p InputIterator2's \c value_type is a model of LessThan Comparable, the ordering on \p + * InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and \p + * InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * OutputIterator is a model of Output + * Iterator. + * + * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to + * operator<. \pre The resulting range shall not overlap with either input range. + * + * The following code snippet demonstrates how to use + * \p merge to compute the merger of two sorted sets of integers. + * + * \code + * #include + * ... + * int A1[6] = {1, 3, 5, 7, 9, 11}; + * int A2[7] = {1, 1, 2, 3, 5, 8, 13}; + * + * int result[13]; + * + * int *result_end = thrust::merge(A1, A1 + 6, A2, A2 + 7, result); + * // result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/merge + * \see \p set_union + * \see \p sort + * \see \p is_sorted + */ +template +OutputIterator +merge(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +/*! \p merge combines two sorted ranges [first1, last1) and [first2, last2) + * into a single sorted range. That is, it copies from [first1, last1) and + * [first2, last2) into [result, result + (last1 - first1) + (last2 - first2)) + * such that the resulting range is in ascending order. \p merge is stable, meaning both that the + * relative order of elements within each input range is preserved, and that for equivalent elements + * in both input ranges the element from the first range precedes the element from the second. The + * return value is result + (last1 - first1) + (last2 - first2). + * + * This version of \p merge compares elements using a function object \p comp. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first input range. + * \param last1 The end of the first input range. + * \param first2 The beginning of the second input range. + * \param last2 The end of the second input range. + * \param result The beginning of the merged output. + * \param comp Comparison operator. + * \return The end of the output range. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1's \c value_type is convertible to \p StrictWeakCompare's \c first_argument_type. and + * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * InputIterator2 is a model of Input Iterator, + * \p InputIterator2's \c value_type is convertible to \p StrictWeakCompare's \c second_argument_type. + * and \p InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. + * \tparam OutputIterator is a model of Output + * Iterator. \tparam StrictWeakCompare is a model of Strict Weak Ordering. + * + * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. + * \pre The resulting range shall not overlap with either input range. + * + * The following code snippet demonstrates how to use + * \p merge to compute the merger of two sets of integers sorted in + * descending order using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * int A1[6] = {11, 9, 7, 5, 3, 1}; + * int A2[7] = {13, 8, 5, 3, 2, 1, 1}; + * + * int result[13]; + * + * int *result_end = thrust::merge(thrust::host, + * A1, A1 + 6, + * A2, A2 + 7, + * result, + * thrust::greater()); + * // result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/merge + * \see \p sort + * \see \p is_sorted + */ +template +_CCCL_HOST_DEVICE OutputIterator merge( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result, + StrictWeakCompare comp); + +/*! \p merge combines two sorted ranges [first1, last1) and [first2, last2) + * into a single sorted range. That is, it copies from [first1, last1) and + * [first2, last2) into [result, result + (last1 - first1) + (last2 - first2)) + * such that the resulting range is in ascending order. \p merge is stable, meaning both that the + * relative order of elements within each input range is preserved, and that for equivalent elements + * in both input ranges the element from the first range precedes the element from the second. The + * return value is result + (last1 - first1) + (last2 - first2). + * + * This version of \p merge compares elements using a function object \p comp. + * + * \param first1 The beginning of the first input range. + * \param last1 The end of the first input range. + * \param first2 The beginning of the second input range. + * \param last2 The end of the second input range. + * \param result The beginning of the merged output. + * \param comp Comparison operator. + * \return The end of the output range. + * + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1's \c value_type is convertible to \p StrictWeakCompare's \c first_argument_type. and + * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * InputIterator2 is a model of Input Iterator, + * \p InputIterator2's \c value_type is convertible to \p StrictWeakCompare's \c second_argument_type. + * and \p InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. + * \tparam OutputIterator is a model of Output + * Iterator. \tparam StrictWeakCompare is a model of Strict Weak Ordering. + * + * \pre The ranges [first1, last1) and [first2, last2) shall be sorted with respect to \p comp. + * \pre The resulting range shall not overlap with either input range. + * + * The following code snippet demonstrates how to use + * \p merge to compute the merger of two sets of integers sorted in + * descending order. + * + * \code + * #include + * #include + * ... + * int A1[6] = {11, 9, 7, 5, 3, 1}; + * int A2[7] = {13, 8, 5, 3, 2, 1, 1}; + * + * int result[13]; + * + * int *result_end = thrust::merge(A1, A1 + 6, A2, A2 + 7, result, thrust::greater()); + * // result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/merge + * \see \p sort + * \see \p is_sorted + */ +template +OutputIterator +merge(InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator2 last2, + OutputIterator result, + StrictWeakCompare comp); + +/*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from + * [keys_first1, keys_last1) and [keys_first2, keys_last2) into a single range, + * [keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that + * the resulting range is in ascending key order. + * + * At the same time, \p merge_by_key copies elements from the two associated ranges [values_first1 + (keys_last1 - + * keys_first1)) and [values_first2 + (keys_last2 - keys_first2)) into a single range, [values_result, + * values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that the resulting range is in + * ascending order implied by each input element's associated key. + * + * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is + * preserved, and that for equivalent elements in all input key ranges the element from the first range + * precedes the element from the second. + * + * The return value is is (keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) + * and (values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first1 The beginning of the first input range of keys. + * \param keys_last1 The end of the first input range of keys. + * \param keys_first2 The beginning of the second input range of keys. + * \param keys_last2 The end of the second input range of keys. + * \param values_first1 The beginning of the first input range of values. + * \param values_first2 The beginning of the first input range of values. + * \param keys_result The beginning of the merged output range of keys. + * \param values_result The beginning of the merged output range of values. + * \return A \p pair \c p such that p.first is the end of the output range of keys, + * and such that p.second is the end of the output range of values. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1 and \p InputIterator2 have the same \c value_type, \p InputIterator1's \c value_type + * is a model of LessThan Comparable, the + * ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and \p + * InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * InputIterator2 is a model of Input Iterator, + * \p InputIterator2 and \p InputIterator1 have the same \c value_type, + * \p InputIterator2's \c value_type is a model of LessThan Comparable, the ordering on \p + * InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and \p + * InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * InputIterator3 is a model of Input Iterator, + * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c + * value_types. \tparam InputIterator4 is a model of Input Iterator, and \p InputIterator4's \c + * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam OutputIterator1 is a model + * of Output Iterator. \tparam OutputIterator2 + * is a model of Output Iterator. + * + * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with + * respect to operator<. \pre The resulting ranges shall not overlap with any input range. + * + * The following code snippet demonstrates how to use + * \p merge_by_key to compute the merger of two sets of integers sorted in + * ascending order using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * int A_keys[6] = {1, 3, 5, 7, 9, 11}; + * int A_vals[6] = {0, 0, 0, 0, 0, 0}; + * + * int B_keys[7] = {1, 1, 2, 3, 5, 8, 13}; + * int B_vals[7] = {1, 1, 1, 1, 1, 1, 1}; + * + * int keys_result[13]; + * int vals_result[13]; + * + * thrust::pair end = + * thrust::merge_by_key(thrust::host, + * A_keys, A_keys + 6, + * B_keys, B_keys + 7, + * A_vals, B_vals, + * keys_result, vals_result); + * + * // keys_result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13} + * // vals_result = {0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1} + * \endcode + * + * \see merge + * \see \p sort_by_key + * \see \p is_sorted + */ +template +_CCCL_HOST_DEVICE thrust::pair merge_by_key( + const thrust::detail::execution_policy_base& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result); + +/*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from + * [keys_first1, keys_last1) and [keys_first2, keys_last2) into a single range, + * [keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that + * the resulting range is in ascending key order. + * + * At the same time, \p merge_by_key copies elements from the two associated ranges [values_first1 + (keys_last1 - + * keys_first1)) and [values_first2 + (keys_last2 - keys_first2)) into a single range, [values_result, + * values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that the resulting range is in + * ascending order implied by each input element's associated key. + * + * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is + * preserved, and that for equivalent elements in all input key ranges the element from the first range + * precedes the element from the second. + * + * The return value is is (keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) + * and (values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)). + * + * \param keys_first1 The beginning of the first input range of keys. + * \param keys_last1 The end of the first input range of keys. + * \param keys_first2 The beginning of the second input range of keys. + * \param keys_last2 The end of the second input range of keys. + * \param values_first1 The beginning of the first input range of values. + * \param values_first2 The beginning of the first input range of values. + * \param keys_result The beginning of the merged output range of keys. + * \param values_result The beginning of the merged output range of values. + * \return A \p pair \c p such that p.first is the end of the output range of keys, + * and such that p.second is the end of the output range of values. + * + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1 and \p InputIterator2 have the same \c value_type, \p InputIterator1's \c value_type + * is a model of LessThan Comparable, the + * ordering on \p InputIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and \p + * InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * InputIterator2 is a model of Input Iterator, + * \p InputIterator2 and \p InputIterator1 have the same \c value_type, + * \p InputIterator2's \c value_type is a model of LessThan Comparable, the ordering on \p + * InputIterator2's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements, and \p + * InputIterator2's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types. \tparam + * InputIterator3 is a model of Input Iterator, + * and \p InputIterator3's \c value_type is convertible to a type in \p OutputIterator2's set of \c + * value_types. \tparam InputIterator4 is a model of Input Iterator, and \p InputIterator4's \c + * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam OutputIterator1 is a model + * of Output Iterator. \tparam OutputIterator2 + * is a model of Output Iterator. + * + * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with + * respect to operator<. \pre The resulting ranges shall not overlap with any input range. + * + * The following code snippet demonstrates how to use + * \p merge_by_key to compute the merger of two sets of integers sorted in + * ascending order. + * + * \code + * #include + * #include + * ... + * int A_keys[6] = {1, 3, 5, 7, 9, 11}; + * int A_vals[6] = {0, 0, 0, 0, 0, 0}; + * + * int B_keys[7] = {1, 1, 2, 3, 5, 8, 13}; + * int B_vals[7] = {1, 1, 1, 1, 1, 1, 1}; + * + * int keys_result[13]; + * int vals_result[13]; + * + * thrust::pair end = thrust::merge_by_key(A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, B_vals, + * keys_result, vals_result); + * + * // keys_result = {1, 1, 1, 2, 3, 3, 5, 5, 7, 8, 9, 11, 13} + * // vals_result = {0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1} + * \endcode + * + * \see merge + * \see \p sort_by_key + * \see \p is_sorted + */ +template +thrust::pair merge_by_key( + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result); + +/*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from + * [keys_first1, keys_last1) and [keys_first2, keys_last2) into a single range, + * [keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that + * the resulting range is in ascending key order. + * + * At the same time, \p merge_by_key copies elements from the two associated ranges [values_first1 + (keys_last1 - + * keys_first1)) and [values_first2 + (keys_last2 - keys_first2)) into a single range, [values_result, + * values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that the resulting range is in + * ascending order implied by each input element's associated key. + * + * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is + * preserved, and that for equivalent elements in all input key ranges the element from the first range + * precedes the element from the second. + * + * The return value is is (keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) + * and (values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)). + * + * This version of \p merge_by_key compares key elements using a function object \p comp. + * + * The algorithm's execution is parallelized using \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first1 The beginning of the first input range of keys. + * \param keys_last1 The end of the first input range of keys. + * \param keys_first2 The beginning of the second input range of keys. + * \param keys_last2 The end of the second input range of keys. + * \param values_first1 The beginning of the first input range of values. + * \param values_first2 The beginning of the first input range of values. + * \param keys_result The beginning of the merged output range of keys. + * \param values_result The beginning of the merged output range of values. + * \param comp Comparison operator. + * \return A \p pair \c p such that p.first is the end of the output range of keys, + * and such that p.second is the end of the output range of values. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1's \c value_type is convertible to \p StrictWeakCompare's \c first_argument_type. and + * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator1's set of \c value_types. \tparam + * InputIterator2 is a model of Input Iterator, + * \p InputIterator2's \c value_type is convertible to \p StrictWeakCompare's \c second_argument_type. + * and \p InputIterator2's \c value_type is convertible to a type in \p OutputIterator1's set of \c + * value_types. \tparam InputIterator3 is a model of Input Iterator, and \p InputIterator3's \c + * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam InputIterator4 is a model + * of Input Iterator, and \p InputIterator4's \c + * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam OutputIterator1 is a model + * of Output Iterator. \tparam OutputIterator2 + * is a model of Output Iterator. \tparam + * StrictWeakCompare is a model of Strict Weak + * Ordering. + * + * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with + * respect to \p comp. \pre The resulting ranges shall not overlap with any input range. + * + * The following code snippet demonstrates how to use + * \p merge_by_key to compute the merger of two sets of integers sorted in + * descending order using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * int A_keys[6] = {11, 9, 7, 5, 3, 1}; + * int A_vals[6] = { 0, 0, 0, 0, 0, 0}; + * + * int B_keys[7] = {13, 8, 5, 3, 2, 1, 1}; + * int B_vals[7] = { 1, 1, 1, 1, 1, 1, 1}; + * + * int keys_result[13]; + * int vals_result[13]; + * + * thrust::pair end = + * thrust::merge_by_key(thrust::host, + * A_keys, A_keys + 6, + * B_keys, B_keys + 7, + * A_vals, B_vals, + * keys_result, vals_result, + * thrust::greater()); + * + * // keys_result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1} + * // vals_result = { 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1} + * \endcode + * + * \see merge + * \see \p sort_by_key + * \see \p is_sorted + */ +template +_CCCL_HOST_DEVICE thrust::pair merge_by_key( + const thrust::detail::execution_policy_base& exec, + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + Compare comp); + +/*! \p merge_by_key performs a key-value merge. That is, \p merge_by_key copies elements from + * [keys_first1, keys_last1) and [keys_first2, keys_last2) into a single range, + * [keys_result, keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that + * the resulting range is in ascending key order. + * + * At the same time, \p merge_by_key copies elements from the two associated ranges [values_first1 + (keys_last1 - + * keys_first1)) and [values_first2 + (keys_last2 - keys_first2)) into a single range, [values_result, + * values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) such that the resulting range is in + * ascending order implied by each input element's associated key. + * + * \p merge_by_key is stable, meaning both that the relative order of elements within each input range is + * preserved, and that for equivalent elements in all input key ranges the element from the first range + * precedes the element from the second. + * + * The return value is is (keys_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)) + * and (values_result + (keys_last1 - keys_first1) + (keys_last2 - keys_first2)). + * + * This version of \p merge_by_key compares key elements using a function object \p comp. + * + * \param keys_first1 The beginning of the first input range of keys. + * \param keys_last1 The end of the first input range of keys. + * \param keys_first2 The beginning of the second input range of keys. + * \param keys_last2 The end of the second input range of keys. + * \param values_first1 The beginning of the first input range of values. + * \param values_first2 The beginning of the first input range of values. + * \param keys_result The beginning of the merged output range of keys. + * \param values_result The beginning of the merged output range of values. + * \param comp Comparison operator. + * \return A \p pair \c p such that p.first is the end of the output range of keys, + * and such that p.second is the end of the output range of values. + * + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1's \c value_type is convertible to \p StrictWeakCompare's \c first_argument_type. and + * \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator1's set of \c value_types. \tparam + * InputIterator2 is a model of Input Iterator, + * \p InputIterator2's \c value_type is convertible to \p StrictWeakCompare's \c second_argument_type. + * and \p InputIterator2's \c value_type is convertible to a type in \p OutputIterator1's set of \c + * value_types. \tparam InputIterator3 is a model of Input Iterator, and \p InputIterator3's \c + * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam InputIterator4 is a model + * of Input Iterator, and \p InputIterator4's \c + * value_type is convertible to a type in \p OutputIterator2's set of \c value_types. \tparam OutputIterator1 is a model + * of Output Iterator. \tparam OutputIterator2 + * is a model of Output Iterator. \tparam + * StrictWeakCompare is a model of Strict Weak + * Ordering. + * + * \pre The ranges [keys_first1, keys_last1) and [keys_first2, keys_last2) shall be sorted with + * respect to \p comp. \pre The resulting ranges shall not overlap with any input range. + * + * The following code snippet demonstrates how to use + * \p merge_by_key to compute the merger of two sets of integers sorted in + * descending order. + * + * \code + * #include + * #include + * ... + * int A_keys[6] = {11, 9, 7, 5, 3, 1}; + * int A_vals[6] = { 0, 0, 0, 0, 0, 0}; + * + * int B_keys[7] = {13, 8, 5, 3, 2, 1, 1}; + * int B_vals[7] = { 1, 1, 1, 1, 1, 1, 1}; + * + * int keys_result[13]; + * int vals_result[13]; + * + * thrust::pair end = thrust::merge_by_key(A_keys, A_keys + 6, B_keys, B_keys + 7, A_vals, B_vals, + * keys_result, vals_result, thrust::greater()); + * + * // keys_result = {13, 11, 9, 8, 7, 5, 5, 3, 3, 2, 1, 1, 1} + * // vals_result = { 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1} + * \endcode + * + * \see merge + * \see \p sort_by_key + * \see \p is_sorted + */ +template +thrust::pair merge_by_key( + InputIterator1 keys_first1, + InputIterator1 keys_last1, + InputIterator2 keys_first2, + InputIterator2 keys_last2, + InputIterator3 values_first1, + InputIterator4 values_first2, + OutputIterator1 keys_result, + OutputIterator2 values_result, + StrictWeakCompare comp); + +/*! \} // merging + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/mismatch.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/mismatch.h new file mode 100644 index 0000000000000000000000000000000000000000..e42bc76a6a93a694144c6f8677c88e5835f32817 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/mismatch.h @@ -0,0 +1,261 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file mismatch.h + * \brief Search for differences between ranges + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup algorithms + */ + +/*! \addtogroup searching + * \ingroup algorithms + * \{ + */ + +/*! \p mismatch finds the first position where the two ranges [first1, last1) + * and [first2, first2 + (last1 - first1)) differ. The two versions of + * \p mismatch use different tests for whether elements differ. + * + * This version of \p mismatch finds the first iterator \c i in [first1, last1) + * such that *i == *(first2 + (i - first1)) is \c false. The return value is a + * \c pair whose first element is \c i and whose second element is *(first2 + (i - first1)). + * If no such iterator \c i exists, the return value is a \c pair whose first element + * is \c last1 and whose second element is *(first2 + (last1 - first1)). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \return The first position where the sequences differ. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator and \p InputIterator1's \c value_type is equality comparable to \p InputIterator2's \c value_type. + * \tparam InputIterator2 is a model of Input + * Iterator. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector vec1(4); + * thrust::device_vector vec2(4); + * + * vec1[0] = 0; vec2[0] = 0; + * vec1[1] = 5; vec2[1] = 5; + * vec1[2] = 3; vec2[2] = 8; + * vec1[3] = 7; vec2[3] = 7; + * + * using Iterator = thrust::device_vector::iterator; + * thrust::pair result; + * + * result = thrust::mismatch(thrust::device, vec1.begin(), vec1.end(), vec2.begin()); + * + * // result.first is vec1.begin() + 2 + * // result.second is vec2.begin() + 2 + * \endcode + * + * \see find + * \see find_if + */ +template +_CCCL_HOST_DEVICE thrust::pair +mismatch(const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2); + +/*! \p mismatch finds the first position where the two ranges [first1, last1) + * and [first2, first2 + (last1 - first1)) differ. The two versions of + * \p mismatch use different tests for whether elements differ. + * + * This version of \p mismatch finds the first iterator \c i in [first1, last1) + * such that *i == *(first2 + (i - first1)) is \c false. The return value is a + * \c pair whose first element is \c i and whose second element is *(first2 + (i - first1)). + * If no such iterator \c i exists, the return value is a \c pair whose first element + * is \c last1 and whose second element is *(first2 + (last1 - first1)). + * + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \return The first position where the sequences differ. + * + * \tparam InputIterator1 is a model of Input + * Iterator and \p InputIterator1's \c value_type is equality comparable to \p InputIterator2's \c value_type. + * \tparam InputIterator2 is a model of Input + * Iterator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector vec1(4); + * thrust::device_vector vec2(4); + * + * vec1[0] = 0; vec2[0] = 0; + * vec1[1] = 5; vec2[1] = 5; + * vec1[2] = 3; vec2[2] = 8; + * vec1[3] = 7; vec2[3] = 7; + * + * using Iterator = thrust::device_vector::iterator; + * thrust::pair result; + * + * result = thrust::mismatch(vec1.begin(), vec1.end(), vec2.begin()); + * + * // result.first is vec1.begin() + 2 + * // result.second is vec2.begin() + 2 + * \endcode + * + * \see find + * \see find_if + */ +template +thrust::pair +mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); + +/*! \p mismatch finds the first position where the two ranges [first1, last1) + * and [first2, first2 + (last1 - first1)) differ. The two versions of + * \p mismatch use different tests for whether elements differ. + * + * This version of \p mismatch finds the first iterator \c i in [first1, last1) + * such that pred(\*i, \*(first2 + (i - first1)) is \c false. The return value is a + * \c pair whose first element is \c i and whose second element is *(first2 + (i - first1)). + * If no such iterator \c i exists, the return value is a \c pair whose first element is + * \c last1 and whose second element is *(first2 + (last1 - first1)). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \param pred The binary predicate to compare elements. + * \return The first position where the sequences differ. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator. \tparam InputIterator2 is a model of Input Iterator. \tparam Predicate is a model of + * Input Iterator. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector vec1(4); + * thrust::device_vector vec2(4); + * + * vec1[0] = 0; vec2[0] = 0; + * vec1[1] = 5; vec2[1] = 5; + * vec1[2] = 3; vec2[2] = 8; + * vec1[3] = 7; vec2[3] = 7; + * + * using Iterator = thrust::device_vector::iterator; + * thrust::pair result; + * + * result = thrust::mismatch(thrust::device, vec1.begin(), vec1.end(), vec2.begin(), thrust::equal_to()); + * + * // result.first is vec1.begin() + 2 + * // result.second is vec2.begin() + 2 + * \endcode + * + * \see find + * \see find_if + */ +template +_CCCL_HOST_DEVICE thrust::pair mismatch( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + BinaryPredicate pred); + +/*! \p mismatch finds the first position where the two ranges [first1, last1) + * and [first2, first2 + (last1 - first1)) differ. The two versions of + * \p mismatch use different tests for whether elements differ. + * + * This version of \p mismatch finds the first iterator \c i in [first1, last1) + * such that pred(\*i, \*(first2 + (i - first1)) is \c false. The return value is a + * \c pair whose first element is \c i and whose second element is *(first2 + (i - first1)). + * If no such iterator \c i exists, the return value is a \c pair whose first element is + * \c last1 and whose second element is *(first2 + (last1 - first1)). + * + * \param first1 The beginning of the first sequence. + * \param last1 The end of the first sequence. + * \param first2 The beginning of the second sequence. + * \param pred The binary predicate to compare elements. + * \return The first position where the sequences differ. + * + * \tparam InputIterator1 is a model of Input + * Iterator. \tparam InputIterator2 is a model of Input Iterator. \tparam Predicate is a model of + * Input Iterator. + * + * \code + * #include + * #include + * ... + * thrust::device_vector vec1(4); + * thrust::device_vector vec2(4); + * + * vec1[0] = 0; vec2[0] = 0; + * vec1[1] = 5; vec2[1] = 5; + * vec1[2] = 3; vec2[2] = 8; + * vec1[3] = 7; vec2[3] = 7; + * + * using Iterator = thrust::device_vector::iterator; + * thrust::pair result; + * + * result = thrust::mismatch(vec1.begin(), vec1.end(), vec2.begin(), thrust::equal_to()); + * + * // result.first is vec1.begin() + 2 + * // result.second is vec2.begin() + 2 + * \endcode + * + * \see find + * \see find_if + */ +template +thrust::pair +mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred); + +/*! \} // end searching + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/optional.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/optional.h new file mode 100644 index 0000000000000000000000000000000000000000..fa181d7a11fdb715e75453df73c9fc0711860ee3 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/optional.h @@ -0,0 +1,2844 @@ +/// +// optional - An implementation of std::optional with extensions +// Written in 2017 by Sy Brand (@TartanLlama) +// +// To the extent possible under law, the author(s) have dedicated all +// copyright and related and neighboring rights to this software to the +// public domain worldwide. This software is distributed without any warranty. +// +// You should have received a copy of the CC0 Public Domain Dedication +// along with this software. If not, see +// . +/// + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include + +#include + +#define THRUST_OPTIONAL_VERSION_MAJOR 0 +#define THRUST_OPTIONAL_VERSION_MINOR 2 + +#include +#include +#include +#include +#include + +_CCCL_SUPPRESS_DEPRECATED_PUSH + +#if _CCCL_COMPILER(MSVC, ==, 19, 00) +# define THRUST_OPTIONAL_MSVC2015 +#endif + +#if _CCCL_STD_VER > 2011 +# define THRUST_OPTIONAL_CPP14 +#endif + +// constexpr implies const in C++11, not C++14 +#if (_CCCL_STD_VER == 2011 || defined(THRUST_OPTIONAL_MSVC2015) || defined(THRUST_OPTIONAL_GCC49)) +/// \exclude +# define THRUST_OPTIONAL_CPP11_CONSTEXPR +#else +/// \exclude +# define THRUST_OPTIONAL_CPP11_CONSTEXPR constexpr +#endif + +THRUST_NAMESPACE_BEGIN + +#ifndef THRUST_MONOSTATE_INPLACE_MUTEX +# define THRUST_MONOSTATE_INPLACE_MUTEX +/// \brief Used to represent an optional with no data; essentially a bool +class CCCL_DEPRECATED_BECAUSE("Use cuda::std::monostate instead") monostate +{}; + +/// \brief A tag type to tell optional to construct its value in-place +struct CCCL_DEPRECATED in_place_t +{ + explicit in_place_t() = default; +}; +/// \brief A tag to tell optional to construct its value in-place +static constexpr in_place_t in_place{}; +#endif + +template +class CCCL_DEPRECATED_BECAUSE("Use cuda::std::optional") optional; + +/// \exclude +namespace detail +{ +#ifndef THRUST_TRAITS_MUTEX +# define THRUST_TRAITS_MUTEX +// C++14-style aliases for brevity +template +using remove_const_t = typename std::remove_const::type; +template +using remove_reference_t = typename std::remove_reference::type; +template +using decay_t = typename std::decay::type; +template +using enable_if_t = typename std::enable_if::type; +template +using conditional_t = typename std::conditional::type; + +// std::conjunction from C++17 +template +struct conjunction : std::true_type +{}; +template +struct conjunction : B +{}; +template +struct conjunction : std::conditional, B>::type +{}; + +# if defined(_LIBCPP_VERSION) && _CCCL_STD_VER == 2011 +# define THRUST_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND +# endif + +// In C++11 mode, there's an issue in libc++'s std::mem_fn +// which results in a hard-error when using it in a noexcept expression +// in some cases. This is a check to workaround the common failing case. +# ifdef THRUST_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND +template +struct is_pointer_to_non_const_member_func : std::false_type +{}; +template +struct is_pointer_to_non_const_member_func : std::true_type +{}; +template +struct is_pointer_to_non_const_member_func : std::true_type +{}; +template +struct is_pointer_to_non_const_member_func : std::true_type +{}; +template +struct is_pointer_to_non_const_member_func : std::true_type +{}; +template +struct is_pointer_to_non_const_member_func : std::true_type +{}; +template +struct is_pointer_to_non_const_member_func : std::true_type +{}; + +template +struct is_const_or_const_ref : std::false_type +{}; +template +struct is_const_or_const_ref : std::true_type +{}; +template +struct is_const_or_const_ref : std::true_type +{}; +# endif + +// std::invoke from C++17 +// https://stackoverflow.com/questions/38288042/c11-14-invoke-workaround +_CCCL_EXEC_CHECK_DISABLE +template < + typename Fn, + typename... Args, +# ifdef THRUST_OPTIONAL_LIBCXX_MEM_FN_WORKAROUND + typename = enable_if_t::value && is_const_or_const_ref::value)>, +# endif + typename = enable_if_t>::value>, + int = 0> +_CCCL_HOST_DEVICE constexpr auto invoke(Fn&& f, Args&&... args) noexcept( + noexcept(std::mem_fn(f)(std::forward(args)...))) -> decltype(std::mem_fn(f)(std::forward(args)...)) +{ + return std::mem_fn(f)(std::forward(args)...); +} + +_CCCL_EXEC_CHECK_DISABLE +template >::value>> +_CCCL_HOST_DEVICE constexpr auto invoke(Fn&& f, Args&&... args) noexcept(noexcept( + std::forward(f)(std::forward(args)...))) -> decltype(std::forward(f)(std::forward(args)...)) +{ + return std::forward(f)(std::forward(args)...); +} +#endif + +// Trait for checking if a type is a thrust::optional +template +struct is_optional_impl : std::false_type +{}; +template +struct is_optional_impl> : std::true_type +{}; +template +using is_optional = is_optional_impl>; + +// Change void to thrust::monostate +template +using fixup_void = conditional_t::value, monostate, U>; + +template > +using get_map_return = optional>>; + +// Check if invoking F for some Us returns void +template +struct returns_void_impl; +template +struct returns_void_impl>, U...> + : std::is_void> +{}; +template +using returns_void = returns_void_impl; + +template +using enable_if_ret_void = enable_if_t::value>; + +template +using disable_if_ret_void = enable_if_t::value>; + +template +using enable_forward_value = + detail::enable_if_t::value && !std::is_same, in_place_t>::value + && !std::is_same, detail::decay_t>::value>; + +template +using enable_from_other = detail::enable_if_t< + std::is_constructible::value && !std::is_constructible&>::value + && !std::is_constructible&&>::value && !std::is_constructible&>::value + && !std::is_constructible&&>::value && !std::is_convertible&, T>::value + && !std::is_convertible&&, T>::value && !std::is_convertible&, T>::value + && !std::is_convertible&&, T>::value>; + +template +using enable_assign_forward = + detail::enable_if_t, detail::decay_t>::value + && !detail::conjunction, std::is_same>>::value + && std::is_constructible::value && std::is_assignable::value>; + +template +using enable_assign_from_other = detail::enable_if_t< + std::is_constructible::value && std::is_assignable::value + && !std::is_constructible&>::value && !std::is_constructible&&>::value + && !std::is_constructible&>::value && !std::is_constructible&&>::value + && !std::is_convertible&, T>::value && !std::is_convertible&&, T>::value + && !std::is_convertible&, T>::value && !std::is_convertible&&, T>::value + && !std::is_assignable&>::value && !std::is_assignable&&>::value + && !std::is_assignable&>::value && !std::is_assignable&&>::value>; + +#if _CCCL_COMPILER(MSVC) +// TODO make a version which works with MSVC +template +struct is_swappable : std::true_type +{}; + +template +struct is_nothrow_swappable : std::true_type +{}; +#else +// https://stackoverflow.com/questions/26744589/what-is-a-proper-way-to-implement-is-swappable-to-test-for-the-swappable-concept +namespace swap_adl_tests +{ +// if swap ADL finds this then it would call std::swap otherwise (same +// signature) +struct tag +{}; + +template +tag swap(T&, T&); +template +tag swap(T (&a)[N], T (&b)[N]); + +// helper functions to test if an unqualified swap is possible, and if it +// becomes std::swap +template +std::false_type can_swap(...) noexcept(false); +template (), std::declval()))> +std::true_type can_swap(int) noexcept(noexcept(swap(std::declval(), std::declval()))); + +template +std::false_type uses_std(...); +template +std::is_same(), std::declval())), tag> uses_std(int); + +template +struct is_std_swap_noexcept + : std::integral_constant::value && std::is_nothrow_move_assignable::value> +{}; + +template +struct is_std_swap_noexcept : is_std_swap_noexcept +{}; + +template +struct is_adl_swap_noexcept : std::integral_constant(0))> +{}; +} // namespace swap_adl_tests + +template +struct is_swappable + : std::integral_constant(0))::value + && (!decltype(detail::swap_adl_tests::uses_std(0))::value + || (std::is_move_assignable::value && std::is_move_constructible::value))> +{}; + +template +struct is_swappable + : std::integral_constant< + bool, + decltype(detail::swap_adl_tests::can_swap(0))::value + && (!decltype(detail::swap_adl_tests::uses_std(0))::value || is_swappable::value)> +{}; + +template +struct is_nothrow_swappable + : std::integral_constant::value + && ((decltype(detail::swap_adl_tests::uses_std(0))::value + && detail::swap_adl_tests::is_std_swap_noexcept::value) + || (!decltype(detail::swap_adl_tests::uses_std(0))::value + && detail::swap_adl_tests::is_adl_swap_noexcept::value))> +{}; +#endif + +// The storage base manages the actual storage, and correctly propagates +// trivial destruction from T. This case is for when T is not trivially +// destructible. +template ::value> +struct optional_storage_base +{ + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional_storage_base() noexcept + : m_dummy() + , m_has_value(false) + {} + + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional_storage_base(in_place_t, U&&... u) + : m_value(std::forward(u)...) + , m_has_value(true) + {} + + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE ~optional_storage_base() + { + if (m_has_value) + { + m_value.~T(); + m_has_value = false; + } + } + + struct dummy + {}; + union + { + dummy m_dummy; + T m_value; + }; + + bool m_has_value; +}; + +// This case is for when T is trivially destructible. +template +struct optional_storage_base +{ + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional_storage_base() noexcept + : m_dummy() + , m_has_value(false) + {} + + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional_storage_base(in_place_t, U&&... u) + : m_value(std::forward(u)...) + , m_has_value(true) + {} + + // No destructor, so this class is trivially destructible + + struct dummy + {}; + union + { + dummy m_dummy; + T m_value; + }; + + bool m_has_value = false; +}; + +// This base class provides some handy member functions which can be used in +// further derived classes +template +struct optional_operations_base : optional_storage_base +{ + using optional_storage_base::optional_storage_base; + + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE void hard_reset() noexcept + { + get().~T(); + this->m_has_value = false; + } + + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE void construct(Args&&... args) noexcept + { + new (thrust::addressof(this->m_value)) T(std::forward(args)...); + this->m_has_value = true; + } + + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE void assign(Opt&& rhs) + { + if (this->has_value()) + { + if (rhs.has_value()) + { + this->m_value = std::forward(rhs).get(); + } + else + { + this->m_value.~T(); + this->m_has_value = false; + } + } + + if (rhs.has_value()) + { + construct(std::forward(rhs).get()); + } + } + + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE bool has_value() const + { + return this->m_has_value; + } + + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR T& get() & + { + return this->m_value; + } + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR const T& get() const& + { + return this->m_value; + } + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR T&& get() && + { + return std::move(this->m_value); + } +#ifndef THRUST_OPTIONAL_NO_CONSTRR + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr const T&& get() const&& + { + return std::move(this->m_value); + } +#endif +}; + +// This class manages conditionally having a trivial copy constructor +// This specialization is for when T is trivially copy constructible +template ::value> +struct optional_copy_base : optional_operations_base +{ + using optional_operations_base::optional_operations_base; +}; + +// This specialization is for when T is not trivially copy constructible +template +struct optional_copy_base : optional_operations_base +{ + using optional_operations_base::optional_operations_base; + + _CCCL_EXEC_CHECK_DISABLE + optional_copy_base() = default; + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional_copy_base(const optional_copy_base& rhs) + { + if (rhs.has_value()) + { + this->construct(rhs.get()); + } + else + { + this->m_has_value = false; + } + } + + _CCCL_EXEC_CHECK_DISABLE + optional_copy_base(optional_copy_base&& rhs) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_copy_base& operator=(const optional_copy_base& rhs) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_copy_base& operator=(optional_copy_base&& rhs) = default; +}; + +template ::value> +struct optional_move_base : optional_copy_base +{ + using optional_copy_base::optional_copy_base; +}; +template +struct optional_move_base : optional_copy_base +{ + using optional_copy_base::optional_copy_base; + + _CCCL_EXEC_CHECK_DISABLE + optional_move_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_move_base(const optional_move_base& rhs) = default; + + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional_move_base(optional_move_base&& rhs) noexcept(std::is_nothrow_move_constructible::value) + { + if (rhs.has_value()) + { + this->construct(std::move(rhs.get())); + } + else + { + this->m_has_value = false; + } + } + _CCCL_EXEC_CHECK_DISABLE + optional_move_base& operator=(const optional_move_base& rhs) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_move_base& operator=(optional_move_base&& rhs) = default; +}; + +// This class manages conditionally having a trivial copy assignment operator +template ::value + && ::cuda::std::is_trivially_copy_constructible::value + && ::cuda::std::is_trivially_destructible::value> +struct optional_copy_assign_base : optional_move_base +{ + using optional_move_base::optional_move_base; +}; + +template +struct optional_copy_assign_base : optional_move_base +{ + using optional_move_base::optional_move_base; + + _CCCL_EXEC_CHECK_DISABLE + optional_copy_assign_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_copy_assign_base(const optional_copy_assign_base& rhs) = default; + + _CCCL_EXEC_CHECK_DISABLE + optional_copy_assign_base(optional_copy_assign_base&& rhs) = default; + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional_copy_assign_base& operator=(const optional_copy_assign_base& rhs) + { + this->assign(rhs); + return *this; + } + _CCCL_EXEC_CHECK_DISABLE + optional_copy_assign_base& operator=(optional_copy_assign_base&& rhs) = default; +}; + +template ::value + && ::cuda::std::is_trivially_move_constructible::value + && ::cuda::std::is_trivially_move_assignable::value> +struct optional_move_assign_base : optional_copy_assign_base +{ + using optional_copy_assign_base::optional_copy_assign_base; +}; + +template +struct optional_move_assign_base : optional_copy_assign_base +{ + using optional_copy_assign_base::optional_copy_assign_base; + + _CCCL_EXEC_CHECK_DISABLE + optional_move_assign_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_move_assign_base(const optional_move_assign_base& rhs) = default; + + _CCCL_EXEC_CHECK_DISABLE + optional_move_assign_base(optional_move_assign_base&& rhs) = default; + + _CCCL_EXEC_CHECK_DISABLE + optional_move_assign_base& operator=(const optional_move_assign_base& rhs) = default; + + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional_move_assign_base& operator=(optional_move_assign_base&& rhs) noexcept( + std::is_nothrow_move_constructible::value && std::is_nothrow_move_assignable::value) + { + this->assign(std::move(rhs)); + return *this; + } +}; + +// optional_delete_ctor_base will conditionally delete copy and move +// constructors depending on whether T is copy/move constructible +template ::value, + bool EnableMove = std::is_move_constructible::value> +struct optional_delete_ctor_base +{ + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base(const optional_delete_ctor_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base(optional_delete_ctor_base&&) noexcept = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base& operator=(const optional_delete_ctor_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base& operator=(optional_delete_ctor_base&&) noexcept = default; +}; + +template +struct optional_delete_ctor_base +{ + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base(const optional_delete_ctor_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base(optional_delete_ctor_base&&) noexcept = delete; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base& operator=(const optional_delete_ctor_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base& operator=(optional_delete_ctor_base&&) noexcept = default; +}; + +template +struct optional_delete_ctor_base +{ + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base(const optional_delete_ctor_base&) = delete; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base(optional_delete_ctor_base&&) noexcept = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base& operator=(const optional_delete_ctor_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base& operator=(optional_delete_ctor_base&&) noexcept = default; +}; + +template +struct optional_delete_ctor_base +{ + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base(const optional_delete_ctor_base&) = delete; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base(optional_delete_ctor_base&&) noexcept = delete; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base& operator=(const optional_delete_ctor_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_ctor_base& operator=(optional_delete_ctor_base&&) noexcept = default; +}; + +// optional_delete_assign_base will conditionally delete copy and move +// constructors depending on whether T is copy/move constructible + assignable +template ::value && std::is_copy_assignable::value), + bool EnableMove = (std::is_move_constructible::value && std::is_move_assignable::value)> +struct optional_delete_assign_base +{ + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base(const optional_delete_assign_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base(optional_delete_assign_base&&) noexcept = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base& operator=(const optional_delete_assign_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base& operator=(optional_delete_assign_base&&) noexcept = default; +}; + +template +struct optional_delete_assign_base +{ + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base(const optional_delete_assign_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base(optional_delete_assign_base&&) noexcept = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base& operator=(const optional_delete_assign_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base& operator=(optional_delete_assign_base&&) noexcept = delete; +}; + +template +struct optional_delete_assign_base +{ + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base(const optional_delete_assign_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base(optional_delete_assign_base&&) noexcept = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base& operator=(const optional_delete_assign_base&) = delete; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base& operator=(optional_delete_assign_base&&) noexcept = default; +}; + +template +struct optional_delete_assign_base +{ + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base() = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base(const optional_delete_assign_base&) = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base(optional_delete_assign_base&&) noexcept = default; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base& operator=(const optional_delete_assign_base&) = delete; + _CCCL_EXEC_CHECK_DISABLE + optional_delete_assign_base& operator=(optional_delete_assign_base&&) noexcept = delete; +}; + +} // namespace detail + +/// \brief A tag type to represent an empty optional +struct CCCL_DEPRECATED nullopt_t +{ + struct do_not_use + {}; + _CCCL_HOST_DEVICE constexpr explicit nullopt_t(do_not_use, do_not_use) noexcept {} +}; +/// \brief Represents an empty optional +/// \synopsis static constexpr nullopt_t nullopt; +/// +/// *Examples*: +/// ``` +/// thrust::optional a = thrust::nullopt; +/// void foo (thrust::optional); +/// foo(thrust::nullopt); //pass an empty optional +/// ``` +#ifdef __CUDA_ARCH__ +__device__ static _CCCL_CONSTEXPR_GLOBAL +#else +static constexpr +#endif // __CUDA_ARCH__ + nullopt_t nullopt{nullopt_t::do_not_use{}, nullopt_t::do_not_use{}}; + +class CCCL_DEPRECATED bad_optional_access : public std::exception +{ +public: + bad_optional_access() = default; + _CCCL_HOST const char* what() const noexcept + { + return "Optional has no value"; + } +}; + +/// An optional object is an object that contains the storage for another +/// object and manages the lifetime of this contained object, if any. The +/// contained object may be initialized after the optional object has been +/// initialized, and may be destroyed before the optional object has been +/// destroyed. The initialization state of the contained object is tracked by +/// the optional object. +template +class optional + : private detail::optional_move_assign_base + , private detail::optional_delete_ctor_base + , private detail::optional_delete_assign_base +{ + using base = detail::optional_move_assign_base; + + static_assert(!std::is_same::value, "instantiation of optional with in_place_t is ill-formed"); + static_assert(!std::is_same, nullopt_t>::value, + "instantiation of optional with nullopt_t is ill-formed"); + +public: +// The different versions for C++14 and 11 are needed because deduced return +// types are not SFINAE-safe. This provides better support for things like +// generic lambdas. C.f. +// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0826r0 +#if defined(THRUST_OPTIONAL_CPP14) && !defined(THRUST_OPTIONAL_GCC49) && !defined(THRUST_OPTIONAL_GCC54) \ + && !defined(THRUST_OPTIONAL_GCC55) + /// \group and_then + /// Carries out some operation which returns an optional on the stored + /// object if there is one. \requires `std::invoke(std::forward(f), + /// value())` returns a `std::optional` for some `U`. \return Let `U` be + /// the result of `std::invoke(std::forward(f), value())`. Returns a + /// `std::optional`. The return value is empty if `*this` is empty, + /// otherwise the return value of `std::invoke(std::forward(f), value())` + /// is returned. + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR auto and_then(F&& f) & + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR auto and_then(F&& f) && + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : result(nullopt); + } + + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) const &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr auto and_then(F&& f) const& + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + +# ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) const &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr auto and_then(F&& f) const&& + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : result(nullopt); + } +# endif +#else + /// \group and_then + /// Carries out some operation which returns an optional on the stored + /// object if there is one. \requires `std::invoke(std::forward(f), + /// value())` returns a `std::optional` for some `U`. + /// \return Let `U` be the result of `std::invoke(std::forward(f), + /// value())`. Returns a `std::optional`. The return value is empty if + /// `*this` is empty, otherwise the return value of + /// `std::invoke(std::forward(f), value())` is returned. + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR detail::invoke_result_t and_then(F&& f) & + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR detail::invoke_result_t and_then(F&& f) && + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : result(nullopt); + } + + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) const &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr detail::invoke_result_t and_then(F&& f) const& + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + +# ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) const &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr detail::invoke_result_t and_then(F&& f) const&& + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : result(nullopt); + } +# endif +#endif + +#if defined(THRUST_OPTIONAL_CPP14) && !defined(THRUST_OPTIONAL_GCC49) && !defined(THRUST_OPTIONAL_GCC54) \ + && !defined(THRUST_OPTIONAL_GCC55) + /// \brief Carries out some operation on the stored object if there is one. + /// \return Let `U` be the result of `std::invoke(std::forward(f), + /// value())`. Returns a `std::optional`. The return value is empty if + /// `*this` is empty, otherwise an `optional` is constructed from the + /// return value of `std::invoke(std::forward(f), value())` and is + /// returned. + /// + /// \group map + /// \synopsis template constexpr auto map(F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR auto map(F&& f) & + { + return optional_map_impl(*this, std::forward(f)); + } + + /// \group map + /// \synopsis template constexpr auto map(F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR auto map(F&& f) && + { + return optional_map_impl(std::move(*this), std::forward(f)); + } + + /// \group map + /// \synopsis template constexpr auto map(F &&f) const&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr auto map(F&& f) const& + { + return optional_map_impl(*this, std::forward(f)); + } + + /// \group map + /// \synopsis template constexpr auto map(F &&f) const&&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr auto map(F&& f) const&& + { + return optional_map_impl(std::move(*this), std::forward(f)); + } +#else + /// \brief Carries out some operation on the stored object if there is one. + /// \return Let `U` be the result of `std::invoke(std::forward(f), + /// value())`. Returns a `std::optional`. The return value is empty if + /// `*this` is empty, otherwise an `optional` is constructed from the + /// return value of `std::invoke(std::forward(f), value())` and is + /// returned. + /// + /// \group map + /// \synopsis template auto map(F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE + THRUST_OPTIONAL_CPP11_CONSTEXPR decltype(optional_map_impl(std::declval(), std::declval())) + map(F&& f) & + { + return optional_map_impl(*this, std::forward(f)); + } + + /// \group map + /// \synopsis template auto map(F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE + THRUST_OPTIONAL_CPP11_CONSTEXPR decltype(optional_map_impl(std::declval(), std::declval())) + map(F&& f) && + { + return optional_map_impl(std::move(*this), std::forward(f)); + } + + /// \group map + /// \synopsis template auto map(F &&f) const&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr decltype(optional_map_impl(std::declval(), std::declval())) + map(F&& f) const& + { + return optional_map_impl(*this, std::forward(f)); + } + +# ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group map + /// \synopsis template auto map(F &&f) const&&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr decltype(optional_map_impl(std::declval(), std::declval())) + map(F&& f) const&& + { + return optional_map_impl(std::move(*this), std::forward(f)); + } +# endif +#endif + + /// \brief Calls `f` if the optional is empty + /// \requires `std::invoke_result_t` must be void or convertible to + /// `optional`. + /// \effects If `*this` has a value, returns `*this`. + /// Otherwise, if `f` returns `void`, calls `std::forward(f)` and returns + /// `std::nullopt`. Otherwise, returns `std::forward(f)()`. + /// + /// \group or_else + /// \synopsis template optional or_else (F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional THRUST_OPTIONAL_CPP11_CONSTEXPR or_else(F&& f) & + { + if (has_value()) + { + return *this; + } + + std::forward(f)(); + return nullopt; + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional THRUST_OPTIONAL_CPP11_CONSTEXPR or_else(F&& f) & + { + return has_value() ? *this : std::forward(f)(); + } + + /// \group or_else + /// \synopsis template optional or_else (F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional or_else(F&& f) && + { + if (has_value()) + { + return std::move(*this); + } + + std::forward(f)(); + return nullopt; + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional THRUST_OPTIONAL_CPP11_CONSTEXPR or_else(F&& f) && + { + return has_value() ? std::move(*this) : std::forward(f)(); + } + + /// \group or_else + /// \synopsis template optional or_else (F &&f) const &; + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional or_else(F&& f) const& + { + if (has_value()) + { + return *this; + } + + std::forward(f)(); + return nullopt; + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional THRUST_OPTIONAL_CPP11_CONSTEXPR or_else(F&& f) const& + { + return has_value() ? *this : std::forward(f)(); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional or_else(F&& f) const&& + { + if (has_value()) + { + return std::move(*this); + } + + std::forward(f)(); + return nullopt; + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional or_else(F&& f) const&& + { + return has_value() ? std::move(*this) : std::forward(f)(); + } +#endif + + /// \brief Maps the stored value with `f` if there is one, otherwise returns + /// `u`. + /// + /// \details If there is a value stored, then `f` is called with `**this` + /// and the value is returned. Otherwise `u` is returned. + /// + /// \group map_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE U map_or(F&& f, U&& u) & + { + return has_value() ? detail::invoke(std::forward(f), **this) : std::forward(u); + } + + /// \group map_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE U map_or(F&& f, U&& u) && + { + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : std::forward(u); + } + + /// \group map_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE U map_or(F&& f, U&& u) const& + { + return has_value() ? detail::invoke(std::forward(f), **this) : std::forward(u); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group map_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE U map_or(F&& f, U&& u) const&& + { + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : std::forward(u); + } +#endif + + /// \brief Maps the stored value with `f` if there is one, otherwise calls + /// `u` and returns the result. + /// + /// \details If there is a value stored, then `f` is + /// called with `**this` and the value is returned. Otherwise + /// `std::forward(u)()` is returned. + /// + /// \group map_or_else + /// \synopsis template \nauto map_or_else(F &&f, U &&u) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE detail::invoke_result_t map_or_else(F&& f, U&& u) & + { + return has_value() ? detail::invoke(std::forward(f), **this) : std::forward(u)(); + } + + /// \group map_or_else + /// \synopsis template \nauto map_or_else(F &&f, U &&u) + /// &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE detail::invoke_result_t map_or_else(F&& f, U&& u) && + { + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : std::forward(u)(); + } + + /// \group map_or_else + /// \synopsis template \nauto map_or_else(F &&f, U &&u) + /// const &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE detail::invoke_result_t map_or_else(F&& f, U&& u) const& + { + return has_value() ? detail::invoke(std::forward(f), **this) : std::forward(u)(); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group map_or_else + /// \synopsis template \nauto map_or_else(F &&f, U &&u) + /// const &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE detail::invoke_result_t map_or_else(F&& f, U&& u) const&& + { + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : std::forward(u)(); + } +#endif + + /// \return `u` if `*this` has a value, otherwise an empty optional. + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr optional::type> conjunction(U&& u) const + { + using result = optional>; + return has_value() ? result{u} : result{nullopt}; + } + + /// \return `rhs` if `*this` is empty, otherwise the current value. + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional disjunction(const optional& rhs) & + { + return has_value() ? *this : rhs; + } + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional disjunction(const optional& rhs) const& + { + return has_value() ? *this : rhs; + } + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional disjunction(const optional& rhs) && + { + return has_value() ? std::move(*this) : rhs; + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional disjunction(const optional& rhs) const&& + { + return has_value() ? std::move(*this) : rhs; + } +#endif + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional disjunction(optional&& rhs) & + { + return has_value() ? *this : std::move(rhs); + } + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional disjunction(optional&& rhs) const& + { + return has_value() ? *this : std::move(rhs); + } + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional disjunction(optional&& rhs) && + { + return has_value() ? std::move(*this) : std::move(rhs); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional disjunction(optional&& rhs) const&& + { + return has_value() ? std::move(*this) : std::move(rhs); + } +#endif + + /// Takes the value out of the optional, leaving it empty + /// \group take + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional take() & + { + optional ret = *this; + reset(); + return ret; + } + + /// \group take + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional take() const& + { + optional ret = *this; + reset(); + return ret; + } + + /// \group take + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional take() && + { + optional ret = std::move(*this); + reset(); + return ret; + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group take + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional take() const&& + { + optional ret = std::move(*this); + reset(); + return ret; + } +#endif + + using value_type = T; + + /// Constructs an optional that does not contain a value. + /// \group ctor_empty + _CCCL_EXEC_CHECK_DISABLE + constexpr optional() noexcept = default; + + /// \group ctor_empty + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional(nullopt_t) noexcept {} + + /// Copy constructor + /// + /// If `rhs` contains a value, the stored value is direct-initialized with + /// it. Otherwise, the constructed optional is empty. + _CCCL_EXEC_CHECK_DISABLE + THRUST_OPTIONAL_CPP11_CONSTEXPR optional(const optional& rhs) = default; + + /// Move constructor + /// + /// If `rhs` contains a value, the stored value is direct-initialized with + /// it. Otherwise, the constructed optional is empty. + _CCCL_EXEC_CHECK_DISABLE + THRUST_OPTIONAL_CPP11_CONSTEXPR optional(optional&& rhs) = default; + + /// Constructs the stored value in-place using the given arguments. + /// \group in_place + /// \synopsis template constexpr explicit optional(in_place_t, Args&&... args); + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr explicit optional( + detail::enable_if_t::value, in_place_t>, Args&&... args) + : base(in_place, std::forward(args)...) + {} + + /// \group in_place + /// \synopsis template \nconstexpr explicit optional(in_place_t, std::initializer_list&, + /// Args&&... args); + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR explicit optional( + detail::enable_if_t&, Args&&...>::value, in_place_t>, + std::initializer_list il, + Args&&... args) + { + this->construct(il, std::forward(args)...); + } + + /// Constructs the stored value with `u`. + /// \synopsis template constexpr optional(U &&u); + _CCCL_EXEC_CHECK_DISABLE + template ::value>* = nullptr, + detail::enable_forward_value* = nullptr> + _CCCL_HOST_DEVICE constexpr optional(U&& u) + : base(in_place, std::forward(u)) + {} + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template ::value>* = nullptr, + detail::enable_forward_value* = nullptr> + _CCCL_HOST_DEVICE constexpr explicit optional(U&& u) + : base(in_place, std::forward(u)) + {} + + /// Converting copy constructor. + /// \synopsis template optional(const optional &rhs); + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr, + detail::enable_if_t::value>* = nullptr> + _CCCL_HOST_DEVICE optional(const optional& rhs) + { + this->construct(*rhs); + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr, + detail::enable_if_t::value>* = nullptr> + _CCCL_HOST_DEVICE explicit optional(const optional& rhs) + { + this->construct(*rhs); + } + + /// Converting move constructor. + /// \synopsis template optional(optional &&rhs); + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr, + detail::enable_if_t::value>* = nullptr> + _CCCL_HOST_DEVICE optional(optional&& rhs) + { + this->construct(std::move(*rhs)); + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr, + detail::enable_if_t::value>* = nullptr> + _CCCL_HOST_DEVICE explicit optional(optional&& rhs) + { + this->construct(std::move(*rhs)); + } + + /// Destroys the stored value if there is one. + _CCCL_EXEC_CHECK_DISABLE + ~optional() = default; + + /// Assignment to empty. + /// + /// Destroys the current value if there is one. + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional& operator=(nullopt_t) noexcept + { + if (has_value()) + { + this->m_value.~T(); + this->m_has_value = false; + } + + return *this; + } + + /// Copy assignment. + /// + /// Copies the value from `rhs` if there is one. Otherwise resets the stored + /// value in `*this`. + _CCCL_EXEC_CHECK_DISABLE + optional& operator=(const optional& rhs) = default; + + /// Move assignment. + /// + /// Moves the value from `rhs` if there is one. Otherwise resets the stored + /// value in `*this`. + _CCCL_EXEC_CHECK_DISABLE + optional& operator=(optional&& rhs) = default; + + /// Assigns the stored value from `u`, destroying the old value if there was + /// one. + /// \synopsis optional &operator=(U &&u); + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional& operator=(U&& u) + { + if (has_value()) + { + this->m_value = std::forward(u); + } + else + { + this->construct(std::forward(u)); + } + + return *this; + } + + /// Converting copy assignment operator. + /// + /// Copies the value from `rhs` if there is one. Otherwise resets the stored + /// value in `*this`. + /// \synopsis optional &operator=(const optional & rhs); + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional& operator=(const optional& rhs) + { + if (has_value()) + { + if (rhs.has_value()) + { + this->m_value = *rhs; + } + else + { + this->hard_reset(); + } + } + + if (rhs.has_value()) + { + this->construct(*rhs); + } + + return *this; + } + + // TODO check exception guarantee + /// Converting move assignment operator. + /// + /// Moves the value from `rhs` if there is one. Otherwise resets the stored + /// value in `*this`. + /// \synopsis optional &operator=(optional && rhs); + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional& operator=(optional&& rhs) + { + if (has_value()) + { + if (rhs.has_value()) + { + this->m_value = std::move(*rhs); + } + else + { + this->hard_reset(); + } + } + + if (rhs.has_value()) + { + this->construct(std::move(*rhs)); + } + + return *this; + } + + /// Constructs the value in-place, destroying the current one if there is + /// one. + /// \group emplace + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE T& emplace(Args&&... args) + { + static_assert(std::is_constructible::value, "T must be constructible with Args"); + + *this = nullopt; + this->construct(std::forward(args)...); + return this->m_value; + } + + /// \group emplace + /// \synopsis template \nT& emplace(std::initializer_list il, Args &&... args); + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE detail::enable_if_t&, Args&&...>::value, T&> + emplace(std::initializer_list il, Args&&... args) + { + *this = nullopt; + this->construct(il, std::forward(args)...); + return this->m_value; + } + + /// Swaps this optional with the other. + /// + /// If neither optionals have a value, nothing happens. + /// If both have a value, the values are swapped. + /// If one has a value, it is moved to the other and the movee is left + /// valueless. + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE void + swap(optional& rhs) noexcept(std::is_nothrow_move_constructible::value && detail::is_nothrow_swappable::value) + { + if (has_value()) + { + if (rhs.has_value()) + { + using ::cuda::std::swap; + swap(**this, *rhs); + } + else + { + new (thrust::addressof(rhs.m_value)) T(std::move(this->m_value)); + this->m_value.T::~T(); + } + } + else if (rhs.has_value()) + { + new (thrust::addressof(this->m_value)) T(std::move(rhs.m_value)); + rhs.m_value.T::~T(); + } + } + + /// \return a pointer to the stored value + /// \requires a value is stored + /// \group pointer + /// \synopsis constexpr const T *operator->() const; + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr const T* operator->() const + { + return thrust::addressof(this->m_value); + } + + /// \group pointer + /// \synopsis constexpr T *operator->(); + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR T* operator->() + { + return thrust::addressof(this->m_value); + } + + /// \return the stored value + /// \requires a value is stored + /// \group deref + /// \synopsis constexpr T &operator*(); + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR T& operator*() & + { + return this->m_value; + } + + /// \group deref + /// \synopsis constexpr const T &operator*() const; + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr const T& operator*() const& + { + return this->m_value; + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR T&& operator*() && + { + return std::move(this->m_value); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr const T&& operator*() const&& + { + return std::move(this->m_value); + } +#endif + + /// \return whether or not the optional has a value + /// \group has_value + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr bool has_value() const noexcept + { + return this->m_has_value; + } + + /// \group has_value + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr explicit operator bool() const noexcept + { + return this->m_has_value; + } + + /// \return the contained value if there is one, otherwise throws + /// [bad_optional_access] + /// \group value + /// \synopsis constexpr T &value(); + _CCCL_HOST THRUST_OPTIONAL_CPP11_CONSTEXPR T& value() & + { + if (has_value()) + { + return this->m_value; + } + throw bad_optional_access(); + } + /// \group value + /// \synopsis constexpr const T &value() const; + _CCCL_HOST THRUST_OPTIONAL_CPP11_CONSTEXPR const T& value() const& + { + if (has_value()) + { + return this->m_value; + } + throw bad_optional_access(); + } + /// \exclude + _CCCL_HOST THRUST_OPTIONAL_CPP11_CONSTEXPR T&& value() && + { + if (has_value()) + { + return std::move(this->m_value); + } + throw bad_optional_access(); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \exclude + _CCCL_HOST THRUST_OPTIONAL_CPP11_CONSTEXPR const T&& value() const&& + { + if (has_value()) + { + return std::move(this->m_value); + } + throw bad_optional_access(); + } +#endif + + /// \return the stored value if there is one, otherwise returns `u` + /// \group value_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr T value_or(U&& u) const& + { + static_assert(std::is_copy_constructible::value && std::is_convertible::value, + "T must be copy constructible and convertible from U"); + return has_value() ? **this : static_cast(std::forward(u)); + } + + /// \group value_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR T value_or(U&& u) && + { + static_assert(std::is_move_constructible::value && std::is_convertible::value, + "T must be move constructible and convertible from U"); + return has_value() ? **this : static_cast(std::forward(u)); + } + + /// Destroys the stored value if one exists, making the optional empty + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE void reset() noexcept + { + if (has_value()) + { + this->m_value.~T(); + this->m_has_value = false; + } + } +}; + +/// \group relop +/// \brief Compares two optional objects +/// \details If both optionals contain a value, they are compared with `T`s +/// relational operators. Otherwise `lhs` and `rhs` are equal only if they are +/// both empty, and `lhs` is less than `rhs` only if `rhs` is empty and `lhs` +/// is not. +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator==(const optional& lhs, const optional& rhs) +{ + return lhs.has_value() == rhs.has_value() && (!lhs.has_value() || *lhs == *rhs); +} +/// \group relop +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator!=(const optional& lhs, const optional& rhs) +{ + return lhs.has_value() != rhs.has_value() || (lhs.has_value() && *lhs != *rhs); +} +/// \group relop +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<(const optional& lhs, const optional& rhs) +{ + return rhs.has_value() && (!lhs.has_value() || *lhs < *rhs); +} +/// \group relop +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>(const optional& lhs, const optional& rhs) +{ + return lhs.has_value() && (!rhs.has_value() || *lhs > *rhs); +} +/// \group relop +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<=(const optional& lhs, const optional& rhs) +{ + return !lhs.has_value() || (rhs.has_value() && *lhs <= *rhs); +} +/// \group relop +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>=(const optional& lhs, const optional& rhs) +{ + return !rhs.has_value() || (lhs.has_value() && *lhs >= *rhs); +} + +/// \group relop_nullopt +/// \brief Compares an optional to a `nullopt` +/// \details Equivalent to comparing the optional to an empty optional +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator==(const optional& lhs, nullopt_t) noexcept +{ + return !lhs.has_value(); +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator==(nullopt_t, const optional& rhs) noexcept +{ + return !rhs.has_value(); +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator!=(const optional& lhs, nullopt_t) noexcept +{ + return lhs.has_value(); +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator!=(nullopt_t, const optional& rhs) noexcept +{ + return rhs.has_value(); +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<(const optional&, nullopt_t) noexcept +{ + return false; +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<(nullopt_t, const optional& rhs) noexcept +{ + return rhs.has_value(); +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<=(const optional& lhs, nullopt_t) noexcept +{ + return !lhs.has_value(); +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<=(nullopt_t, const optional&) noexcept +{ + return true; +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>(const optional& lhs, nullopt_t) noexcept +{ + return lhs.has_value(); +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>(nullopt_t, const optional&) noexcept +{ + return false; +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>=(const optional&, nullopt_t) noexcept +{ + return true; +} +/// \group relop_nullopt +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>=(nullopt_t, const optional& rhs) noexcept +{ + return !rhs.has_value(); +} + +/// \group relop_t +/// \brief Compares the optional with a value. +/// \details If the optional has a value, it is compared with the other value +/// using `T`s relational operators. Otherwise, the optional is considered +/// less than the value. +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator==(const optional& lhs, const U& rhs) +{ + return lhs.has_value() ? *lhs == rhs : false; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator==(const U& lhs, const optional& rhs) +{ + return rhs.has_value() ? lhs == *rhs : false; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator!=(const optional& lhs, const U& rhs) +{ + return lhs.has_value() ? *lhs != rhs : true; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator!=(const U& lhs, const optional& rhs) +{ + return rhs.has_value() ? lhs != *rhs : true; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<(const optional& lhs, const U& rhs) +{ + return lhs.has_value() ? *lhs < rhs : true; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<(const U& lhs, const optional& rhs) +{ + return rhs.has_value() ? lhs < *rhs : false; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<=(const optional& lhs, const U& rhs) +{ + return lhs.has_value() ? *lhs <= rhs : true; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator<=(const U& lhs, const optional& rhs) +{ + return rhs.has_value() ? lhs <= *rhs : false; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>(const optional& lhs, const U& rhs) +{ + return lhs.has_value() ? *lhs > rhs : false; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>(const U& lhs, const optional& rhs) +{ + return rhs.has_value() ? lhs > *rhs : true; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>=(const optional& lhs, const U& rhs) +{ + return lhs.has_value() ? *lhs >= rhs : false; +} +/// \group relop_t +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE inline constexpr bool operator>=(const U& lhs, const optional& rhs) +{ + return rhs.has_value() ? lhs >= *rhs : true; +} + +/// \synopsis template \nvoid swap(optional &lhs, optional &rhs); +_CCCL_EXEC_CHECK_DISABLE +template ::value>* = nullptr, + detail::enable_if_t::value>* = nullptr> +_CCCL_HOST_DEVICE void swap(optional& lhs, optional& rhs) noexcept(noexcept(lhs.swap(rhs))) +{ + return lhs.swap(rhs); +} + +namespace detail +{ +struct i_am_secret +{}; +} // namespace detail + +_CCCL_EXEC_CHECK_DISABLE +template ::value, detail::decay_t, T>> +CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional") +_CCCL_HOST_DEVICE inline constexpr optional make_optional(U&& v) +{ + return optional(std::forward(v)); +} + +_CCCL_EXEC_CHECK_DISABLE +template +CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional") +_CCCL_HOST_DEVICE inline constexpr optional make_optional(Args&&... args) +{ + return optional(in_place, std::forward(args)...); +} +_CCCL_EXEC_CHECK_DISABLE +template +CCCL_DEPRECATED_BECAUSE("Use cuda::std::make_optional") +_CCCL_HOST_DEVICE inline constexpr optional make_optional(std::initializer_list il, Args&&... args) +{ + return optional(in_place, il, std::forward(args)...); +} + +#if _CCCL_STD_VER >= 2017 +template +optional(T) -> optional; +#endif + +// Doxygen chokes on the trailing return types used below. +#if !defined(_CCCL_DOXYGEN_INVOKED) +/// \exclude +namespace detail +{ +# ifdef THRUST_OPTIONAL_CPP14 +_CCCL_EXEC_CHECK_DISABLE +template (), *std::declval())), + detail::enable_if_t::value>* = nullptr> +_CCCL_HOST_DEVICE constexpr auto optional_map_impl(Opt&& opt, F&& f) +{ + return opt.has_value() ? detail::invoke(std::forward(f), *std::forward(opt)) : optional(nullopt); +} + +_CCCL_EXEC_CHECK_DISABLE +template (), *std::declval())), + detail::enable_if_t::value>* = nullptr> +_CCCL_HOST_DEVICE auto optional_map_impl(Opt&& opt, F&& f) +{ + if (opt.has_value()) + { + detail::invoke(std::forward(f), *std::forward(opt)); +# if _CCCL_COMPILER(MSVC) + // MSVC fails to suppress the warning on make_optional + _CCCL_SUPPRESS_DEPRECATED_PUSH + return optional(monostate{}); + _CCCL_SUPPRESS_DEPRECATED_POP +# elif _CCCL_COMPILER(NVHPC) + // NVHPC cannot have a diagnostic pop after a return statement + _CCCL_SUPPRESS_DEPRECATED_PUSH + auto o = optional(monostate{}); + _CCCL_SUPPRESS_DEPRECATED_POP + return ::cuda::std::move(o); +# else + _CCCL_SUPPRESS_DEPRECATED_PUSH + return make_optional(monostate{}); + _CCCL_SUPPRESS_DEPRECATED_POP +# endif + } + + return optional(nullopt); +} +# else +_CCCL_EXEC_CHECK_DISABLE +template (), *std::declval())), + detail::enable_if_t::value>* = nullptr> +_CCCL_HOST_DEVICE constexpr optional optional_map_impl(Opt&& opt, F&& f) +{ + return opt.has_value() ? detail::invoke(std::forward(f), *std::forward(opt)) : optional(nullopt); +} + +_CCCL_EXEC_CHECK_DISABLE +template (), *std::declval())), + detail::enable_if_t::value>* = nullptr> +_CCCL_HOST_DEVICE auto optional_map_impl(Opt&& opt, F&& f) -> optional +{ + if (opt.has_value()) + { + detail::invoke(std::forward(f), *std::forward(opt)); + return monostate{}; + } + + return nullopt; +} +# endif +} // namespace detail +#endif // !defined(_CCCL_DOXYGEN_INVOKED) + +/// Specialization for when `T` is a reference. `optional` acts similarly +/// to a `T*`, but provides more operations and shows intent more clearly. +/// +/// *Examples*: +/// +/// ``` +/// int i = 42; +/// thrust::optional o = i; +/// *o == 42; //true +/// i = 12; +/// *o = 12; //true +/// &*o == &i; //true +/// ``` +/// +/// Assignment has rebind semantics rather than assign-through semantics: +/// +/// ``` +/// int j = 8; +/// o = j; +/// +/// &*o == &j; //true +/// ``` +template +class optional +{ +public: +// The different versions for C++14 and 11 are needed because deduced return +// types are not SFINAE-safe. This provides better support for things like +// generic lambdas. C.f. +// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0826r0 +#if defined(THRUST_OPTIONAL_CPP14) && !defined(THRUST_OPTIONAL_GCC49) && !defined(THRUST_OPTIONAL_GCC54) \ + && !defined(THRUST_OPTIONAL_GCC55) + /// \group and_then + /// Carries out some operation which returns an optional on the stored + /// object if there is one. \requires `std::invoke(std::forward(f), + /// value())` returns a `std::optional` for some `U`. \return Let `U` be + /// the result of `std::invoke(std::forward(f), value())`. Returns a + /// `std::optional`. The return value is empty if `*this` is empty, + /// otherwise the return value of `std::invoke(std::forward(f), value())` + /// is returned. + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR auto and_then(F&& f) & + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR auto and_then(F&& f) && + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) const &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr auto and_then(F&& f) const& + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + +# ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) const &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr auto and_then(F&& f) const&& + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } +# endif +#else + /// \group and_then + /// Carries out some operation which returns an optional on the stored + /// object if there is one. \requires `std::invoke(std::forward(f), + /// value())` returns a `std::optional` for some `U`. \return Let `U` be + /// the result of `std::invoke(std::forward(f), value())`. Returns a + /// `std::optional`. The return value is empty if `*this` is empty, + /// otherwise the return value of `std::invoke(std::forward(f), value())` + /// is returned. + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR detail::invoke_result_t and_then(F&& f) & + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR detail::invoke_result_t and_then(F&& f) && + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) const &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr detail::invoke_result_t and_then(F&& f) const& + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } + +# ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group and_then + /// \synopsis template \nconstexpr auto and_then(F &&f) const &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr detail::invoke_result_t and_then(F&& f) const&& + { + using result = detail::invoke_result_t; + static_assert(detail::is_optional::value, "F must return an optional"); + + return has_value() ? detail::invoke(std::forward(f), **this) : result(nullopt); + } +# endif +#endif + +#if defined(THRUST_OPTIONAL_CPP14) && !defined(THRUST_OPTIONAL_GCC49) && !defined(THRUST_OPTIONAL_GCC54) \ + && !defined(THRUST_OPTIONAL_GCC55) + /// \brief Carries out some operation on the stored object if there is one. + /// \return Let `U` be the result of `std::invoke(std::forward(f), + /// value())`. Returns a `std::optional`. The return value is empty if + /// `*this` is empty, otherwise an `optional` is constructed from the + /// return value of `std::invoke(std::forward(f), value())` and is + /// returned. + /// + /// \group map + /// \synopsis template constexpr auto map(F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR auto map(F&& f) & + { + return detail::optional_map_impl(*this, std::forward(f)); + } + + /// \group map + /// \synopsis template constexpr auto map(F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR auto map(F&& f) && + { + return detail::optional_map_impl(std::move(*this), std::forward(f)); + } + + /// \group map + /// \synopsis template constexpr auto map(F &&f) const&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr auto map(F&& f) const& + { + return detail::optional_map_impl(*this, std::forward(f)); + } + + /// \group map + /// \synopsis template constexpr auto map(F &&f) const&&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr auto map(F&& f) const&& + { + return detail::optional_map_impl(std::move(*this), std::forward(f)); + } +#else + /// \brief Carries out some operation on the stored object if there is one. + /// \return Let `U` be the result of `std::invoke(std::forward(f), + /// value())`. Returns a `std::optional`. The return value is empty if + /// `*this` is empty, otherwise an `optional` is constructed from the + /// return value of `std::invoke(std::forward(f), value())` and is + /// returned. + /// + /// \group map + /// \synopsis template auto map(F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE + THRUST_OPTIONAL_CPP11_CONSTEXPR decltype(detail::optional_map_impl(std::declval(), std::declval())) + map(F&& f) & + { + return detail::optional_map_impl(*this, std::forward(f)); + } + + /// \group map + /// \synopsis template auto map(F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE + THRUST_OPTIONAL_CPP11_CONSTEXPR decltype(detail::optional_map_impl(std::declval(), std::declval())) + map(F&& f) && + { + return detail::optional_map_impl(std::move(*this), std::forward(f)); + } + + /// \group map + /// \synopsis template auto map(F &&f) const&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr decltype(detail::optional_map_impl(std::declval(), std::declval())) + map(F&& f) const& + { + return detail::optional_map_impl(*this, std::forward(f)); + } + +# ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group map + /// \synopsis template auto map(F &&f) const&&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr decltype(detail::optional_map_impl(std::declval(), std::declval())) + map(F&& f) const&& + { + return detail::optional_map_impl(std::move(*this), std::forward(f)); + } +# endif +#endif + + /// \brief Calls `f` if the optional is empty + /// \requires `std::invoke_result_t` must be void or convertible to + /// `optional`. \effects If `*this` has a value, returns `*this`. + /// Otherwise, if `f` returns `void`, calls `std::forward(f)` and returns + /// `std::nullopt`. Otherwise, returns `std::forward(f)()`. + /// + /// \group or_else + /// \synopsis template optional or_else (F &&f) &; + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional THRUST_OPTIONAL_CPP11_CONSTEXPR or_else(F&& f) & + { + if (has_value()) + { + return *this; + } + + std::forward(f)(); + return nullopt; + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional THRUST_OPTIONAL_CPP11_CONSTEXPR or_else(F&& f) & + { + return has_value() ? *this : std::forward(f)(); + } + + /// \group or_else + /// \synopsis template optional or_else (F &&f) &&; + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional or_else(F&& f) && + { + if (has_value()) + { + return std::move(*this); + } + + std::forward(f)(); + return nullopt; + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional THRUST_OPTIONAL_CPP11_CONSTEXPR or_else(F&& f) && + { + return has_value() ? std::move(*this) : std::forward(f)(); + } + + /// \group or_else + /// \synopsis template optional or_else (F &&f) const &; + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional or_else(F&& f) const& + { + if (has_value()) + { + return *this; + } + + std::forward(f)(); + return nullopt; + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional THRUST_OPTIONAL_CPP11_CONSTEXPR or_else(F&& f) const& + { + return has_value() ? *this : std::forward(f)(); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional or_else(F&& f) const&& + { + if (has_value()) + { + return std::move(*this); + } + + std::forward(f)(); + return nullopt; + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template * = nullptr> + _CCCL_HOST_DEVICE optional or_else(F&& f) const&& + { + return has_value() ? std::move(*this) : std::forward(f)(); + } +#endif + + /// \brief Maps the stored value with `f` if there is one, otherwise returns + /// `u`. + /// + /// \details If there is a value stored, then `f` is called with `**this` + /// and the value is returned. Otherwise `u` is returned. + /// + /// \group map_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE U map_or(F&& f, U&& u) & + { + return has_value() ? detail::invoke(std::forward(f), **this) : std::forward(u); + } + + /// \group map_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE U map_or(F&& f, U&& u) && + { + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : std::forward(u); + } + + /// \group map_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE U map_or(F&& f, U&& u) const& + { + return has_value() ? detail::invoke(std::forward(f), **this) : std::forward(u); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group map_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE U map_or(F&& f, U&& u) const&& + { + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : std::forward(u); + } +#endif + + /// \brief Maps the stored value with `f` if there is one, otherwise calls + /// `u` and returns the result. + /// + /// \details If there is a value stored, then `f` is + /// called with `**this` and the value is returned. Otherwise + /// `std::forward(u)()` is returned. + /// + /// \group map_or_else + /// \synopsis template \nauto map_or_else(F &&f, U &&u) &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE detail::invoke_result_t map_or_else(F&& f, U&& u) & + { + return has_value() ? detail::invoke(std::forward(f), **this) : std::forward(u)(); + } + + /// \group map_or_else + /// \synopsis template \nauto map_or_else(F &&f, U &&u) + /// &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE detail::invoke_result_t map_or_else(F&& f, U&& u) && + { + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : std::forward(u)(); + } + + /// \group map_or_else + /// \synopsis template \nauto map_or_else(F &&f, U &&u) + /// const &; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE detail::invoke_result_t map_or_else(F&& f, U&& u) const& + { + return has_value() ? detail::invoke(std::forward(f), **this) : std::forward(u)(); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group map_or_else + /// \synopsis template \nauto map_or_else(F &&f, U &&u) + /// const &&; + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE detail::invoke_result_t map_or_else(F&& f, U&& u) const&& + { + return has_value() ? detail::invoke(std::forward(f), std::move(**this)) : std::forward(u)(); + } +#endif + + /// \return `u` if `*this` has a value, otherwise an empty optional. + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr optional::type> conjunction(U&& u) const + { + using result = optional>; + return has_value() ? result{u} : result{nullopt}; + } + + /// \return `rhs` if `*this` is empty, otherwise the current value. + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional disjunction(const optional& rhs) & + { + return has_value() ? *this : rhs; + } + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional disjunction(const optional& rhs) const& + { + return has_value() ? *this : rhs; + } + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional disjunction(const optional& rhs) && + { + return has_value() ? std::move(*this) : rhs; + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional disjunction(const optional& rhs) const&& + { + return has_value() ? std::move(*this) : rhs; + } +#endif + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional disjunction(optional&& rhs) & + { + return has_value() ? *this : std::move(rhs); + } + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional disjunction(optional&& rhs) const& + { + return has_value() ? *this : std::move(rhs); + } + + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR optional disjunction(optional&& rhs) && + { + return has_value() ? std::move(*this) : std::move(rhs); + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group disjunction + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional disjunction(optional&& rhs) const&& + { + return has_value() ? std::move(*this) : std::move(rhs); + } +#endif + + /// Takes the value out of the optional, leaving it empty + /// \group take + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional take() & + { + optional ret = *this; + reset(); + return ret; + } + + /// \group take + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional take() const& + { + optional ret = *this; + reset(); + return ret; + } + + /// \group take + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional take() && + { + optional ret = std::move(*this); + reset(); + return ret; + } + +#ifndef THRUST_OPTIONAL_NO_CONSTRR + /// \group take + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional take() const&& + { + optional ret = std::move(*this); + reset(); + return ret; + } +#endif + + using value_type = T&; + + /// Constructs an optional that does not contain a value. + /// \group ctor_empty + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional() noexcept + : m_value(nullptr) + {} + + /// \group ctor_empty + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr optional(nullopt_t) noexcept + : m_value(nullptr) + {} + + /// Copy constructor + /// + /// If `rhs` contains a value, the stored value is direct-initialized with + /// it. Otherwise, the constructed optional is empty. + _CCCL_EXEC_CHECK_DISABLE + THRUST_OPTIONAL_CPP11_CONSTEXPR optional(const optional& rhs) noexcept = default; + + /// Move constructor + /// + /// If `rhs` contains a value, the stored value is direct-initialized with + /// it. Otherwise, the constructed optional is empty. + _CCCL_EXEC_CHECK_DISABLE + THRUST_OPTIONAL_CPP11_CONSTEXPR optional(optional&& rhs) = default; + + /// Constructs the stored value with `u`. + /// \synopsis template constexpr optional(U &&u); + _CCCL_EXEC_CHECK_DISABLE + template >::value>* = nullptr> + _CCCL_HOST_DEVICE constexpr optional(U&& u) + : m_value(thrust::addressof(u)) + { + static_assert(std::is_lvalue_reference::value, "U must be an lvalue"); + } + + /// \exclude + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr explicit optional(const optional& rhs) + : optional(*rhs) + {} + + /// No-op + _CCCL_EXEC_CHECK_DISABLE + ~optional() = default; + + /// Assignment to empty. + /// + /// Destroys the current value if there is one. + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE optional& operator=(nullopt_t) noexcept + { + m_value = nullptr; + return *this; + } + + /// Copy assignment. + /// + /// Rebinds this optional to the referee of `rhs` if there is one. Otherwise + /// resets the stored value in `*this`. + _CCCL_EXEC_CHECK_DISABLE + optional& operator=(const optional& rhs) = default; + + /// Rebinds this optional to `u`. + /// + /// \requires `U` must be an lvalue reference. + /// \synopsis optional &operator=(U &&u); + _CCCL_EXEC_CHECK_DISABLE + template >::value>* = nullptr> + _CCCL_HOST_DEVICE optional& operator=(U&& u) + { + static_assert(std::is_lvalue_reference::value, "U must be an lvalue"); + m_value = thrust::addressof(u); + return *this; + } + + /// Converting copy assignment operator. + /// + /// Rebinds this optional to the referee of `rhs` if there is one. Otherwise + /// resets the stored value in `*this`. + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE optional& operator=(const optional& rhs) + { + m_value = thrust::addressof(rhs.value()); + return *this; + } + + /// Constructs the value in-place, destroying the current one if there is + /// one. + /// + /// \group emplace + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE T& emplace(U& u) noexcept + { + m_value = thrust::addressof(u); + return *m_value; + } + + /// Swaps this optional with the other. + /// + /// If neither optionals have a value, nothing happens. + /// If both have a value, the values are swapped. + /// If one has a value, it is moved to the other and the movee is left + /// valueless. + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE void swap(optional& rhs) noexcept + { + std::swap(m_value, rhs.m_value); + } + + /// \return a pointer to the stored value + /// \requires a value is stored + /// \group pointer + /// \synopsis constexpr const T *operator->() const; + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr const T* operator->() const + { + return m_value; + } + + /// \group pointer + /// \synopsis constexpr T *operator->(); + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR T* operator->() + { + return m_value; + } + + /// \return the stored value + /// \requires a value is stored + /// \group deref + /// \synopsis constexpr T &operator*(); + _CCCL_EXEC_CHECK_DISABLE + THRUST_OPTIONAL_CPP11_CONSTEXPR T& operator*() + { + return *m_value; + } + + /// \group deref + /// \synopsis constexpr const T &operator*() const; + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr const T& operator*() const + { + return *m_value; + } + + /// \return whether or not the optional has a value + /// \group has_value + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr bool has_value() const noexcept + { + return m_value != nullptr; + } + + /// \group has_value + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE constexpr explicit operator bool() const noexcept + { + return m_value != nullptr; + } + + /// \return the contained value if there is one, otherwise throws + /// [bad_optional_access] + /// \group value + /// synopsis constexpr T &value(); + _CCCL_HOST THRUST_OPTIONAL_CPP11_CONSTEXPR T& value() + { + if (has_value()) + { + return *m_value; + } + throw bad_optional_access(); + } + /// \group value + /// \synopsis constexpr const T &value() const; + _CCCL_HOST THRUST_OPTIONAL_CPP11_CONSTEXPR const T& value() const + { + if (has_value()) + { + return *m_value; + } + throw bad_optional_access(); + } + + /// \return the stored value if there is one, otherwise returns `u` + /// \group value_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE constexpr T value_or(U&& u) const& + { + static_assert(std::is_copy_constructible::value && std::is_convertible::value, + "T must be copy constructible and convertible from U"); + return has_value() ? **this : static_cast(std::forward(u)); + } + + /// \group value_or + _CCCL_EXEC_CHECK_DISABLE + template + _CCCL_HOST_DEVICE THRUST_OPTIONAL_CPP11_CONSTEXPR T value_or(U&& u) && + { + static_assert(std::is_move_constructible::value && std::is_convertible::value, + "T must be move constructible and convertible from U"); + return has_value() ? **this : static_cast(std::forward(u)); + } + + /// Destroys the stored value if one exists, making the optional empty + _CCCL_EXEC_CHECK_DISABLE + void reset() noexcept + { + m_value = nullptr; + } + +private: + T* m_value; +}; + +THRUST_NAMESPACE_END + +namespace std +{ +// TODO SFINAE +template +struct hash> +{ + _CCCL_EXEC_CHECK_DISABLE + _CCCL_HOST_DEVICE ::std::size_t operator()(const THRUST_NS_QUALIFIER::optional& o) const + { + if (!o.has_value()) + { + return 0; + } + + return std::hash<::cuda::std::remove_const_t>()(*o); + } +}; +} // namespace std + +_CCCL_SUPPRESS_DEPRECATED_POP diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/pair.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/pair.h new file mode 100644 index 0000000000000000000000000000000000000000..9f35a388bc72d3caf85f9d52b80045a70aa66623 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/pair.h @@ -0,0 +1,102 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file pair.h + * \brief A type encapsulating a heterogeneous pair of elements + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup utility + * \{ + */ + +/*! \addtogroup pair + * \{ + */ + +/*! This convenience metafunction is included for compatibility with + * \p tuple. It returns either the type of a \p pair's + * \c first_type or \c second_type in its nested type, \c type. + * + * \tparam N This parameter selects the member of interest. + * \tparam T A \c pair type of interest. + */ +#ifdef _CCCL_DOXYGEN_INVOKED // Provide a fake alias for doxygen +template +using tuple_element = _CUDA_VSTD::tuple_element; +#else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv +using _CUDA_VSTD::tuple_element; +#endif // _CCCL_DOXYGEN_INVOKED + +/*! This convenience metafunction is included for compatibility with + * \p tuple. It returns \c 2, the number of elements of a \p pair, + * in its nested data member, \c value. + * + * \tparam Pair A \c pair type of interest. + */ +#ifdef _CCCL_DOXYGEN_INVOKED // Provide a fake alias for doxygen +template +using tuple_size = _CUDA_VSTD::tuple_size; +#else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv +using _CUDA_VSTD::tuple_size; +#endif // _CCCL_DOXYGEN_INVOKED + +/*! \p pair is a generic data structure encapsulating a heterogeneous + * pair of values. + * + * \tparam T1 The type of \p pair's first object type. There are no + * requirements on the type of \p T1. T1's type is + * provided by pair::first_type. + * + * \tparam T2 The type of \p pair's second object type. There are no + * requirements on the type of \p T2. T2's type is + * provided by pair::second_type. + */ +#ifdef _CCCL_DOXYGEN_INVOKED // Provide a fake alias for doxygen +template +using pair = _CUDA_VSTD::pair; +#else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv +using _CUDA_VSTD::pair; +#endif // _CCCL_DOXYGEN_INVOKED + +using _CUDA_VSTD::get; +using _CUDA_VSTD::make_pair; + +/*! \endcond + */ + +/*! \} // pair + */ + +/*! \} // utility + */ + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/partition.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/partition.h new file mode 100644 index 0000000000000000000000000000000000000000..a9b3a4d19898bae1619f2ce896468f2acec9a419 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/partition.h @@ -0,0 +1,1383 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file partition.h + * \brief Reorganizes a range based on a predicate + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup reordering + * \ingroup algorithms + * + * \addtogroup partitioning + * \ingroup reordering + * \{ + */ + +/*! \p partition reorders the elements [first, last) based on the function + * object \p pred, such that all of the elements that satisfy \p pred precede the + * elements that fail to satisfy it. The postcondition is that, for some iterator + * \c middle in the range [first, last), pred(*i) is \c true for every + * iterator \c i in the range [first,middle) and \c false for every iterator + * \c i in the range [middle, last). The return value of \p partition is + * \c middle. + * + * Note that the relative order of elements in the two reordered sequences is not + * necessarily the same as it was in the original sequence. A different algorithm, + * \p stable_partition, does guarantee to preserve the relative order. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence to reorder. + * \param last The end of the sequence to reorder. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return An iterator referring to the first element of the second partition, that is, + * the sequence of the elements which do not satisfy \p pred. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type, and \p + * ForwardIterator is mutable. \tparam Predicate is a model of Predicate. + * + * The following code snippet demonstrates how to use \p partition to reorder a + * sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::partition(thrust::host, + * A, A + N, + * is_even()); + * // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partition + * \see \p stable_partition + * \see \p partition_copy + */ +template +_CCCL_HOST_DEVICE ForwardIterator partition( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + Predicate pred); + +/*! \p partition reorders the elements [first, last) based on the function + * object \p pred, such that all of the elements that satisfy \p pred precede the + * elements that fail to satisfy it. The postcondition is that, for some iterator + * \c middle in the range [first, last), pred(*i) is \c true for every + * iterator \c i in the range [first,middle) and \c false for every iterator + * \c i in the range [middle, last). The return value of \p partition is + * \c middle. + * + * Note that the relative order of elements in the two reordered sequences is not + * necessarily the same as it was in the original sequence. A different algorithm, + * \p stable_partition, does guarantee to preserve the relative order. + * + * \param first The beginning of the sequence to reorder. + * \param last The end of the sequence to reorder. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return An iterator referring to the first element of the second partition, that is, + * the sequence of the elements which do not satisfy \p pred. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type, and \p + * ForwardIterator is mutable. \tparam Predicate is a model of Predicate. + * + * The following code snippet demonstrates how to use \p partition to reorder a + * sequence so that even numbers precede odd numbers. + * + * \code + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::partition(A, A + N, + * is_even()); + * // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partition + * \see \p stable_partition + * \see \p partition_copy + */ +template +ForwardIterator partition(ForwardIterator first, ForwardIterator last, Predicate pred); + +/*! \p partition reorders the elements [first, last) based on the function + * object \p pred applied to a stencil range [stencil, stencil + (last - first)), + * such that all of the elements whose corresponding stencil element satisfies \p pred precede all of the elements + * whose corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator \c middle in + * the range [first, last), pred(*stencil_i) is \c true for every iterator \c stencil_i in the range + * [stencil,stencil + (middle - first)) and \c false for every iterator \c stencil_i in the range + * [stencil + (middle - first), stencil + (last - first)). + * The return value of \p stable_partition is \c middle. + * + * Note that the relative order of elements in the two reordered sequences is not + * necessarily the same as it was in the original sequence. A different algorithm, + * \p stable_partition, does guarantee to preserve the relative order. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence to reorder. + * \param last The end of the sequence to reorder. + * \param stencil The beginning of the stencil sequence. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return An iterator referring to the first element of the second partition, that is, + * the sequence of the elements whose stencil elements do not satisfy \p pred. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam InputIterator is a model of Input Iterator, and \p InputIterator's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam Predicate is a model of Predicate. + * + * \pre The ranges [first,last) and [stencil, stencil + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p partition to reorder a + * sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; + * int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::partition(thrust::host, A, A + N, S, is_even()); + * // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} + * // S is unmodified + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partition + * \see \p stable_partition + * \see \p partition_copy + */ +template +_CCCL_HOST_DEVICE ForwardIterator partition( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator stencil, + Predicate pred); + +/*! \p partition reorders the elements [first, last) based on the function + * object \p pred applied to a stencil range [stencil, stencil + (last - first)), + * such that all of the elements whose corresponding stencil element satisfies \p pred precede all of the elements + * whose corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator \c middle in + * the range [first, last), pred(*stencil_i) is \c true for every iterator \c stencil_i in the range + * [stencil,stencil + (middle - first)) and \c false for every iterator \c stencil_i in the range + * [stencil + (middle - first), stencil + (last - first)). + * The return value of \p stable_partition is \c middle. + * + * Note that the relative order of elements in the two reordered sequences is not + * necessarily the same as it was in the original sequence. A different algorithm, + * \p stable_partition, does guarantee to preserve the relative order. + * + * \param first The beginning of the sequence to reorder. + * \param last The end of the sequence to reorder. + * \param stencil The beginning of the stencil sequence. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return An iterator referring to the first element of the second partition, that is, + * the sequence of the elements whose stencil elements do not satisfy \p pred. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam InputIterator is a model of Input Iterator, and \p InputIterator's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam Predicate is a model of Predicate. + * + * \pre The ranges [first,last) and [stencil, stencil + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p partition to reorder a + * sequence so that even numbers precede odd numbers. + * + * \code + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; + * int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::partition(A, A + N, S, is_even()); + * // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} + * // S is unmodified + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partition + * \see \p stable_partition + * \see \p partition_copy + */ +template +ForwardIterator partition(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred); + +/*! \p partition_copy differs from \p partition only in that the reordered + * sequence is written to different output sequences, rather than in place. + * + * \p partition_copy copies the elements [first, last) based on the + * function object \p pred. All of the elements that satisfy \p pred are copied + * to the range beginning at \p out_true and all the elements that fail to satisfy it + * are copied to the range beginning at \p out_false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence to reorder. + * \param last The end of the sequence to reorder. + * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. + * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return A \p pair p such that p.first is the end of the output range beginning + * at \p out_true and p.second is the end of the output range beginning at + * \p out_false. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type and \p + * InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. \tparam + * OutputIterator1 is a model of Output + * Iterator. \tparam OutputIterator2 is a model of Output Iterator. \tparam Predicate is a model + * of Predicate. + * + * \pre The input range shall not overlap with either output range. + * + * The following code snippet demonstrates how to use \p partition_copy to separate a + * sequence into two output sequences of even and odd numbers using the \p thrust::host execution policy for + * parallelization: + * + * \code + * #include + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * int *evens = result; + * int *odds = result + 5; + * thrust::partition_copy(thrust::host, A, A + N, evens, odds, is_even()); + * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * // evens points to {2, 4, 6, 8, 10} + * // odds points to {1, 3, 5, 7, 9} + * \endcode + * + * \note The relative order of elements in the two reordered sequences is not + * necessarily the same as it was in the original sequence. A different algorithm, + * \p stable_partition_copy, does guarantee to preserve the relative order. + * + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf + * \see \p stable_partition_copy + * \see \p partition + */ +template +_CCCL_HOST_DEVICE thrust::pair partition_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator1 out_true, + OutputIterator2 out_false, + Predicate pred); + +/*! \p partition_copy differs from \p partition only in that the reordered + * sequence is written to different output sequences, rather than in place. + * + * \p partition_copy copies the elements [first, last) based on the + * function object \p pred. All of the elements that satisfy \p pred are copied + * to the range beginning at \p out_true and all the elements that fail to satisfy it + * are copied to the range beginning at \p out_false. + * + * \param first The beginning of the sequence to reorder. + * \param last The end of the sequence to reorder. + * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. + * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return A \p pair p such that p.first is the end of the output range beginning + * at \p out_true and p.second is the end of the output range beginning at + * \p out_false. + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type and \p + * InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. \tparam + * OutputIterator1 is a model of Output + * Iterator. \tparam OutputIterator2 is a model of Output Iterator. \tparam Predicate is a model + * of Predicate. + * + * \pre The input range shall not overlap with either output range. + * + * The following code snippet demonstrates how to use \p partition_copy to separate a + * sequence into two output sequences of even and odd numbers. + * + * \code + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * int *evens = result; + * int *odds = result + 5; + * thrust::partition_copy(A, A + N, evens, odds, is_even()); + * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * // evens points to {2, 4, 6, 8, 10} + * // odds points to {1, 3, 5, 7, 9} + * \endcode + * + * \note The relative order of elements in the two reordered sequences is not + * necessarily the same as it was in the original sequence. A different algorithm, + * \p stable_partition_copy, does guarantee to preserve the relative order. + * + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf + * \see \p stable_partition_copy + * \see \p partition + */ +template +thrust::pair partition_copy( + InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred); + +/*! \p partition_copy differs from \p partition only in that the reordered + * sequence is written to different output sequences, rather than in place. + * + * \p partition_copy copies the elements [first, last) based on the + * function object \p pred which is applied to a range of stencil elements. All of the elements + * whose corresponding stencil element satisfies \p pred are copied to the range beginning at \p out_true + * and all the elements whose stencil element fails to satisfy it are copied to the range beginning + * at \p out_false. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence to reorder. + * \param last The end of the sequence to reorder. + * \param stencil The beginning of the stencil sequence. + * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. + * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return A \p pair p such that p.first is the end of the output range beginning + * at \p out_true and p.second is the end of the output range beginning at + * \p out_false. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c + * value_types. \tparam InputIterator2 is a model of Input Iterator, and \p InputIterator2's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam OutputIterator1 is a model of Output Iterator. \tparam OutputIterator2 is a + * model of Output Iterator. \tparam Predicate + * is a model of Predicate. + * + * \pre The input ranges shall not overlap with either output range. + * + * The following code snippet demonstrates how to use \p partition_copy to separate a + * sequence into two output sequences of even and odd numbers using the \p thrust::host execution + * policy for parallelization. + * + * \code + * #include + * #include + * #include + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * int *evens = result; + * int *odds = result + 5; + * thrust::stable_partition_copy(thrust::host, A, A + N, S, evens, odds, thrust::identity()); + * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * // S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1} + * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * // evens points to {2, 4, 6, 8, 10} + * // odds points to {1, 3, 5, 7, 9} + * \endcode + * + * \note The relative order of elements in the two reordered sequences is not + * necessarily the same as it was in the original sequence. A different algorithm, + * \p stable_partition_copy, does guarantee to preserve the relative order. + * + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf + * \see \p stable_partition_copy + * \see \p partition + */ +template +_CCCL_HOST_DEVICE thrust::pair partition_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator1 out_true, + OutputIterator2 out_false, + Predicate pred); + +/*! \p partition_copy differs from \p partition only in that the reordered + * sequence is written to different output sequences, rather than in place. + * + * \p partition_copy copies the elements [first, last) based on the + * function object \p pred which is applied to a range of stencil elements. All of the elements + * whose corresponding stencil element satisfies \p pred are copied to the range beginning at \p out_true + * and all the elements whose stencil element fails to satisfy it are copied to the range beginning + * at \p out_false. + * + * \param first The beginning of the sequence to reorder. + * \param last The end of the sequence to reorder. + * \param stencil The beginning of the stencil sequence. + * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. + * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return A \p pair p such that p.first is the end of the output range beginning + * at \p out_true and p.second is the end of the output range beginning at + * \p out_false. + * + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c + * value_types. \tparam InputIterator2 is a model of Input Iterator, and \p InputIterator2's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam OutputIterator1 is a model of Output Iterator. \tparam OutputIterator2 is a + * model of Output Iterator. \tparam Predicate + * is a model of Predicate. + * + * \pre The input ranges shall not overlap with either output range. + * + * The following code snippet demonstrates how to use \p partition_copy to separate a + * sequence into two output sequences of even and odd numbers. + * + * \code + * #include + * #include + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * int *evens = result; + * int *odds = result + 5; + * thrust::stable_partition_copy(A, A + N, S, evens, odds, thrust::identity()); + * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * // S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1} + * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * // evens points to {2, 4, 6, 8, 10} + * // odds points to {1, 3, 5, 7, 9} + * \endcode + * + * \note The relative order of elements in the two reordered sequences is not + * necessarily the same as it was in the original sequence. A different algorithm, + * \p stable_partition_copy, does guarantee to preserve the relative order. + * + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf + * \see \p stable_partition_copy + * \see \p partition + */ +template +thrust::pair partition_copy( + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator1 out_true, + OutputIterator2 out_false, + Predicate pred); + +/*! \p stable_partition is much like \p partition : it reorders the elements in the + * range [first, last) based on the function object \p pred, such that all of + * the elements that satisfy \p pred precede all of the elements that fail to satisfy + * it. The postcondition is that, for some iterator \p middle in the range + * [first, last), pred(*i) is \c true for every iterator \c i in the + * range [first,middle) and \c false for every iterator \c i in the range + * [middle, last). The return value of \p stable_partition is \c middle. + * + * \p stable_partition differs from \p partition in that \p stable_partition is + * guaranteed to preserve relative order. That is, if \c x and \c y are elements in + * [first, last), and \c stencil_x and \c stencil_y are the stencil elements + * in corresponding positions within [stencil, stencil + (last - first)), + * and pred(stencil_x) == pred(stencil_y), and if \c x precedes + * \c y, then it will still be true after \p stable_partition that \c x precedes \c y. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element of the sequence to reorder. + * \param last One position past the last element of the sequence to reorder. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return An iterator referring to the first element of the second partition, that is, + * the sequence of the elements which do not satisfy pred. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type, and \p + * ForwardIterator is mutable. \tparam Predicate is a model of Predicate. + * + * The following code snippet demonstrates how to use \p stable_partition to reorder a + * sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::stable_partition(thrust::host, + * A, A + N, + * is_even()); + * // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/stable_partition + * \see \p partition + * \see \p stable_partition_copy + */ +template +_CCCL_HOST_DEVICE ForwardIterator stable_partition( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + Predicate pred); + +/*! \p stable_partition is much like \p partition : it reorders the elements in the + * range [first, last) based on the function object \p pred, such that all of + * the elements that satisfy \p pred precede all of the elements that fail to satisfy + * it. The postcondition is that, for some iterator \p middle in the range + * [first, last), pred(*i) is \c true for every iterator \c i in the + * range [first,middle) and \c false for every iterator \c i in the range + * [middle, last). The return value of \p stable_partition is \c middle. + * + * \p stable_partition differs from \p partition in that \p stable_partition is + * guaranteed to preserve relative order. That is, if \c x and \c y are elements in + * [first, last), and \c stencil_x and \c stencil_y are the stencil elements + * in corresponding positions within [stencil, stencil + (last - first)), + * and pred(stencil_x) == pred(stencil_y), and if \c x precedes + * \c y, then it will still be true after \p stable_partition that \c x precedes \c y. + * + * \param first The first element of the sequence to reorder. + * \param last One position past the last element of the sequence to reorder. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return An iterator referring to the first element of the second partition, that is, + * the sequence of the elements which do not satisfy pred. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type, and \p + * ForwardIterator is mutable. \tparam Predicate is a model of Predicate. + * + * The following code snippet demonstrates how to use \p stable_partition to reorder a + * sequence so that even numbers precede odd numbers. + * + * \code + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::stable_partition(A, A + N, + * is_even()); + * // A is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/stable_partition + * \see \p partition + * \see \p stable_partition_copy + */ +template +ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred); + +/*! \p stable_partition is much like \p partition: it reorders the elements in the + * range [first, last) based on the function object \p pred applied to a stencil + * range [stencil, stencil + (last - first)), such that all of + * the elements whose corresponding stencil element satisfies \p pred precede all of the elements whose + * corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator + * \c middle in the range [first, last), pred(*stencil_i) is \c true for every iterator + * \c stencil_i in the range [stencil,stencil + (middle - first)) and \c false for every iterator \c stencil_i + * in the range [stencil + (middle - first), stencil + (last - first)). + * The return value of \p stable_partition is \c middle. + * + * \p stable_partition differs from \p partition in that \p stable_partition is + * guaranteed to preserve relative order. That is, if \c x and \c y are elements in + * [first, last), such that pred(x) == pred(y), and if \c x precedes + * \c y, then it will still be true after \p stable_partition that \c x precedes \c y. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element of the sequence to reorder. + * \param last One position past the last element of the sequence to reorder. + * \param stencil The beginning of the stencil sequence. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return An iterator referring to the first element of the second partition, that is, + * the sequence of the elements whose stencil elements do not satisfy \p pred. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam InputIterator is a model of Input Iterator, and \p InputIterator's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam Predicate is a model of Predicate. + * + * \pre The range [first, last) shall not overlap with the range [stencil, stencil + (last - first)). + * + * The following code snippet demonstrates how to use \p stable_partition to reorder a + * sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; + * int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::stable_partition(thrust::host, A, A + N, S, is_even()); + * // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} + * // S is unmodified + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/stable_partition + * \see \p partition + * \see \p stable_partition_copy + */ +template +_CCCL_HOST_DEVICE ForwardIterator stable_partition( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator stencil, + Predicate pred); + +/*! \p stable_partition is much like \p partition: it reorders the elements in the + * range [first, last) based on the function object \p pred applied to a stencil + * range [stencil, stencil + (last - first)), such that all of + * the elements whose corresponding stencil element satisfies \p pred precede all of the elements whose + * corresponding stencil element fails to satisfy it. The postcondition is that, for some iterator + * \c middle in the range [first, last), pred(*stencil_i) is \c true for every iterator + * \c stencil_i in the range [stencil,stencil + (middle - first)) and \c false for every iterator \c stencil_i + * in the range [stencil + (middle - first), stencil + (last - first)). + * The return value of \p stable_partition is \c middle. + * + * \p stable_partition differs from \p partition in that \p stable_partition is + * guaranteed to preserve relative order. That is, if \c x and \c y are elements in + * [first, last), such that pred(x) == pred(y), and if \c x precedes + * \c y, then it will still be true after \p stable_partition that \c x precedes \c y. + * + * \param first The first element of the sequence to reorder. + * \param last One position past the last element of the sequence to reorder. + * \param stencil The beginning of the stencil sequence. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return An iterator referring to the first element of the second partition, that is, + * the sequence of the elements whose stencil elements do not satisfy \p pred. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam InputIterator is a model of Input Iterator, and \p InputIterator's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam Predicate is a model of Predicate. + * + * \pre The range [first, last) shall not overlap with the range [stencil, stencil + (last - first)). + * + * The following code snippet demonstrates how to use \p stable_partition to reorder a + * sequence so that even numbers precede odd numbers. + * + * \code + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; + * int S[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::stable_partition(A, A + N, S, is_even()); + * // A is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} + * // S is unmodified + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/stable_partition + * \see \p partition + * \see \p stable_partition_copy + */ +template +ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred); + +/*! \p stable_partition_copy differs from \p stable_partition only in that the reordered + * sequence is written to different output sequences, rather than in place. + * + * \p stable_partition_copy copies the elements [first, last) based on the + * function object \p pred. All of the elements that satisfy \p pred are copied + * to the range beginning at \p out_true and all the elements that fail to satisfy it + * are copied to the range beginning at \p out_false. + * + * \p stable_partition_copy differs from \p partition_copy in that + * \p stable_partition_copy is guaranteed to preserve relative order. That is, if + * \c x and \c y are elements in [first, last), such that + * pred(x) == pred(y), and if \c x precedes \c y, then it will still be true + * after \p stable_partition_copy that \c x precedes \c y in the output. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element of the sequence to reorder. + * \param last One position past the last element of the sequence to reorder. + * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. + * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return A \p pair p such that p.first is the end of the output range beginning + * at \p out_true and p.second is the end of the output range beginning at + * \p out_false. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type and \p + * InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. \tparam + * OutputIterator1 is a model of Output + * Iterator. \tparam OutputIterator2 is a model of Output Iterator. \tparam Predicate is a model + * of Predicate. + * + * \pre The input ranges shall not overlap with either output range. + * + * The following code snippet demonstrates how to use \p stable_partition_copy to + * reorder a sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for + * parallelization: + * + * \code + * #include + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * int *evens = result; + * int *odds = result + 5; + * thrust::stable_partition_copy(thrust::host, A, A + N, evens, odds, is_even()); + * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * // evens points to {2, 4, 6, 8, 10} + * // odds points to {1, 3, 5, 7, 9} + * \endcode + * + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf + * \see \p partition_copy + * \see \p stable_partition + */ +template +_CCCL_HOST_DEVICE thrust::pair stable_partition_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator1 out_true, + OutputIterator2 out_false, + Predicate pred); + +/*! \p stable_partition_copy differs from \p stable_partition only in that the reordered + * sequence is written to different output sequences, rather than in place. + * + * \p stable_partition_copy copies the elements [first, last) based on the + * function object \p pred. All of the elements that satisfy \p pred are copied + * to the range beginning at \p out_true and all the elements that fail to satisfy it + * are copied to the range beginning at \p out_false. + * + * \p stable_partition_copy differs from \p partition_copy in that + * \p stable_partition_copy is guaranteed to preserve relative order. That is, if + * \c x and \c y are elements in [first, last), such that + * pred(x) == pred(y), and if \c x precedes \c y, then it will still be true + * after \p stable_partition_copy that \c x precedes \c y in the output. + * + * \param first The first element of the sequence to reorder. + * \param last One position past the last element of the sequence to reorder. + * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. + * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return A \p pair p such that p.first is the end of the output range beginning + * at \p out_true and p.second is the end of the output range beginning at + * \p out_false. + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type and \p + * InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c value_types. \tparam + * OutputIterator1 is a model of Output + * Iterator. \tparam OutputIterator2 is a model of Output Iterator. \tparam Predicate is a model + * of Predicate. + * + * \pre The input ranges shall not overlap with either output range. + * + * The following code snippet demonstrates how to use \p stable_partition_copy to + * reorder a sequence so that even numbers precede odd numbers. + * + * \code + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * int *evens = result; + * int *odds = result + 5; + * thrust::stable_partition_copy(A, A + N, evens, odds, is_even()); + * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * // evens points to {2, 4, 6, 8, 10} + * // odds points to {1, 3, 5, 7, 9} + * \endcode + * + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf + * \see \p partition_copy + * \see \p stable_partition + */ +template +thrust::pair stable_partition_copy( + InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred); + +/*! \p stable_partition_copy differs from \p stable_partition only in that the reordered + * sequence is written to different output sequences, rather than in place. + * + * \p stable_partition_copy copies the elements [first, last) based on the + * function object \p pred which is applied to a range of stencil elements. All of the elements + * whose corresponding stencil element satisfies \p pred are copied to the range beginning at \p out_true + * and all the elements whose stencil element fails to satisfy it are copied to the range beginning + * at \p out_false. + * + * \p stable_partition_copy differs from \p partition_copy in that + * \p stable_partition_copy is guaranteed to preserve relative order. That is, if + * \c x and \c y are elements in [first, last), such that + * pred(x) == pred(y), and if \c x precedes \c y, then it will still be true + * after \p stable_partition_copy that \c x precedes \c y in the output. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element of the sequence to reorder. + * \param last One position past the last element of the sequence to reorder. + * \param stencil The beginning of the stencil sequence. + * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. + * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return A \p pair p such that p.first is the end of the output range beginning + * at \p out_true and p.second is the end of the output range beginning at + * \p out_false. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c + * value_types. \tparam InputIterator2 is a model of Input Iterator, and \p InputIterator2's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam OutputIterator1 is a model of Output Iterator. \tparam OutputIterator2 is a + * model of Output Iterator. \tparam Predicate + * is a model of Predicate. + * + * \pre The input ranges shall not overlap with either output range. + * + * The following code snippet demonstrates how to use \p stable_partition_copy to + * reorder a sequence so that even numbers precede odd numbers using the \p thrust::host execution policy for + * parallelization: + * + * \code + * #include + * #include + * #include + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * int *evens = result; + * int *odds = result + 5; + * thrust::stable_partition_copy(thrust::host, A, A + N, S, evens, odds, thrust::identity()); + * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * // S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1} + * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * // evens points to {2, 4, 6, 8, 10} + * // odds points to {1, 3, 5, 7, 9} + * \endcode + * + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf + * \see \p partition_copy + * \see \p stable_partition + */ +template +_CCCL_HOST_DEVICE thrust::pair stable_partition_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator1 out_true, + OutputIterator2 out_false, + Predicate pred); + +/*! \p stable_partition_copy differs from \p stable_partition only in that the reordered + * sequence is written to different output sequences, rather than in place. + * + * \p stable_partition_copy copies the elements [first, last) based on the + * function object \p pred which is applied to a range of stencil elements. All of the elements + * whose corresponding stencil element satisfies \p pred are copied to the range beginning at \p out_true + * and all the elements whose stencil element fails to satisfy it are copied to the range beginning + * at \p out_false. + * + * \p stable_partition_copy differs from \p partition_copy in that + * \p stable_partition_copy is guaranteed to preserve relative order. That is, if + * \c x and \c y are elements in [first, last), such that + * pred(x) == pred(y), and if \c x precedes \c y, then it will still be true + * after \p stable_partition_copy that \c x precedes \c y in the output. + * + * \param first The first element of the sequence to reorder. + * \param last One position past the last element of the sequence to reorder. + * \param stencil The beginning of the stencil sequence. + * \param out_true The destination of the resulting sequence of elements which satisfy \p pred. + * \param out_false The destination of the resulting sequence of elements which fail to satisfy \p pred. + * \param pred A function object which decides to which partition each element of the + * sequence [first, last) belongs. + * \return A \p pair p such that p.first is the end of the output range beginning + * at \p out_true and p.second is the end of the output range beginning at + * \p out_false. + * + * \tparam InputIterator1 is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p OutputIterator1 and \p OutputIterator2's \c + * value_types. \tparam InputIterator2 is a model of Input Iterator, and \p InputIterator2's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam OutputIterator1 is a model of Output Iterator. \tparam OutputIterator2 is a + * model of Output Iterator. \tparam Predicate + * is a model of Predicate. + * + * \pre The input ranges shall not overlap with either output range. + * + * The following code snippet demonstrates how to use \p stable_partition_copy to + * reorder a sequence so that even numbers precede odd numbers. + * + * \code + * #include + * #include + * ... + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int S[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * int *evens = result; + * int *odds = result + 5; + * thrust::stable_partition_copy(A, A + N, S, evens, odds, thrust::identity()); + * // A remains {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * // S remains {0, 1, 0, 1, 0, 1, 0, 1, 0, 1} + * // result is now {2, 4, 6, 8, 10, 1, 3, 5, 7, 9} + * // evens points to {2, 4, 6, 8, 10} + * // odds points to {1, 3, 5, 7, 9} + * \endcode + * + * \see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2569.pdf + * \see \p partition_copy + * \see \p stable_partition + */ +template +thrust::pair stable_partition_copy( + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator1 out_true, + OutputIterator2 out_false, + Predicate pred); + +/*! \} // end stream_compaction + */ + +/*! \} // end reordering + */ + +/*! \addtogroup searching + * \{ + */ + +/*! \p partition_point returns an iterator pointing to the end of the true + * partition of a partitioned range. \p partition_point requires the input range + * [first,last) to be a partition; that is, all elements which satisfy + * pred shall appear before those that do not. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range to consider. + * \param last The end of the range to consider. + * \param pred A function object which decides to which partition each element of the + * range [first, last) belongs. + * \return An iterator \c mid such that all_of(first, mid, pred) + * and none_of(mid, last, pred) are both true. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type. \tparam + * Predicate is a model of Predicate. + * + * \pre The range [first, last) shall be partitioned by \p pred. + * + * \note Though similar, \p partition_point is not redundant with \p find_if_not. + * \p partition_point's precondition provides an opportunity for a + * faster implementation. + * + * \code + * #include + * #include + * + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * + * ... + * + * int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; + * int * B = thrust::partition_point(thrust::host, A, A + 10, is_even()); + * // B - A is 5 + * // [A, B) contains only even values + * \endcode + * + * \see \p partition + * \see \p find_if_not + */ +template +_CCCL_HOST_DEVICE ForwardIterator partition_point( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + Predicate pred); + +/*! \p partition_point returns an iterator pointing to the end of the true + * partition of a partitioned range. \p partition_point requires the input range + * [first,last) to be a partition; that is, all elements which satisfy + * pred shall appear before those that do not. + * \param first The beginning of the range to consider. + * \param last The end of the range to consider. + * \param pred A function object which decides to which partition each element of the + * range [first, last) belongs. + * \return An iterator \c mid such that all_of(first, mid, pred) + * and none_of(mid, last, pred) are both true. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p Predicate's \c argument_type. \tparam + * Predicate is a model of Predicate. + * + * \pre The range [first, last) shall be partitioned by \p pred. + * + * \note Though similar, \p partition_point is not redundant with \p find_if_not. + * \p partition_point's precondition provides an opportunity for a + * faster implementation. + * + * \code + * #include + * + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * + * ... + * + * int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; + * int * B = thrust::partition_point(A, A + 10, is_even()); + * // B - A is 5 + * // [A, B) contains only even values + * \endcode + * + * \see \p partition + * \see \p find_if_not + */ +template +ForwardIterator partition_point(ForwardIterator first, ForwardIterator last, Predicate pred); + +/*! \} // searching + */ + +/*! \addtogroup reductions + * \{ + * \addtogroup predicates + * \{ + */ + +/*! \p is_partitioned returns \c true if the given range + * is partitioned with respect to a predicate, and \c false otherwise. + * + * Specifically, \p is_partitioned returns \c true if [first, last) + * is empty of if [first, last) is partitioned by \p pred, i.e. if + * all elements that satisfy \p pred appear before those that do not. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range to consider. + * \param last The end of the range to consider. + * \param pred A function object which decides to which partition each element of the + * range [first, last) belongs. + * \return \c true if the range [first, last) is partitioned with respect + * to \p pred, or if [first, last) is empty. \c false, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. \tparam + * Predicate is a model of Predicate. + * + * \code + * #include + * #include + * + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * + * ... + * + * int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; + * int B[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * + * thrust::is_partitioned(thrust::host, A, A + 10, is_even()); // returns true + * thrust::is_partitioned(thrust::host, B, B + 10, is_even()); // returns false + * \endcode + * + * \see \p partition + */ +template +_CCCL_HOST_DEVICE bool is_partitioned( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + Predicate pred); + +/*! \p is_partitioned returns \c true if the given range + * is partitioned with respect to a predicate, and \c false otherwise. + * + * Specifically, \p is_partitioned returns \c true if [first, last) + * is empty of if [first, last) is partitioned by \p pred, i.e. if + * all elements that satisfy \p pred appear before those that do not. + * + * \param first The beginning of the range to consider. + * \param last The end of the range to consider. + * \param pred A function object which decides to which partition each element of the + * range [first, last) belongs. + * \return \c true if the range [first, last) is partitioned with respect + * to \p pred, or if [first, last) is empty. \c false, otherwise. + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. \tparam + * Predicate is a model of Predicate. + * + * \code + * #include + * + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int &x) + * { + * return (x % 2) == 0; + * } + * }; + * + * ... + * + * int A[] = {2, 4, 6, 8, 10, 1, 3, 5, 7, 9}; + * int B[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * + * thrust::is_partitioned(A, A + 10, is_even()); // returns true + * thrust::is_partitioned(B, B + 10, is_even()); // returns false + * \endcode + * + * \see \p partition + */ +template +bool is_partitioned(InputIterator first, InputIterator last, Predicate pred); + +/*! \} // end predicates + * \} // end reductions + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/per_device_resource.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/per_device_resource.h new file mode 100644 index 0000000000000000000000000000000000000000..57d420daeb5c41c7a365d22df5229413971d1b65 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/per_device_resource.h @@ -0,0 +1,98 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! Returns a global instance of \p MR for the current device of the provided system. + * + * \tparam MR type of a memory resource to get an instance from. Must be \p DefaultConstructible. + * \param system execution policy for which the resource is requested. + * \return a pointer to a global instance of \p MR for the current device. + */ +template +_CCCL_HOST MR* get_per_device_resource(const thrust::detail::execution_policy_base& system) +{ + using thrust::system::detail::generic::get_per_device_resource; + + return get_per_device_resource(thrust::detail::derived_cast(thrust::detail::strip_const(system))); +} + +/*! A helper allocator class that uses global per device instances of a given upstream memory resource. Requires the + * memory resource to be default constructible. + * + * \tparam T the type that will be allocated by this allocator. + * \tparam MR the upstream memory resource to use for memory allocation. Must derive from + * \p thrust::mr::memory_resource and must be \p final. + * \tparam ExecutionPolicy the execution policy of the system to be used to retrieve the resource for the current + * device. + */ +template +class per_device_allocator : public thrust::mr::allocator +{ + using base = thrust::mr::allocator; + +public: + /*! The \p rebind metafunction provides the type of an \p per_device_allocator instantiated with another type. + * + * \tparam U the other type to use for instantiation. + */ + template + struct rebind + { + /*! The alias \p other gives the type of the rebound \p per_device_allocator. + */ + using other = per_device_allocator; + }; + + /*! Default constructor. Uses \p get_global_resource to get the global instance of \p Upstream and initializes the + * \p allocator base subobject with that resource. + */ + _CCCL_HOST per_device_allocator() + : base(get_per_device_resource(ExecutionPolicy())) + {} + + /*! Copy constructor. Copies the memory resource pointer. */ + _CCCL_HOST_DEVICE per_device_allocator(const per_device_allocator& other) + : base(other) + {} + + /*! Conversion constructor from an allocator of a different type. Copies the memory resource pointer. */ + template + _CCCL_HOST_DEVICE per_device_allocator(const per_device_allocator& other) + : base(other) + {} + + /*! Destructor. */ + _CCCL_HOST_DEVICE ~per_device_allocator() {} +}; + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random.h new file mode 100644 index 0000000000000000000000000000000000000000..d6c4e3149851e755154b36e599dfc888ae54763d --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/random.h @@ -0,0 +1,120 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file random.h + * \brief Pseudo-random number generators. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +// RNGs +#include +#include +#include +#include +#include + +// distributions +#include +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup random Random Number Generation + * \{ + */ + +/*! \namespace thrust::random + * \brief \p thrust::random is the namespace which contains random number engine class templates, + * random number engine adaptor class templates, engines with predefined parameters, + * and random number distribution class templates. They are provided in a separate namespace + * for import convenience but are also aliased in the top-level \p thrust namespace for + * easy access. + */ +namespace random +{ + +/*! \addtogroup predefined_random Random Number Engines with Predefined Parameters + * \ingroup random + * \{ + */ + +/*! \typedef ranlux24 + * \brief A random number engine with predefined parameters which implements the + * RANLUX level-3 random number generation algorithm. + * \note The 10000th consecutive invocation of a default-constructed object of type \p ranlux24 + * shall produce the value \c 9901578 . + */ +using ranlux24 = discard_block_engine; + +/*! \typedef ranlux48 + * \brief A random number engine with predefined parameters which implements the + * RANLUX level-4 random number generation algorithm. + * \note The 10000th consecutive invocation of a default-constructed object of type \p ranlux48 + * shall produce the value \c 88229545517833 . + */ +using ranlux48 = discard_block_engine; + +/*! \typedef taus88 + * \brief A random number engine with predefined parameters which implements + * L'Ecuyer's 1996 three-component Tausworthe random number generator. + * + * \note The 10000th consecutive invocation of a default-constructed object of type \p taus88 + * shall produce the value \c 3535848941 . + */ +using taus88 = + xor_combine_engine, + 0, + xor_combine_engine, + 0, + linear_feedback_shift_engine, + 0>, + 0>; + +/*! \typedef default_random_engine + * \brief An implementation-defined "default" random number engine. + * \note \p default_random_engine is currently an alias for \p minstd_rand, and may change + * in a future version. + */ +using default_random_engine = minstd_rand; + +/*! \} // end predefined_random + */ + +} // namespace random + +/*! \} // end random + */ + +// import names into thrust:: +using random::default_random_engine; +using random::ranlux24; +using random::ranlux48; +using random::taus88; + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/remove.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/remove.h new file mode 100644 index 0000000000000000000000000000000000000000..80dfa786dcc8e8440214a15ca4c2f50d412023c0 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/remove.h @@ -0,0 +1,768 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file remove.h + * \brief Functions for removing elements from a range + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup stream_compaction Stream Compaction + * \ingroup reordering + * \{ + * + */ + +/*! \p remove removes from the range [first, last) all elements that are + * equal to \p value. That is, \p remove returns an iterator \p new_last such + * that the range [first, new_last) contains no elements equal to + * \p value. The iterators in the range [new_first,last) are all still + * dereferenceable, but the elements that they point to are unspecified. \p remove + * is stable, meaning that the relative order of elements that are not equal to + * \p value is unchanged. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param value The value to remove from the range [first, last). + * Elements which are equal to value are removed from the sequence. + * \return A \p ForwardIterator pointing to the end of the resulting range of + * elements which are not equal to \p value. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam T is a model of Equality Comparable, and objects of type \p + * T can be compared for equality with objects of \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p remove to remove a number + * of interest from a range using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int A[N] = {3, 1, 4, 1, 5, 9}; + * int *new_end = thrust::remove(A, A + N, 1); + * // The first four values of A are now {3, 4, 5, 9} + * // Values beyond new_end are unspecified + * \endcode + * + * \note The meaning of "removal" is somewhat subtle. \p remove does not destroy any + * iterators, and does not change the distance between \p first and \p last. + * (There's no way that it could do anything of the sort.) So, for example, if + * \c V is a device_vector, remove(V.begin(), V.end(), 0) does not + * change V.size(): \c V will contain just as many elements as it did + * before. \p remove returns an iterator that points to the end of the resulting + * range after elements have been removed from it; it follows that the elements + * after that iterator are of no interest, and may be discarded. If you are + * removing elements from a + * Sequence, you may + * simply erase them. That is, a reasonable way of removing elements from a + * Sequence is + * S.erase(remove(S.begin(), S.end(), x), S.end()). + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove + * \see remove_if + * \see remove_copy + * \see remove_copy_if + */ +template +_CCCL_HOST_DEVICE ForwardIterator remove( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const T& value); + +/*! \p remove removes from the range [first, last) all elements that are + * equal to \p value. That is, \p remove returns an iterator \p new_last such + * that the range [first, new_last) contains no elements equal to + * \p value. The iterators in the range [new_first,last) are all still + * dereferenceable, but the elements that they point to are unspecified. \p remove + * is stable, meaning that the relative order of elements that are not equal to + * \p value is unchanged. + * + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param value The value to remove from the range [first, last). + * Elements which are equal to value are removed from the sequence. + * \return A \p ForwardIterator pointing to the end of the resulting range of + * elements which are not equal to \p value. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam T is a model of Equality Comparable, and objects of type \p + * T can be compared for equality with objects of \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p remove to remove a number + * of interest from a range. + * + * \code + * #include + * ... + * const int N = 6; + * int A[N] = {3, 1, 4, 1, 5, 9}; + * int *new_end = thrust::remove(A, A + N, 1); + * // The first four values of A are now {3, 4, 5, 9} + * // Values beyond new_end are unspecified + * \endcode + * + * \note The meaning of "removal" is somewhat subtle. \p remove does not destroy any + * iterators, and does not change the distance between \p first and \p last. + * (There's no way that it could do anything of the sort.) So, for example, if + * \c V is a device_vector, remove(V.begin(), V.end(), 0) does not + * change V.size(): \c V will contain just as many elements as it did + * before. \p remove returns an iterator that points to the end of the resulting + * range after elements have been removed from it; it follows that the elements + * after that iterator are of no interest, and may be discarded. If you are + * removing elements from a + * Sequence, you may + * simply erase them. That is, a reasonable way of removing elements from a + * Sequence is + * S.erase(remove(S.begin(), S.end(), x), S.end()). + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove + * \see remove_if + * \see remove_copy + * \see remove_copy_if + */ +template +ForwardIterator remove(ForwardIterator first, ForwardIterator last, const T& value); + +/*! \p remove_copy copies elements that are not equal to \p value from the range + * [first, last) to a range beginning at \p result. The return value is + * the end of the resulting range. This operation is stable, meaning that the + * relative order of the elements that are copied is the same as in + * the range [first, last). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param result The resulting range is copied to the sequence beginning at this + * location. + * \param value The value to omit from the copied range. + * \return An OutputIterator pointing to the end of the resulting range of elements + * which are not equal to \p value. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c + * value_types. \tparam OutputIterator is a model of Output Iterator. \tparam T is a model of Equality Comparable, and objects of type \p + * T can be compared for equality with objects of \p InputIterator's \c value_type. + * + * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). + * + * The following code snippet demonstrates how to use \p remove_copy to copy + * a sequence of numbers to an output range while omitting a value of interest using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int V[N] = {-2, 0, -1, 0, 1, 2}; + * int result[N-2]; + * thrust::remove_copy(thrust::host, V, V + N, result, 0); + * // V remains {-2, 0, -1, 0, 1, 2} + * // result is now {-2, -1, 1, 2} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove_copy + * \see remove + * \see remove_if + * \see remove_copy_if + */ +template +_CCCL_HOST_DEVICE OutputIterator remove_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + const T& value); + +/*! \p remove_copy copies elements that are not equal to \p value from the range + * [first, last) to a range beginning at \p result. The return value is + * the end of the resulting range. This operation is stable, meaning that the + * relative order of the elements that are copied is the same as in + * the range [first, last). + * + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param result The resulting range is copied to the sequence beginning at this + * location. + * \param value The value to omit from the copied range. + * \return An OutputIterator pointing to the end of the resulting range of elements + * which are not equal to \p value. + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c + * value_types. \tparam OutputIterator is a model of Output Iterator. \tparam T is a model of Equality Comparable, and objects of type \p + * T can be compared for equality with objects of \p InputIterator's \c value_type. + * + * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). + * + * The following code snippet demonstrates how to use \p remove_copy to copy + * a sequence of numbers to an output range while omitting a value of interest. + * + * \code + * #include + * ... + * const int N = 6; + * int V[N] = {-2, 0, -1, 0, 1, 2}; + * int result[N-2]; + * thrust::remove_copy(V, V + N, result, 0); + * // V remains {-2, 0, -1, 0, 1, 2} + * // result is now {-2, -1, 1, 2} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove_copy + * \see remove + * \see remove_if + * \see remove_copy_if + */ +template +OutputIterator remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value); + +/*! \p remove_if removes from the range [first, last) every element \p x + * such that pred(x) is \c true. That is, \p remove_if returns an + * iterator \c new_last such that the range [first,new_last) contains + * no elements for which \p pred is \c true. The iterators in the range + * [new_last,last) are all still dereferenceable, but the elements that + * they point to are unspecified. \p remove_if is stable, meaning that the + * relative order of elements that are not removed is unchanged. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param pred A predicate to evaluate for each element of the range + * [first,last). Elements for which \p pred evaluates to + * \c true are removed from the sequence. + * \return A ForwardIterator pointing to the end of the resulting range of + * elements for which \p pred evaluated to \c true. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type is convertible to \p Predicate's + * \c argument_type. \tparam Predicate is a model of Predicate. + * + * The following code snippet demonstrates how to use \p remove_if to remove + * all even numbers from an array of integers using the \p thrust::host execution policy for + * parallelization: + * + * \code + * #include + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * int *new_end = thrust::remove_if(thrust::host, A, A + N, is_even()); + * // The first three values of A are now {1, 5, 7} + * // Values beyond new_end are unspecified + * \endcode + * + * \note The meaning of "removal" is somewhat subtle. \p remove_if does not + * destroy any iterators, and does not change the distance between \p first and + * \p last. (There's no way that it could do anything of the sort.) So, for + * example, if \c V is a device_vector, + * remove_if(V.begin(), V.end(), pred) does not change + * V.size(): \c V will contain just as many elements as it did before. + * \p remove_if returns an iterator that points to the end of the resulting + * range after elements have been removed from it; it follows that the elements + * after that iterator are of no interest, and may be discarded. If you are + * removing elements from a + * Sequence, you may + * simply erase them. That is, a reasonable way of removing elements from a + * Sequence is + * S.erase(remove_if(S.begin(), S.end(), pred), S.end()). + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove + * \see remove + * \see remove_copy + * \see remove_copy_if + */ +template +_CCCL_HOST_DEVICE ForwardIterator remove_if( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + Predicate pred); + +/*! \p remove_if removes from the range [first, last) every element \p x + * such that pred(x) is \c true. That is, \p remove_if returns an + * iterator \c new_last such that the range [first,new_last) contains + * no elements for which \p pred is \c true. The iterators in the range + * [new_last,last) are all still dereferenceable, but the elements that + * they point to are unspecified. \p remove_if is stable, meaning that the + * relative order of elements that are not removed is unchanged. + * + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param pred A predicate to evaluate for each element of the range + * [first,last). Elements for which \p pred evaluates to + * \c true are removed from the sequence. + * \return A ForwardIterator pointing to the end of the resulting range of + * elements for which \p pred evaluated to \c true. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type is convertible to \p Predicate's + * \c argument_type. \tparam Predicate is a model of Predicate. + * + * The following code snippet demonstrates how to use \p remove_if to remove + * all even numbers from an array of integers. + * + * \code + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * int *new_end = thrust::remove_if(A, A + N, is_even()); + * // The first three values of A are now {1, 5, 7} + * // Values beyond new_end are unspecified + * \endcode + * + * \note The meaning of "removal" is somewhat subtle. \p remove_if does not + * destroy any iterators, and does not change the distance between \p first and + * \p last. (There's no way that it could do anything of the sort.) So, for + * example, if \c V is a device_vector, + * remove_if(V.begin(), V.end(), pred) does not change + * V.size(): \c V will contain just as many elements as it did before. + * \p remove_if returns an iterator that points to the end of the resulting + * range after elements have been removed from it; it follows that the elements + * after that iterator are of no interest, and may be discarded. If you are + * removing elements from a + * Sequence, you may + * simply erase them. That is, a reasonable way of removing elements from a + * Sequence is + * S.erase(remove_if(S.begin(), S.end(), pred), S.end()). + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove + * \see remove + * \see remove_copy + * \see remove_copy_if + */ +template +ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, Predicate pred); + +/*! \p remove_copy_if copies elements from the range [first,last) to a + * range beginning at \p result, except that elements for which \p pred is + * \c true are not copied. The return value is the end of the resulting range. + * This operation is stable, meaning that the relative order of the elements that + * are copied is the same as the range [first,last). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param result The resulting range is copied to the sequence beginning at this + * location. + * \param pred A predicate to evaluate for each element of the range [first,last). + * Elements for which \p pred evaluates to \c false are not copied + * to the resulting sequence. + * \return An OutputIterator pointing to the end of the resulting range. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, + * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. + * \tparam OutputIterator is a model of Output + * Iterator. \tparam Predicate is a model of Predicate. + * + * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). + * + * The following code snippet demonstrates how to use \p remove_copy_if to copy + * a sequence of numbers to an output range while omitting even numbers using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * const int N = 6; + * int V[N] = {-2, 0, -1, 0, 1, 2}; + * int result[2]; + * thrust::remove_copy_if(thrust::host, V, V + N, result, is_even()); + * // V remains {-2, 0, -1, 0, 1, 2} + * // result is now {-1, 1} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove_copy + * \see remove + * \see remove_copy + * \see remove_if + */ +template +_CCCL_HOST_DEVICE OutputIterator remove_copy_if( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + Predicate pred); + +/*! \p remove_copy_if copies elements from the range [first,last) to a + * range beginning at \p result, except that elements for which \p pred is + * \c true are not copied. The return value is the end of the resulting range. + * This operation is stable, meaning that the relative order of the elements that + * are copied is the same as the range [first,last). + * + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param result The resulting range is copied to the sequence beginning at this + * location. + * \param pred A predicate to evaluate for each element of the range [first,last). + * Elements for which \p pred evaluates to \c false are not copied + * to the resulting sequence. + * \return An OutputIterator pointing to the end of the resulting range. + * + * \tparam InputIterator is a model of Input + * Iterator, \p InputIterator's \c value_type is convertible to a type in \p OutputIterator's set of \c value_types, + * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. + * \tparam OutputIterator is a model of Output + * Iterator. \tparam Predicate is a model of Predicate. + * + * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). + * + * The following code snippet demonstrates how to use \p remove_copy_if to copy + * a sequence of numbers to an output range while omitting even numbers. + * + * \code + * #include + * ... + * struct is_even + * { + * __host__ __device__ + * bool operator()(const int x) + * { + * return (x % 2) == 0; + * } + * }; + * ... + * const int N = 6; + * int V[N] = {-2, 0, -1, 0, 1, 2}; + * int result[2]; + * thrust::remove_copy_if(V, V + N, result, is_even()); + * // V remains {-2, 0, -1, 0, 1, 2} + * // result is now {-1, 1} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove_copy + * \see remove + * \see remove_copy + * \see remove_if + */ +template +OutputIterator remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred); + +/*! \p remove_if removes from the range [first, last) every element \p x + * such that pred(x) is \c true. That is, \p remove_if returns an + * iterator \c new_last such that the range [first, new_last) contains + * no elements for which \p pred of the corresponding stencil value is \c true. + * The iterators in the range [new_last,last) are all still dereferenceable, + * but the elements that they point to are unspecified. \p remove_if is stable, + * meaning that the relative order of elements that are not removed is unchanged. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param stencil The beginning of the stencil sequence. + * \param pred A predicate to evaluate for each element of the range + * [stencil, stencil + (last - first)). Elements for which \p pred evaluates to + * \c true are removed from the sequence [first, last) + * \return A ForwardIterator pointing to the end of the resulting range of + * elements for which \p pred evaluated to \c true. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator and \p ForwardIterator is mutable. \tparam InputIterator is a model of Input Iterator, and \p InputIterator's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam Predicate is a model of Predicate. + * + * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). + * \pre The range [stencil, stencil + (last - first)) shall not overlap the range + * [result, result + (last - first)). + * + * The following code snippet demonstrates how to use \p remove_if to remove + * specific elements from an array of integers using the \p thrust::host execution policy for + * parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * int S[N] = {0, 1, 1, 1, 0, 0}; + * + * int *new_end = thrust::remove_if(thrust::host, A, A + N, S, thrust::identity()); + * // The first three values of A are now {1, 5, 7} + * // Values beyond new_end are unspecified + * \endcode + * + * \note The range [first, last) is not permitted to overlap with the range [stencil, stencil + (last - + * first)). + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove + * \see remove + * \see remove_copy + * \see remove_copy_if + */ +template +_CCCL_HOST_DEVICE ForwardIterator remove_if( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator stencil, + Predicate pred); + +/*! \p remove_if removes from the range [first, last) every element \p x + * such that pred(x) is \c true. That is, \p remove_if returns an + * iterator \c new_last such that the range [first, new_last) contains + * no elements for which \p pred of the corresponding stencil value is \c true. + * The iterators in the range [new_last,last) are all still dereferenceable, + * but the elements that they point to are unspecified. \p remove_if is stable, + * meaning that the relative order of elements that are not removed is unchanged. + * + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param stencil The beginning of the stencil sequence. + * \param pred A predicate to evaluate for each element of the range + * [stencil, stencil + (last - first)). Elements for which \p pred evaluates to + * \c true are removed from the sequence [first, last) + * \return A ForwardIterator pointing to the end of the resulting range of + * elements for which \p pred evaluated to \c true. + * + * \tparam ForwardIterator is a model of Forward + * Iterator and \p ForwardIterator is mutable. \tparam InputIterator is a model of Input Iterator, and \p InputIterator's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam Predicate is a model of Predicate. + * + * \pre The range [first, last) shall not overlap the range [result, result + (last - first)). + * \pre The range [stencil, stencil + (last - first)) shall not overlap the range + * [result, result + (last - first)). + * + * The following code snippet demonstrates how to use \p remove_if to remove + * specific elements from an array of integers. + * + * \code + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * int S[N] = {0, 1, 1, 1, 0, 0}; + * + * int *new_end = thrust::remove_if(A, A + N, S, thrust::identity()); + * // The first three values of A are now {1, 5, 7} + * // Values beyond new_end are unspecified + * \endcode + * + * \note The range [first, last) is not permitted to overlap with the range [stencil, stencil + (last - + * first)). + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove + * \see remove + * \see remove_copy + * \see remove_copy_if + */ +template +ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred); + +/*! \p remove_copy_if copies elements from the range [first,last) to a + * range beginning at \p result, except that elements for which \p pred of the + * corresponding stencil value is \c true are not copied. The return value is + * the end of the resulting range. This operation is stable, meaning that the + * relative order of the elements that are copied is the same as the + * range [first,last). + * + * The algorithm's execution policy is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param stencil The beginning of the stencil sequence. + * \param result The resulting range is copied to the sequence beginning at this + * location. + * \param pred A predicate to evaluate for each element of the range [first,last). + * Elements for which \p pred evaluates to \c false are not copied + * to the resulting sequence. + * \return An OutputIterator pointing to the end of the resulting range. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c + * value_types. \tparam InputIterator2 is a model of Input Iterator, and \p InputIterator2's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam OutputIterator is a model of Output Iterator. \tparam Predicate is a model + * of Predicate. + * + * \pre The range [stencil, stencil + (last - first)) shall not overlap the range + * [result, result + (last - first)). + * + * The following code snippet demonstrates how to use \p remove_copy_if to copy + * a sequence of numbers to an output range while omitting specific elements using the \p thrust::host + * execution policy for parallelization. + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int V[N] = {-2, 0, -1, 0, 1, 2}; + * int S[N] = { 1, 1, 0, 1, 0, 1}; + * int result[2]; + * thrust::remove_copy_if(thrust::host, V, V + N, S, result, thrust::identity()); + * // V remains {-2, 0, -1, 0, 1, 2} + * // result is now {-1, 1} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove_copy + * \see remove + * \see remove_copy + * \see remove_if + * \see copy_if + */ +template +_CCCL_HOST_DEVICE OutputIterator remove_copy_if( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator result, + Predicate pred); + +/*! \p remove_copy_if copies elements from the range [first,last) to a + * range beginning at \p result, except that elements for which \p pred of the + * corresponding stencil value is \c true are not copied. The return value is + * the end of the resulting range. This operation is stable, meaning that the + * relative order of the elements that are copied is the same as the + * range [first,last). + * + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param stencil The beginning of the stencil sequence. + * \param result The resulting range is copied to the sequence beginning at this + * location. + * \param pred A predicate to evaluate for each element of the range [first,last). + * Elements for which \p pred evaluates to \c false are not copied + * to the resulting sequence. + * \return An OutputIterator pointing to the end of the resulting range. + * + * \tparam InputIterator1 is a model of Input + * Iterator, \p InputIterator1's \c value_type is convertible to a type in \p OutputIterator's set of \c + * value_types. \tparam InputIterator2 is a model of Input Iterator, and \p InputIterator2's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam OutputIterator is a model of Output Iterator. \tparam Predicate is a model + * of Predicate. + * + * \pre The range [stencil, stencil + (last - first)) shall not overlap the range + * [result, result + (last - first)). + * + * The following code snippet demonstrates how to use \p remove_copy_if to copy + * a sequence of numbers to an output range while omitting specific elements. + * + * \code + * #include + * ... + * const int N = 6; + * int V[N] = {-2, 0, -1, 0, 1, 2}; + * int S[N] = { 1, 1, 0, 1, 0, 1}; + * int result[2]; + * thrust::remove_copy_if(V, V + N, S, result, thrust::identity()); + * // V remains {-2, 0, -1, 0, 1, 2} + * // result is now {-1, 1} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/remove_copy + * \see remove + * \see remove_copy + * \see remove_if + * \see copy_if + */ +template +OutputIterator remove_copy_if( + InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred); + +/*! \} // end stream_compaction + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/replace.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/replace.h new file mode 100644 index 0000000000000000000000000000000000000000..5d0b58e6d0607237d1f47558902cab9b2d4902b3 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/replace.h @@ -0,0 +1,827 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file replace.h + * \brief Functions for replacing elements in a range with a particular value + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup transformations + * \addtogroup replacing + * \ingroup transformations + * \{ + */ + +/*! \p replace replaces every element in the range [first, last) equal to \p old_value + * with \p new_value. That is: for every iterator \c i, if *i == old_value + * then it performs the assignment *i = new_value. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence of interest. + * \param last The end of the sequence of interest. + * \param old_value The value to replace. + * \param new_value The new value to replace \p old_value. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam T is a model of Assignable, \p T is a model of EqualityComparable, objects of \p T may be + * compared for equality with objects of \p ForwardIterator's \c value_type, and \p T is convertible to \p + * ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p replace to replace + * a value of interest in a \c device_vector with another using the \p thrust::device + * execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 1; + * A[1] = 2; + * A[2] = 3; + * A[3] = 1; + * + * thrust::replace(thrust::device, A.begin(), A.end(), 1, 99); + * + * // A contains [99, 2, 3, 99] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace + * \see \c replace_if + * \see \c replace_copy + * \see \c replace_copy_if + */ +template +_CCCL_HOST_DEVICE void +replace(const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const T& old_value, + const T& new_value); + +/*! \p replace replaces every element in the range [first, last) equal to \p old_value + * with \p new_value. That is: for every iterator \c i, if *i == old_value + * then it performs the assignment *i = new_value. + * + * \param first The beginning of the sequence of interest. + * \param last The end of the sequence of interest. + * \param old_value The value to replace. + * \param new_value The new value to replace \p old_value. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam T is a model of Assignable, \p T is a model of EqualityComparable, objects of \p T may be + * compared for equality with objects of \p ForwardIterator's \c value_type, and \p T is convertible to \p + * ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p replace to replace + * a value of interest in a \c device_vector with another. + * + * \code + * #include + * #include + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 1; + * A[1] = 2; + * A[2] = 3; + * A[3] = 1; + * + * thrust::replace(A.begin(), A.end(), 1, 99); + * + * // A contains [99, 2, 3, 99] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace + * \see \c replace_if + * \see \c replace_copy + * \see \c replace_copy_if + */ +template +void replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value); + +/*! \p replace_if replaces every element in the range [first, last) for which + * \p pred returns \c true with \p new_value. That is: for every iterator \c i, if + * pred(*i) is \c true then it performs the assignment *i = new_value. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence of interest. + * \param last The end of the sequence of interest. + * \param pred The predicate to test on every value of the range [first,last). + * \param new_value The new value to replace elements which pred(*i) evaluates + * to \c true. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type is convertible to \p Predicate's + * \c argument_type. \tparam Predicate is a model of Predicate. \tparam T is a model of Assignable, and \p T is convertible to \p + * ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p replace_if to replace + * a \c device_vector's negative elements with \c 0 using the \p thrust::device execution policy + * for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * struct is_less_than_zero + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x < 0; + * } + * }; + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 1; + * A[1] = -3; + * A[2] = 2; + * A[3] = -1; + * + * is_less_than_zero pred; + * + * thrust::replace_if(thrust::device, A.begin(), A.end(), pred, 0); + * + * // A contains [1, 0, 2, 0] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace + * \see \c replace + * \see \c replace_copy + * \see \c replace_copy_if + */ +template +_CCCL_HOST_DEVICE void replace_if( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + Predicate pred, + const T& new_value); + +/*! \p replace_if replaces every element in the range [first, last) for which + * \p pred returns \c true with \p new_value. That is: for every iterator \c i, if + * pred(*i) is \c true then it performs the assignment *i = new_value. + * + * \param first The beginning of the sequence of interest. + * \param last The end of the sequence of interest. + * \param pred The predicate to test on every value of the range [first,last). + * \param new_value The new value to replace elements which pred(*i) evaluates + * to \c true. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type is convertible to \p Predicate's + * \c argument_type. \tparam Predicate is a model of Predicate. \tparam T is a model of Assignable, and \p T is convertible to \p + * ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p replace_if to replace + * a \c device_vector's negative elements with \c 0. + * + * \code + * #include + * #include + * ... + * struct is_less_than_zero + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x < 0; + * } + * }; + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 1; + * A[1] = -3; + * A[2] = 2; + * A[3] = -1; + * + * is_less_than_zero pred; + * + * thrust::replace_if(A.begin(), A.end(), pred, 0); + * + * // A contains [1, 0, 2, 0] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace + * \see \c replace + * \see \c replace_copy + * \see \c replace_copy_if + */ +template +void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value); + +/*! \p replace_if replaces every element in the range [first, last) for which + * pred(*s) returns \c true with \p new_value. That is: for every iterator + * \c i in the range [first, last), and \c s in the range [stencil, stencil + (last - first)), + * if pred(*s) is \c true then it performs the assignment *i = new_value. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence of interest. + * \param last The end of the sequence of interest. + * \param stencil The beginning of the stencil sequence. + * \param pred The predicate to test on every value of the range [first,last). + * \param new_value The new value to replace elements which pred(*i) evaluates + * to \c true. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam InputIterator is a model of Input Iterator, and \p InputIterator's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam Predicate is a model of Predicate. \tparam T is a model of Assignable, and \p T is convertible to \p + * ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p replace_if to replace + * a \c device_vector's element with \c 0 when its corresponding stencil element is less than zero + * using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * + * struct is_less_than_zero + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x < 0; + * } + * }; + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 10; + * A[1] = 20; + * A[2] = 30; + * A[3] = 40; + * + * thrust::device_vector S(4); + * S[0] = -1; + * S[1] = 0; + * S[2] = -1; + * S[3] = 0; + * + * is_less_than_zero pred; + * thrust::replace_if(thrust::device, A.begin(), A.end(), S.begin(), pred, 0); + * + * // A contains [0, 20, 0, 40] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace + * \see \c replace + * \see \c replace_copy + * \see \c replace_copy_if + */ +template +_CCCL_HOST_DEVICE void replace_if( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + InputIterator stencil, + Predicate pred, + const T& new_value); + +/*! \p replace_if replaces every element in the range [first, last) for which + * pred(*s) returns \c true with \p new_value. That is: for every iterator + * \c i in the range [first, last), and \c s in the range [stencil, stencil + (last - first)), + * if pred(*s) is \c true then it performs the assignment *i = new_value. + * + * \param first The beginning of the sequence of interest. + * \param last The end of the sequence of interest. + * \param stencil The beginning of the stencil sequence. + * \param pred The predicate to test on every value of the range [first,last). + * \param new_value The new value to replace elements which pred(*i) evaluates + * to \c true. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable. \tparam InputIterator is a model of Input Iterator, and \p InputIterator's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam Predicate is a model of Predicate. \tparam T is a model of Assignable, and \p T is convertible to \p + * ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p replace_if to replace + * a \c device_vector's element with \c 0 when its corresponding stencil element is less than zero. + * + * \code + * #include + * #include + * + * struct is_less_than_zero + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x < 0; + * } + * }; + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 10; + * A[1] = 20; + * A[2] = 30; + * A[3] = 40; + * + * thrust::device_vector S(4); + * S[0] = -1; + * S[1] = 0; + * S[2] = -1; + * S[3] = 0; + * + * is_less_than_zero pred; + * thrust::replace_if(A.begin(), A.end(), S.begin(), pred, 0); + * + * // A contains [0, 20, 0, 40] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace + * \see \c replace + * \see \c replace_copy + * \see \c replace_copy_if + */ +template +void replace_if(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred, const T& new_value); + +/*! \p replace_copy copies elements from the range [first, last) to the range + * [result, result + (last-first)), except that any element equal to \p old_value + * is not copied; \p new_value is copied instead. + * + * More precisely, for every integer \c n such that 0 <= n < last-first, \p replace_copy + * performs the assignment *(result+n) = new_value if *(first+n) == old_value, + * and *(result+n) = *(first+n) otherwise. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence to copy from. + * \param last The end of the sequence to copy from. + * \param result The beginning of the sequence to copy to. + * \param old_value The value to replace. + * \param new_value The replacement value for which *i == old_value evaluates to \c true. + * \return result + (last-first) + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator. \tparam OutputIterator is a model of Output Iterator. \tparam T is a model of Assignable, \p T is a model of Equality Comparable, \p T may be compared + * for equality with \p InputIterator's \c value_type, and \p T is convertible to \p OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - + * first)) shall not overlap otherwise. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector A(4); + * A[0] = 1; + * A[1] = 2; + * A[2] = 3; + * A[3] = 1; + * + * thrust::device_vector B(4); + * + * thrust::replace_copy(thrust::device, A.begin(), A.end(), B.begin(), 1, 99); + * + * // B contains [99, 2, 3, 99] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace_copy + * \see \c copy + * \see \c replace + * \see \c replace_if + * \see \c replace_copy_if + */ +template +_CCCL_HOST_DEVICE OutputIterator replace_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + const T& old_value, + const T& new_value); + +/*! \p replace_copy copies elements from the range [first, last) to the range + * [result, result + (last-first)), except that any element equal to \p old_value + * is not copied; \p new_value is copied instead. + * + * More precisely, for every integer \c n such that 0 <= n < last-first, \p replace_copy + * performs the assignment *(result+n) = new_value if *(first+n) == old_value, + * and *(result+n) = *(first+n) otherwise. + * + * \param first The beginning of the sequence to copy from. + * \param last The end of the sequence to copy from. + * \param result The beginning of the sequence to copy to. + * \param old_value The value to replace. + * \param new_value The replacement value for which *i == old_value evaluates to \c true. + * \return result + (last-first) + * + * \tparam InputIterator is a model of Input + * Iterator. \tparam OutputIterator is a model of Output Iterator. \tparam T is a model of Assignable, \p T is a model of Equality Comparable, \p T may be compared + * for equality with \p InputIterator's \c value_type, and \p T is convertible to \p OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - + * first)) shall not overlap otherwise. + * + * \code + * #include + * #include + * ... + * thrust::device_vector A(4); + * A[0] = 1; + * A[1] = 2; + * A[2] = 3; + * A[3] = 1; + * + * thrust::device_vector B(4); + * + * thrust::replace_copy(A.begin(), A.end(), B.begin(), 1, 99); + * + * // B contains [99, 2, 3, 99] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace_copy + * \see \c copy + * \see \c replace + * \see \c replace_if + * \see \c replace_copy_if + */ +template +OutputIterator +replace_copy(InputIterator first, InputIterator last, OutputIterator result, const T& old_value, const T& new_value); + +/*! \p replace_copy_if copies elements from the range [first, last) to the range + * [result, result + (last-first)), except that any element for which \p pred + * is \c true is not copied; \p new_value is copied instead. + * + * More precisely, for every integer \c n such that 0 <= n < last-first, + * \p replace_copy_if performs the assignment *(result+n) = new_value if + * pred(*(first+n)), and *(result+n) = *(first+n) otherwise. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence to copy from. + * \param last The end of the sequence to copy from. + * \param result The beginning of the sequence to copy to. + * \param pred The predicate to test on every value of the range [first,last). + * \param new_value The replacement value to assign pred(*i) evaluates to \c true. + * \return result + (last-first) + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + Iterator, + * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. + * \tparam OutputIterator is a model of Output + Iterator. + * \tparam Predicate is a model of Predicate. + * \tparam T is a model of Assignable, + * and \p T is convertible to \p OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - + first)) shall not overlap otherwise. + * + * \code + * #include + * #include + * #include + * + * struct is_less_than_zero + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x < 0; + * } + * }; + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 1; + * A[1] = -3; + * A[2] = 2; + * A[3] = -1; + + * thrust::device_vector B(4); + * is_less_than_zero pred; + * + * thrust::replace_copy_if(thrust::device, A.begin(), A.end(), B.begin(), pred, 0); + * + * // B contains [1, 0, 2, 0] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace_copy + * \see \c replace + * \see \c replace_if + * \see \c replace_copy + */ +template +_CCCL_HOST_DEVICE OutputIterator replace_copy_if( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + Predicate pred, + const T& new_value); + +/*! \p replace_copy_if copies elements from the range [first, last) to the range + * [result, result + (last-first)), except that any element for which \p pred + * is \c true is not copied; \p new_value is copied instead. + * + * More precisely, for every integer \c n such that 0 <= n < last-first, + * \p replace_copy_if performs the assignment *(result+n) = new_value if + * pred(*(first+n)), and *(result+n) = *(first+n) otherwise. + * + * \param first The beginning of the sequence to copy from. + * \param last The end of the sequence to copy from. + * \param result The beginning of the sequence to copy to. + * \param pred The predicate to test on every value of the range [first,last). + * \param new_value The replacement value to assign pred(*i) evaluates to \c true. + * \return result + (last-first) + * + * \tparam InputIterator is a model of Input + Iterator, + * and \p InputIterator's \c value_type is convertible to \p Predicate's \c argument_type. + * \tparam OutputIterator is a model of Output + Iterator. + * \tparam Predicate is a model of Predicate. + * \tparam T is a model of Assignable, + * and \p T is convertible to \p OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - + first)) shall not overlap otherwise. + * + * \code + * #include + * #include + * + * struct is_less_than_zero + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x < 0; + * } + * }; + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 1; + * A[1] = -3; + * A[2] = 2; + * A[3] = -1; + + * thrust::device_vector B(4); + * is_less_than_zero pred; + * + * thrust::replace_copy_if(A.begin(), A.end(), B.begin(), pred, 0); + * + * // B contains [1, 0, 2, 0] + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/replace_copy + * \see \c replace + * \see \c replace_if + * \see \c replace_copy + */ +template +OutputIterator +replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value); + +/*! This version of \p replace_copy_if copies elements from the range [first, last) to the range + * [result, result + (last-first)), except that any element whose corresponding stencil + * element causes \p pred to be \c true is not copied; \p new_value is copied instead. + * + * More precisely, for every integer \c n such that 0 <= n < last-first, + * \p replace_copy_if performs the assignment *(result+n) = new_value if + * pred(*(stencil+n)), and *(result+n) = *(first+n) otherwise. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence to copy from. + * \param last The end of the sequence to copy from. + * \param stencil The beginning of the stencil sequence. + * \param result The beginning of the sequence to copy to. + * \param pred The predicate to test on every value of the range [stencil, stencil + (last - first)). + * \param new_value The replacement value to assign when pred(*s) evaluates to \c true. + * \return result + (last-first) + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator. \tparam InputIterator2 is a model of Input Iterator and \p InputIterator2's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam OutputIterator is a model of Output Iterator. \tparam Predicate is a model + * of Predicate. \tparam T is a model of Assignable, and \p T is convertible to \p + * OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - + * first)) shall not overlap otherwise. \pre \p stencil may equal \p result, but the ranges [stencil, stencil + + * (last - first)) and [result, result + (last - first)) shall not overlap otherwise. + * + * \code + * #include + * #include + * #include + * + * struct is_less_than_zero + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x < 0; + * } + * }; + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 10; + * A[1] = 20; + * A[2] = 30; + * A[3] = 40; + * + * thrust::device_vector S(4); + * S[0] = -1; + * S[1] = 0; + * S[2] = -1; + * S[3] = 0; + * + * thrust::device_vector B(4); + * is_less_than_zero pred; + * + * thrust::replace_if(thrust::device, A.begin(), A.end(), S.begin(), B.begin(), pred, 0); + * + * // B contains [0, 20, 0, 40] + * \endcode + * + * \see \c replace_copy + * \see \c replace_if + */ +template +_CCCL_HOST_DEVICE OutputIterator replace_copy_if( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator result, + Predicate pred, + const T& new_value); + +/*! This version of \p replace_copy_if copies elements from the range [first, last) to the range + * [result, result + (last-first)), except that any element whose corresponding stencil + * element causes \p pred to be \c true is not copied; \p new_value is copied instead. + * + * More precisely, for every integer \c n such that 0 <= n < last-first, + * \p replace_copy_if performs the assignment *(result+n) = new_value if + * pred(*(stencil+n)), and *(result+n) = *(first+n) otherwise. + * + * \param first The beginning of the sequence to copy from. + * \param last The end of the sequence to copy from. + * \param stencil The beginning of the stencil sequence. + * \param result The beginning of the sequence to copy to. + * \param pred The predicate to test on every value of the range [stencil, stencil + (last - first)). + * \param new_value The replacement value to assign when pred(*s) evaluates to \c true. + * \return result + (last-first) + * + * \tparam InputIterator1 is a model of Input + * Iterator. \tparam InputIterator2 is a model of Input Iterator and \p InputIterator2's \c + * value_type is convertible to \p Predicate's \c argument_type. \tparam OutputIterator is a model of Output Iterator. \tparam Predicate is a model + * of Predicate. \tparam T is a model of Assignable, and \p T is convertible to \p + * OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the ranges [first, last) and [result, result + (last - + * first)) shall not overlap otherwise. \pre \p stencil may equal \p result, but the ranges [stencil, stencil + + * (last - first)) and [result, result + (last - first)) shall not overlap otherwise. + * + * \code + * #include + * #include + * + * struct is_less_than_zero + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x < 0; + * } + * }; + * + * ... + * + * thrust::device_vector A(4); + * A[0] = 10; + * A[1] = 20; + * A[2] = 30; + * A[3] = 40; + * + * thrust::device_vector S(4); + * S[0] = -1; + * S[1] = 0; + * S[2] = -1; + * S[3] = 0; + * + * thrust::device_vector B(4); + * is_less_than_zero pred; + * + * thrust::replace_if(A.begin(), A.end(), S.begin(), B.begin(), pred, 0); + * + * // B contains [0, 20, 0, 40] + * \endcode + * + * \see \c replace_copy + * \see \c replace_if + */ +template +OutputIterator replace_copy_if( + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + OutputIterator result, + Predicate pred, + const T& new_value); + +/*! \} // end replacing + * \} // transformations + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/reverse.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/reverse.h new file mode 100644 index 0000000000000000000000000000000000000000..f59a5176584de235a397d6e13809ab76fba10ac2 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/reverse.h @@ -0,0 +1,213 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file reverse.h + * \brief Reverses the order of a range + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup reordering + * \ingroup algorithms + */ + +/*! \p reverse reverses a range. That is: for every i such that + * 0 <= i <= (last - first) / 2, it exchanges *(first + i) + * and *(last - (i + 1)). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range to reverse. + * \param last The end of the range to reverse. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam BidirectionalIterator is a model of Bidirectional Iterator and \p + * BidirectionalIterator is mutable. + * + * The following code snippet demonstrates how to use \p reverse to reverse a + * \p device_vector of integers using the \p thrust::device execution policy for + * parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int data[N] = {0, 1, 2, 3, 4, 5}; + * thrust::device_vector v(data, data + N); + * thrust::reverse(thrust::device, v.begin(), v.end()); + * // v is now {5, 4, 3, 2, 1, 0} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/reverse + * \see \p reverse_copy + * \see \p reverse_iterator + */ +template +_CCCL_HOST_DEVICE void reverse(const thrust::detail::execution_policy_base& exec, + BidirectionalIterator first, + BidirectionalIterator last); + +/*! \p reverse reverses a range. That is: for every i such that + * 0 <= i <= (last - first) / 2, it exchanges *(first + i) + * and *(last - (i + 1)). + * + * \param first The beginning of the range to reverse. + * \param last The end of the range to reverse. + * + * \tparam BidirectionalIterator is a model of Bidirectional Iterator and \p + * BidirectionalIterator is mutable. + * + * The following code snippet demonstrates how to use \p reverse to reverse a + * \p device_vector of integers. + * + * \code + * #include + * ... + * const int N = 6; + * int data[N] = {0, 1, 2, 3, 4, 5}; + * thrust::device_vector v(data, data + N); + * thrust::reverse(v.begin(), v.end()); + * // v is now {5, 4, 3, 2, 1, 0} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/reverse + * \see \p reverse_copy + * \see \p reverse_iterator + */ +template +void reverse(BidirectionalIterator first, BidirectionalIterator last); + +/*! \p reverse_copy differs from \p reverse only in that the reversed range + * is written to a different output range, rather than inplace. + * + * \p reverse_copy copies elements from the range [first, last) to the + * range [result, result + (last - first)) such that the copy is a + * reverse of the original range. Specifically: for every i such that + * 0 <= i < (last - first), \p reverse_copy performs the assignment + * *(result + (last - first) - i) = *(first + i). + * + * The return value is result + (last - first)). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range to reverse. + * \param last The end of the range to reverse. + * \param result The beginning of the output range. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam BidirectionalIterator is a model of Bidirectional Iterator, and \p + * BidirectionalIterator's \p value_type is convertible to \p OutputIterator's \p value_type. \tparam OutputIterator is + * a model of Output Iterator. + * + * \pre The range [first, last) and the range [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p reverse_copy to reverse + * an input \p device_vector of integers to an output \p device_vector using the \p thrust::device + * execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int data[N] = {0, 1, 2, 3, 4, 5}; + * thrust::device_vector input(data, data + N); + * thrust::device_vector output(N); + * thrust::reverse_copy(thrust::device, v.begin(), v.end(), output.begin()); + * // input is still {0, 1, 2, 3, 4, 5} + * // output is now {5, 4, 3, 2, 1, 0} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/reverse_copy + * \see \p reverse + * \see \p reverse_iterator + */ +template +_CCCL_HOST_DEVICE OutputIterator reverse_copy( + const thrust::detail::execution_policy_base& exec, + BidirectionalIterator first, + BidirectionalIterator last, + OutputIterator result); + +/*! \p reverse_copy differs from \p reverse only in that the reversed range + * is written to a different output range, rather than inplace. + * + * \p reverse_copy copies elements from the range [first, last) to the + * range [result, result + (last - first)) such that the copy is a + * reverse of the original range. Specifically: for every i such that + * 0 <= i < (last - first), \p reverse_copy performs the assignment + * *(result + (last - first) - i) = *(first + i). + * + * The return value is result + (last - first)). + * + * \param first The beginning of the range to reverse. + * \param last The end of the range to reverse. + * \param result The beginning of the output range. + * + * \tparam BidirectionalIterator is a model of Bidirectional Iterator, and \p + * BidirectionalIterator's \p value_type is convertible to \p OutputIterator's \p value_type. \tparam OutputIterator is + * a model of Output Iterator. + * + * \pre The range [first, last) and the range [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p reverse_copy to reverse + * an input \p device_vector of integers to an output \p device_vector. + * + * \code + * #include + * ... + * const int N = 6; + * int data[N] = {0, 1, 2, 3, 4, 5}; + * thrust::device_vector input(data, data + N); + * thrust::device_vector output(N); + * thrust::reverse_copy(v.begin(), v.end(), output.begin()); + * // input is still {0, 1, 2, 3, 4, 5} + * // output is now {5, 4, 3, 2, 1, 0} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/reverse_copy + * \see \p reverse + * \see \p reverse_iterator + */ +template +OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result); + +/*! \} // end reordering + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/scan.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/scan.h new file mode 100644 index 0000000000000000000000000000000000000000..f0711704a8374fa67a362aab654a6936f7f4aa3d --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/scan.h @@ -0,0 +1,1695 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file scan.h + * \brief Functions for computing prefix sums + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup algorithms + */ + +/*! \addtogroup prefixsums Prefix Sums + * \ingroup algorithms + * \{ + */ + +/*! \p inclusive_scan computes an inclusive prefix sum operation. The + * term 'inclusive' means that each result includes the corresponding + * input operand in the partial sum. More precisely, *first is + * assigned to *result and the sum of *first and + * *(first + 1) is assigned to *(result + 1), and so on. + * This version of \p inclusive_scan assumes plus as the associative operator. + * When the input and output sequences are the same, the scan is performed + * in-place. + * + * \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary + * difference between the two functions is that \c std::partial_sum guarantees + * a serial summation order, while \p inclusive_scan requires associativity of + * the binary operation to parallelize the prefix sum. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output + * Iterator, and if \c x and \c y are objects of \c OutputIterator's \c value_type, then x + y is defined. + * If \c T is \c OutputIterator's \c value_type, then T(0) is defined. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan to compute an in-place + * prefix sum using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::inclusive_scan(thrust::host, data, data + 6, data); // in-place scan + * + * // data is now {1, 1, 3, 5, 6, 9} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + * + */ +template +_CCCL_HOST_DEVICE OutputIterator inclusive_scan( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result); + +/*! \p inclusive_scan computes an inclusive prefix sum operation. The + * term 'inclusive' means that each result includes the corresponding + * input operand in the partial sum. More precisely, *first is + * assigned to *result and the sum of *first and + * *(first + 1) is assigned to *(result + 1), and so on. + * This version of \p inclusive_scan assumes plus as the associative operator. + * When the input and output sequences are the same, the scan is performed + * in-place. + * + * \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary + * difference between the two functions is that \c std::partial_sum guarantees + * a serial summation order, while \p inclusive_scan requires associativity of + * the binary operation to parallelize the prefix sum. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output + * Iterator, and if \c x and \c y are objects of \c OutputIterator's \c value_type, then x + y is defined. + * If \c T is \c OutputIterator's \c value_type, then T(0) is defined. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan + * + * \code + * #include + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::inclusive_scan(data, data + 6, data); // in-place scan + * + * // data is now {1, 1, 3, 5, 6, 9} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + * + */ +template +OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); + +/*! \p inclusive_scan computes an inclusive prefix sum operation. The + * term 'inclusive' means that each result includes the corresponding + * input operand in the partial sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary + * difference between the two functions is that \c std::partial_sum guarantees + * a serial summation order, while \p inclusive_scan requires associativity of + * the binary operation to parallelize the prefix sum. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output Iterator + * and \c OutputIterator's \c value_type is convertible to + * both \c AssociativeOperator's \c first_argument_type and + * \c second_argument_type. + * \tparam AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan to compute an in-place + * prefix sum using the \p thrust::host execution policy for parallelization: + * + * \code + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * + * thrust::maximum binary_op; + * + * thrust::inclusive_scan(thrust::host, data, data + 10, data, binary_op); // in-place scan + * + * // data is now {-5, 0, 2, 2, 2, 4, 4, 4, 4, 8} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +_CCCL_HOST_DEVICE OutputIterator inclusive_scan( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + AssociativeOperator binary_op); + +/*! \p inclusive_scan computes an inclusive prefix sum operation. The + * term 'inclusive' means that each result includes the corresponding + * input operand in the partial sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * \p inclusive_scan is similar to \c std::partial_sum in the STL. The primary + * difference between the two functions is that \c std::partial_sum guarantees + * a serial summation order, while \p inclusive_scan requires associativity of + * the binary operation to parallelize the prefix sum. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output Iterator + * and \c OutputIterator's \c value_type is convertible to + * both \c AssociativeOperator's \c first_argument_type and + * \c second_argument_type. + * \tparam AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan + * + * \code + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * + * thrust::maximum binary_op; + * + * thrust::inclusive_scan(data, data + 10, data, binary_op); // in-place scan + * + * // data is now {-5, 0, 2, 2, 2, 4, 4, 4, 4, 8} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +OutputIterator +inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, AssociativeOperator binary_op); + +/*! \p inclusive_scan computes an inclusive prefix sum operation. The + * term 'inclusive' means that each result includes the corresponding + * input operand in the partial sum. More precisely, + * binary_op(init, \*first) is assigned to *result + * and so on. This version of \p inclusive_scan requires both an associative + * operator and an initial value \p init. When the input and + * output sequences are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param init The initial value. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output Iterator + * and \c OutputIterator's \c value_type is convertible to both \c AssociativeOperator's \c first_argument_type and + * \c second_argument_type. + * \tparam T is convertible to \c OutputIterator's \c value_type. + * \tparam AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan with initial value to compute an in-place + * prefix sum using the \p thrust::host execution policy for parallelization: + * + * \code + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * thrust::inclusive_scan(thrust::host, data, data + 10, data, 1, thrust::maximum<>{}); // in-place scan + * // data is now {1, 1, 2, 2, 2, 4, 4, 4, 4, 8} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +_CCCL_HOST_DEVICE OutputIterator inclusive_scan( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + T init, + AssociativeOperator binary_op); + +/*! \p inclusive_scan computes an inclusive prefix sum operation. The + * term 'inclusive' means that each result includes the corresponding + * input operand in the partial sum. More precisely, + * binary_op(init, \*first) is assigned to *result + * and so on. This version of \p inclusive_scan requires both an associative + * operator and an initial value \p init. When the input and + * output sequences are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param init The initial value. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output Iterator + * and \c OutputIterator's \c value_type is convertible to both \c AssociativeOperator's \c first_argument_type and + * \c second_argument_type. + * \tparam T is convertible to \c OutputIterator's \c value_type. + * \tparam AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan with initial value: + * + * \code + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * thrust::maximum binary_op; + * thrust::inclusive_scan(data, data + 10, data, 1, thrust::maximum<>{}); // in-place scan + * // data is now {1, 1, 2, 2, 2, 4, 4, 4, 4, 8} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +OutputIterator +inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, AssociativeOperator binary_op); + +/*! \p exclusive_scan computes an exclusive prefix sum operation. The + * term 'exclusive' means that each result does not include the + * corresponding input operand in the partial sum. More precisely, + * 0 is assigned to *result and the sum of + * 0 and *first is assigned to *(result + 1), + * and so on. This version of \p exclusive_scan assumes plus as the + * associative operator and \c 0 as the initial value. When the input and + * output sequences are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output + * Iterator, and if \c x and \c y are objects of \c OutputIterator's \c value_type, then x + y is defined. + * If \c T is \c OutputIterator's \c value_type, then T(0) is defined. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan to compute an in-place + * prefix sum using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::exclusive_scan(thrust::host, data, data + 6, data); // in-place scan + * + * // data is now {0, 1, 1, 3, 5, 6} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +_CCCL_HOST_DEVICE OutputIterator exclusive_scan( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result); + +/*! \p exclusive_scan computes an exclusive prefix sum operation. The + * term 'exclusive' means that each result does not include the + * corresponding input operand in the partial sum. More precisely, + * 0 is assigned to *result and the sum of + * 0 and *first is assigned to *(result + 1), + * and so on. This version of \p exclusive_scan assumes plus as the + * associative operator and \c 0 as the initial value. When the input and + * output sequences are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output + * Iterator, and if \c x and \c y are objects of \c OutputIterator's \c value_type, then x + y is defined. + * If \c T is \c OutputIterator's \c value_type, then T(0) is defined. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan + * + * \code + * #include + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::exclusive_scan(data, data + 6, data); // in-place scan + * + * // data is now {0, 1, 1, 3, 5, 6} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result); + +/*! \p exclusive_scan computes an exclusive prefix sum operation. The + * term 'exclusive' means that each result does not include the + * corresponding input operand in the partial sum. More precisely, + * \p init is assigned to *result and the sum of \p init and + * *first is assigned to *(result + 1), and so on. + * This version of \p exclusive_scan assumes plus as the associative + * operator but requires an initial value \p init. When the input and + * output sequences are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param init The initial value. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output + * Iterator, and if \c x and \c y are objects of \c OutputIterator's \c value_type, then x + y is defined. + * \tparam T is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan to compute an in-place + * prefix sum using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::exclusive_scan(thrust::host, data, data + 6, data, 4); // in-place scan + * + * // data is now {4, 5, 5, 7, 9, 10} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +_CCCL_HOST_DEVICE OutputIterator exclusive_scan( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + T init); + +/*! \p exclusive_scan computes an exclusive prefix sum operation. The + * term 'exclusive' means that each result does not include the + * corresponding input operand in the partial sum. More precisely, + * \p init is assigned to *result and the sum of \p init and + * *first is assigned to *(result + 1), and so on. + * This version of \p exclusive_scan assumes plus as the associative + * operator but requires an initial value \p init. When the input and + * output sequences are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param init The initial value. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output + * Iterator, and if \c x and \c y are objects of \c OutputIterator's \c value_type, then x + y is defined. + * \tparam T is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan + * + * \code + * #include + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::exclusive_scan(data, data + 6, data, 4); // in-place scan + * + * // data is now {4, 5, 5, 7, 9, 10} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init); + +/*! \p exclusive_scan computes an exclusive prefix sum operation. The + * term 'exclusive' means that each result does not include the + * corresponding input operand in the partial sum. More precisely, + * \p init is assigned to \*result and the value + * binary_op(init, \*first) is assigned to \*(result + 1), + * and so on. This version of the function requires both an associative + * operator and an initial value \p init. When the input and output + * sequences are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param init The initial value. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output Iterator + * and \c OutputIterator's \c value_type is convertible to + * both \c AssociativeOperator's \c first_argument_type and + * \c second_argument_type. + * \tparam T is convertible to \c OutputIterator's \c value_type. + * \tparam AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan to compute an in-place + * prefix sum using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * + * thrust::maximum binary_op; + * + * thrust::exclusive_scan(thrust::host, data, data + 10, data, 1, binary_op); // in-place scan + * + * // data is now {1, 1, 1, 2, 2, 2, 4, 4, 4, 4 } + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +_CCCL_HOST_DEVICE OutputIterator exclusive_scan( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + T init, + AssociativeOperator binary_op); + +/*! \p exclusive_scan computes an exclusive prefix sum operation. The + * term 'exclusive' means that each result does not include the + * corresponding input operand in the partial sum. More precisely, + * \p init is assigned to \*result and the value + * binary_op(init, \*first) is assigned to \*(result + 1), + * and so on. This version of the function requires both an associative + * operator and an initial value \p init. When the input and output + * sequences are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param init The initial value. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam + * OutputIterator is a model of Output Iterator + * and \c OutputIterator's \c value_type is convertible to + * both \c AssociativeOperator's \c first_argument_type and + * \c second_argument_type. + * \tparam T is convertible to \c OutputIterator's \c value_type. + * \tparam AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result but the range [first, last) and the range + * [result, result + (last - first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan + * + * \code + * #include + * #include + * + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * + * thrust::maximum binary_op; + * + * thrust::exclusive_scan(data, data + 10, data, 1, binary_op); // in-place scan + * + * // data is now {1, 1, 1, 2, 2, 2, 4, 4, 4, 4 } + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/partial_sum + */ +template +OutputIterator +exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, AssociativeOperator binary_op); + +/*! \addtogroup segmentedprefixsums Segmented Prefix Sums + * \ingroup prefixsums + * \{ + */ + +/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix + * sum operation. The term 'inclusive' means that each result includes + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate inclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p inclusive_scan_by_key assumes \c equal_to as the binary + * predicate used to compare adjacent keys. Specifically, consecutive iterators + * i and i+1 in the range [first1, last1) + * belong to the same segment if *i == *(i+1), and belong to + * different segments otherwise. + * + * This version of \p inclusive_scan_by_key assumes \c plus as the associative + * operator used to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator \tparam InputIterator2 is a model of Input Iterator and \c InputIterator2's \c + * value_type is convertible to \c OutputIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator, and if \c x and \c y are + * objects of \c OutputIterator's \c value_type, then binary_op(x,y) is defined. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan_by_key using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * + * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * + * thrust::inclusive_scan_by_key(thrust::host, keys, keys + 10, data, data); // in-place scan + * + * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; + * \endcode + * + * \see inclusive_scan + * \see exclusive_scan_by_key + * + */ +template +_CCCL_HOST_DEVICE OutputIterator inclusive_scan_by_key( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result); + +/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix + * sum operation. The term 'inclusive' means that each result includes + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate inclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p inclusive_scan_by_key assumes \c equal_to as the binary + * predicate used to compare adjacent keys. Specifically, consecutive iterators + * i and i+1 in the range [first1, last1) + * belong to the same segment if *i == *(i+1), and belong to + * different segments otherwise. + * + * This version of \p inclusive_scan_by_key assumes \c plus as the associative + * operator used to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \return The end of the output sequence. + * + * \tparam InputIterator1 is a model of Input + * Iterator \tparam InputIterator2 is a model of Input Iterator and \c InputIterator2's \c + * value_type is convertible to \c OutputIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator, and if \c x and \c y are + * objects of \c OutputIterator's \c value_type, then binary_op(x,y) is defined. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan_by_key + * + * \code + * #include + * + * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * + * thrust::inclusive_scan_by_key(keys, keys + 10, data, data); // in-place scan + * + * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; + * \endcode + * + * \see inclusive_scan + * \see exclusive_scan_by_key + * + */ +template +OutputIterator +inclusive_scan_by_key(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result); + +/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix + * sum operation. The term 'inclusive' means that each result includes + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate inclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p inclusive_scan_by_key uses the binary predicate + * \c pred to compare adjacent keys. Specifically, consecutive iterators + * i and i+1 in the range [first1, last1) + * belong to the same segment if binary_pred(*i, *(i+1)) is true, and belong to + * different segments otherwise. + * + * This version of \p inclusive_scan_by_key assumes \c plus as the associative + * operator used to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param binary_pred The binary predicate used to determine equality of keys. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator \tparam InputIterator2 is a model of Input Iterator and \c InputIterator2's \c + * value_type is convertible to \c OutputIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator, and if \c x and \c y are + * objects of \c OutputIterator's \c value_type, then binary_op(x,y) is defined. \tparam BinaryPredicate is a + * model of Binary Predicate. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan_by_key using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * + * thrust::equal_to binary_pred; + * + * thrust::inclusive_scan_by_key(thrust::host, keys, keys + 10, data, data, binary_pred); // in-place scan + * + * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; + * \endcode + * + * \see inclusive_scan + * \see exclusive_scan_by_key + * + */ +template +_CCCL_HOST_DEVICE OutputIterator inclusive_scan_by_key( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + BinaryPredicate binary_pred); + +/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix + * sum operation. The term 'inclusive' means that each result includes + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate inclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p inclusive_scan_by_key uses the binary predicate + * \c pred to compare adjacent keys. Specifically, consecutive iterators + * i and i+1 in the range [first1, last1) + * belong to the same segment if binary_pred(*i, *(i+1)) is true, and belong to + * different segments otherwise. + * + * This version of \p inclusive_scan_by_key assumes \c plus as the associative + * operator used to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param binary_pred The binary predicate used to determine equality of keys. + * \return The end of the output sequence. + * + * \tparam InputIterator1 is a model of Input + * Iterator \tparam InputIterator2 is a model of Input Iterator and \c InputIterator2's \c + * value_type is convertible to \c OutputIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator, and if \c x and \c y are + * objects of \c OutputIterator's \c value_type, then binary_op(x,y) is defined. \tparam BinaryPredicate is a + * model of Binary Predicate. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan_by_key + * + * \code + * #include + * #include + * + * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * + * thrust::equal_to binary_pred; + * + * thrust::inclusive_scan_by_key(keys, keys + 10, data, data, binary_pred); // in-place scan + * + * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; + * \endcode + * + * \see inclusive_scan + * \see exclusive_scan_by_key + * + */ +template +OutputIterator inclusive_scan_by_key( + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + BinaryPredicate binary_pred); + +/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix + * sum operation. The term 'inclusive' means that each result includes + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate inclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p inclusive_scan_by_key uses the binary predicate + * \c pred to compare adjacent keys. Specifically, consecutive iterators + * i and i+1 in the range [first1, last1) + * belong to the same segment if binary_pred(*i, *(i+1)) is true, and belong to + * different segments otherwise. + * + * This version of \p inclusive_scan_by_key uses the associative operator + * \c binary_op to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param binary_pred The binary predicate used to determine equality of keys. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator \tparam InputIterator2 is a model of Input Iterator and \c InputIterator2's \c + * value_type is convertible to \c OutputIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator, and if \c x and \c y are + * objects of \c OutputIterator's \c value_type, then binary_op(x,y) is defined. \tparam BinaryPredicate is a + * model of Binary Predicate. \tparam + * AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan_by_key using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * + * thrust::equal_to binary_pred; + * thrust::plus binary_op; + * + * thrust::inclusive_scan_by_key(thrust::host, keys, keys + 10, data, data, binary_pred, binary_op); // in-place scan + * + * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; + * \endcode + * + * \see inclusive_scan + * \see exclusive_scan_by_key + * + */ +template +_CCCL_HOST_DEVICE OutputIterator inclusive_scan_by_key( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + BinaryPredicate binary_pred, + AssociativeOperator binary_op); + +/*! \p inclusive_scan_by_key computes an inclusive key-value or 'segmented' prefix + * sum operation. The term 'inclusive' means that each result includes + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate inclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p inclusive_scan_by_key uses the binary predicate + * \c pred to compare adjacent keys. Specifically, consecutive iterators + * i and i+1 in the range [first1, last1) + * belong to the same segment if binary_pred(*i, *(i+1)) is true, and belong to + * different segments otherwise. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * This version of \p inclusive_scan_by_key uses the associative operator + * \c binary_op to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param binary_pred The binary predicate used to determine equality of keys. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam InputIterator1 is a model of Input + * Iterator \tparam InputIterator2 is a model of Input Iterator and \c InputIterator2's \c + * value_type is convertible to \c OutputIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator, and if \c x and \c y are + * objects of \c OutputIterator's \c value_type, then binary_op(x,y) is defined. \tparam BinaryPredicate is a + * model of Binary Predicate. \tparam + * AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p inclusive_scan_by_key + * + * \code + * #include + * #include + * + * int data[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * + * thrust::equal_to binary_pred; + * thrust::plus binary_op; + * + * thrust::inclusive_scan_by_key(keys, keys + 10, data, data, binary_pred, binary_op); // in-place scan + * + * // data is now {1, 2, 3, 1, 2, 1, 1, 2, 3, 4}; + * \endcode + * + * \see inclusive_scan + * \see exclusive_scan_by_key + * + */ +template +OutputIterator inclusive_scan_by_key( + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + BinaryPredicate binary_pred, + AssociativeOperator binary_op); + +/*! \p exclusive_scan_by_key computes an exclusive segmented prefix + * + * This version of \p exclusive_scan_by_key uses the value \c 0 to + * initialize the exclusive scan operation. + * + * This version of \p exclusive_scan_by_key assumes \c plus as the associative + * operator used to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * This version of \p exclusive_scan_by_key assumes \c equal_to as the binary + * predicate used to compare adjacent keys. Specifically, consecutive iterators + * i and i+1 in the range [first1, last1 + * belong to the same segment if *i == *(i+1), and belong to + * different segments otherwise. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * Refer to the most general form of \p exclusive_scan_by_key for additional details. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan_by_key using the + * \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * + * thrust::exclusive_scan_by_key(thrust::host, key, key + 10, vals, vals); // in-place scan + * + * // vals is now {0, 1, 2, 0, 1, 0, 0, 1, 2, 3}; + * \endcode + * + * \see exclusive_scan + * + */ +template +_CCCL_HOST_DEVICE OutputIterator exclusive_scan_by_key( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result); + +/*! \p exclusive_scan_by_key computes an exclusive segmented prefix + * + * This version of \p exclusive_scan_by_key uses the value \c 0 to + * initialize the exclusive scan operation. + * + * This version of \p exclusive_scan_by_key assumes \c plus as the associative + * operator used to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * This version of \p exclusive_scan_by_key assumes \c equal_to as the binary + * predicate used to compare adjacent keys. Specifically, consecutive iterators + * i and i+1 in the range [first1, last1 + * belong to the same segment if *i == *(i+1), and belong to + * different segments otherwise. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * Refer to the most general form of \p exclusive_scan_by_key for additional details. + * + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan_by_key. + * + * \code + * #include + * + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * + * thrust::exclusive_scan_by_key(key, key + 10, vals, vals); // in-place scan + * + * // vals is now {0, 1, 2, 0, 1, 0, 0, 1, 2, 3}; + * \endcode + * + * \see exclusive_scan + * + */ +template +OutputIterator +exclusive_scan_by_key(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result); + +/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix + * sum operation. The term 'exclusive' means that each result does not include + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate exclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p exclusive_scan_by_key uses the value \c init to + * initialize the exclusive scan operation. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param init The initial of the exclusive sum value. + * \return The end of the output sequence. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan_by_key using the \p + * thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * + * int init = 5; + * + * thrust::exclusive_scan_by_key(thrust::host, key, key + 10, vals, vals, init); // in-place scan + * + * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; + * \endcode + * + * \see exclusive_scan + * \see inclusive_scan_by_key + * + */ +template +_CCCL_HOST_DEVICE OutputIterator exclusive_scan_by_key( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + T init); + +/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix + * sum operation. The term 'exclusive' means that each result does not include + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate exclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p exclusive_scan_by_key uses the value \c init to + * initialize the exclusive scan operation. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param init The initial of the exclusive sum value. + * \return The end of the output sequence. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan_by_key + * + * \code + * #include + * #include + * + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * + * int init = 5; + * + * thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init); // in-place scan + * + * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; + * \endcode + * + * \see exclusive_scan + * \see inclusive_scan_by_key + * + */ +template +OutputIterator exclusive_scan_by_key( + InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, T init); + +/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix + * sum operation. The term 'exclusive' means that each result does not include + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate exclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p exclusive_scan_by_key uses the value \c init to + * initialize the exclusive scan operation. + * + * This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred + * to compare adjacent keys. Specifically, consecutive iterators i and + * i+1 in the range [first1, last1) belong to the same segment if + * binary_pred(*i, *(i+1)) is true, and belong to different segments otherwise. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param init The initial of the exclusive sum value. + * \param binary_pred The binary predicate used to determine equality of keys. + * \return The end of the output sequence. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan_by_key using the + * \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * + * int init = 5; + * + * thrust::equal_to binary_pred; + * + * thrust::exclusive_scan_by_key(thrust::host, key, key + 10, vals, vals, init, binary_pred); // in-place scan + * + * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; + * \endcode + * + * \see exclusive_scan + * \see inclusive_scan_by_key + * + */ +template +_CCCL_HOST_DEVICE OutputIterator exclusive_scan_by_key( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + T init, + BinaryPredicate binary_pred); + +/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix + * sum operation. The term 'exclusive' means that each result does not include + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate exclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p exclusive_scan_by_key uses the value \c init to + * initialize the exclusive scan operation. + * + * This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred + * to compare adjacent keys. Specifically, consecutive iterators i and + * i+1 in the range [first1, last1) belong to the same segment if + * binary_pred(*i, *(i+1)) is true, and belong to different segments otherwise. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param init The initial of the exclusive sum value. + * \param binary_pred The binary predicate used to determine equality of keys. + * \return The end of the output sequence. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan_by_key + * + * \code + * #include + * #include + * + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * + * int init = 5; + * + * thrust::equal_to binary_pred; + * + * thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init, binary_pred); // in-place scan + * + * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; + * \endcode + * + * \see exclusive_scan + * \see inclusive_scan_by_key + * + */ +template +OutputIterator exclusive_scan_by_key( + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + T init, + BinaryPredicate binary_pred); + +/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix + * sum operation. The term 'exclusive' means that each result does not include + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate exclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p exclusive_scan_by_key uses the value \c init to + * initialize the exclusive scan operation. + * + * This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred + * to compare adjacent keys. Specifically, consecutive iterators i and + * i+1 in the range [first1, last1) belong to the same segment if + * binary_pred(*i, *(i+1)) is true, and belong to different segments otherwise. + * + * This version of \p exclusive_scan_by_key uses the associative operator + * \c binary_op to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param init The initial of the exclusive sum value. + * \param binary_pred The binary predicate used to determine equality of keys. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator \tparam InputIterator2 is a model of Input Iterator and \c InputIterator2's \c + * value_type is convertible to \c OutputIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator, and if \c x and \c y are + * objects of \c OutputIterator's \c value_type, then binary_op(x,y) is defined. \tparam T is convertible to \c + * OutputIterator's \c value_type. \tparam BinaryPredicate is a model of Binary Predicate. \tparam AssociativeOperator + * is a model of Binary Function and + * \c AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan_by_key using the + * \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * + * int init = 5; + * + * thrust::equal_to binary_pred; + * thrust::plus binary_op; + * + * thrust::exclusive_scan_by_key(thrust::host, key, key + 10, vals, vals, init, binary_pred, binary_op); // in-place + * scan + * + * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; + * \endcode + * + * \see exclusive_scan + * \see inclusive_scan_by_key + * + */ +template +_CCCL_HOST_DEVICE OutputIterator exclusive_scan_by_key( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + T init, + BinaryPredicate binary_pred, + AssociativeOperator binary_op); + +/*! \p exclusive_scan_by_key computes an exclusive key-value or 'segmented' prefix + * sum operation. The term 'exclusive' means that each result does not include + * the corresponding input operand in the partial sum. The term 'segmented' + * means that the partial sums are broken into distinct segments. In other + * words, within each segment a separate exclusive scan operation is computed. + * Refer to the code sample below for example usage. + * + * This version of \p exclusive_scan_by_key uses the value \c init to + * initialize the exclusive scan operation. + * + * This version of \p exclusive_scan_by_key uses the binary predicate \c binary_pred + * to compare adjacent keys. Specifically, consecutive iterators i and + * i+1 in the range [first1, last1) belong to the same segment if + * binary_pred(*i, *(i+1)) is true, and belong to different segments otherwise. + * + * This version of \p exclusive_scan_by_key uses the associative operator + * \c binary_op to perform the prefix sum. When the input and output sequences + * are the same, the scan is performed in-place. + * + * Results are not deterministic for pseudo-associative operators (e.g., + * addition of floating-point types). Results for pseudo-associative + * operators may vary from run to run. + * + * \param first1 The beginning of the key sequence. + * \param last1 The end of the key sequence. + * \param first2 The beginning of the input value sequence. + * \param result The beginning of the output value sequence. + * \param init The initial of the exclusive sum value. + * \param binary_pred The binary predicate used to determine equality of keys. + * \param binary_op The associative operator used to 'sum' values. + * \return The end of the output sequence. + * + * \tparam InputIterator1 is a model of Input + * Iterator \tparam InputIterator2 is a model of Input Iterator and \c InputIterator2's \c + * value_type is convertible to \c OutputIterator's \c value_type. \tparam OutputIterator is a model of Output Iterator, and if \c x and \c y are + * objects of \c OutputIterator's \c value_type, then binary_op(x,y) is defined. \tparam T is convertible to \c + * OutputIterator's \c value_type. \tparam BinaryPredicate is a model of Binary Predicate. \tparam AssociativeOperator + * is a model of Binary Function and + * \c AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first1 may equal \p result but the range [first1, last1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * \pre \p first2 may equal \p result but the range [first2, first2 + (last1 - first1) and the range + * [result, result + (last1 - first1)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p exclusive_scan_by_key + * + * \code + * #include + * #include + * + * int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; + * int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + * + * int init = 5; + * + * thrust::equal_to binary_pred; + * thrust::plus binary_op; + * + * thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init, binary_pred, binary_op); // in-place scan + * + * // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8}; + * \endcode + * + * \see exclusive_scan + * \see inclusive_scan_by_key + * + */ +template +OutputIterator exclusive_scan_by_key( + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + T init, + BinaryPredicate binary_pred, + AssociativeOperator binary_op); + +/*! \} // end segmentedprefixsums + */ + +/*! \} // end prefix sums + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/scatter.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/scatter.h new file mode 100644 index 0000000000000000000000000000000000000000..de46c812fb45949666da2d738ae0f35a8ed1f7f0 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/scatter.h @@ -0,0 +1,446 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file scatter.h + * \brief Irregular copying to a destination range + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup scattering + * \ingroup copying + * \{ + */ + +/*! \p scatter copies elements from a source range into an output array + * according to a map. For each iterator \c i in the range [\p first, \p last), + * the value \c *i is assigned to output[*(map + (i - first))]. The + * output iterator must permit random access. If the same index + * appears more than once in the range [map, map + (last - first)), + * the result is undefined. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first Beginning of the sequence of values to scatter. + * \param last End of the sequence of values to scatter. + * \param map Beginning of the sequence of output indices. + * \param result Destination of the source elements. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 must be a model of Input + * Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. + * \tparam InputIterator2 must be a model of Input + * Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c + * difference_type. \tparam RandomAccessIterator must be a model of Random Access iterator. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[map, map + (last - first))` for all iterators `i` in the range `[map, map + (last - first))`. + * + * \pre The expression `result[*i]` shall be valid for all iterators in the range `[map, map + (last - first))`. + * + * The following code snippet demonstrates how to use \p scatter to reorder a range using + * the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * // mark even indices with a 1; odd indices with a 0 + * int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; + * thrust::device_vector d_values(values, values + 10); + * + * // scatter all even indices into the first half of the + * // range, and odd indices vice versa + * int map[10] = {0, 5, 1, 6, 2, 7, 3, 8, 4, 9}; + * thrust::device_vector d_map(map, map + 10); + * + * thrust::device_vector d_output(10); + * thrust::scatter(thrust::device, + * d_values.begin(), d_values.end(), + * d_map.begin(), d_output.begin()); + * // d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} + * \endcode + * + * \note \p scatter is the inverse of thrust::gather. + */ +template +_CCCL_HOST_DEVICE void +scatter(const thrust::detail::execution_policy_base& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 map, + RandomAccessIterator result); + +/*! \p scatter copies elements from a source range into an output array + * according to a map. For each iterator \c i in the range [\p first, \p last), + * the value \c *i is assigned to output[*(map + (i - first))]. The + * output iterator must permit random access. If the same index + * appears more than once in the range [map, map + (last - first)), + * the result is undefined. + * + * \param first Beginning of the sequence of values to scatter. + * \param last End of the sequence of values to scatter. + * \param map Beginning of the sequence of output indices. + * \param result Destination of the source elements. + * + * \tparam InputIterator1 must be a model of Input + * Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. + * \tparam InputIterator2 must be a model of Input + * Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c + * difference_type. \tparam RandomAccessIterator must be a model of Random Access iterator. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The expression `result[*i]` shall be valid for all iterators in the range `[map,map + (last - first))`. + * + * The following code snippet demonstrates how to use \p scatter to reorder a range. + * + * \code + * #include + * #include + * ... + * // mark even indices with a 1; odd indices with a 0 + * int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; + * thrust::device_vector d_values(values, values + 10); + * + * // scatter all even indices into the first half of the + * // range, and odd indices vice versa + * int map[10] = {0, 5, 1, 6, 2, 7, 3, 8, 4, 9}; + * thrust::device_vector d_map(map, map + 10); + * + * thrust::device_vector d_output(10); + * thrust::scatter(d_values.begin(), d_values.end(), + * d_map.begin(), d_output.begin()); + * // d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} + * \endcode + * + * \note \p scatter is the inverse of thrust::gather. + */ +template +void scatter(InputIterator1 first, InputIterator1 last, InputIterator2 map, RandomAccessIterator result); + +/*! \p scatter_if conditionally copies elements from a source range into an + * output array according to a map. For each iterator \c i in the + * range [first, last) such that *(stencil + (i - first)) is + * true, the value \c *i is assigned to output[*(map + (i - first))]. + * The output iterator must permit random access. If the same index + * appears more than once in the range [map, map + (last - first)) + * the result is undefined. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first Beginning of the sequence of values to scatter. + * \param last End of the sequence of values to scatter. + * \param map Beginning of the sequence of output indices. + * \param stencil Beginning of the sequence of predicate values. + * \param output Beginning of the destination range. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 must be a model of Input + * Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. + * \tparam InputIterator2 must be a model of Input + * Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c + * difference_type. \tparam InputIterator3 must be a model of Input Iterator and \c InputIterator3's \c + * value_type must be convertible to \c bool. \tparam RandomAccessIterator must be a model of Random Access iterator. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for + * which the following condition holds: `*(stencil + i) != false`. + * + * \code + * #include + * #include + * ... + * int V[8] = {10, 20, 30, 40, 50, 60, 70, 80}; + * int M[8] = {0, 5, 1, 6, 2, 7, 3, 4}; + * int S[8] = {1, 0, 1, 0, 1, 0, 1, 0}; + * int D[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + * + * thrust::scatter_if(thrust::host, V, V + 8, M, S, D); + * + * // D contains [10, 30, 50, 70, 0, 0, 0, 0]; + * \endcode + * + * \note \p scatter_if is the inverse of thrust::gather_if. + */ +template +_CCCL_HOST_DEVICE void scatter_if( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 map, + InputIterator3 stencil, + RandomAccessIterator output); + +/*! \p scatter_if conditionally copies elements from a source range into an + * output array according to a map. For each iterator \c i in the + * range [first, last) such that *(stencil + (i - first)) is + * true, the value \c *i is assigned to output[*(map + (i - first))]. + * The output iterator must permit random access. If the same index + * appears more than once in the range [map, map + (last - first)) + * the result is undefined. + * + * \param first Beginning of the sequence of values to scatter. + * \param last End of the sequence of values to scatter. + * \param map Beginning of the sequence of output indices. + * \param stencil Beginning of the sequence of predicate values. + * \param output Beginning of the destination range. + * + * \tparam InputIterator1 must be a model of Input + * Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. + * \tparam InputIterator2 must be a model of Input + * Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c + * difference_type. \tparam InputIterator3 must be a model of Input Iterator and \c InputIterator3's \c + * value_type must be convertible to \c bool. \tparam RandomAccessIterator must be a model of Random Access iterator. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for + * which the following condition holds: `*(stencil + i) != false`. + * + * \code + * #include + * ... + * int V[8] = {10, 20, 30, 40, 50, 60, 70, 80}; + * int M[8] = {0, 5, 1, 6, 2, 7, 3, 4}; + * int S[8] = {1, 0, 1, 0, 1, 0, 1, 0}; + * int D[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + * + * thrust::scatter_if(V, V + 8, M, S, D); + * + * // D contains [10, 30, 50, 70, 0, 0, 0, 0]; + * \endcode + * + * \note \p scatter_if is the inverse of thrust::gather_if. + */ +template +void scatter_if( + InputIterator1 first, InputIterator1 last, InputIterator2 map, InputIterator3 stencil, RandomAccessIterator output); + +/*! \p scatter_if conditionally copies elements from a source range into an + * output array according to a map. For each iterator \c i in the + * range [first, last) such that pred(*(stencil + (i - first))) is + * \c true, the value \c *i is assigned to output[*(map + (i - first))]. + * The output iterator must permit random access. If the same index + * appears more than once in the range [map, map + (last - first)) + * the result is undefined. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first Beginning of the sequence of values to scatter. + * \param last End of the sequence of values to scatter. + * \param map Beginning of the sequence of output indices. + * \param stencil Beginning of the sequence of predicate values. + * \param output Beginning of the destination range. + * \param pred Predicate to apply to the stencil values. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 must be a model of Input + * Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. + * \tparam InputIterator2 must be a model of Input + * Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c + * difference_type. \tparam InputIterator3 must be a model of Input Iterator and \c InputIterator3's \c + * value_type must be convertible to \c Predicate's \c argument_type. \tparam RandomAccessIterator must be a model of Random Access iterator. \tparam + * Predicate must be a model of Predicate. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for + * which the following condition holds: `pred(*(stencil + i)) != false`. + * + * \code + * #include + * #include + * + * struct is_even + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return (x % 2) == 0; + * } + * }; + * + * ... + * + * int V[8] = {10, 20, 30, 40, 50, 60, 70, 80}; + * int M[8] = {0, 5, 1, 6, 2, 7, 3, 4}; + * int S[8] = {2, 1, 2, 1, 2, 1, 2, 1}; + * int D[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + * + * is_even pred; + * thrust::scatter_if(thrust::host, V, V + 8, M, S, D, pred); + * + * // D contains [10, 30, 50, 70, 0, 0, 0, 0]; + * \endcode + * + * \note \p scatter_if is the inverse of thrust::gather_if. + */ +template +_CCCL_HOST_DEVICE void scatter_if( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 map, + InputIterator3 stencil, + RandomAccessIterator output, + Predicate pred); + +/*! \p scatter_if conditionally copies elements from a source range into an + * output array according to a map. For each iterator \c i in the + * range [first, last) such that pred(*(stencil + (i - first))) is + * \c true, the value \c *i is assigned to output[*(map + (i - first))]. + * The output iterator must permit random access. If the same index + * appears more than once in the range [map, map + (last - first)) + * the result is undefined. + * + * \param first Beginning of the sequence of values to scatter. + * \param last End of the sequence of values to scatter. + * \param map Beginning of the sequence of output indices. + * \param stencil Beginning of the sequence of predicate values. + * \param output Beginning of the destination range. + * \param pred Predicate to apply to the stencil values. + * + * \tparam InputIterator1 must be a model of Input + * Iterator and \c InputIterator1's \c value_type must be convertible to \c RandomAccessIterator's \c value_type. + * \tparam InputIterator2 must be a model of Input + * Iterator and \c InputIterator2's \c value_type must be convertible to \c RandomAccessIterator's \c + * difference_type. \tparam InputIterator3 must be a model of Input Iterator and \c InputIterator3's \c + * value_type must be convertible to \c Predicate's \c argument_type. \tparam RandomAccessIterator must be a model of Random Access iterator. \tparam + * Predicate must be a model of Predicate. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[first,last)` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[map,map + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The iterator `result + i` shall not refer to any element referenced by any iterator `j` in the range + * `[stencil,stencil + (last - first))` for all iterators `i` in the range `[map,map + (last - first))`. + * + * \pre The expression `result[*i]` shall be valid for all iterators `i` in the range `[map,map + (last - first))` for + * which the following condition holds: `pred(*(stencil + i)) != false`. + * + * \code + * #include + * + * struct is_even + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return (x % 2) == 0; + * } + * }; + * + * ... + * + * int V[8] = {10, 20, 30, 40, 50, 60, 70, 80}; + * int M[8] = {0, 5, 1, 6, 2, 7, 3, 4}; + * int S[8] = {2, 1, 2, 1, 2, 1, 2, 1}; + * int D[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + * + * is_even pred; + * thrust::scatter_if(V, V + 8, M, S, D, pred); + * + * // D contains [10, 30, 50, 70, 0, 0, 0, 0]; + * \endcode + * + * \note \p scatter_if is the inverse of thrust::gather_if. + */ +template +void scatter_if(InputIterator1 first, + InputIterator1 last, + InputIterator2 map, + InputIterator3 stencil, + RandomAccessIterator output, + Predicate pred); + +/*! \} // end scattering + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/sequence.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/sequence.h new file mode 100644 index 0000000000000000000000000000000000000000..91c11904f68393187ec9cb9d06a32f1d6612b67f --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/sequence.h @@ -0,0 +1,277 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file sequence.h + * \brief Fills a range with a sequence of numbers + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup transformations + * \{ + */ + +/*! \p sequence fills the range [first, last) with a sequence of numbers. + * + * For each iterator \c i in the range [first, last), this version of + * \p sequence performs the assignment *i = (i - first). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and if \c x and \c y are objects of \c ForwardIterator's \c + * value_type, then x + y is defined, and if \c T is \p ForwardIterator's \c value_type, then T(0) is + * defined. + * + * The following code snippet demonstrates how to use \p sequence to fill a range + * with a sequence of numbers using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 10; + * int A[N]; + * thrust::sequence(thrust::host, A, A + 10); + * // A is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} + * \endcode + * + * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no + * guarantee on order of execution. + * + * \see https://en.cppreference.com/w/cpp/algorithm/iota + */ +template +_CCCL_HOST_DEVICE void +sequence(const thrust::detail::execution_policy_base& exec, ForwardIterator first, ForwardIterator last); + +/*! \p sequence fills the range [first, last) with a sequence of numbers. + * + * For each iterator \c i in the range [first, last), this version of + * \p sequence performs the assignment *i = (i - first). + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and if \c x and \c y are objects of \c ForwardIterator's \c + * value_type, then x + y is defined, and if \c T is \p ForwardIterator's \c value_type, then T(0) is + * defined. + * + * The following code snippet demonstrates how to use \p sequence to fill a range + * with a sequence of numbers. + * + * \code + * #include + * ... + * const int N = 10; + * int A[N]; + * thrust::sequence(A, A + 10); + * // A is now {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} + * \endcode + * + * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no + * guarantee on order of execution. + * + * \see https://en.cppreference.com/w/cpp/algorithm/iota + */ +template +void sequence(ForwardIterator first, ForwardIterator last); + +/*! \p sequence fills the range [first, last) with a sequence of numbers. + * + * For each iterator \c i in the range [first, last), this version of + * \p sequence performs the assignment *i = init + (i - first). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param init The first value of the sequence of numbers. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and if \c x and \c y are objects of \c ForwardIterator's \c + * value_type, then x + y is defined, and if \c T is \p ForwardIterator's \c value_type, then T(0) is + * defined. \tparam T is a model of Assignable, + * and \p T is convertible to \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p sequence to fill a range + * with a sequence of numbers starting from the value 1 using the \p thrust::host execution + * policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 10; + * int A[N]; + * thrust::sequence(thrust::host, A, A + 10, 1); + * // A is now {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * \endcode + * + * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no + * guarantee on order of execution. + * + * \see https://en.cppreference.com/w/cpp/algorithm/iota + */ +template +_CCCL_HOST_DEVICE void sequence( + const thrust::detail::execution_policy_base& exec, ForwardIterator first, ForwardIterator last, T init); + +/*! \p sequence fills the range [first, last) with a sequence of numbers. + * + * For each iterator \c i in the range [first, last), this version of + * \p sequence performs the assignment *i = init + (i - first). + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param init The first value of the sequence of numbers. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and if \c x and \c y are objects of \c ForwardIterator's \c + * value_type, then x + y is defined, and if \c T is \p ForwardIterator's \c value_type, then T(0) is + * defined. \tparam T is a model of Assignable, + * and \p T is convertible to \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p sequence to fill a range + * with a sequence of numbers starting from the value 1. + * + * \code + * #include + * ... + * const int N = 10; + * int A[N]; + * thrust::sequence(A, A + 10, 1); + * // A is now {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + * \endcode + * + * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no + * guarantee on order of execution. + * + * \see https://en.cppreference.com/w/cpp/algorithm/iota + */ +template +void sequence(ForwardIterator first, ForwardIterator last, T init); + +/*! \p sequence fills the range [first, last) with a sequence of numbers. + * + * For each iterator \c i in the range [first, last), this version of + * \p sequence performs the assignment *i = init + step * (i - first). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param init The first value of the sequence of numbers + * \param step The difference between consecutive elements. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and if \c x and \c y are objects of \c ForwardIterator's \c + * value_type, then x + y is defined, and if \c T is \p ForwardIterator's \c value_type, then T(0) is + * defined. \tparam T is a model of Assignable, + * and \p T is convertible to \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p sequence to fill a range + * with a sequence of numbers starting from the value 1 with a step size of 3 using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 10; + * int A[N]; + * thrust::sequence(thrust::host, A, A + 10, 1, 3); + * // A is now {1, 4, 7, 10, 13, 16, 19, 22, 25, 28} + * \endcode + * + * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no + * guarantee on order of execution. + * + * \see https://en.cppreference.com/w/cpp/algorithm/iota + */ +template +_CCCL_HOST_DEVICE void sequence( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + T init, + T step); + +/*! \p sequence fills the range [first, last) with a sequence of numbers. + * + * For each iterator \c i in the range [first, last), this version of + * \p sequence performs the assignment *i = init + step * (i - first). + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param init The first value of the sequence of numbers + * \param step The difference between consecutive elements. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and if \c x and \c y are objects of \c ForwardIterator's \c + * value_type, then x + y is defined, and if \c T is \p ForwardIterator's \c value_type, then T(0) is + * defined. \tparam T is a model of Assignable, + * and \p T is convertible to \p ForwardIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p sequence to fill a range + * with a sequence of numbers starting from the value 1 with a step size of 3. + * + * \code + * #include + * ... + * const int N = 10; + * int A[N]; + * thrust::sequence(A, A + 10, 1, 3); + * // A is now {1, 4, 7, 10, 13, 16, 19, 22, 25, 28} + * \endcode + * + * \note Unlike the similar C++ STL function \c std::iota, \p sequence offers no + * guarantee on order of execution. + * + * \see https://en.cppreference.com/w/cpp/algorithm/iota + */ +template +void sequence(ForwardIterator first, ForwardIterator last, T init, T step); + +/*! \} // end transformations + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/shuffle.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/shuffle.h new file mode 100644 index 0000000000000000000000000000000000000000..30ec9130f5fe916747c7cfb891d53ee13eee1969 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/shuffle.h @@ -0,0 +1,182 @@ +/* + * Copyright 2008-2020 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file shuffle.h + * \brief Reorders range by a uniform random permutation + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup reordering + * \ingroup algorithms + * + * \addtogroup shuffling + * \ingroup reordering + * \{ + */ + +/*! \p shuffle reorders the elements [first, last) by a uniform pseudorandom permutation, defined by + * random engine \p g. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence to shuffle. + * \param last The end of the sequence to shuffle. + * \param g A UniformRandomBitGenerator + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomIterator is a random access iterator + * \tparam URBG is a uniform random bit generator + * + * The following code snippet demonstrates how to use \p shuffle to create a random permutation + * using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::default_random_engine g; + * thrust::shuffle(thrust::host, A, A + N, g); + * // A is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9} + * \endcode + * + * \see \p shuffle_copy + */ +template +_CCCL_HOST_DEVICE void shuffle( + const thrust::detail::execution_policy_base& exec, RandomIterator first, RandomIterator last, URBG&& g); + +/*! \p shuffle reorders the elements [first, last) by a uniform pseudorandom permutation, defined by + * random engine \p g. + * + * \param first The beginning of the sequence to shuffle. + * \param last The end of the sequence to shuffle. + * \param g A UniformRandomBitGenerator + * + * \tparam RandomIterator is a random access iterator + * \tparam URBG is a uniform random bit generator + * + * The following code snippet demonstrates how to use \p shuffle to create a random permutation. + * + * \code + * #include + * #include + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * const int N = sizeof(A)/sizeof(int); + * thrust::default_random_engine g; + * thrust::shuffle(A, A + N, g); + * // A is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9} + * \endcode + * + * \see \p shuffle_copy + */ +template +_CCCL_HOST_DEVICE void shuffle(RandomIterator first, RandomIterator last, URBG&& g); + +/*! shuffle_copy differs from shuffle only in that the reordered sequence is written to different output sequences, + rather than in place. + * \p shuffle_copy reorders the elements [first, last) by a uniform pseudorandom permutation, defined by + * random engine \p g. + * + * The algorithm's execution is parallelized as determined by \p exec. + + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence to shuffle. + * \param last The end of the sequence to shuffle. + * \param result Destination of shuffled sequence + * \param g A UniformRandomBitGenerator + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomIterator is a random access iterator + * \tparam OutputIterator is a model of Output + Iterator. + * \tparam URBG is a uniform random bit generator + * + * The following code snippet demonstrates how to use \p shuffle_copy to create a random permutation. + * + * \code + * #include + * #include + * #include + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * thrust::default_random_engine g; + * thrust::shuffle_copy(thrust::host, A, A + N, result, g); + * // result is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9} + * \endcode + * + * \see \p shuffle + */ +template +_CCCL_HOST_DEVICE void shuffle_copy( + const thrust::detail::execution_policy_base& exec, + RandomIterator first, + RandomIterator last, + OutputIterator result, + URBG&& g); + +/*! shuffle_copy differs from shuffle only in that the reordered sequence is written to different output sequences, + *rather than in place. \p shuffle_copy reorders the elements [first, last) by a uniform pseudorandom + *permutation, defined by random engine \p g. + * + * \param first The beginning of the sequence to shuffle. + * \param last The end of the sequence to shuffle. + * \param result Destination of shuffled sequence + * \param g A UniformRandomBitGenerator + * + * \tparam RandomIterator is a random access iterator + * \tparam OutputIterator is a model of Output + *Iterator. \tparam URBG is a uniform random bit generator + * + * The following code snippet demonstrates how to use \p shuffle_copy to create a random permutation. + * + * \code + * #include + * #include + * int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * int result[10]; + * const int N = sizeof(A)/sizeof(int); + * thrust::default_random_engine g; + * thrust::shuffle_copy(A, A + N, result, g); + * // result is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9} + * \endcode + * + * \see \p shuffle + */ +template +_CCCL_HOST_DEVICE void shuffle_copy(RandomIterator first, RandomIterator last, OutputIterator result, URBG&& g); + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/sort.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/sort.h new file mode 100644 index 0000000000000000000000000000000000000000..61c968fec72c74f3590e4b07ccbf8f7f04f650ab --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/sort.h @@ -0,0 +1,1319 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file thrust/sort.h + * \brief Functions for reorganizing ranges into sorted order + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup sorting + * \ingroup algorithms + * \{ + */ + +/*! \p sort sorts the elements in [first, last) into + * ascending order, meaning that if \c i and \c j are any two valid + * iterators in [first, last) such that \c i precedes \c j, + * then \c *j is not less than \c *i. Note: \c sort is not guaranteed + * to be stable. That is, suppose that \c *i and \c *j are equivalent: + * neither one is less than the other. It is not guaranteed that the + * relative order of these two elements will be preserved by \p sort. + * + * This version of \p sort compares objects using \c operator<. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomAccessIterator is a model of Random Access Iterator, \p + * RandomAccessIterator is mutable, and \p RandomAccessIterator's \c value_type is a model of LessThan Comparable, and the ordering + * relation on \p RandomAccessIterator's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. + * + * The following code snippet demonstrates how to use \p sort to sort + * a sequence of integers using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * thrust::sort(thrust::host, A, A + N); + * // A is now {1, 2, 4, 5, 7, 8} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p stable_sort + * \see \p sort_by_key + */ +template +_CCCL_HOST_DEVICE void sort(const thrust::detail::execution_policy_base& exec, + RandomAccessIterator first, + RandomAccessIterator last); + +/*! \p sort sorts the elements in [first, last) into + * ascending order, meaning that if \c i and \c j are any two valid + * iterators in [first, last) such that \c i precedes \c j, + * then \c *j is not less than \c *i. Note: \c sort is not guaranteed + * to be stable. That is, suppose that \c *i and \c *j are equivalent: + * neither one is less than the other. It is not guaranteed that the + * relative order of these two elements will be preserved by \p sort. + * + * This version of \p sort compares objects using \c operator<. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * + * \tparam RandomAccessIterator is a model of Random Access Iterator, \p + * RandomAccessIterator is mutable, and \p RandomAccessIterator's \c value_type is a model of LessThan Comparable, and the ordering + * relation on \p RandomAccessIterator's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. + * + * The following code snippet demonstrates how to use \p sort to sort + * a sequence of integers. + * + * \code + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * thrust::sort(A, A + N); + * // A is now {1, 2, 4, 5, 7, 8} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p stable_sort + * \see \p sort_by_key + */ +template +void sort(RandomAccessIterator first, RandomAccessIterator last); + +/*! \p sort sorts the elements in [first, last) into + * ascending order, meaning that if \c i and \c j are any two valid + * iterators in [first, last) such that \c i precedes \c j, + * then \c *j is not less than \c *i. Note: \c sort is not guaranteed + * to be stable. That is, suppose that \c *i and \c *j are equivalent: + * neither one is less than the other. It is not guaranteed that the + * relative order of these two elements will be preserved by \p sort. + * + * This version of \p sort compares objects using a function object + * \p comp. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp Comparison operator. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomAccessIterator is a model of Random Access Iterator, \p + * RandomAccessIterator is mutable, and \p RandomAccessIterator's \c value_type is convertible to \p + * StrictWeakOrdering's \c first_argument_type and \c second_argument_type. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * The following code demonstrates how to sort integers in descending order + * using the greater comparison operator using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * thrust::sort(thrust::host, A, A + N, thrust::greater()); + * // A is now {8, 7, 5, 4, 2, 1}; + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p stable_sort + * \see \p sort_by_key + */ +template +_CCCL_HOST_DEVICE void +sort(const thrust::detail::execution_policy_base& exec, + RandomAccessIterator first, + RandomAccessIterator last, + StrictWeakOrdering comp); + +/*! \p sort sorts the elements in [first, last) into + * ascending order, meaning that if \c i and \c j are any two valid + * iterators in [first, last) such that \c i precedes \c j, + * then \c *j is not less than \c *i. Note: \c sort is not guaranteed + * to be stable. That is, suppose that \c *i and \c *j are equivalent: + * neither one is less than the other. It is not guaranteed that the + * relative order of these two elements will be preserved by \p sort. + * + * This version of \p sort compares objects using a function object + * \p comp. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp Comparison operator. + * + * \tparam RandomAccessIterator is a model of Random Access Iterator, \p + * RandomAccessIterator is mutable, and \p RandomAccessIterator's \c value_type is convertible to \p + * StrictWeakOrdering's \c first_argument_type and \c second_argument_type. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * The following code demonstrates how to sort integers in descending order + * using the greater comparison operator. + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * thrust::sort(A, A + N, thrust::greater()); + * // A is now {8, 7, 5, 4, 2, 1}; + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p stable_sort + * \see \p sort_by_key + */ +template +_CCCL_HOST_DEVICE void sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp); + +/*! \p stable_sort is much like \c sort: it sorts the elements in + * [first, last) into ascending order, meaning that if \c i + * and \c j are any two valid iterators in [first, last) such + * that \c i precedes \c j, then \c *j is not less than \c *i. + * + * As the name suggests, \p stable_sort is stable: it preserves the + * relative ordering of equivalent elements. That is, if \c x and \c y + * are elements in [first, last) such that \c x precedes \c y, + * and if the two elements are equivalent (neither x < y nor + * y < x) then a postcondition of \p stable_sort is that \c x + * still precedes \c y. + * + * This version of \p stable_sort compares objects using \c operator<. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomAccessIterator is a model of Random Access Iterator, \p + * RandomAccessIterator is mutable, and \p RandomAccessIterator's \c value_type is a model of LessThan Comparable, and the ordering + * relation on \p RandomAccessIterator's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. + * + * The following code snippet demonstrates how to use \p sort to sort + * a sequence of integers using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * thrust::stable_sort(thrust::host, A, A + N); + * // A is now {1, 2, 4, 5, 7, 8} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/stable_sort + * \see \p sort + * \see \p stable_sort_by_key + */ +template +_CCCL_HOST_DEVICE void stable_sort(const thrust::detail::execution_policy_base& exec, + RandomAccessIterator first, + RandomAccessIterator last); + +/*! \p stable_sort is much like \c sort: it sorts the elements in + * [first, last) into ascending order, meaning that if \c i + * and \c j are any two valid iterators in [first, last) such + * that \c i precedes \c j, then \c *j is not less than \c *i. + * + * As the name suggests, \p stable_sort is stable: it preserves the + * relative ordering of equivalent elements. That is, if \c x and \c y + * are elements in [first, last) such that \c x precedes \c y, + * and if the two elements are equivalent (neither x < y nor + * y < x) then a postcondition of \p stable_sort is that \c x + * still precedes \c y. + * + * This version of \p stable_sort compares objects using \c operator<. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * + * \tparam RandomAccessIterator is a model of Random Access Iterator, \p + * RandomAccessIterator is mutable, and \p RandomAccessIterator's \c value_type is a model of LessThan Comparable, and the ordering + * relation on \p RandomAccessIterator's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. + * + * The following code snippet demonstrates how to use \p sort to sort + * a sequence of integers. + * + * \code + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * thrust::stable_sort(A, A + N); + * // A is now {1, 2, 4, 5, 7, 8} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/stable_sort + * \see \p sort + * \see \p stable_sort_by_key + */ +template +void stable_sort(RandomAccessIterator first, RandomAccessIterator last); + +/*! \p stable_sort is much like \c sort: it sorts the elements in + * [first, last) into ascending order, meaning that if \c i + * and \c j are any two valid iterators in [first, last) such + * that \c i precedes \c j, then \c *j is not less than \c *i. + * + * As the name suggests, \p stable_sort is stable: it preserves the + * relative ordering of equivalent elements. That is, if \c x and \c y + * are elements in [first, last) such that \c x precedes \c y, + * and if the two elements are equivalent (neither x < y nor + * y < x) then a postcondition of \p stable_sort is that \c x + * still precedes \c y. + * + * This version of \p stable_sort compares objects using a function object + * \p comp. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp Comparison operator. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomAccessIterator is a model of Random Access Iterator, \p + * RandomAccessIterator is mutable, and \p RandomAccessIterator's \c value_type is convertible to \p + * StrictWeakOrdering's \c first_argument_type and \c second_argument_type. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * The following code demonstrates how to sort integers in descending order + * using the greater comparison operator using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * thrust::sort(A, A + N, thrust::greater()); + * // A is now {8, 7, 5, 4, 2, 1}; + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/stable_sort + * \see \p sort + * \see \p stable_sort_by_key + */ +template +_CCCL_HOST_DEVICE void stable_sort( + const thrust::detail::execution_policy_base& exec, + RandomAccessIterator first, + RandomAccessIterator last, + StrictWeakOrdering comp); + +/*! \p stable_sort is much like \c sort: it sorts the elements in + * [first, last) into ascending order, meaning that if \c i + * and \c j are any two valid iterators in [first, last) such + * that \c i precedes \c j, then \c *j is not less than \c *i. + * + * As the name suggests, \p stable_sort is stable: it preserves the + * relative ordering of equivalent elements. That is, if \c x and \c y + * are elements in [first, last) such that \c x precedes \c y, + * and if the two elements are equivalent (neither x < y nor + * y < x) then a postcondition of \p stable_sort is that \c x + * still precedes \c y. + * + * This version of \p stable_sort compares objects using a function object + * \p comp. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp Comparison operator. + * + * \tparam RandomAccessIterator is a model of Random Access Iterator, \p + * RandomAccessIterator is mutable, and \p RandomAccessIterator's \c value_type is convertible to \p + * StrictWeakOrdering's \c first_argument_type and \c second_argument_type. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * The following code demonstrates how to sort integers in descending order + * using the greater comparison operator. + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int A[N] = {1, 4, 2, 8, 5, 7}; + * thrust::sort(A, A + N, thrust::greater()); + * // A is now {8, 7, 5, 4, 2, 1}; + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/stable_sort + * \see \p sort + * \see \p stable_sort_by_key + */ +template +void stable_sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp); + +/////////////// +// Key Value // +/////////////// + +/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the + * elements in [keys_first, keys_last) and [values_first, + * values_first + (keys_last - keys_first)) into ascending key order, + * meaning that if \c i and \c j are any two valid iterators in [keys_first, + * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators + * in [values_first, values_first + (keys_last - keys_first)) + * corresponding to \c i and \c j respectively, then \c *j is not less than + * \c *i. + * + * Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that + * \c *i and \c *j are equivalent: neither one is less than the other. It is not + * guaranteed that the relative order of these two keys or the relative + * order of their corresponding values will be preserved by \p sort_by_key. + * + * This version of \p sort_by_key compares key objects using \c operator<. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first The beginning of the key sequence. + * \param keys_last The end of the key sequence. + * \param values_first The beginning of the value sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomAccessIterator1 is a model of Random Access Iterator, \p + * RandomAccessIterator1 is mutable, and \p RandomAccessIterator1's \c value_type is a model of LessThan Comparable, and the ordering + * relation on \p RandomAccessIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. \tparam + * RandomAccessIterator2 is a model of Random + * Access Iterator, and \p RandomAccessIterator2 is mutable. + * + * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + + * (keys_last - keys_first)). + * + * The following code snippet demonstrates how to use \p sort_by_key to sort + * an array of character values using integers as sorting keys using the \p thrust::host execution policy + * for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int keys[N] = { 1, 4, 2, 8, 5, 7}; + * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; + * thrust::sort_by_key(thrust::host, keys, keys + N, values); + * // keys is now { 1, 2, 4, 5, 7, 8} + * // values is now {'a', 'c', 'b', 'e', 'f', 'd'} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p stable_sort_by_key + * \see \p sort + */ +template +_CCCL_HOST_DEVICE void sort_by_key( + const thrust::detail::execution_policy_base& exec, + RandomAccessIterator1 keys_first, + RandomAccessIterator1 keys_last, + RandomAccessIterator2 values_first); + +/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the + * elements in [keys_first, keys_last) and [values_first, + * values_first + (keys_last - keys_first)) into ascending key order, + * meaning that if \c i and \c j are any two valid iterators in [keys_first, + * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators + * in [values_first, values_first + (keys_last - keys_first)) + * corresponding to \c i and \c j respectively, then \c *j is not less than + * \c *i. + * + * Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that + * \c *i and \c *j are equivalent: neither one is less than the other. It is not + * guaranteed that the relative order of these two keys or the relative + * order of their corresponding values will be preserved by \p sort_by_key. + * + * This version of \p sort_by_key compares key objects using \c operator<. + * + * \param keys_first The beginning of the key sequence. + * \param keys_last The end of the key sequence. + * \param values_first The beginning of the value sequence. + * + * \tparam RandomAccessIterator1 is a model of Random Access Iterator, \p + * RandomAccessIterator1 is mutable, and \p RandomAccessIterator1's \c value_type is a model of LessThan Comparable, and the ordering + * relation on \p RandomAccessIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. \tparam + * RandomAccessIterator2 is a model of Random + * Access Iterator, and \p RandomAccessIterator2 is mutable. + * + * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + + * (keys_last - keys_first)). + * + * The following code snippet demonstrates how to use \p sort_by_key to sort + * an array of character values using integers as sorting keys. + * + * \code + * #include + * ... + * const int N = 6; + * int keys[N] = { 1, 4, 2, 8, 5, 7}; + * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; + * thrust::sort_by_key(keys, keys + N, values); + * // keys is now { 1, 2, 4, 5, 7, 8} + * // values is now {'a', 'c', 'b', 'e', 'f', 'd'} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p stable_sort_by_key + * \see \p sort + */ +template +void sort_by_key(RandomAccessIterator1 keys_first, RandomAccessIterator1 keys_last, RandomAccessIterator2 values_first); + +/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the + * elements in [keys_first, keys_last) and [values_first, + * values_first + (keys_last - keys_first)) into ascending key order, + * meaning that if \c i and \c j are any two valid iterators in [keys_first, + * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators + * in [values_first, values_first + (keys_last - keys_first)) + * corresponding to \c i and \c j respectively, then \c *j is not less than + * \c *i. + * + * Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that + * \c *i and \c *j are equivalent: neither one is less than the other. It is not + * guaranteed that the relative order of these two keys or the relative + * order of their corresponding values will be preserved by \p sort_by_key. + * + * This version of \p sort_by_key compares key objects using a function object + * \c comp. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first The beginning of the key sequence. + * \param keys_last The end of the key sequence. + * \param values_first The beginning of the value sequence. + * \param comp Comparison operator. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomAccessIterator1 is a model of Random Access Iterator, \p + * RandomAccessIterator1 is mutable, and \p RandomAccessIterator1's \c value_type is convertible to \p + * StrictWeakOrdering's \c first_argument_type and \c second_argument_type. \tparam RandomAccessIterator2 is a model of + * Random Access Iterator, and \p + * RandomAccessIterator2 is mutable. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + + * (keys_last - keys_first)). + * + * The following code snippet demonstrates how to use \p sort_by_key to sort + * an array of character values using integers as sorting keys using the \p thrust::host execution policy + * for parallelization.The keys are sorted in descending order using the greater comparison operator. + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int keys[N] = { 1, 4, 2, 8, 5, 7}; + * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; + * thrust::sort_by_key(thrust::host, keys, keys + N, values, thrust::greater()); + * // keys is now { 8, 7, 5, 4, 2, 1} + * // values is now {'d', 'f', 'e', 'b', 'c', 'a'} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p stable_sort_by_key + * \see \p sort + */ +template +_CCCL_HOST_DEVICE void sort_by_key( + const thrust::detail::execution_policy_base& exec, + RandomAccessIterator1 keys_first, + RandomAccessIterator1 keys_last, + RandomAccessIterator2 values_first, + StrictWeakOrdering comp); + +/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the + * elements in [keys_first, keys_last) and [values_first, + * values_first + (keys_last - keys_first)) into ascending key order, + * meaning that if \c i and \c j are any two valid iterators in [keys_first, + * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators + * in [values_first, values_first + (keys_last - keys_first)) + * corresponding to \c i and \c j respectively, then \c *j is not less than + * \c *i. + * + * Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that + * \c *i and \c *j are equivalent: neither one is less than the other. It is not + * guaranteed that the relative order of these two keys or the relative + * order of their corresponding values will be preserved by \p sort_by_key. + * + * This version of \p sort_by_key compares key objects using a function object + * \c comp. + * + * \param keys_first The beginning of the key sequence. + * \param keys_last The end of the key sequence. + * \param values_first The beginning of the value sequence. + * \param comp Comparison operator. + * + * \tparam RandomAccessIterator1 is a model of Random Access Iterator, \p + * RandomAccessIterator1 is mutable, and \p RandomAccessIterator1's \c value_type is convertible to \p + * StrictWeakOrdering's \c first_argument_type and \c second_argument_type. \tparam RandomAccessIterator2 is a model of + * Random Access Iterator, and \p + * RandomAccessIterator2 is mutable. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + + * (keys_last - keys_first)). + * + * The following code snippet demonstrates how to use \p sort_by_key to sort + * an array of character values using integers as sorting keys. The keys + * are sorted in descending order using the greater comparison operator. + * + * \code + * #include + * ... + * const int N = 6; + * int keys[N] = { 1, 4, 2, 8, 5, 7}; + * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; + * thrust::sort_by_key(keys, keys + N, values, thrust::greater()); + * // keys is now { 8, 7, 5, 4, 2, 1} + * // values is now {'d', 'f', 'e', 'b', 'c', 'a'} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p stable_sort_by_key + * \see \p sort + */ +template +void sort_by_key(RandomAccessIterator1 keys_first, + RandomAccessIterator1 keys_last, + RandomAccessIterator2 values_first, + StrictWeakOrdering comp); + +/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key + * sorts the elements in [keys_first, keys_last) and [values_first, + * values_first + (keys_last - keys_first)) into ascending key order, + * meaning that if \c i and \c j are any two valid iterators in [keys_first, + * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators + * in [values_first, values_first + (keys_last - keys_first)) + * corresponding to \c i and \c j respectively, then \c *j is not less than + * \c *i. + * + * As the name suggests, \p stable_sort_by_key is stable: it preserves the + * relative ordering of equivalent elements. That is, if \c x and \c y + * are elements in [keys_first, keys_last) such that \c x precedes \c y, + * and if the two elements are equivalent (neither x < y nor + * y < x) then a postcondition of \p stable_sort_by_key is that \c x + * still precedes \c y. + * + * This version of \p stable_sort_by_key compares key objects using \c operator<. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first The beginning of the key sequence. + * \param keys_last The end of the key sequence. + * \param values_first The beginning of the value sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomAccessIterator1 is a model of Random Access Iterator, \p + * RandomAccessIterator1 is mutable, and \p RandomAccessIterator1's \c value_type is a model of LessThan Comparable, and the ordering + * relation on \p RandomAccessIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. \tparam + * RandomAccessIterator2 is a model of Random + * Access Iterator, and \p RandomAccessIterator2 is mutable. + * + * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + + * (keys_last - keys_first)). + * + * The following code snippet demonstrates how to use \p stable_sort_by_key to sort + * an array of characters using integers as sorting keys using the \p thrust::host execution policy for + * parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int keys[N] = { 1, 4, 2, 8, 5, 7}; + * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; + * thrust::stable_sort_by_key(thrust::host, keys, keys + N, values); + * // keys is now { 1, 2, 4, 5, 7, 8} + * // values is now {'a', 'c', 'b', 'e', 'f', 'd'} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p sort_by_key + * \see \p stable_sort + */ +template +_CCCL_HOST_DEVICE void stable_sort_by_key( + const thrust::detail::execution_policy_base& exec, + RandomAccessIterator1 keys_first, + RandomAccessIterator1 keys_last, + RandomAccessIterator2 values_first); + +/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key + * sorts the elements in [keys_first, keys_last) and [values_first, + * values_first + (keys_last - keys_first)) into ascending key order, + * meaning that if \c i and \c j are any two valid iterators in [keys_first, + * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators + * in [values_first, values_first + (keys_last - keys_first)) + * corresponding to \c i and \c j respectively, then \c *j is not less than + * \c *i. + * + * As the name suggests, \p stable_sort_by_key is stable: it preserves the + * relative ordering of equivalent elements. That is, if \c x and \c y + * are elements in [keys_first, keys_last) such that \c x precedes \c y, + * and if the two elements are equivalent (neither x < y nor + * y < x) then a postcondition of \p stable_sort_by_key is that \c x + * still precedes \c y. + * + * This version of \p stable_sort_by_key compares key objects using \c operator<. + * + * \param keys_first The beginning of the key sequence. + * \param keys_last The end of the key sequence. + * \param values_first The beginning of the value sequence. + * + * \tparam RandomAccessIterator1 is a model of Random Access Iterator, \p + * RandomAccessIterator1 is mutable, and \p RandomAccessIterator1's \c value_type is a model of LessThan Comparable, and the ordering + * relation on \p RandomAccessIterator1's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. \tparam + * RandomAccessIterator2 is a model of Random + * Access Iterator, and \p RandomAccessIterator2 is mutable. + * + * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + + * (keys_last - keys_first)). + * + * The following code snippet demonstrates how to use \p stable_sort_by_key to sort + * an array of characters using integers as sorting keys. + * + * \code + * #include + * ... + * const int N = 6; + * int keys[N] = { 1, 4, 2, 8, 5, 7}; + * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; + * thrust::stable_sort_by_key(keys, keys + N, values); + * // keys is now { 1, 2, 4, 5, 7, 8} + * // values is now {'a', 'c', 'b', 'e', 'f', 'd'} + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p sort_by_key + * \see \p stable_sort + */ +template +void stable_sort_by_key( + RandomAccessIterator1 keys_first, RandomAccessIterator1 keys_last, RandomAccessIterator2 values_first); + +/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key + * sorts the elements in [keys_first, keys_last) and [values_first, + * values_first + (keys_last - keys_first)) into ascending key order, + * meaning that if \c i and \c j are any two valid iterators in [keys_first, + * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators + * in [values_first, values_first + (keys_last - keys_first)) + * corresponding to \c i and \c j respectively, then \c *j is not less than + * \c *i. + * + * As the name suggests, \p stable_sort_by_key is stable: it preserves the + * relative ordering of equivalent elements. That is, if \c x and \c y + * are elements in [keys_first, keys_last) such that \c x precedes \c y, + * and if the two elements are equivalent (neither x < y nor + * y < x) then a postcondition of \p stable_sort_by_key is that \c x + * still precedes \c y. + * + * This version of \p stable_sort_by_key compares key objects using the function + * object \p comp. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first The beginning of the key sequence. + * \param keys_last The end of the key sequence. + * \param values_first The beginning of the value sequence. + * \param comp Comparison operator. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam RandomAccessIterator1 is a model of Random Access Iterator, \p + * RandomAccessIterator1 is mutable, and \p RandomAccessIterator1's \c value_type is convertible to \p + * StrictWeakOrdering's \c first_argument_type and \c second_argument_type. \tparam RandomAccessIterator2 is a model of + * Random Access Iterator, and \p + * RandomAccessIterator2 is mutable. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + + * (keys_last - keys_first)). + * + * The following code snippet demonstrates how to use \p sort_by_key to sort + * an array of character values using integers as sorting keys using the \p thrust::host execution policy for + * parallelization. The keys are sorted in descending order using the greater comparison operator. + * + * \code + * #include + * #include + * ... + * const int N = 6; + * int keys[N] = { 1, 4, 2, 8, 5, 7}; + * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; + * thrust::stable_sort_by_key(thrust::host, keys, keys + N, values, thrust::greater()); + * // keys is now { 8, 7, 5, 4, 2, 1} + * // values is now {'d', 'f', 'e', 'b', 'c', 'a'} + * \endcode + * + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p sort_by_key + * \see \p stable_sort + */ +template +_CCCL_HOST_DEVICE void stable_sort_by_key( + const thrust::detail::execution_policy_base& exec, + RandomAccessIterator1 keys_first, + RandomAccessIterator1 keys_last, + RandomAccessIterator2 values_first, + StrictWeakOrdering comp); + +/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key + * sorts the elements in [keys_first, keys_last) and [values_first, + * values_first + (keys_last - keys_first)) into ascending key order, + * meaning that if \c i and \c j are any two valid iterators in [keys_first, + * keys_last) such that \c i precedes \c j, and \c p and \c q are iterators + * in [values_first, values_first + (keys_last - keys_first)) + * corresponding to \c i and \c j respectively, then \c *j is not less than + * \c *i. + * + * As the name suggests, \p stable_sort_by_key is stable: it preserves the + * relative ordering of equivalent elements. That is, if \c x and \c y + * are elements in [keys_first, keys_last) such that \c x precedes \c y, + * and if the two elements are equivalent (neither x < y nor + * y < x) then a postcondition of \p stable_sort_by_key is that \c x + * still precedes \c y. + * + * This version of \p stable_sort_by_key compares key objects using the function + * object \p comp. + * + * \param keys_first The beginning of the key sequence. + * \param keys_last The end of the key sequence. + * \param values_first The beginning of the value sequence. + * \param comp Comparison operator. + * + * \tparam RandomAccessIterator1 is a model of Random Access Iterator, \p + * RandomAccessIterator1 is mutable, and \p RandomAccessIterator1's \c value_type is convertible to \p + * StrictWeakOrdering's \c first_argument_type and \c second_argument_type. \tparam RandomAccessIterator2 is a model of + * Random Access Iterator, and \p + * RandomAccessIterator2 is mutable. \tparam StrictWeakOrdering is a model of Strict Weak Ordering. + * + * \pre The range [keys_first, keys_last)) shall not overlap the range [values_first, values_first + + * (keys_last - keys_first)). + * + * The following code snippet demonstrates how to use \p sort_by_key to sort + * an array of character values using integers as sorting keys. The keys + * are sorted in descending order using the greater comparison operator. + * + * \code + * #include + * ... + * const int N = 6; + * int keys[N] = { 1, 4, 2, 8, 5, 7}; + * char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; + * thrust::stable_sort_by_key(keys, keys + N, values, thrust::greater()); + * // keys is now { 8, 7, 5, 4, 2, 1} + * // values is now {'d', 'f', 'e', 'b', 'c', 'a'} + * \endcode + * + * + * \see https://en.cppreference.com/w/cpp/algorithm/sort + * \see \p sort_by_key + * \see \p stable_sort + */ +template +void stable_sort_by_key(RandomAccessIterator1 keys_first, + RandomAccessIterator1 keys_last, + RandomAccessIterator2 values_first, + StrictWeakOrdering comp); + +/*! \} // end sorting + */ + +/*! \addtogroup reductions + * \{ + * \addtogroup predicates + * \{ + */ + +/*! \p is_sorted returns \c true if the range [first, last) is + * sorted in ascending order, and \c false otherwise. + * + * Specifically, this version of \p is_sorted returns \c false if for + * some iterator \c i in the range [first, last - 1) the + * expression *(i + 1) < *i is \c true. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \return \c true, if the sequence is sorted; \c false, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator's \c value_type is a model of LessThan Comparable, and the ordering on + * objects of \p ForwardIterator's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. + * + * + * The following code demonstrates how to use \p is_sorted to test whether the + * contents of a \c device_vector are stored in ascending order using the \p thrust::device execution policy + * for parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::device_vector v(6); + * v[0] = 1; + * v[1] = 4; + * v[2] = 2; + * v[3] = 8; + * v[4] = 5; + * v[5] = 7; + * + * bool result = thrust::is_sorted(thrust::device, v.begin(), v.end()); + * + * // result == false + * + * thrust::sort(v.begin(), v.end()); + * result = thrust::is_sorted(thrust::device, v.begin(), v.end()); + * + * // result == true + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/is_sorted + * \see is_sorted_until + * \see \c sort + * \see \c stable_sort + * \see \c less + */ +template +_CCCL_HOST_DEVICE bool is_sorted( + const thrust::detail::execution_policy_base& exec, ForwardIterator first, ForwardIterator last); + +/*! \p is_sorted returns \c true if the range [first, last) is + * sorted in ascending order, and \c false otherwise. + * + * Specifically, this version of \p is_sorted returns \c false if for + * some iterator \c i in the range [first, last - 1) the + * expression *(i + 1) < *i is \c true. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \return \c true, if the sequence is sorted; \c false, otherwise. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator's \c value_type is a model of LessThan Comparable, and the ordering on + * objects of \p ForwardIterator's \c value_type is a strict weak ordering, as defined in the LessThan Comparable requirements. + * + * + * The following code demonstrates how to use \p is_sorted to test whether the + * contents of a \c device_vector are stored in ascending order. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector v(6); + * v[0] = 1; + * v[1] = 4; + * v[2] = 2; + * v[3] = 8; + * v[4] = 5; + * v[5] = 7; + * + * bool result = thrust::is_sorted(v.begin(), v.end()); + * + * // result == false + * + * thrust::sort(v.begin(), v.end()); + * result = thrust::is_sorted(v.begin(), v.end()); + * + * // result == true + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/is_sorted + * \see is_sorted_until + * \see \c sort + * \see \c stable_sort + * \see \c less + */ +template +bool is_sorted(ForwardIterator first, ForwardIterator last); + +/*! \p is_sorted returns \c true if the range [first, last) is sorted in ascending + * order according to a user-defined comparison operation, and \c false otherwise. + * + * Specifically, this version of \p is_sorted returns \c false if for some iterator \c i in + * the range [first, last - 1) the expression comp(*(i + 1), *i) is \c true. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp Comparison operator. + * \return \c true, if the sequence is sorted according to comp; \c false, otherwise. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to both \c StrictWeakOrdering's \c + * first_argument_type and \c second_argument_type. \tparam Compare is a model of Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p is_sorted to test whether the + * contents of a \c device_vector are stored in descending order using the \p thrust::device execution + * policy for parallelization: + * + * \code + * #include + * #include + * #include + * #include + * ... + * thrust::device_vector v(6); + * v[0] = 1; + * v[1] = 4; + * v[2] = 2; + * v[3] = 8; + * v[4] = 5; + * v[5] = 7; + * + * thrust::greater comp; + * bool result = thrust::is_sorted(thrust::device, v.begin(), v.end(), comp); + * + * // result == false + * + * thrust::sort(v.begin(), v.end(), comp); + * result = thrust::is_sorted(thrust::device, v.begin(), v.end(), comp); + * + * // result == true + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/is_sorted + * \see \c sort + * \see \c stable_sort + * \see \c less + */ +template +_CCCL_HOST_DEVICE bool +is_sorted(const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + Compare comp); + +/*! \p is_sorted returns \c true if the range [first, last) is sorted in ascending + * order according to a user-defined comparison operation, and \c false otherwise. + * + * Specifically, this version of \p is_sorted returns \c false if for some iterator \c i in + * the range [first, last - 1) the expression comp(*(i + 1), *i) is \c true. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param comp Comparison operator. + * \return \c true, if the sequence is sorted according to comp; \c false, otherwise. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to both \c StrictWeakOrdering's \c + * first_argument_type and \c second_argument_type. \tparam Compare is a model of Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p is_sorted to test whether the + * contents of a \c device_vector are stored in descending order. + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector v(6); + * v[0] = 1; + * v[1] = 4; + * v[2] = 2; + * v[3] = 8; + * v[4] = 5; + * v[5] = 7; + * + * thrust::greater comp; + * bool result = thrust::is_sorted(v.begin(), v.end(), comp); + * + * // result == false + * + * thrust::sort(v.begin(), v.end(), comp); + * result = thrust::is_sorted(v.begin(), v.end(), comp); + * + * // result == true + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/is_sorted + * \see \c sort + * \see \c stable_sort + * \see \c less + */ +template +bool is_sorted(ForwardIterator first, ForwardIterator last, Compare comp); + +/*! This version of \p is_sorted_until returns the last iterator \c i in [first,last] for + * which the range [first,last) is sorted using \c operator<. If distance(first,last) < 2, + * \p is_sorted_until simply returns \p last. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \return The last iterator in the input range for which it is sorted. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator and \p ForwardIterator's \c value_type is a model of LessThan Comparable. + * + * The following code snippet demonstrates how to use \p is_sorted_until to find the first position + * in an array where the data becomes unsorted using the \p thrust::host execution policy for + * parallelization: + * + * \code + * #include + * #include + * + * ... + * + * int A[8] = {0, 1, 2, 3, 0, 1, 2, 3}; + * + * int * B = thrust::is_sorted_until(thrust::host, A, A + 8); + * + * // B - A is 4 + * // [A, B) is sorted + * \endcode + * + * \see \p is_sorted + * \see \p sort + * \see \p sort_by_key + * \see \p stable_sort + * \see \p stable_sort_by_key + */ +template +_CCCL_HOST_DEVICE ForwardIterator is_sorted_until( + const thrust::detail::execution_policy_base& exec, ForwardIterator first, ForwardIterator last); + +/*! This version of \p is_sorted_until returns the last iterator \c i in [first,last] for + * which the range [first,last) is sorted using \c operator<. If distance(first,last) < 2, + * \p is_sorted_until simply returns \p last. + * + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \return The last iterator in the input range for which it is sorted. + * + * \tparam ForwardIterator is a model of Forward + * Iterator and \p ForwardIterator's \c value_type is a model of LessThan Comparable. + * + * The following code snippet demonstrates how to use \p is_sorted_until to find the first position + * in an array where the data becomes unsorted: + * + * \code + * #include + * + * ... + * + * int A[8] = {0, 1, 2, 3, 0, 1, 2, 3}; + * + * int * B = thrust::is_sorted_until(A, A + 8); + * + * // B - A is 4 + * // [A, B) is sorted + * \endcode + * + * \see \p is_sorted + * \see \p sort + * \see \p sort_by_key + * \see \p stable_sort + * \see \p stable_sort_by_key + */ +template +ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last); + +/*! This version of \p is_sorted_until returns the last iterator \c i in [first,last] for + * which the range [first,last) is sorted using the function object \c comp. If distance(first,last) < + * 2, \p is_sorted_until simply returns \p last. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization: + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param comp The function object to use for comparison. + * \return The last iterator in the input range for which it is sorted. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator and \p ForwardIterator's \c value_type is convertible to \p Compare's \c argument_type. \tparam Compare + * is a model of Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p is_sorted_until to find the first position + * in an array where the data becomes unsorted in descending order using the \p thrust::host execution + * policy for parallelization: + * + * \code + * #include + * #include + * #include + * + * ... + * + * int A[8] = {3, 2, 1, 0, 3, 2, 1, 0}; + * + * thrust::greater comp; + * int * B = thrust::is_sorted_until(thrust::host, A, A + 8, comp); + * + * // B - A is 4 + * // [A, B) is sorted in descending order + * \endcode + * + * \see \p is_sorted + * \see \p sort + * \see \p sort_by_key + * \see \p stable_sort + * \see \p stable_sort_by_key + */ +template +_CCCL_HOST_DEVICE ForwardIterator is_sorted_until( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + Compare comp); + +/*! This version of \p is_sorted_until returns the last iterator \c i in [first,last] for + * which the range [first,last) is sorted using the function object \c comp. If distance(first,last) < + * 2, \p is_sorted_until simply returns \p last. + * + * \param first The beginning of the range of interest. + * \param last The end of the range of interest. + * \param comp The function object to use for comparison. + * \return The last iterator in the input range for which it is sorted. + * + * \tparam ForwardIterator is a model of Forward + * Iterator and \p ForwardIterator's \c value_type is convertible to \p Compare's \c argument_type. \tparam Compare + * is a model of Strict Weak Ordering. + * + * The following code snippet demonstrates how to use \p is_sorted_until to find the first position + * in an array where the data becomes unsorted in descending order: + * + * \code + * #include + * #include + * + * ... + * + * int A[8] = {3, 2, 1, 0, 3, 2, 1, 0}; + * + * thrust::greater comp; + * int * B = thrust::is_sorted_until(A, A + 8, comp); + * + * // B - A is 4 + * // [A, B) is sorted in descending order + * \endcode + * + * \see \p is_sorted + * \see \p sort + * \see \p sort_by_key + * \see \p stable_sort + * \see \p stable_sort_by_key + */ +template +ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp); + +/*! \} // end predicates + * \} // end reductions + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/swap.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/swap.h new file mode 100644 index 0000000000000000000000000000000000000000..63468b5902bd50186073cdeb63deafabaf518daa --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/swap.h @@ -0,0 +1,147 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file swap.h + * \brief Functions for swapping the value of elements + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +#include + +THRUST_NAMESPACE_BEGIN + +using ::cuda::std::swap; + +/*! \addtogroup copying + * \{ + */ + +/*! \p swap_ranges swaps each of the elements in the range [first1, last1) + * with the corresponding element in the range [first2, first2 + (last1 - first1)). + * That is, for each integer \c n such that 0 <= n < (last1 - first1), it swaps + * *(first1 + n) and *(first2 + n). The return value is + * first2 + (last1 - first1). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first sequence to swap. + * \param last1 One position past the last element of the first sequence to swap. + * \param first2 The beginning of the second sequence to swap. + * \return An iterator pointing to one position past the last element of the second + * sequence to swap. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator1 is a model of Forward + * Iterator, and \p ForwardIterator1's \c value_type must be convertible to \p ForwardIterator2's \c value_type. + * \tparam ForwardIterator2 is a model of Forward + * Iterator, and \p ForwardIterator2's \c value_type must be convertible to \p ForwardIterator1's \c value_type. + * + * \pre \p first1 may equal \p first2, but the range [first1, last1) shall not overlap the range [first2, + * first2 + (last1 - first1)) otherwise. + * + * The following code snippet demonstrates how to use \p swap_ranges to + * swap the contents of two \c thrust::device_vectors using the \p thrust::device execution + * policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * thrust::device_vector v1(2), v2(2); + * v1[0] = 1; + * v1[1] = 2; + * v2[0] = 3; + * v2[1] = 4; + * + * thrust::swap_ranges(thrust::device, v1.begin(), v1.end(), v2.begin()); + * + * // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/swap_ranges + * \see \c swap + */ +template +_CCCL_HOST_DEVICE ForwardIterator2 swap_ranges( + const thrust::detail::execution_policy_base& exec, + ForwardIterator1 first1, + ForwardIterator1 last1, + ForwardIterator2 first2); + +/*! \p swap_ranges swaps each of the elements in the range [first1, last1) + * with the corresponding element in the range [first2, first2 + (last1 - first1)). + * That is, for each integer \c n such that 0 <= n < (last1 - first1), it swaps + * *(first1 + n) and *(first2 + n). The return value is + * first2 + (last1 - first1). + * + * \param first1 The beginning of the first sequence to swap. + * \param last1 One position past the last element of the first sequence to swap. + * \param first2 The beginning of the second sequence to swap. + * \return An iterator pointing to one position past the last element of the second + * sequence to swap. + * + * \tparam ForwardIterator1 is a model of Forward + * Iterator, and \p ForwardIterator1's \c value_type must be convertible to \p ForwardIterator2's \c value_type. + * \tparam ForwardIterator2 is a model of Forward + * Iterator, and \p ForwardIterator2's \c value_type must be convertible to \p ForwardIterator1's \c value_type. + * + * \pre \p first1 may equal \p first2, but the range [first1, last1) shall not overlap the range [first2, + * first2 + (last1 - first1)) otherwise. + * + * The following code snippet demonstrates how to use \p swap_ranges to + * swap the contents of two \c thrust::device_vectors. + * + * \code + * #include + * #include + * ... + * thrust::device_vector v1(2), v2(2); + * v1[0] = 1; + * v1[1] = 2; + * v2[0] = 3; + * v2[1] = 4; + * + * thrust::swap_ranges(v1.begin(), v1.end(), v2.begin()); + * + * // v1[0] == 3, v1[1] == 4, v2[0] == 1, v2[1] == 2 + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/swap_ranges + * \see \c swap + */ +template +ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); + +/*! \} // copying + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system_error.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system_error.h new file mode 100644 index 0000000000000000000000000000000000000000..a3d1a0f4155fda4f1592c7c7ad2013fa04d24387 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/system_error.h @@ -0,0 +1,57 @@ +/* + * Copyright 2008-2021 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file thrust/system_error.h + * \brief System diagnostics + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup system + * \{ + */ + +/*! \namespace thrust::system + * \brief \p thrust::system is the namespace which contains specific Thrust + * backend systems. It also contains functionality for reporting error + * conditions originating from the operating system or other low-level + * application program interfaces such as the CUDA runtime. They are + * provided in a separate namespace for import convenience but are + * also aliased in the top-level \p thrust namespace for easy access. + */ +namespace system +{ +} // namespace system + +/*! \} // end system + */ + +THRUST_NAMESPACE_END + +#include +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/tabulate.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/tabulate.h new file mode 100644 index 0000000000000000000000000000000000000000..300a32363ef3b1249a4981f033cd5f4243d85eb0 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/tabulate.h @@ -0,0 +1,127 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file tabulate.h + * \brief Fills a range with the tabulation of a function + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup transformations + * \{ + */ + +/*! \p tabulate fills the range [first, last) with the value of a function applied to each + * element's index. + * + * For each iterator \c i in the range [first, last), \p tabulate performs the assignment + * *i = unary_op(i - first). + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the range. + * \param last The end of the range. + * \param unary_op The unary operation to apply. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and if \c x and \c y are objects of \c ForwardIterator's \c + * value_type, then x + y is defined, and if \c T is \p ForwardIterator's \c value_type, then T(0) is + * defined. \tparam UnaryOperation is a model of Unary Function and \c UnaryFunction's + * \c result_type is convertible to \c OutputIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p tabulate to generate the first \c n non-positive integers + * using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * const int N = 10; + * int A[N]; + * thrust::tabulate(thrust::host, A, A + 10, thrust::negate()); + * // A is now {0, -1, -2, -3, -4, -5, -6, -7, -8, -9} + * \endcode + * + * \see thrust::fill + * \see thrust::generate + * \see thrust::sequence + */ +template +_CCCL_HOST_DEVICE void +tabulate(const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + UnaryOperation unary_op); + +/*! \p tabulate fills the range [first, last) with the value of a function applied to each + * element's index. + * + * For each iterator \c i in the range [first, last), \p tabulate performs the assignment + * *i = unary_op(i - first). + * + * \param first The beginning of the range. + * \param last The end of the range. + * \param unary_op The unary operation to apply. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and if \c x and \c y are objects of \c ForwardIterator's \c + * value_type, then x + y is defined, and if \c T is \p ForwardIterator's \c value_type, then T(0) is + * defined. \tparam UnaryOperation is a model of Unary Function and \c UnaryFunction's + * \c result_type is convertible to \c OutputIterator's \c value_type. + * + * The following code snippet demonstrates how to use \p tabulate to generate the first \c n non-positive integers: + * + * \code + * #include + * #include + * ... + * const int N = 10; + * int A[N]; + * thrust::tabulate(A, A + 10, thrust::negate()); + * // A is now {0, -1, -2, -3, -4, -5, -6, -7, -8, -9} + * \endcode + * + * \see thrust::fill + * \see thrust::generate + * \see thrust::sequence + */ +template +void tabulate(ForwardIterator first, ForwardIterator last, UnaryOperation unary_op); + +/*! \} // end transformations + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/transform.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/transform.h new file mode 100644 index 0000000000000000000000000000000000000000..9c96f9ca6f58b82cbcd01fe188f88211660689d5 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/transform.h @@ -0,0 +1,741 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file thrust/transform.h + * \brief Transforms input ranges using a function object + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup algorithms + */ + +/*! \addtogroup transformations + * \ingroup algorithms + * \{ + */ + +//! This version of \p transform applies a unary function to each element of an input sequence and stores the result in +//! the corresponding position in an output sequence. Specifically, for each iterator i in the range [\p first, +//! \p last) the operation op(*i) is performed and the result is assigned to *o, where o is +//! the corresponding output iterator in the range [\p result, \p result + (\p last - \p first) ). The input and output +//! sequences may coincide, resulting in an in-place transformation. +//! +//! The algorithm's execution is parallelized as determined by \p exec. +//! +//! \param exec The execution policy to use for parallelization. +//! \param first The beginning of the input sequence. +//! \param last The end of the input sequence. +//! \param result The beginning of the output sequence. +//! \param op The transformation operation. Relying on the address of op's arguments in its implementation is +//! deprecated. +//! \return The end of the output sequence. +//! +//! \tparam DerivedPolicy The name of the derived execution policy. +//! \tparam InputIterator is a model of Input +//! Iterator and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type. \tparam +//! OutputIterator is a model of Output +//! Iterator. +//! \tparam UnaryFunction is a unary function type which's return type is convertible to \c OutputIterator's \c +//! value_type. +//! +//! \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, +//! result + (last - first)) otherwise. +//! +//! The following code snippet demonstrates how to use \p transform to negate a range in-place using the \p thrust::host +//! execution policy for parallelization: +//! +//! \code +//! #include +//! #include +//! #include +//! ... +//! +//! int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; +//! +//! thrust::negate op; +//! thrust::transform(thrust::host, data, data + 10, data, op); // in-place transformation +//! +//! // data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8}; +//! \endcode +//! +//! @rst +//! Some backends of transform may take advantage knowing if the transformation operation supports +//! :ref:`copyable arguments `. +//! @endrst +//! +//! \see https://en.cppreference.com/w/cpp/algorithm/transform +template +_CCCL_HOST_DEVICE OutputIterator transform( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + UnaryFunction op); + +//! This version of \p transform applies a unary function to each element of an input sequence and stores the result in +//! the corresponding position in an output sequence. Specifically, for each iterator i in the range [\p first, +//! \p last) the operation op(*i) is performed and the result is assigned to *o, where o is +//! the corresponding output iterator in the range [\p result, \p result + (\p last - \p first) ). The input and output +//! sequences may coincide, resulting in an in-place transformation. +//! +//! \param first The beginning of the input sequence. +//! \param last The end of the input sequence. +//! \param result The beginning of the output sequence. +//! \param op The transformation operation. Relying on the address of op's arguments in its implementation is +//! deprecated. +//! \return The end of the output sequence. +//! +//! \tparam InputIterator is a model of Input +//! Iterator and \c InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type. +//! \tparam OutputIterator is a model of Output +//! Iterator. +//! \tparam UnaryFunction is a unary function type which's return type is convertible to \c OutputIterator's \c +//! value_type. +//! +//! \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, +//! result + (last - first)) otherwise. +//! +//! The following code snippet demonstrates how to use \p transform +//! +//! \code +//! #include +//! #include +//! +//! int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; +//! +//! thrust::negate op; +//! thrust::transform(data, data + 10, data, op); // in-place transformation +//! +//! // data is now {5, 0, -2, 3, -2, -4, 0, 1, -2, -8}; +//! \endcode +//! +//! @rst +//! Some backends of transform may take advantage knowing if the transformation operation supports +//! :ref:`copyable arguments `. +//! @endrst +//! +//! \see https://en.cppreference.com/w/cpp/algorithm/transform +template +OutputIterator transform(InputIterator first, InputIterator last, OutputIterator result, UnaryFunction op); + +//! This version of \p transform applies a binary function to each pair of elements from two input sequences and stores +//! the result in the corresponding position in an output sequence. Specifically, for each iterator i in the +//! range [\p first1, \p last1) and j = first + (i - first1) in the range [\p first2, \p last2) the operation +//! op(*i,*j) is performed and the result is assigned to *o, where o is the corresponding +//! output iterator in the range [\p result, \p result + (\p last - \p first) ). The input and output sequences may +//! coincide, resulting in an in-place transformation. +//! +//! The algorithm's execution is parallelized as determined by \p exec. +//! +//! \param exec The execution policy to use for parallelization. +//! \param first1 The beginning of the first input sequence. +//! \param last1 The end of the first input sequence. +//! \param first2 The beginning of the second input sequence. +//! \param result The beginning of the output sequence. +//! \param op The transformation operation. Relying on the address of op's arguments in its implementation is +//! deprecated. +//! \return The end of the output sequence. +//! +//! \tparam DerivedPolicy The name of the derived execution policy. +//! \tparam InputIterator1 is a model of Input +//! Iterator and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type. +//! \tparam InputIterator2 is a model of Input +//! Iterator and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type. +//! \tparam OutputIterator is a model of Output +//! Iterator. +//! \tparam BinaryFunction is a binary function type which's return type is convertible to \c OutputIterator's \c +//! value_type. +//! +//! \pre \p first1 may equal \p result, but the range [first1, last1) shall not overlap the range [result, +//! result + (last1 - first1)) otherwise. \pre \p first2 may equal \p result, but the range [first2, first2 + +//! (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. +//! +//! The following code snippet demonstrates how to use \p transform to compute the sum of two ranges using the \p +//! thrust::host execution policy for parallelization: +//! +//! \code +//! #include +//! #include +//! #include +//! ... +//! +//! int input1[6] = {-5, 0, 2, 3, 2, 4}; +//! int input2[6] = { 3, 6, -2, 1, 2, 3}; +//! int output[6]; +//! +//! thrust::plus op; +//! thrust::transform(thrust::host, input1, input1 + 6, input2, output, op); +//! +//! // output is now {-2, 6, 0, 4, 4, 7}; +//! \endcode +//! +//! @rst +//! Some backends of transform may take advantage knowing if the transformation operation supports +//! :ref:`copyable arguments `. +//! @endrst +//! +//! \see https://en.cppreference.com/w/cpp/algorithm/transform +template +_CCCL_HOST_DEVICE OutputIterator transform( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + OutputIterator result, + BinaryFunction op); + +//! This version of \p transform applies a binary function to each pair of elements from two input sequences and stores +//! the result in the corresponding position in an output sequence. Specifically, for each iterator i in the +//! range [\p first1, \p last1) and j = first + (i - first1) in the range [\p first2, \p last2) the operation +//! op(*i,*j) is performed and the result is assigned to *o, where o is the corresponding +//! output iterator in the range [\p result, \p result + (\p last - \p first) ). The input and output sequences may +//! coincide, resulting in an in-place transformation. +//! +//! \param first1 The beginning of the first input sequence. +//! \param last1 The end of the first input sequence. +//! \param first2 The beginning of the second input sequence. +//! \param result The beginning of the output sequence. +//! \param op The transformation operation. Relying on the address of op's arguments in its implementation is +//! deprecated. +//! \return The end of the output sequence. +//! +//! \tparam InputIterator1 is a model of Input +//! Iterator and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type. +//! \tparam InputIterator2 is a model of Input +//! Iterator and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type. +//! \tparam OutputIterator is a model of Output +//! Iterator. +//! \tparam BinaryFunction is a binary function type which's return type is convertible to \c OutputIterator's \c +//! value_type. +//! +//! \pre \p first1 may equal \p result, but the range [first1, last1) shall not overlap the range [result, +//! result + (last1 - first1)) otherwise. \pre \p first2 may equal \p result, but the range [first2, first2 + +//! (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. +//! +//! The following code snippet demonstrates how to use \p transform +//! +//! \code +//! #include +//! #include +//! +//! int input1[6] = {-5, 0, 2, 3, 2, 4}; +//! int input2[6] = { 3, 6, -2, 1, 2, 3}; +//! int output[6]; +//! +//! thrust::plus op; +//! thrust::transform(input1, input1 + 6, input2, output, op); +//! +//! // output is now {-2, 6, 0, 4, 4, 7}; +//! \endcode +//! +//! @rst +//! Some backends of transform may take advantage knowing if the transformation operation supports +//! :ref:`copyable arguments `. +//! @endrst +//! +//! \see https://en.cppreference.com/w/cpp/algorithm/transform +template +OutputIterator +transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryFunction op); + +/*! This version of \p transform_if conditionally applies a unary function + * to each element of an input sequence and stores the result in the corresponding + * position in an output sequence if the corresponding position in the input sequence + * satisfies a predicate. Otherwise, the corresponding position in the + * output sequence is not modified. + * + * Specifically, for each iterator i in the range [first, last) the + * predicate pred(*i) is evaluated. If this predicate + * evaluates to \c true, the result of op(*i) is assigned to *o, + * where o is the corresponding output iterator in the range + * [result, result + (last - first) ). Otherwise, op(*i) is + * not evaluated and no assignment occurs. The input and output sequences may coincide, + * resulting in an in-place transformation. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param op The transformation operation. Relying on the address of op's arguments in its implementation is + * deprecated. + * \param pred The predicate operation. Relying on the address of pred's arguments in its implementation is deprecated. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \c InputIterator's \c value_type is convertible to \c Predicate's \c argument_type, and \c + * InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type. \tparam ForwardIterator is a + * model of Forward Iterator. \tparam + * UnaryFunction is a model of Unary + * Function and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. \tparam + * Predicate is a model of Predicate. + * + * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, + * result + (last - first)) otherwise. + * + * The following code snippet demonstrates how to use \p transform_if to negate the odd-valued + * elements of a range using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * + * struct is_odd + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x % 2; + * } + * }; + * + * thrust::negate op; + * thrust::identity identity; + * + * // negate odd elements + * thrust::transform_if(thrust::host, data, data + 10, data, op, is_odd()); // in-place transformation + * + * // data is now {5, 0, 2, 3, 2, 4, 0, 1, 2, 8}; + * \endcode + * + * \see thrust::transform + */ +template +_CCCL_HOST_DEVICE ForwardIterator transform_if( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + ForwardIterator result, + UnaryFunction op, + Predicate pred); + +/*! This version of \p transform_if conditionally applies a unary function + * to each element of an input sequence and stores the result in the corresponding + * position in an output sequence if the corresponding position in the input sequence + * satisfies a predicate. Otherwise, the corresponding position in the + * output sequence is not modified. + * + * Specifically, for each iterator i in the range [first, last) the + * predicate pred(*i) is evaluated. If this predicate + * evaluates to \c true, the result of op(*i) is assigned to *o, + * where o is the corresponding output iterator in the range + * [result, result + (last - first) ). Otherwise, op(*i) is + * not evaluated and no assignment occurs. The input and output sequences may coincide, + * resulting in an in-place transformation. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param op The transformation operation. Relying on the address of op's arguments in its implementation is + * deprecated. + * \param pred The predicate operation. Relying on the address of pred's arguments in its implementation + * is deprecated. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator, and \c InputIterator's \c value_type is convertible to \c Predicate's \c argument_type, and \c + * InputIterator's \c value_type is convertible to \c UnaryFunction's \c argument_type. \tparam ForwardIterator is a + * model of Forward Iterator. \tparam + * UnaryFunction is a model of Unary + * Function and \c UnaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. \tparam + * Predicate is a model of Predicate. + * + * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, + * result + (last - first)) otherwise. + * + * The following code snippet demonstrates how to use \p transform_if: + * + * \code + * #include + * #include + * + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * + * struct is_odd + * { + * __host__ __device__ + * bool operator()(int x) + * { + * return x % 2; + * } + * }; + * + * thrust::negate op; + * thrust::identity identity; + * + * // negate odd elements + * thrust::transform_if(data, data + 10, data, op, is_odd()); // in-place transformation + * + * // data is now {5, 0, 2, 3, 2, 4, 0, 1, 2, 8}; + * \endcode + * + * \see thrust::transform + */ +template +ForwardIterator +transform_if(InputIterator first, InputIterator last, ForwardIterator result, UnaryFunction op, Predicate pred); + +/*! This version of \p transform_if conditionally applies a unary function + * to each element of an input sequence and stores the result in the corresponding + * position in an output sequence if the corresponding position in a stencil sequence + * satisfies a predicate. Otherwise, the corresponding position in the + * output sequence is not modified. + * + * Specifically, for each iterator i in the range [first, last) the + * predicate pred(*s) is evaluated, where s is the corresponding input + * iterator in the range [stencil, stencil + (last - first) ). If this predicate + * evaluates to \c true, the result of op(*i) is assigned to *o, + * where o is the corresponding output iterator in the range + * [result, result + (last - first) ). Otherwise, op(*i) is + * not evaluated and no assignment occurs. The input and output sequences may coincide, + * resulting in an in-place transformation. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param stencil The beginning of the stencil sequence. + * \param result The beginning of the output sequence. + * \param op The transformation operation. Relying on the address of op's arguments in its implementation is + * deprecated. + * \param pred The predicate operation. Relying on the address of pred's arguments in its implementation + * is deprecated. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator and \c InputIterator1's \c value_type is convertible to \c UnaryFunction's \c argument_type. \tparam + * InputIterator2 is a model of Input Iterator + * and \c InputIterator2's \c value_type is convertible to \c Predicate's \c argument_type. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam UnaryFunction is a model of Unary Function and \c UnaryFunction's + * \c result_type is convertible to \c OutputIterator's \c value_type. \tparam Predicate is a model of Predicate. + * + * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, + * result + (last - first)) otherwise. \pre \p stencil may equal \p result, but the range [stencil, stencil + + * (last - first)) shall not overlap the range [result, result + (last - first)) otherwise. + * + * The following code snippet demonstrates how to use \p transform_if using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * int stencil[10] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; + * + * thrust::negate op; + * thrust::identity identity; + * + * thrust::transform_if(thrust::host, data, data + 10, stencil, data, op, identity); // in-place transformation + * + * // data is now {5, 0, -2, -3, -2, 4, 0, -1, -2, 8}; + * \endcode + * + * \see thrust::transform + */ +template +_CCCL_HOST_DEVICE ForwardIterator transform_if( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + ForwardIterator result, + UnaryFunction op, + Predicate pred); + +/*! This version of \p transform_if conditionally applies a unary function + * to each element of an input sequence and stores the result in the corresponding + * position in an output sequence if the corresponding position in a stencil sequence + * satisfies a predicate. Otherwise, the corresponding position in the + * output sequence is not modified. + * + * Specifically, for each iterator i in the range [first, last) the + * predicate pred(*s) is evaluated, where s is the corresponding input + * iterator in the range [stencil, stencil + (last - first) ). If this predicate + * evaluates to \c true, the result of op(*i) is assigned to *o, + * where o is the corresponding output iterator in the range + * [result, result + (last - first) ). Otherwise, op(*i) is + * not evaluated and no assignment occurs. The input and output sequences may coincide, + * resulting in an in-place transformation. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param stencil The beginning of the stencil sequence. + * \param result The beginning of the output sequence. + * \param op The transformation operation. Relying on the address of op's arguments in its implementation is + * deprecated. + * \param pred The predicate operation. Relying on the address of pred's arguments in its implementation + * is deprecated. + * \return The end of the output sequence. + * + * \tparam InputIterator1 is a model of Input + * Iterator and \c InputIterator1's \c value_type is convertible to \c UnaryFunction's \c argument_type. \tparam + * InputIterator2 is a model of Input Iterator + * and \c InputIterator2's \c value_type is convertible to \c Predicate's \c argument_type. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam UnaryFunction is a model of Unary Function and \c UnaryFunction's + * \c result_type is convertible to \c OutputIterator's \c value_type. \tparam Predicate is a model of Predicate. + * + * \pre \p first may equal \p result, but the range [first, last) shall not overlap the range [result, + * result + (last - first)) otherwise. \pre \p stencil may equal \p result, but the range [stencil, stencil + + * (last - first)) shall not overlap the range [result, result + (last - first)) otherwise. + * + * The following code snippet demonstrates how to use \p transform_if: + * + * \code + * #include + * #include + * + * int data[10] = {-5, 0, 2, -3, 2, 4, 0, -1, 2, 8}; + * int stencil[10] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; + * + * thrust::negate op; + * thrust::identity identity; + * + * thrust::transform_if(data, data + 10, stencil, data, op, identity); // in-place transformation + * + * // data is now {5, 0, -2, -3, -2, 4, 0, -1, -2, 8}; + * \endcode + * + * \see thrust::transform + */ +template +ForwardIterator transform_if( + InputIterator1 first, + InputIterator1 last, + InputIterator2 stencil, + ForwardIterator result, + UnaryFunction op, + Predicate pred); + +/*! This version of \p transform_if conditionally applies a binary function + * to each pair of elements from two input sequences and stores the result in the corresponding + * position in an output sequence if the corresponding position in a stencil sequence + * satisfies a predicate. Otherwise, the corresponding position in the + * output sequence is not modified. + * + * Specifically, for each iterator i in the range [first1, last1) and + * j = first2 + (i - first1) in the range [first2, first2 + (last1 - first1) ), + * the predicate pred(*s) is evaluated, where s is the corresponding input + * iterator in the range [stencil, stencil + (last1 - first1) ). If this predicate + * evaluates to \c true, the result of binary_op(*i,*j) is assigned to *o, + * where o is the corresponding output iterator in the range + * [result, result + (last1 - first1) ). Otherwise, binary_op(*i,*j) is + * not evaluated and no assignment occurs. The input and output sequences may coincide, + * resulting in an in-place transformation. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first1 The beginning of the first input sequence. + * \param last1 The end of the first input sequence. + * \param first2 The beginning of the second input sequence. + * \param stencil The beginning of the stencil sequence. + * \param result The beginning of the output sequence. + * \param binary_op The transformation operation. + * \param pred The predicate operation. Relying on the address of pred's arguments in its implementation + * is deprecated. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type. + * \tparam InputIterator2 is a model of Input + * Iterator and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam BinaryFunction is a model of Binary Function and \c + * BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. \tparam Predicate is a model of + * Predicate. + * + * \pre \p first1 may equal \p result, but the range [first1, last1) shall not overlap the range [result, + * result + (last1 - first1)) otherwise. \pre \p first2 may equal \p result, but the range [first2, first2 + + * (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. \pre \p + * stencil may equal \p result, but the range [stencil, stencil + (last1 - first1)) shall not overlap the range + * [result, result + (last1 - first1)) otherwise. + * + * The following code snippet demonstrates how to use \p transform_if using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * ... + * + * int input1[6] = {-5, 0, 2, 3, 2, 4}; + * int input2[6] = { 3, 6, -2, 1, 2, 3}; + * int stencil[8] = { 1, 0, 1, 0, 1, 0}; + * int output[6]; + * + * thrust::plus op; + * thrust::identity identity; + * + * thrust::transform_if(thrust::host, input1, input1 + 6, input2, stencil, output, op, identity); + * + * // output is now {-2, 0, 0, 3, 4, 4}; + * \endcode + * + * \see thrust::transform + */ +template +_CCCL_HOST_DEVICE ForwardIterator transform_if( + const thrust::detail::execution_policy_base& exec, + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator3 stencil, + ForwardIterator result, + BinaryFunction binary_op, + Predicate pred); + +/*! This version of \p transform_if conditionally applies a binary function + * to each pair of elements from two input sequences and stores the result in the corresponding + * position in an output sequence if the corresponding position in a stencil sequence + * satisfies a predicate. Otherwise, the corresponding position in the + * output sequence is not modified. + * + * Specifically, for each iterator i in the range [first1, last1) and + * j = first2 + (i - first1) in the range [first2, first2 + (last1 - first1) ), + * the predicate pred(*s) is evaluated, where s is the corresponding input + * iterator in the range [stencil, stencil + (last1 - first1) ). If this predicate + * evaluates to \c true, the result of binary_op(*i,*j) is assigned to *o, + * where o is the corresponding output iterator in the range + * [result, result + (last1 - first1) ). Otherwise, binary_op(*i,*j) is + * not evaluated and no assignment occurs. The input and output sequences may coincide, + * resulting in an in-place transformation. + * + * \param first1 The beginning of the first input sequence. + * \param last1 The end of the first input sequence. + * \param first2 The beginning of the second input sequence. + * \param stencil The beginning of the stencil sequence. + * \param result The beginning of the output sequence. + * \param binary_op The transformation operation. Relying on the address of binary_op's arguments in its implementation + * is deprecated. + * \param pred The predicate operation. Relying on the address of pred's arguments in its implementation + * is deprecated. + * \return The end of the output sequence. + * + * \tparam InputIterator1 is a model of Input + * Iterator and \c InputIterator1's \c value_type is convertible to \c BinaryFunction's \c first_argument_type. + * \tparam InputIterator2 is a model of Input + * Iterator and \c InputIterator2's \c value_type is convertible to \c BinaryFunction's \c second_argument_type. + * \tparam ForwardIterator is a model of Forward + * Iterator. \tparam BinaryFunction is a model of Binary Function and \c + * BinaryFunction's \c result_type is convertible to \c OutputIterator's \c value_type. \tparam Predicate is a model of + * Predicate. + * + * \pre \p first1 may equal \p result, but the range [first1, last1) shall not overlap the range [result, + * result + (last1 - first1)) otherwise. \pre \p first2 may equal \p result, but the range [first2, first2 + + * (last1 - first1)) shall not overlap the range [result, result + (last1 - first1)) otherwise. \pre \p + * stencil may equal \p result, but the range [stencil, stencil + (last1 - first1)) shall not overlap the range + * [result, result + (last1 - first1)) otherwise. + * + * The following code snippet demonstrates how to use \p transform_if: + * + * \code + * #include + * #include + * + * int input1[6] = {-5, 0, 2, 3, 2, 4}; + * int input2[6] = { 3, 6, -2, 1, 2, 3}; + * int stencil[8] = { 1, 0, 1, 0, 1, 0}; + * int output[6]; + * + * thrust::plus op; + * thrust::identity identity; + * + * thrust::transform_if(input1, input1 + 6, input2, stencil, output, op, identity); + * + * // output is now {-2, 0, 0, 3, 4, 4}; + * \endcode + * + * \see thrust::transform + */ +template +ForwardIterator transform_if( + InputIterator1 first1, + InputIterator1 last1, + InputIterator2 first2, + InputIterator3 stencil, + ForwardIterator result, + BinaryFunction binary_op, + Predicate pred); + +/*! \} // end transformations + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/transform_reduce.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/transform_reduce.h new file mode 100644 index 0000000000000000000000000000000000000000..227dd2d2e6e5ef12f1642056289e81096efcc96a --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/transform_reduce.h @@ -0,0 +1,192 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file transform_reduce.h + * \brief Fused transform / reduction + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup reductions + * \{ + * \addtogroup transformed_reductions Transformed Reductions + * \ingroup reductions + * \{ + */ + +/*! \p transform_reduce fuses the \p transform and \p reduce operations. + * \p transform_reduce is equivalent to performing a transformation defined by + * \p unary_op into a temporary sequence and then performing \p reduce on the + * transformed sequence. In most cases, fusing these two operations together is + * more efficient, since fewer memory reads and writes are required. + * + * \p transform_reduce performs a reduction on the transformation of the + * sequence [first, last) according to \p unary_op. Specifically, + * \p unary_op is applied to each element of the sequence and then the result + * is reduced to a single value with \p binary_op using the initial value + * \p init. Note that the transformation \p unary_op is not applied to + * the initial value \p init. The order of reduction is not specified, + * so \p binary_op must be both commutative and associative. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param unary_op The function to apply to each element of the input sequence. + * \param init The result is initialized to this value. + * \param binary_op The reduction operation. + * \return The result of the transformed reduction. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam + * UnaryFunction is a model of Unary + * Function, and \p UnaryFunction's \c result_type is convertible to \c OutputType. \tparam OutputType is a model of + * Assignable, and is convertible to \p + * BinaryFunction's \c first_argument_type and \c second_argument_type. \tparam BinaryFunction is a model of Binary Function, and \p + * BinaryFunction's \c result_type is convertible to \p OutputType. + * + * The following code snippet demonstrates how to use \p transform_reduce + * to compute the maximum value of the absolute value of the elements + * of a range using the \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * + * template + * struct absolute_value : public unary_function + * { + * __host__ __device__ T operator()(const T &x) const + * { + * return x < T(0) ? -x : x; + * } + * }; + * + * ... + * + * int data[6] = {-1, 0, -2, -2, 1, -3}; + * int result = thrust::transform_reduce(thrust::host, + * data, data + 6, + * absolute_value(), + * 0, + * thrust::maximum()); + * // result == 3 + * \endcode + * + * \see \c transform + * \see \c reduce + */ +template +_CCCL_HOST_DEVICE OutputType transform_reduce( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + UnaryFunction unary_op, + OutputType init, + BinaryFunction binary_op); + +/*! \p transform_reduce fuses the \p transform and \p reduce operations. + * \p transform_reduce is equivalent to performing a transformation defined by + * \p unary_op into a temporary sequence and then performing \p reduce on the + * transformed sequence. In most cases, fusing these two operations together is + * more efficient, since fewer memory reads and writes are required. + * + * \p transform_reduce performs a reduction on the transformation of the + * sequence [first, last) according to \p unary_op. Specifically, + * \p unary_op is applied to each element of the sequence and then the result + * is reduced to a single value with \p binary_op using the initial value + * \p init. Note that the transformation \p unary_op is not applied to + * the initial value \p init. The order of reduction is not specified, + * so \p binary_op must be both commutative and associative. + * + * \param first The beginning of the sequence. + * \param last The end of the sequence. + * \param unary_op The function to apply to each element of the input sequence. + * \param init The result is initialized to this value. + * \param binary_op The reduction operation. + * \return The result of the transformed reduction. + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is convertible to \p UnaryFunction's \c argument_type. \tparam + * UnaryFunction is a model of Unary + * Function, and \p UnaryFunction's \c result_type is convertible to \c OutputType. \tparam OutputType is a model of + * Assignable, and is convertible to \p + * BinaryFunction's \c first_argument_type and \c second_argument_type. \tparam BinaryFunction is a model of Binary Function, and \p + * BinaryFunction's \c result_type is convertible to \p OutputType. + * + * The following code snippet demonstrates how to use \p transform_reduce + * to compute the maximum value of the absolute value of the elements + * of a range. + * + * \code + * #include + * #include + * + * template + * struct absolute_value : public unary_function + * { + * __host__ __device__ T operator()(const T &x) const + * { + * return x < T(0) ? -x : x; + * } + * }; + * + * ... + * + * int data[6] = {-1, 0, -2, -2, 1, -3}; + * int result = thrust::transform_reduce(data, data + 6, + * absolute_value(), + * 0, + * thrust::maximum()); + * // result == 3 + * \endcode + * + * \see \c transform + * \see \c reduce + */ +template +OutputType transform_reduce( + InputIterator first, InputIterator last, UnaryFunction unary_op, OutputType init, BinaryFunction binary_op); + +/*! \} // end transformed_reductions + * \} // end reductions + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/transform_scan.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/transform_scan.h new file mode 100644 index 0000000000000000000000000000000000000000..6ec5d8f2e216c8b0b427043c0874b23744b77c9b --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/transform_scan.h @@ -0,0 +1,450 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file transform_scan.h + * \brief Fused transform / prefix-sum + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup algorithms + */ + +/*! \addtogroup prefixsums Prefix Sums + * \ingroup algorithms + * \{ + */ + +/*! \addtogroup transformed_prefixsums Transformed Prefix Sums + * \ingroup prefixsums + * \{ + */ + +/*! \p transform_inclusive_scan fuses the \p transform and \p inclusive_scan + * operations. \p transform_inclusive_scan is equivalent to performing a + * transformation defined by \p unary_op into a temporary sequence and then + * performing an \p inclusive_scan on the transformed sequence. In most + * cases, fusing these two operations together is more efficient, since + * fewer memory reads and writes are required. In \p transform_inclusive_scan, + * unary_op(\*first) is assigned to \*result and the result + * of binary_op(unary_op(\*first), unary_op(\*(first + 1))) is + * assigned to \*(result + 1), and so on. The transform scan + * operation is permitted to be in-place. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param unary_op The function used to transform the input sequence. + * \param binary_op The associative operator used to 'sum' transformed values. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c unary_op's input type. \tparam OutputIterator + * is a model of Output Iterator. \tparam + * UnaryFunction is a model of Unary + * Function and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type is convertible + * to \c OutputIterator's \c value_type. \tparam AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p transform_inclusive_scan using the + * \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::negate unary_op; + * thrust::plus binary_op; + * + * thrust::transform_inclusive_scan(thrust::host, data, data + 6, data, unary_op, binary_op); // in-place scan + * + * // data is now {-1, -1, -3, -5, -6, -9} + * \endcode + * + * \see \p transform + * \see \p inclusive_scan + * + */ +template +_CCCL_HOST_DEVICE OutputIterator transform_inclusive_scan( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + UnaryFunction unary_op, + AssociativeOperator binary_op); + +/*! \p transform_inclusive_scan fuses the \p transform and \p inclusive_scan + * operations. \p transform_inclusive_scan is equivalent to performing a + * transformation defined by \p unary_op into a temporary sequence and then + * performing an \p inclusive_scan on the transformed sequence. In most + * cases, fusing these two operations together is more efficient, since + * fewer memory reads and writes are required. In \p transform_inclusive_scan, + * unary_op(\*first) is assigned to \*result and the result + * of binary_op(unary_op(\*first), unary_op(\*(first + 1))) is + * assigned to \*(result + 1), and so on. The transform scan + * operation is permitted to be in-place. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param unary_op The function used to transform the input sequence. + * \param binary_op The associative operator used to 'sum' transformed values. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c unary_op's input type. \tparam OutputIterator + * is a model of Output Iterator. \tparam + * UnaryFunction is a model of Unary + * Function and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type is convertible + * to \c OutputIterator's \c value_type. \tparam AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p transform_inclusive_scan + * + * \code + * #include + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::negate unary_op; + * thrust::plus binary_op; + * + * thrust::transform_inclusive_scan(data, data + 6, data, unary_op, binary_op); // in-place scan + * + * // data is now {-1, -1, -3, -5, -6, -9} + * \endcode + * + * \see \p transform + * \see \p inclusive_scan + * + */ +template +OutputIterator transform_inclusive_scan( + InputIterator first, InputIterator last, OutputIterator result, UnaryFunction unary_op, AssociativeOperator binary_op); + +/*! \p transform_inclusive_scan fuses the \p transform and \p inclusive_scan + * operations. \p transform_inclusive_scan is equivalent to performing a + * transformation defined by \p unary_op into a temporary sequence and then + * performing an \p inclusive_scan on the transformed sequence. In most + * cases, fusing these two operations together is more efficient, since + * fewer memory reads and writes are required. In \p transform_inclusive_scan, + * if binary_op(init, unary_op(\*first)) is accum, it is assigned to + * \*result and the result of binary_op(accum, + * unary_op(\*(first + 1))) is assigned to \*(result + 1), + * and so on. The transform scan operation is permitted to be in-place. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param unary_op The function used to transform the input sequence. + * \param init The initial value of the \p transform_inclusive_scan + * \param binary_op The associative operator used to 'sum' transformed values. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c unary_op's input type. + * \tparam OutputIterator is a model of Output + * Iterator. + * \tparam UnaryFunction is a model of + * Unary Function and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type is + * convertible to \c OutputIterator's \c value_type. + * \tparam T is convertible to \c OutputIterator's \c value_type. + * \tparam AssociativeOperator is a model of + * Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p transform_inclusive_scan using the + * \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::negate unary_op; + * thrust::plus binary_op; + * + * thrust::transform_inclusive_scan(thrust::host, data, data + 6, data, unary_op, 4, binary_op); // in-place scan + * + * // data is now {3, 3, 1, -1, -2, -5} + * \endcode + * + * \see \p transform + * \see \p inclusive_scan + * + */ +template +_CCCL_HOST_DEVICE OutputIterator transform_inclusive_scan( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + UnaryFunction unary_op, + T init, + AssociativeOperator binary_op); + +/*! \p transform_inclusive_scan fuses the \p transform and \p inclusive_scan + * operations. \p transform_inclusive_scan is equivalent to performing a + * transformation defined by \p unary_op into a temporary sequence and then + * performing an \p inclusive_scan on the transformed sequence. In most + * cases, fusing these two operations together is more efficient, since + * fewer memory reads and writes are required.In \p transform_inclusive_scan, + * if binary_op(init, unary_op(\*first)) is accum, it is assigned to + * \*result and the result of binary_op(accum, + * unary_op(\*(first + 1))) is assigned to \*(result + 1), + * and so on. The transform scan operation is permitted to be in-place. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param unary_op The function used to transform the input sequence. + * \param init The initial value of the \p transform_inclusive_scan + * \param binary_op The associative operator used to 'sum' transformed values. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c unary_op's input type. + * \tparam OutputIterator is a model of Output + * Iterator. + * \tparam UnaryFunction is a model of + * Unary Function and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type is + * convertible to \c OutputIterator's \c value_type. + * \tparam T is convertible to \c OutputIterator's \c value_type. + * \tparam AssociativeOperator is a model of + * Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p transform_inclusive_scan + * + * \code + * #include + * ... + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::negate unary_op; + * thrust::plus binary_op; + * + * thrust::transform_inclusive_scan(data, data + 6, data, unary_op, 4, binary_op); // in-place scan + * + * // data is now {3, 3, 1, -1, -2, -5} + * \endcode + * + * \see \p transform + * \see \p inclusive_scan + * + */ +template +OutputIterator transform_inclusive_scan( + InputIterator first, + InputIterator last, + OutputIterator result, + UnaryFunction unary_op, + T init, + AssociativeOperator binary_op); + +/*! \p transform_exclusive_scan fuses the \p transform and \p exclusive_scan + * operations. \p transform_exclusive_scan is equivalent to performing a + * transformation defined by \p unary_op into a temporary sequence and then + * performing an \p exclusive_scan on the transformed sequence. In most + * cases, fusing these two operations together is more efficient, since + * fewer memory reads and writes are required. In + * \p transform_exclusive_scan, \p init is assigned to \*result + * and the result of binary_op(init, unary_op(\*first)) is assigned + * to \*(result + 1), and so on. The transform scan operation is + * permitted to be in-place. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param unary_op The function used to transform the input sequence. + * \param init The initial value of the \p exclusive_scan + * \param binary_op The associative operator used to 'sum' transformed values. + * \return The end of the output sequence. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c unary_op's input type. \tparam OutputIterator + * is a model of Output Iterator. \tparam + * UnaryFunction is a model of Unary + * Function and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type is convertible + * to \c OutputIterator's \c value_type. \tparam T is convertible to \c OutputIterator's \c value_type. \tparam + * AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p transform_exclusive_scan using the + * \p thrust::host execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::negate unary_op; + * thrust::plus binary_op; + * + * thrust::transform_exclusive_scan(thrust::host, data, data + 6, data, unary_op, 4, binary_op); // in-place scan + * + * // data is now {4, 3, 3, 1, -1, -2} + * \endcode + * + * \see \p transform + * \see \p exclusive_scan + * + */ +template +_CCCL_HOST_DEVICE OutputIterator transform_exclusive_scan( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + UnaryFunction unary_op, + T init, + AssociativeOperator binary_op); + +/*! \p transform_exclusive_scan fuses the \p transform and \p exclusive_scan + * operations. \p transform_exclusive_scan is equivalent to performing a + * transformation defined by \p unary_op into a temporary sequence and then + * performing an \p exclusive_scan on the transformed sequence. In most + * cases, fusing these two operations together is more efficient, since + * fewer memory reads and writes are required. In + * \p transform_exclusive_scan, \p init is assigned to \*result + * and the result of binary_op(init, unary_op(\*first)) is assigned + * to \*(result + 1), and so on. The transform scan operation is + * permitted to be in-place. + * + * \param first The beginning of the input sequence. + * \param last The end of the input sequence. + * \param result The beginning of the output sequence. + * \param unary_op The function used to transform the input sequence. + * \param init The initial value of the \p exclusive_scan + * \param binary_op The associative operator used to 'sum' transformed values. + * \return The end of the output sequence. + * + * \tparam InputIterator is a model of Input + * Iterator and \c InputIterator's \c value_type is convertible to \c unary_op's input type. \tparam OutputIterator + * is a model of Output Iterator. \tparam + * UnaryFunction is a model of Unary + * Function and accepts inputs of \c InputIterator's \c value_type. \c UnaryFunction's result_type is convertible + * to \c OutputIterator's \c value_type. \tparam T is convertible to \c OutputIterator's \c value_type. \tparam + * AssociativeOperator is a model of Binary Function and \c + * AssociativeOperator's \c result_type is convertible to \c OutputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p transform_exclusive_scan + * + * \code + * #include + * + * int data[6] = {1, 0, 2, 2, 1, 3}; + * + * thrust::negate unary_op; + * thrust::plus binary_op; + * + * thrust::transform_exclusive_scan(data, data + 6, data, unary_op, 4, binary_op); // in-place scan + * + * // data is now {4, 3, 3, 1, -1, -2} + * \endcode + * + * \see \p transform + * \see \p exclusive_scan + * + */ +template +OutputIterator transform_exclusive_scan( + InputIterator first, + InputIterator last, + OutputIterator result, + UnaryFunction unary_op, + T init, + AssociativeOperator binary_op); + +/*! \} // end transformed_prefixsums + */ + +/*! \} // end prefixsums + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/tuple.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/tuple.h new file mode 100644 index 0000000000000000000000000000000000000000..ff57db3fd9782e63ee31ec0441136f94f56c52ed --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/tuple.h @@ -0,0 +1,293 @@ +/* + * Copyright 2008-2018 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file tuple.h + * \brief A type encapsulating a heterogeneous collection of elements. + */ + +/* + * Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) + * + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying NOTICE file for the complete license) + * + * For more information, see http://www.boost.org + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include + +THRUST_NAMESPACE_BEGIN + +// define null_type for backwards compatibility +struct CCCL_DEPRECATED_BECAUSE("Please remove null_type from parameters to tuple<...>") null_type +{}; + +_CCCL_SUPPRESS_DEPRECATED_PUSH + +_CCCL_HOST_DEVICE inline bool operator==(const null_type&, const null_type&) +{ + return true; +} + +_CCCL_HOST_DEVICE inline bool operator>=(const null_type&, const null_type&) +{ + return true; +} + +_CCCL_HOST_DEVICE inline bool operator<=(const null_type&, const null_type&) +{ + return true; +} + +_CCCL_HOST_DEVICE inline bool operator!=(const null_type&, const null_type&) +{ + return false; +} + +_CCCL_HOST_DEVICE inline bool operator<(const null_type&, const null_type&) +{ + return false; +} + +_CCCL_HOST_DEVICE inline bool operator>(const null_type&, const null_type&) +{ + return false; +} + +_CCCL_SUPPRESS_DEPRECATED_POP + +/*! \addtogroup utility + * \{ + */ + +/*! \addtogroup tuple + * \{ + */ + +/*! This metafunction returns the type of a + * \p tuple's Nth element. + * + * \tparam N This parameter selects the element of interest. + * \tparam T A \c tuple type of interest. + * + * \see pair + * \see tuple + */ +#ifdef _CCCL_DOXYGEN_INVOKED // Provide a fake alias for doxygen +template +using tuple_element = _CUDA_VSTD::tuple_element; +#else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv +using _CUDA_VSTD::tuple_element; +#endif // _CCCL_DOXYGEN_INVOKED + +/*! This metafunction returns the number of elements + * of a \p tuple type of interest. + * + * \tparam T A \c tuple type of interest. + * + * \see pair + * \see tuple + */ +#ifdef _CCCL_DOXYGEN_INVOKED // Provide a fake alias for doxygen +template +using tuple_size = _CUDA_VSTD::tuple_size; +#else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv +using _CUDA_VSTD::tuple_size; +#endif // _CCCL_DOXYGEN_INVOKED + +/*! \brief \p tuple is a heterogeneous, fixed-size collection of values. + * An instantiation of \p tuple with two arguments is similar to an + * instantiation of \p pair with the same two arguments. Individual elements + * of a \p tuple may be accessed with the \p get function. + * + * \tparam Ts The type of the N \c tuple element. Thrust's \p tuple + * type currently supports up to ten elements. + * + * The following code snippet demonstrates how to create a new \p tuple object + * and inspect and modify the value of its elements. + * + * \code + * #include + * #include + * + * int main() { + * // Create a tuple containing an `int`, a `float`, and a string. + * thrust::tuple t(13, 0.1f, "thrust"); + * + * // Individual members are accessed with the free function `get`. + * std::cout << "The first element's value is " << thrust::get<0>(t) << std::endl; + * + * // ... or the member function `get`. + * std::cout << "The second element's value is " << t.get<1>() << std::endl; + * + * // We can also modify elements with the same function. + * thrust::get<0>(t) += 10; + * } + * \endcode + * + * \see pair + * \see get + * \see make_tuple + * \see tuple_element + * \see tuple_size + * \see tie + */ +#ifdef _CCCL_DOXYGEN_INVOKED // Provide a fake alias for doxygen +template +using tuple = _CUDA_VSTD::tuple; +#else // ^^^ _CCCL_DOXYGEN_INVOKED ^^^ / vvv !_CCCL_DOXYGEN_INVOKED vvv +using _CUDA_VSTD::tuple; +#endif // _CCCL_DOXYGEN_INVOKED + +using _CUDA_VSTD::get; +using _CUDA_VSTD::make_tuple; +using _CUDA_VSTD::tie; + +/*! \endcond + */ + +/*! \} // tuple + */ + +/*! \} // utility + */ + +THRUST_NAMESPACE_END + +_LIBCUDACXX_BEGIN_NAMESPACE_STD +_CCCL_SUPPRESS_DEPRECATED_PUSH + +template <> +struct tuple_size> : tuple_size> +{}; + +template +struct tuple_size> : tuple_size> +{}; + +template +struct tuple_size> : tuple_size> +{}; + +template +struct tuple_size> : tuple_size> +{}; + +template +struct tuple_size> : tuple_size> +{}; + +template +struct tuple_size> : tuple_size> +{}; + +template +struct tuple_size> : tuple_size> +{}; + +template +struct tuple_size< + tuple> + : tuple_size> +{}; + +template +struct tuple_size> + : tuple_size> +{}; + +template +struct tuple_size> + : tuple_size> +{}; + +_CCCL_SUPPRESS_DEPRECATED_POP +_LIBCUDACXX_END_NAMESPACE_STD diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/uninitialized_copy.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/uninitialized_copy.h new file mode 100644 index 0000000000000000000000000000000000000000..3ec0a12c5bd309464901f9123986a7bbbf87ee22 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/uninitialized_copy.h @@ -0,0 +1,300 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file uninitialized_copy.h + * \brief Copy construction into a range of uninitialized elements from a source range + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup copying + * \{ + */ + +/*! In \c thrust, the function \c thrust::device_new allocates memory for + * an object and then creates an object at that location by calling a constructor. + * Occasionally, however, it is useful to separate those two operations. + * If each iterator in the range [result, result + (last - first)) points + * to uninitialized memory, then \p uninitialized_copy creates a copy of + * [first, last) in that range. That is, for each iterator \c i in + * the input, \p uninitialized_copy creates a copy of \c *i in the location pointed + * to by the corresponding iterator in the output range by \p ForwardIterator's + * \c value_type's copy constructor with *i as its argument. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element of the input range to copy from. + * \param last The last element of the input range to copy from. + * \param result The first element of the output range to copy to. + * \return An iterator pointing to the last element of the output range. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator. \tparam ForwardIterator is a model of Forward Iterator, \p ForwardIterator is + * mutable, and \p ForwardIterator's \c value_type has a constructor that takes a single argument whose type is \p + * InputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p uninitialized_copy to initialize + * a range of uninitialized memory using the \p thrust::device execution policy for + * parallelization: + * + * \code + * #include + * #include + * #include + * #include + * + * struct Int + * { + * __host__ __device__ + * Int(int x) : val(x) {} + * int val; + * }; + * ... + * const int N = 137; + * + * Int val(46); + * thrust::device_vector input(N, val); + * thrust::device_ptr array = thrust::device_malloc(N); + * thrust::uninitialized_copy(thrust::device, input.begin(), input.end(), array); + * + * // Int x = array[i]; + * // x.val == 46 for all 0 <= i < N + * \endcode + * + * \see https://en.cppreference.com/w/cpp/memory/uninitialized_copy + * \see \c copy + * \see \c uninitialized_fill + * \see \c device_new + * \see \c device_malloc + */ +template +_CCCL_HOST_DEVICE ForwardIterator uninitialized_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + ForwardIterator result); + +/*! In \c thrust, the function \c thrust::device_new allocates memory for + * an object and then creates an object at that location by calling a constructor. + * Occasionally, however, it is useful to separate those two operations. + * If each iterator in the range [result, result + (last - first)) points + * to uninitialized memory, then \p uninitialized_copy creates a copy of + * [first, last) in that range. That is, for each iterator \c i in + * the input, \p uninitialized_copy creates a copy of \c *i in the location pointed + * to by the corresponding iterator in the output range by \p ForwardIterator's + * \c value_type's copy constructor with *i as its argument. + * + * \param first The first element of the input range to copy from. + * \param last The last element of the input range to copy from. + * \param result The first element of the output range to copy to. + * \return An iterator pointing to the last element of the output range. + * + * \tparam InputIterator is a model of Input + * Iterator. \tparam ForwardIterator is a model of Forward Iterator, \p ForwardIterator is + * mutable, and \p ForwardIterator's \c value_type has a constructor that takes a single argument whose type is \p + * InputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, last) and the range [result, result + (last - + * first)) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p uninitialized_copy to initialize + * a range of uninitialized memory. + * + * \code + * #include + * #include + * #include + * + * struct Int + * { + * __host__ __device__ + * Int(int x) : val(x) {} + * int val; + * }; + * ... + * const int N = 137; + * + * Int val(46); + * thrust::device_vector input(N, val); + * thrust::device_ptr array = thrust::device_malloc(N); + * thrust::uninitialized_copy(input.begin(), input.end(), array); + * + * // Int x = array[i]; + * // x.val == 46 for all 0 <= i < N + * \endcode + * + * \see https://en.cppreference.com/w/cpp/memory/uninitialized_copy + * \see \c copy + * \see \c uninitialized_fill + * \see \c device_new + * \see \c device_malloc + */ +template +ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); + +/*! In \c thrust, the function \c thrust::device_new allocates memory for + * an object and then creates an object at that location by calling a constructor. + * Occasionally, however, it is useful to separate those two operations. + * If each iterator in the range [result, result + n) points + * to uninitialized memory, then \p uninitialized_copy_n creates a copy of + * [first, first + n) in that range. That is, for each iterator \c i in + * the input, \p uninitialized_copy_n creates a copy of \c *i in the location pointed + * to by the corresponding iterator in the output range by \p InputIterator's + * \c value_type's copy constructor with *i as its argument. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element of the input range to copy from. + * \param n The number of elements to copy. + * \param result The first element of the output range to copy to. + * \return An iterator pointing to the last element of the output range. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator. \tparam Size is an integral type. \tparam ForwardIterator is a model of Forward Iterator, \p ForwardIterator is + * mutable, and \p ForwardIterator's \c value_type has a constructor that takes a single argument whose type is \p + * InputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, first + n) and the range [result, result + + * n) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p uninitialized_copy to initialize + * a range of uninitialized memory using the \p thrust::device execution policy for + * parallelization: + * + * \code + * #include + * #include + * #include + * #include + * + * struct Int + * { + * __host__ __device__ + * Int(int x) : val(x) {} + * int val; + * }; + * ... + * const int N = 137; + * + * Int val(46); + * thrust::device_vector input(N, val); + * thrust::device_ptr array = thrust::device_malloc(N); + * thrust::uninitialized_copy_n(thrust::device, input.begin(), N, array); + * + * // Int x = array[i]; + * // x.val == 46 for all 0 <= i < N + * \endcode + * + * \see https://en.cppreference.com/w/cpp/memory/uninitialized_copy + * \see \c uninitialized_copy + * \see \c copy + * \see \c uninitialized_fill + * \see \c device_new + * \see \c device_malloc + */ +template +_CCCL_HOST_DEVICE ForwardIterator uninitialized_copy_n( + const thrust::detail::execution_policy_base& exec, InputIterator first, Size n, ForwardIterator result); + +/*! In \c thrust, the function \c thrust::device_new allocates memory for + * an object and then creates an object at that location by calling a constructor. + * Occasionally, however, it is useful to separate those two operations. + * If each iterator in the range [result, result + n) points + * to uninitialized memory, then \p uninitialized_copy_n creates a copy of + * [first, first + n) in that range. That is, for each iterator \c i in + * the input, \p uninitialized_copy_n creates a copy of \c *i in the location pointed + * to by the corresponding iterator in the output range by \p InputIterator's + * \c value_type's copy constructor with *i as its argument. + * + * \param first The first element of the input range to copy from. + * \param n The number of elements to copy. + * \param result The first element of the output range to copy to. + * \return An iterator pointing to the last element of the output range. + * + * \tparam InputIterator is a model of Input + * Iterator. \tparam Size is an integral type. \tparam ForwardIterator is a model of Forward Iterator, \p ForwardIterator is + * mutable, and \p ForwardIterator's \c value_type has a constructor that takes a single argument whose type is \p + * InputIterator's \c value_type. + * + * \pre \p first may equal \p result, but the range [first, first + n) and the range [result, result + + * n) shall not overlap otherwise. + * + * The following code snippet demonstrates how to use \p uninitialized_copy to initialize + * a range of uninitialized memory. + * + * \code + * #include + * #include + * #include + * + * struct Int + * { + * __host__ __device__ + * Int(int x) : val(x) {} + * int val; + * }; + * ... + * const int N = 137; + * + * Int val(46); + * thrust::device_vector input(N, val); + * thrust::device_ptr array = thrust::device_malloc(N); + * thrust::uninitialized_copy_n(input.begin(), N, array); + * + * // Int x = array[i]; + * // x.val == 46 for all 0 <= i < N + * \endcode + * + * \see https://en.cppreference.com/w/cpp/memory/uninitialized_copy + * \see \c uninitialized_copy + * \see \c copy + * \see \c uninitialized_fill + * \see \c device_new + * \see \c device_malloc + */ +template +ForwardIterator uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); + +/*! \} // copying + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/uninitialized_fill.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/uninitialized_fill.h new file mode 100644 index 0000000000000000000000000000000000000000..bdd86e416623a05a6e1d527a718bcfda2dcce250 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/uninitialized_fill.h @@ -0,0 +1,268 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file uninitialized_fill.h + * \brief Copy construction into a range of uninitialized elements from a source value + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup filling + * \ingroup transformations + * \{ + */ + +/*! In \c thrust, the function \c thrust::device_new allocates memory for + * an object and then creates an object at that location by calling a + * constructor. Occasionally, however, it is useful to separate those two + * operations. If each iterator in the range [first, last) points + * to uninitialized memory, then \p uninitialized_fill creates copies of \c x + * in that range. That is, for each iterator \c i in the range [first, last), + * \p uninitialized_fill creates a copy of \c x in the location pointed to \c i by + * calling \p ForwardIterator's \c value_type's copy constructor. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element of the range of interest. + * \param last The last element of the range of interest. + * \param x The value to use as the exemplar of the copy constructor. + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes a + * single argument of type \p T. + * + * The following code snippet demonstrates how to use \p uninitialized_fill to initialize a range of + * uninitialized memory using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * + * struct Int + * { + * __host__ __device__ + * Int(int x) : val(x) {} + * int val; + * }; + * ... + * const int N = 137; + * + * Int val(46); + * thrust::device_ptr array = thrust::device_malloc(N); + * thrust::uninitialized_fill(thrust::device, array, array + N, val); + * + * // Int x = array[i]; + * // x.val == 46 for all 0 <= i < N + * \endcode + * + * \see https://en.cppreference.com/w/cpp/memory/uninitialized_fill + * \see \c uninitialized_fill_n + * \see \c fill + * \see \c uninitialized_copy + * \see \c device_new + * \see \c device_malloc + */ +template +_CCCL_HOST_DEVICE void uninitialized_fill( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + const T& x); + +/*! In \c thrust, the function \c thrust::device_new allocates memory for + * an object and then creates an object at that location by calling a + * constructor. Occasionally, however, it is useful to separate those two + * operations. If each iterator in the range [first, last) points + * to uninitialized memory, then \p uninitialized_fill creates copies of \c x + * in that range. That is, for each iterator \c i in the range [first, last), + * \p uninitialized_fill creates a copy of \c x in the location pointed to \c i by + * calling \p ForwardIterator's \c value_type's copy constructor. + * + * \param first The first element of the range of interest. + * \param last The last element of the range of interest. + * \param x The value to use as the exemplar of the copy constructor. + * + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes a + * single argument of type \p T. + * + * The following code snippet demonstrates how to use \p uninitialized_fill to initialize a range of + * uninitialized memory. + * + * \code + * #include + * #include + * + * struct Int + * { + * __host__ __device__ + * Int(int x) : val(x) {} + * int val; + * }; + * ... + * const int N = 137; + * + * Int val(46); + * thrust::device_ptr array = thrust::device_malloc(N); + * thrust::uninitialized_fill(array, array + N, val); + * + * // Int x = array[i]; + * // x.val == 46 for all 0 <= i < N + * \endcode + * + * \see https://en.cppreference.com/w/cpp/memory/uninitialized_fill + * \see \c uninitialized_fill_n + * \see \c fill + * \see \c uninitialized_copy + * \see \c device_new + * \see \c device_malloc + */ +template +void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); + +/*! In \c thrust, the function \c thrust::device_new allocates memory for + * an object and then creates an object at that location by calling a + * constructor. Occasionally, however, it is useful to separate those two + * operations. If each iterator in the range [first, first+n) points + * to uninitialized memory, then \p uninitialized_fill creates copies of \c x + * in that range. That is, for each iterator \c i in the range [first, first+n), + * \p uninitialized_fill creates a copy of \c x in the location pointed to \c i by + * calling \p ForwardIterator's \c value_type's copy constructor. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The first element of the range of interest. + * \param n The size of the range of interest. + * \param x The value to use as the exemplar of the copy constructor. + * \return first+n + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes a + * single argument of type \p T. + * + * The following code snippet demonstrates how to use \p uninitialized_fill to initialize a range of + * uninitialized memory using the \p thrust::device execution policy for parallelization: + * + * \code + * #include + * #include + * #include + * + * struct Int + * { + * __host__ __device__ + * Int(int x) : val(x) {} + * int val; + * }; + * ... + * const int N = 137; + * + * Int val(46); + * thrust::device_ptr array = thrust::device_malloc(N); + * thrust::uninitialized_fill_n(thrust::device, array, N, val); + * + * // Int x = array[i]; + * // x.val == 46 for all 0 <= i < N + * \endcode + * + * \see https://en.cppreference.com/w/cpp/memory/uninitialized_fill + * \see \c uninitialized_fill + * \see \c fill + * \see \c uninitialized_copy_n + * \see \c device_new + * \see \c device_malloc + */ +template +_CCCL_HOST_DEVICE ForwardIterator uninitialized_fill_n( + const thrust::detail::execution_policy_base& exec, ForwardIterator first, Size n, const T& x); + +/*! In \c thrust, the function \c thrust::device_new allocates memory for + * an object and then creates an object at that location by calling a + * constructor. Occasionally, however, it is useful to separate those two + * operations. If each iterator in the range [first, first+n) points + * to uninitialized memory, then \p uninitialized_fill creates copies of \c x + * in that range. That is, for each iterator \c i in the range [first, first+n), + * \p uninitialized_fill creates a copy of \c x in the location pointed to \c i by + * calling \p ForwardIterator's \c value_type's copy constructor. + * + * \param first The first element of the range of interest. + * \param n The size of the range of interest. + * \param x The value to use as the exemplar of the copy constructor. + * \return first+n + * + * \tparam ForwardIterator is a model of Forward + * Iterator, \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type has a constructor that takes a + * single argument of type \p T. + * + * The following code snippet demonstrates how to use \p uninitialized_fill to initialize a range of + * uninitialized memory. + * + * \code + * #include + * #include + * + * struct Int + * { + * __host__ __device__ + * Int(int x) : val(x) {} + * int val; + * }; + * ... + * const int N = 137; + * + * Int val(46); + * thrust::device_ptr array = thrust::device_malloc(N); + * thrust::uninitialized_fill_n(array, N, val); + * + * // Int x = array[i]; + * // x.val == 46 for all 0 <= i < N + * \endcode + * + * \see https://en.cppreference.com/w/cpp/memory/uninitialized_fill + * \see \c uninitialized_fill + * \see \c fill + * \see \c uninitialized_copy_n + * \see \c device_new + * \see \c device_malloc + */ +template +ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x); + +/*! \} // end filling + * \} // transformations + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/unique.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/unique.h new file mode 100644 index 0000000000000000000000000000000000000000..e5711bd2d40493d05fdbebff3d1c55b67d0df5d2 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/unique.h @@ -0,0 +1,1090 @@ +/* + * Copyright 2008-2013 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file unique.h + * \brief Move unique elements to the front of a range + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#include +#include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup stream_compaction + * \{ + */ + +/*! For each group of consecutive elements in the range [first, last) + * with the same value, \p unique removes all but the first element of + * the group. The return value is an iterator \c new_last such that + * no two consecutive elements in the range [first, new_last) are + * equal. The iterators in the range [new_last, last) are all still + * dereferenceable, but the elements that they point to are unspecified. + * \p unique is stable, meaning that the relative order of elements that are + * not removed is unchanged. + * + * This version of \p unique uses \c operator== to test for equality. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input range. + * \param last The end of the input range. + * \return The end of the unique range [first, new_last). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type is a model of Equality Comparable. + * + * The following code snippet demonstrates how to use \p unique to + * compact a sequence of numbers to remove consecutive duplicates using the \p thrust::host execution policy + * for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int *new_end = thrust::unique(thrust::host, A, A + N); + * // The first four values of A are now {1, 3, 2, 1} + * // Values beyond new_end are unspecified. + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/unique + * \see unique_copy + */ +template +_CCCL_HOST_DEVICE ForwardIterator +unique(const thrust::detail::execution_policy_base& exec, ForwardIterator first, ForwardIterator last); + +/*! For each group of consecutive elements in the range [first, last) + * with the same value, \p unique removes all but the first element of + * the group. The return value is an iterator \c new_last such that + * no two consecutive elements in the range [first, new_last) are + * equal. The iterators in the range [new_last, last) are all still + * dereferenceable, but the elements that they point to are unspecified. + * \p unique is stable, meaning that the relative order of elements that are + * not removed is unchanged. + * + * This version of \p unique uses \c operator== to test for equality. + * + * \param first The beginning of the input range. + * \param last The end of the input range. + * \return The end of the unique range [first, new_last). + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type is a model of Equality Comparable. + * + * The following code snippet demonstrates how to use \p unique to + * compact a sequence of numbers to remove consecutive duplicates. + * + * \code + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int *new_end = thrust::unique(A, A + N); + * // The first four values of A are now {1, 3, 2, 1} + * // Values beyond new_end are unspecified. + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/unique + * \see unique_copy + */ +template +ForwardIterator unique(ForwardIterator first, ForwardIterator last); + +/*! For each group of consecutive elements in the range [first, last) + * with the same value, \p unique removes all but the first element of + * the group. The return value is an iterator \c new_last such that + * no two consecutive elements in the range [first, new_last) are + * equal. The iterators in the range [new_last, last) are all still + * dereferenceable, but the elements that they point to are unspecified. + * \p unique is stable, meaning that the relative order of elements that are + * not removed is unchanged. + * + * This version of \p unique uses the function object \p binary_pred to test + * for equality. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param binary_pred The binary predicate used to determine equality. + * \return The end of the unique range [first, new_last) + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type is convertible to \p + * BinaryPredicate's \c first_argument_type and to \p BinaryPredicate's \c second_argument_type. \tparam BinaryPredicate + * is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p unique to + * compact a sequence of numbers to remove consecutive duplicates using the \p thrust::host execution policy + * for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int *new_end = thrust::unique(thrust::host, A, A + N, thrust::equal_to()); + * // The first four values of A are now {1, 3, 2, 1} + * // Values beyond new_end are unspecified. + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/unique + * \see unique_copy + */ +template +_CCCL_HOST_DEVICE ForwardIterator unique( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + BinaryPredicate binary_pred); + +/*! For each group of consecutive elements in the range [first, last) + * with the same value, \p unique removes all but the first element of + * the group. The return value is an iterator \c new_last such that + * no two consecutive elements in the range [first, new_last) are + * equal. The iterators in the range [new_last, last) are all still + * dereferenceable, but the elements that they point to are unspecified. + * \p unique is stable, meaning that the relative order of elements that are + * not removed is unchanged. + * + * This version of \p unique uses the function object \p binary_pred to test + * for equality. + * + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param binary_pred The binary predicate used to determine equality. + * \return The end of the unique range [first, new_last) + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator is mutable, and \p ForwardIterator's \c value_type is convertible to \p + * BinaryPredicate's \c first_argument_type and to \p BinaryPredicate's \c second_argument_type. \tparam BinaryPredicate + * is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p unique to + * compact a sequence of numbers to remove consecutive duplicates. + * + * \code + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int *new_end = thrust::unique(A, A + N, thrust::equal_to()); + * // The first four values of A are now {1, 3, 2, 1} + * // Values beyond new_end are unspecified. + * \endcode + * + * \see https://en.cppreference.com/w/cpp/algorithm/unique + * \see unique_copy + */ +template +ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred); + +/*! \p unique_copy copies elements from the range [first, last) + * to a range beginning with \p result, except that in a consecutive group + * of duplicate elements only the first one is copied. The return value + * is the end of the range to which the elements are copied. + * + * The reason there are two different versions of unique_copy is that there + * are two different definitions of what it means for a consecutive group of + * elements to be duplicates. In the first version, the test is simple + * equality: the elements in a range [f, l) are duplicates if, + * for every iterator \p i in the range, either i == f or else + * *i == *(i-1). In the second, the test is an arbitrary + * \p BinaryPredicate \p binary_pred: the elements in [f, l) are + * duplicates if, for every iterator \p i in the range, either i == f + * or else binary_pred(*i, *(i-1)) is \p true. + * + * This version of \p unique_copy uses \c operator== to test for equality. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param result The beginning of the output range. + * \return The end of the unique range [result, result_end). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is a model of Equality Comparable. \tparam OutputIterator + * is a model of Output Iterator and and \p + * InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. + * + * \pre The range [first,last) and the range [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p unique_copy to + * compact a sequence of numbers to remove consecutive duplicates using the \p thrust::host execution + * policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int B[N]; + * int *result_end = thrust::unique_copy(thrust::host, A, A + N, B); + * // The first four values of B are now {1, 3, 2, 1} and (result_end - B) is 4 + * // Values beyond result_end are unspecified + * \endcode + * + * \see unique + * \see https://en.cppreference.com/w/cpp/algorithm/unique_copy + */ +template +_CCCL_HOST_DEVICE OutputIterator unique_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result); + +/*! \p unique_copy copies elements from the range [first, last) + * to a range beginning with \p result, except that in a consecutive group + * of duplicate elements only the first one is copied. The return value + * is the end of the range to which the elements are copied. + * + * The reason there are two different versions of unique_copy is that there + * are two different definitions of what it means for a consecutive group of + * elements to be duplicates. In the first version, the test is simple + * equality: the elements in a range [f, l) are duplicates if, + * for every iterator \p i in the range, either i == f or else + * *i == *(i-1). In the second, the test is an arbitrary + * \p BinaryPredicate \p binary_pred: the elements in [f, l) are + * duplicates if, for every iterator \p i in the range, either i == f + * or else binary_pred(*i, *(i-1)) is \p true. + * + * This version of \p unique_copy uses \c operator== to test for equality. + * + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param result The beginning of the output range. + * \return The end of the unique range [result, result_end). + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is a model of Equality Comparable. \tparam OutputIterator + * is a model of Output Iterator and and \p + * InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. + * + * \pre The range [first,last) and the range [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p unique_copy to + * compact a sequence of numbers to remove consecutive duplicates. + * + * \code + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int B[N]; + * int *result_end = thrust::unique_copy(A, A + N, B); + * // The first four values of B are now {1, 3, 2, 1} and (result_end - B) is 4 + * // Values beyond result_end are unspecified + * \endcode + * + * \see unique + * \see https://en.cppreference.com/w/cpp/algorithm/unique_copy + */ +template +OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result); + +/*! \p unique_copy copies elements from the range [first, last) + * to a range beginning with \p result, except that in a consecutive group + * of duplicate elements only the first one is copied. The return value + * is the end of the range to which the elements are copied. + * + * This version of \p unique_copy uses the function object \c binary_pred + * to test for equality. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param result The beginning of the output range. + * \param binary_pred The binary predicate used to determine equality. + * \return The end of the unique range [result, result_end). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is a model of Equality Comparable. \tparam OutputIterator + * is a model of Output Iterator and and \p + * InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam BinaryPredicate is a model + * of Binary Predicate. + * + * \pre The range [first,last) and the range [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p unique_copy to + * compact a sequence of numbers to remove consecutive duplicates using the \p thrust::host execution + * policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int B[N]; + * int *result_end = thrust::unique_copy(thrust::host, A, A + N, B, thrust::equal_to()); + * // The first four values of B are now {1, 3, 2, 1} and (result_end - B) is 4 + * // Values beyond result_end are unspecified. + * \endcode + * + * \see unique + * \see https://en.cppreference.com/w/cpp/algorithm/unique_copy + */ +template +_CCCL_HOST_DEVICE OutputIterator unique_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator first, + InputIterator last, + OutputIterator result, + BinaryPredicate binary_pred); + +/*! \p unique_copy copies elements from the range [first, last) + * to a range beginning with \p result, except that in a consecutive group + * of duplicate elements only the first one is copied. The return value + * is the end of the range to which the elements are copied. + * + * This version of \p unique_copy uses the function object \c binary_pred + * to test for equality. + * + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param result The beginning of the output range. + * \param binary_pred The binary predicate used to determine equality. + * \return The end of the unique range [result, result_end). + * + * \tparam InputIterator is a model of Input + * Iterator, and \p InputIterator's \c value_type is a model of Equality Comparable. \tparam OutputIterator + * is a model of Output Iterator and and \p + * InputIterator's \c value_type is convertible to \c OutputIterator's \c value_type. \tparam BinaryPredicate is a model + * of Binary Predicate. + * + * \pre The range [first,last) and the range [result, result + (last - first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p unique_copy to + * compact a sequence of numbers to remove consecutive duplicates. + * + * \code + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int B[N]; + * int *result_end = thrust::unique_copy(A, A + N, B, thrust::equal_to()); + * // The first four values of B are now {1, 3, 2, 1} and (result_end - B) is 4 + * // Values beyond result_end are unspecified. + * \endcode + * + * \see unique + * \see https://en.cppreference.com/w/cpp/algorithm/unique_copy + */ +template +OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate binary_pred); + +/*! \p unique_by_key is a generalization of \p unique to key-value pairs. + * For each group of consecutive keys in the range [keys_first, keys_last) + * that are equal, \p unique_by_key removes all but the first element of + * the group. Similarly, the corresponding values in the range + * [values_first, values_first + (keys_last - keys_first)) + * are also removed. + * + * The return value is a \p pair of iterators (new_keys_last,new_values_last) + * such that no two consecutive elements in the range [keys_first, new_keys_last) + * are equal. + * + * This version of \p unique_by_key uses \c operator== to test for equality and + * \c project1st to reduce values with equal keys. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first The beginning of the key range. + * \param keys_last The end of the key range. + * \param values_first The beginning of the value range. + * \return A pair of iterators at end of the ranges [key_first, keys_new_last) and [values_first, + * values_new_last). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator1 is a model of Forward + * Iterator, and \p ForwardIterator1 is mutable, and \p ForwardIterator's \c value_type is a model of Equality Comparable. \tparam + * ForwardIterator2 is a model of Forward + * Iterator, and \p ForwardIterator2 is mutable. + * + * \pre The range [keys_first, keys_last) and the range [values_first, values_first + (keys_last - + * keys_first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p unique_by_key to + * compact a sequence of key/value pairs to remove consecutive duplicates using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys + * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values + * + * thrust::pair new_end; + * new_end = thrust::unique_by_key(thrust::host, A, A + N, B); + * + * // The first four keys in A are now {1, 3, 2, 1} and new_end.first - A is 4. + * // The first four values in B are now {9, 8, 5, 3} and new_end.second - B is 4. + * \endcode + * + * \see unique + * \see unique_by_key_copy + * \see reduce_by_key + */ +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key( + const thrust::detail::execution_policy_base& exec, + ForwardIterator1 keys_first, + ForwardIterator1 keys_last, + ForwardIterator2 values_first); + +/*! \p unique_by_key is a generalization of \p unique to key-value pairs. + * For each group of consecutive keys in the range [keys_first, keys_last) + * that are equal, \p unique_by_key removes all but the first element of + * the group. Similarly, the corresponding values in the range + * [values_first, values_first + (keys_last - keys_first)) + * are also removed. + * + * The return value is a \p pair of iterators (new_keys_last,new_values_last) + * such that no two consecutive elements in the range [keys_first, new_keys_last) + * are equal. + * + * This version of \p unique_by_key uses \c operator== to test for equality and + * \c project1st to reduce values with equal keys. + * + * \param keys_first The beginning of the key range. + * \param keys_last The end of the key range. + * \param values_first The beginning of the value range. + * \return A pair of iterators at end of the ranges [key_first, keys_new_last) and [values_first, + * values_new_last). + * + * \tparam ForwardIterator1 is a model of Forward + * Iterator, and \p ForwardIterator1 is mutable, and \p ForwardIterator's \c value_type is a model of Equality Comparable. \tparam + * ForwardIterator2 is a model of Forward + * Iterator, and \p ForwardIterator2 is mutable. + * + * \pre The range [keys_first, keys_last) and the range [values_first, values_first + (keys_last - + * keys_first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p unique_by_key to + * compact a sequence of key/value pairs to remove consecutive duplicates. + * + * \code + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys + * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values + * + * thrust::pair new_end; + * new_end = thrust::unique_by_key(A, A + N, B); + * + * // The first four keys in A are now {1, 3, 2, 1} and new_end.first - A is 4. + * // The first four values in B are now {9, 8, 5, 3} and new_end.second - B is 4. + * \endcode + * + * \see unique + * \see unique_by_key_copy + * \see reduce_by_key + */ +template +thrust::pair +unique_by_key(ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first); + +/*! \p unique_by_key is a generalization of \p unique to key-value pairs. + * For each group of consecutive keys in the range [keys_first, keys_last) + * that are equal, \p unique_by_key removes all but the first element of + * the group. Similarly, the corresponding values in the range + * [values_first, values_first + (keys_last - keys_first)) + * are also removed. + * + * This version of \p unique_by_key uses the function object \c binary_pred + * to test for equality and \c project1st to reduce values with equal keys. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first The beginning of the key range. + * \param keys_last The end of the key range. + * \param values_first The beginning of the value range. + * \param binary_pred The binary predicate used to determine equality. + * \return The end of the unique range [first, new_last). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator1 is a model of Forward + * Iterator, and \p ForwardIterator1 is mutable, and \p ForwardIterator's \c value_type is a model of Equality Comparable. \tparam + * ForwardIterator2 is a model of Forward + * Iterator, and \p ForwardIterator2 is mutable. \tparam BinaryPredicate is a model of Binary Predicate. + * + * \pre The range [keys_first, keys_last) and the range [values_first, values_first + (keys_last - + * keys_first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p unique_by_key to + * compact a sequence of key/value pairs to remove consecutive duplicates using the \p thrust::host + * execution policy for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys + * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values + * + * thrust::pair new_end; + * thrust::equal_to binary_pred; + * new_end = thrust::unique_by_key(thrust::host, A, A + N, B, binary_pred); + * + * // The first four keys in A are now {1, 3, 2, 1} and new_end.first - A is 4. + * // The first four values in B are now {9, 8, 5, 3} and new_end.second - B is 4. + * \endcode + * + * \see unique + * \see unique_by_key_copy + * \see reduce_by_key + */ +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key( + const thrust::detail::execution_policy_base& exec, + ForwardIterator1 keys_first, + ForwardIterator1 keys_last, + ForwardIterator2 values_first, + BinaryPredicate binary_pred); + +/*! \p unique_by_key is a generalization of \p unique to key-value pairs. + * For each group of consecutive keys in the range [keys_first, keys_last) + * that are equal, \p unique_by_key removes all but the first element of + * the group. Similarly, the corresponding values in the range + * [values_first, values_first + (keys_last - keys_first)) + * are also removed. + * + * This version of \p unique_by_key uses the function object \c binary_pred + * to test for equality and \c project1st to reduce values with equal keys. + * + * \param keys_first The beginning of the key range. + * \param keys_last The end of the key range. + * \param values_first The beginning of the value range. + * \param binary_pred The binary predicate used to determine equality. + * \return The end of the unique range [first, new_last). + * + * \tparam ForwardIterator1 is a model of Forward + * Iterator, and \p ForwardIterator1 is mutable, and \p ForwardIterator's \c value_type is a model of Equality Comparable. \tparam + * ForwardIterator2 is a model of Forward + * Iterator, and \p ForwardIterator2 is mutable. \tparam BinaryPredicate is a model of Binary Predicate. + * + * \pre The range [keys_first, keys_last) and the range [values_first, values_first + (keys_last - + * keys_first)) shall not overlap. + * + * The following code snippet demonstrates how to use \p unique_by_key to + * compact a sequence of key/value pairs to remove consecutive duplicates. + * + * \code + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // keys + * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // values + * + * thrust::pair new_end; + * thrust::equal_to binary_pred; + * new_end = thrust::unique_by_key(A, A + N, B, binary_pred); + * + * // The first four keys in A are now {1, 3, 2, 1} and new_end.first - A is 4. + * // The first four values in B are now {9, 8, 5, 3} and new_end.second - B is 4. + * \endcode + * + * \see unique + * \see unique_by_key_copy + * \see reduce_by_key + */ +template +thrust::pair unique_by_key( + ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first, BinaryPredicate binary_pred); + +/*! \p unique_by_key_copy is a generalization of \p unique_copy to key-value pairs. + * For each group of consecutive keys in the range [keys_first, keys_last) + * that are equal, \p unique_by_key_copy copies the first element of the group to + * a range beginning with \c keys_result and the corresponding values from the range + * [values_first, values_first + (keys_last - keys_first)) are copied to a range + * beginning with \c values_result. + * + * This version of \p unique_by_key_copy uses \c operator== to test for equality and + * \c project1st to reduce values with equal keys. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first The beginning of the input key range. + * \param keys_last The end of the input key range. + * \param values_first The beginning of the input value range. + * \param keys_result The beginning of the output key range. + * \param values_result The beginning of the output value range. + * \return A pair of iterators at end of the ranges [keys_result, keys_result_last) and [values_result, + * values_result_last). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, \tparam InputIterator2 is a model of Input Iterator, \tparam OutputIterator1 is a + * model of Output Iterator and and \p + * InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. \tparam OutputIterator2 is a + * model of Output Iterator and and \p + * InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. + * + * \pre The input ranges shall not overlap either output range. + * + * The following code snippet demonstrates how to use \p unique_by_key_copy to + * compact a sequence of key/value pairs and with equal keys using the \p thrust::host execution policy + * for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys + * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values + * int C[N]; // output keys + * int D[N]; // output values + * + * thrust::pair new_end; + * new_end = thrust::unique_by_key_copy(thrust::host, A, A + N, B, C, D); + * + * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. + * // The first four values in D are now {9, 8, 5, 3} and new_end.second - D is 4. + * \endcode + * + * \see unique_copy + * \see unique_by_key + * \see reduce_by_key + */ +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_result, + OutputIterator2 values_result); + +/*! \p unique_by_key_copy is a generalization of \p unique_copy to key-value pairs. + * For each group of consecutive keys in the range [keys_first, keys_last) + * that are equal, \p unique_by_key_copy copies the first element of the group to + * a range beginning with \c keys_result and the corresponding values from the range + * [values_first, values_first + (keys_last - keys_first)) are copied to a range + * beginning with \c values_result. + * + * This version of \p unique_by_key_copy uses \c operator== to test for equality and + * \c project1st to reduce values with equal keys. + * + * \param keys_first The beginning of the input key range. + * \param keys_last The end of the input key range. + * \param values_first The beginning of the input value range. + * \param keys_result The beginning of the output key range. + * \param values_result The beginning of the output value range. + * \return A pair of iterators at end of the ranges [keys_result, keys_result_last) and [values_result, + * values_result_last). + * + * \tparam InputIterator1 is a model of Input + * Iterator, \tparam InputIterator2 is a model of Input Iterator, \tparam OutputIterator1 is a + * model of Output Iterator and and \p + * InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. \tparam OutputIterator2 is a + * model of Output Iterator and and \p + * InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. + * + * \pre The input ranges shall not overlap either output range. + * + * The following code snippet demonstrates how to use \p unique_by_key_copy to + * compact a sequence of key/value pairs and with equal keys. + * + * \code + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys + * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values + * int C[N]; // output keys + * int D[N]; // output values + * + * thrust::pair new_end; + * new_end = thrust::unique_by_key_copy(A, A + N, B, C, D); + * + * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. + * // The first four values in D are now {9, 8, 5, 3} and new_end.second - D is 4. + * \endcode + * + * \see unique_copy + * \see unique_by_key + * \see reduce_by_key + */ +template +thrust::pair unique_by_key_copy( + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_result, + OutputIterator2 values_result); + +/*! \p unique_by_key_copy is a generalization of \p unique_copy to key-value pairs. + * For each group of consecutive keys in the range [keys_first, keys_last) + * that are equal, \p unique_by_key_copy copies the first element of the group to + * a range beginning with \c keys_result and the corresponding values from the range + * [values_first, values_first + (keys_last - keys_first)) are copied to a range + * beginning with \c values_result. + * + * This version of \p unique_by_key_copy uses the function object \c binary_pred + * to test for equality and \c project1st to reduce values with equal keys. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param keys_first The beginning of the input key range. + * \param keys_last The end of the input key range. + * \param values_first The beginning of the input value range. + * \param keys_result The beginning of the output key range. + * \param values_result The beginning of the output value range. + * \param binary_pred The binary predicate used to determine equality. + * \return A pair of iterators at end of the ranges [keys_result, keys_result_last) and [values_result, + * values_result_last). + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam InputIterator1 is a model of Input + * Iterator, \tparam InputIterator2 is a model of Input Iterator, \tparam OutputIterator1 is a + * model of Output Iterator and and \p + * InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. \tparam OutputIterator2 is a + * model of Output Iterator and and \p + * InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. \tparam BinaryPredicate is a + * model of Binary Predicate. + * + * \pre The input ranges shall not overlap either output range. + * + * The following code snippet demonstrates how to use \p unique_by_key_copy to + * compact a sequence of key/value pairs and with equal keys using the \p thrust::host execution policy for + * parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys + * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values + * int C[N]; // output keys + * int D[N]; // output values + * + * thrust::pair new_end; + * thrust::equal_to binary_pred; + * new_end = thrust::unique_by_key_copy(thrust::host, A, A + N, B, C, D, binary_pred); + * + * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. + * // The first four values in D are now {9, 8, 5, 3} and new_end.second - D is 4. + * \endcode + * + * \see unique_copy + * \see unique_by_key + * \see reduce_by_key + */ +template +_CCCL_HOST_DEVICE thrust::pair unique_by_key_copy( + const thrust::detail::execution_policy_base& exec, + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_result, + OutputIterator2 values_result, + BinaryPredicate binary_pred); + +/*! \p unique_by_key_copy is a generalization of \p unique_copy to key-value pairs. + * For each group of consecutive keys in the range [keys_first, keys_last) + * that are equal, \p unique_by_key_copy copies the first element of the group to + * a range beginning with \c keys_result and the corresponding values from the range + * [values_first, values_first + (keys_last - keys_first)) are copied to a range + * beginning with \c values_result. + * + * This version of \p unique_by_key_copy uses the function object \c binary_pred + * to test for equality and \c project1st to reduce values with equal keys. + * + * \param keys_first The beginning of the input key range. + * \param keys_last The end of the input key range. + * \param values_first The beginning of the input value range. + * \param keys_result The beginning of the output key range. + * \param values_result The beginning of the output value range. + * \param binary_pred The binary predicate used to determine equality. + * \return A pair of iterators at end of the ranges [keys_result, keys_result_last) and [values_result, + * values_result_last). + * + * \tparam InputIterator1 is a model of Input + * Iterator, \tparam InputIterator2 is a model of Input Iterator, \tparam OutputIterator1 is a + * model of Output Iterator and and \p + * InputIterator1's \c value_type is convertible to \c OutputIterator1's \c value_type. \tparam OutputIterator2 is a + * model of Output Iterator and and \p + * InputIterator2's \c value_type is convertible to \c OutputIterator2's \c value_type. \tparam BinaryPredicate is a + * model of Binary Predicate. + * + * \pre The input ranges shall not overlap either output range. + * + * The following code snippet demonstrates how to use \p unique_by_key_copy to + * compact a sequence of key/value pairs and with equal keys. + * + * \code + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; // input keys + * int B[N] = {9, 8, 7, 6, 5, 4, 3}; // input values + * int C[N]; // output keys + * int D[N]; // output values + * + * thrust::pair new_end; + * thrust::equal_to binary_pred; + * new_end = thrust::unique_by_key_copy(A, A + N, B, C, D, binary_pred); + * + * // The first four keys in C are now {1, 3, 2, 1} and new_end.first - C is 4. + * // The first four values in D are now {9, 8, 5, 3} and new_end.second - D is 4. + * \endcode + * + * \see unique_copy + * \see unique_by_key + * \see reduce_by_key + */ +template +thrust::pair unique_by_key_copy( + InputIterator1 keys_first, + InputIterator1 keys_last, + InputIterator2 values_first, + OutputIterator1 keys_result, + OutputIterator2 values_result, + BinaryPredicate binary_pred); + +/*! \p unique_count counts runs of equal elements in the range [first, last) + * with the same value, + * + * This version of \p unique_count uses the function object \p binary_pred to test for equality. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param binary_pred The binary predicate used to determine equality. + * \return The number of runs of equal elements in [first, new_last) + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type + * and to \p BinaryPredicate's \c second_argument_type. \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p unique_count to + * determine a number of runs of equal elements using the \p thrust::host execution policy + * for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int count = thrust::unique_count(thrust::host, A, A + N, thrust::equal_to()); + * // count is now 4 + * \endcode + * + * \see unique_copy + * \see unique_by_key_copy + * \see reduce_by_key_copy + */ +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type unique_count( + const thrust::detail::execution_policy_base& exec, + ForwardIterator first, + ForwardIterator last, + BinaryPredicate binary_pred); + +/*! \p unique_count counts runs of equal elements in the range [first, last) + * with the same value, + * + * This version of \p unique_count uses \c operator== to test for equality. + * + * The algorithm's execution is parallelized as determined by \p exec. + * + * \param exec The execution policy to use for parallelization. + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param binary_pred The binary predicate used to determine equality. + * \return The number of runs of equal elements in [first, new_last) + * + * \tparam DerivedPolicy The name of the derived execution policy. + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type + * and to \p BinaryPredicate's \c second_argument_type. \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p unique_count to + * determine the number of runs of equal elements using the \p thrust::host execution policy + * for parallelization: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int count = thrust::unique_count(thrust::host, A, A + N); + * // count is now 4 + * \endcode + * + * \see unique_copy + * \see unique_by_key_copy + * \see reduce_by_key_copy + */ +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type unique_count( + const thrust::detail::execution_policy_base& exec, ForwardIterator first, ForwardIterator last); + +/*! \p unique_count counts runs of equal elements in the range [first, last) + * with the same value, + * + * This version of \p unique_count uses the function object \p binary_pred to test for equality. + * + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param binary_pred The binary predicate used to determine equality. + * \return The number of runs of equal elements in [first, new_last) + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type + * and to \p BinaryPredicate's \c second_argument_type. + * \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p unique_count to + * determine the number of runs of equal elements: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int count = thrust::unique_count(A, A + N, thrust::equal_to()); + * // count is now 4 + * \endcode + * + * \see unique_copy + * \see unique_by_key_copy + * \see reduce_by_key_copy + */ +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +unique_count(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred); + +/*! \p unique_count counts runs of equal elements in the range [first, last) + * with the same value, + * + * This version of \p unique_count uses \c operator== to test for equality. + * + * \param first The beginning of the input range. + * \param last The end of the input range. + * \param binary_pred The binary predicate used to determine equality. + * \return The number of runs of equal elements in [first, new_last) + * + * \tparam ForwardIterator is a model of Forward + * Iterator, and \p ForwardIterator's \c value_type is convertible to \p BinaryPredicate's \c first_argument_type + * and to \p BinaryPredicate's \c second_argument_type. + * \tparam BinaryPredicate is a model of Binary Predicate. + * + * The following code snippet demonstrates how to use \p unique_count to + * determine the number of runs of equal elements: + * + * \code + * #include + * #include + * ... + * const int N = 7; + * int A[N] = {1, 3, 3, 3, 2, 2, 1}; + * int count = thrust::unique_count(thrust::host, A, A + N); + * // count is now 4 + * \endcode + * + * \see unique_copy + * \see unique_by_key_copy + * \see reduce_by_key_copy + */ +template +_CCCL_HOST_DEVICE typename thrust::iterator_traits::difference_type +unique_count(ForwardIterator first, ForwardIterator last); + +/*! \} // end stream_compaction + */ + +THRUST_NAMESPACE_END + +#include diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/universal_allocator.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/universal_allocator.h new file mode 100644 index 0000000000000000000000000000000000000000..5a95d2791130be161960881c7eb0d24cf78082f7 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/universal_allocator.h @@ -0,0 +1,83 @@ +/* + * Copyright 2008-2020 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file universal_allocator.h + * \brief An allocator which creates new elements in memory accessible to both + * hosts and devices. + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +// #include the device system's vector header +#define __THRUST_DEVICE_SYSTEM_MEMORY_HEADER <__THRUST_DEVICE_SYSTEM_ROOT/memory.h> +#include __THRUST_DEVICE_SYSTEM_MEMORY_HEADER +#undef __THRUST_DEVICE_SYSTEM_MEMORY_HEADER + +THRUST_NAMESPACE_BEGIN + +/** \addtogroup memory_resources Memory Resources + * \ingroup memory_management_classes + * \{ + */ + +/*! \brief An allocator which creates new elements in memory accessible by + * both hosts and devices. + * + * \see https://en.cppreference.com/w/cpp/named_req/Allocator + */ +using thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::universal_allocator; + +/*! \p universal_ptr stores a pointer to an object allocated in memory accessible + * to both hosts and devices. + * + * Algorithms dispatched with this type of pointer will be dispatched to + * either host or device, depending on which backend you are using. Explicit + * policies (\p thrust::device, etc) can be used to specify where an algorithm + * should be run. + * + * \p universal_ptr has pointer semantics: it may be dereferenced safely from + * both hosts and devices and may be manipulated with pointer arithmetic. + * + * \p universal_ptr can be created with \p universal_allocator or by explicitly + * calling its constructor with a raw pointer. + * + * The raw pointer encapsulated by a \p universal_ptr may be obtained by + * either its get method or the \p raw_pointer_cast free function. + * + * \note \p universal_ptr is not a smart pointer; it is the programmer's + * responsibility to deallocate memory pointed to by \p universal_ptr. + * + * \see host_ptr For the documentation of the complete interface which is + * shared by \p universal_ptr. + * \see raw_pointer_cast + */ +template +using universal_ptr = thrust::system::__THRUST_DEVICE_SYSTEM_NAMESPACE::universal_pointer; + +/*! \} + */ + +THRUST_NAMESPACE_END diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/version.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/version.h new file mode 100644 index 0000000000000000000000000000000000000000..5fe9a97ac294a3b796515f80bb65de76c2e7bbdb --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/version.h @@ -0,0 +1,93 @@ +/* + * Copyright 2008-2022 NVIDIA Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/*! \file version.h + * \brief Compile-time macros encoding Thrust release version + * + * is the only Thrust header that is guaranteed to + * change with every thrust release. + * + * It is also the only header that does not cause THRUST_HOST_SYSTEM + * and THRUST_DEVICE_SYSTEM to be defined. This way, a user may include + * this header and inspect THRUST_VERSION before programmatically defining + * either of these macros herself. + */ + +#pragma once + +#include // IWYU pragma: export + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include // IWYU pragma: export + +// This is the only Thrust header that is guaranteed to +// change with every Thrust release. +// +// THRUST_VERSION % 100 is the sub-minor version +// THRUST_VERSION / 100 % 1000 is the minor version +// THRUST_VERSION / 100000 is the major version +// +// Because this header does not #include , +// it is the only Thrust header that does not cause +// THRUST_HOST_SYSTEM and THRUST_DEVICE_SYSTEM to be defined. + +/*! \def THRUST_VERSION + * \brief The preprocessor macro \p THRUST_VERSION encodes the version + * number of the Thrust library as MMMmmmpp. + * + * \note THRUST_VERSION is formatted as `MMMmmmpp`, which differs from `CCCL_VERSION` that uses `MMMmmmppp`. + * + * THRUST_VERSION % 100 is the sub-minor version. + * THRUST_VERSION / 100 % 1000 is the minor version. + * THRUST_VERSION / 100000 is the major version. + */ +#define THRUST_VERSION 200800 // macro expansion with ## requires this to be a single value + +/*! \def THRUST_MAJOR_VERSION + * \brief The preprocessor macro \p THRUST_MAJOR_VERSION encodes the + * major version number of the Thrust library. + */ +#define THRUST_MAJOR_VERSION (THRUST_VERSION / 100000) + +/*! \def THRUST_MINOR_VERSION + * \brief The preprocessor macro \p THRUST_MINOR_VERSION encodes the + * minor version number of the Thrust library. + */ +#define THRUST_MINOR_VERSION (THRUST_VERSION / 100 % 1000) + +/*! \def THRUST_SUBMINOR_VERSION + * \brief The preprocessor macro \p THRUST_SUBMINOR_VERSION encodes the + * sub-minor version number of the Thrust library. + */ +#define THRUST_SUBMINOR_VERSION (THRUST_VERSION % 100) + +/*! \def THRUST_PATCH_NUMBER + * \brief The preprocessor macro \p THRUST_PATCH_NUMBER encodes the + * patch number of the Thrust library. + * Legacy; will be 0 for all future releases. + */ +#define THRUST_PATCH_NUMBER 0 + +static_assert(THRUST_MAJOR_VERSION == CCCL_MAJOR_VERSION, ""); +static_assert(THRUST_MINOR_VERSION == CCCL_MINOR_VERSION, ""); +static_assert(THRUST_SUBMINOR_VERSION == CCCL_PATCH_VERSION, ""); diff --git a/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/zip_function.h b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/zip_function.h new file mode 100644 index 0000000000000000000000000000000000000000..24c52cc34ebca8edcc865e05a45e888a53302494 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/cupy/_core/include/cupy/_cccl/thrust/thrust/zip_function.h @@ -0,0 +1,212 @@ + +/*! \file thrust/zip_function.h + * \brief Adaptor type that turns an N-ary function object into one that takes + * a tuple of size N so it can easily be used with algorithms taking zip + * iterators + */ + +#pragma once + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header +#include +#if !defined(THRUST_LEGACY_GCC) + +# include +# include +# include + +# include + +THRUST_NAMESPACE_BEGIN + +/*! \addtogroup function_objects Function Objects + * \{ + */ + +/*! \addtogroup function_object_adaptors Function Object Adaptors + * \ingroup function_objects + * \{ + */ + +namespace detail +{ +namespace zip_detail +{ + +// Add workaround for decltype(auto) on C++11-only compilers: +# if _CCCL_STD_VER >= 2014 + +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE decltype(auto) apply_impl(Function&& func, Tuple&& args, index_sequence) +{ + return func(thrust::get(THRUST_FWD(args))...); +} + +template +_CCCL_HOST_DEVICE decltype(auto) apply(Function&& func, Tuple&& args) +{ + constexpr auto tuple_size = thrust::tuple_size::type>::value; + return apply_impl(THRUST_FWD(func), THRUST_FWD(args), make_index_sequence{}); +} + +# else // _CCCL_STD_VER + +_CCCL_EXEC_CHECK_DISABLE +template +_CCCL_HOST_DEVICE auto apply_impl(Function&& func, Tuple&& args, index_sequence) + THRUST_DECLTYPE_RETURNS(func(thrust::get(THRUST_FWD(args))...)) + + template + _CCCL_HOST_DEVICE auto apply(Function&& func, Tuple&& args) THRUST_DECLTYPE_RETURNS(apply_impl( + THRUST_FWD(func), + THRUST_FWD(args), + make_index_sequence::type>::value>{})) + +# endif // _CCCL_STD_VER + +} // namespace zip_detail +} // namespace detail + +/*! \p zip_function is a function object that allows the easy use of N-ary + * function objects with \p zip_iterators without redefining them to take a + * \p tuple instead of N arguments. + * + * This means that if a functor that takes 2 arguments which could be used with + * the \p transform function and \p device_iterators can be extended to take 3 + * arguments and \p zip_iterators without rewriting the functor in terms of + * \p tuple. + * + * The \p make_zip_function convenience function is provided to avoid having + * to explicitly define the type of the functor when creating a \p zip_function, + * whic is especially helpful when using lambdas as the functor. + * + * \code + * #include + * #include + * #include + * #include + * + * struct SumTuple { + * float operator()(auto tup) const { + * return thrust::get<0>(tup) + thrust::get<1>(tup) + thrust::get<2>(tup); + * } + * }; + * struct SumArgs { + * float operator()(float a, float b, float c) const { + * return a + b + c; + * } + * }; + * + * int main() { + * thrust::device_vector A{0.f, 1.f, 2.f}; + * thrust::device_vector B{1.f, 2.f, 3.f}; + * thrust::device_vector C{2.f, 3.f, 4.f}; + * thrust::device_vector D(3); + * + * auto begin = thrust::make_zip_iterator(thrust::make_tuple(A.begin(), B.begin(), C.begin())); + * auto end = thrust::make_zip_iterator(thrust::make_tuple(A.end(), B.end(), C.end())); + * + * // The following four invocations of transform are equivalent: + * // Transform with 3-tuple + * thrust::transform(begin, end, D.begin(), SumTuple{}); + * + * // Transform with 3 parameters + * thrust::zip_function adapted{}; + * thrust::transform(begin, end, D.begin(), adapted); + * + * // Transform with 3 parameters with convenience function + * thrust::transform(begin, end, D.begin(), thrust::make_zip_function(SumArgs{})); + * + * // Transform with 3 parameters with convenience function and lambda + * thrust::transform(begin, end, D.begin(), thrust::make_zip_function([] (float a, float b, float c) { + * return a + b + c; + * })); + * return 0; + * } + * \endcode + * + * \see make_zip_function + * \see zip_iterator + */ +template +class zip_function +{ +public: + //! Default constructs the contained function object. + zip_function() = default; + + _CCCL_HOST_DEVICE zip_function(Function func) + : func(std::move(func)) + {} + +// Add workaround for decltype(auto) on C++11-only compilers: +# if _CCCL_STD_VER >= 2014 + + template + _CCCL_HOST_DEVICE decltype(auto) operator()(Tuple&& args) const + { + return detail::zip_detail::apply(func, THRUST_FWD(args)); + } + +# else // _CCCL_STD_VER + + // Can't just use THRUST_DECLTYPE_RETURNS here since we need to use + // std::declval for the signature components: + template + _CCCL_HOST_DEVICE auto operator()(Tuple&& args) const + noexcept(noexcept(detail::zip_detail::apply(std::declval(), THRUST_FWD(args)))) + -> decltype(detail::zip_detail::apply(std::declval(), THRUST_FWD(args))) + { + return detail::zip_detail::apply(func, THRUST_FWD(args)); + } + +# endif // _CCCL_STD_VER + + //! Returns a reference to the underlying function. + _CCCL_HOST_DEVICE Function& underlying_function() const + { + return func; + } + +private: + mutable Function func; +}; + +/*! \p make_zip_function creates a \p zip_function from a function object. + * + * \param fun The N-ary function object. + * \return A \p zip_function that takes a N-tuple. + * + * \see zip_function + */ +template +_CCCL_HOST_DEVICE zip_function::type> make_zip_function(Function&& fun) +{ + using func_t = typename std::decay::type; + return zip_function(THRUST_FWD(fun)); +} + +/*! \} // end function_object_adaptors + */ + +/*! \} // end function_objects + */ + +THRUST_NAMESPACE_END + +_LIBCUDACXX_BEGIN_NAMESPACE_CUDA +template +struct proclaims_copyable_arguments> : proclaims_copyable_arguments +{}; +_LIBCUDACXX_END_NAMESPACE_CUDA + +#endif