[INFRA] Import NVIDIA/CCCL upstream as optimization reference library

CCCL (CUDA C++ Core Libraries) provides:
- CUB: device/block/warp-level GPU primitives (reduce, scan, sort, topk)
- Thrust: high-level parallel algorithms (transform_reduce, sort, scan)
- libcudacxx: CUDA C++ standard library (atomics, barriers, memory)
- cudax: experimental features (memory resources, allocators)
- Tuning policies: per-SM hardware-specific algorithm parameters

Competition optimization vectors mapped to CCCL:
- Output TPS (83% weight): warp_reduce, block_reduce, device_topk
- Input TPS (14% weight): device_scan, block_load, prefetch
- Cache TPS (3% weight): prefix caching strategy patterns
- Memory (0.9 util): pooled/cached/buddy allocators

Source: https://github.com/NVIDIA/cccl (shallow clone, HEAD only)
License: Apache-2.0
This commit is contained in:
EngineX CI
2026-07-30 09:35:51 +00:00
parent b4d01f481e
commit 56fd68e7dd
8871 changed files with 1454674 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_ADJACENT_FIND_H
#define _CUDA_STD___ALGORITHM_ADJACENT_FIND_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _BinaryPredicate>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator
adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
{
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (__pred(*__first, *__i))
{
__last = __first;
break;
}
__first = __i;
}
}
return __last;
}
template <class _ForwardIterator>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
{
return ::cuda::std::adjacent_find(__first, __last, __equal_to{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_ADJACENT_FIND_H

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_ALL_OF_H
#define _CUDA_STD___ALGORITHM_ALL_OF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Predicate>
[[nodiscard]] _CCCL_API constexpr bool all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
bool __result = true;
for (; __first != __last; ++__first)
{
if (!__pred(*__first))
{
__result = false;
break;
}
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_ALL_OF_H

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_ANY_OF_H
#define _CUDA_STD___ALGORITHM_ANY_OF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Predicate>
[[nodiscard]] _CCCL_API constexpr bool any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
bool __result = false;
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
__result = true;
break;
}
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_ANY_OF_H

View File

@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_BINARY_SEARCH_H
#define _CUDA_STD___ALGORITHM_BINARY_SEARCH_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/lower_bound.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Tp, class _Compare>
[[nodiscard]] _CCCL_API constexpr bool
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
{
__first =
::cuda::std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare>>(__first, __last, __value, __comp);
return __first != __last && !__comp(__value, *__first);
}
template <class _ForwardIterator, class _Tp>
[[nodiscard]] _CCCL_API constexpr bool
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
{
return ::cuda::std::binary_search(__first, __last, __value, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_BINARY_SEARCH_H

View File

@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_CLAMP_H
#define _CUDA_STD___ALGORITHM_CLAMP_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp, class _Compare>
[[nodiscard]] _CCCL_API constexpr const _Tp&
clamp(const _Tp& __v _CCCL_LIFETIMEBOUND,
const _Tp& __lo _CCCL_LIFETIMEBOUND,
const _Tp& __hi _CCCL_LIFETIMEBOUND,
_Compare __comp)
{
_CCCL_ASSERT(!__comp(__hi, __lo), "Bad bounds passed to cuda::std::clamp");
return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v;
}
template <class _Tp>
[[nodiscard]] _CCCL_API constexpr const _Tp&
clamp(const _Tp& __v _CCCL_LIFETIMEBOUND, const _Tp& __lo _CCCL_LIFETIMEBOUND, const _Tp& __hi _CCCL_LIFETIMEBOUND)
{
_CCCL_ASSERT(!(__hi < __lo), "Bad bounds passed to cuda::std::clamp");
return __v < __lo ? __lo : __hi < __v ? __hi : __v;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_CLAMP_H

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_COMP_H
#define _CUDA_STD___ALGORITHM_COMP_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__type_traits/integral_constant.h>
#if defined(_LIBCUDACXX_HAS_STRING)
# include <cuda/std/__type_traits/predicate_traits.h>
#endif // _LIBCUDACXX_HAS_STRING
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
struct __equal_to
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
[[nodiscard]] _CCCL_API constexpr bool operator()(const _T1& __lhs, const _T2& __rhs) const
noexcept(noexcept(__lhs == __rhs))
{
return __lhs == __rhs;
}
};
struct __less
{
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp, class _Up>
[[nodiscard]] _CCCL_API constexpr bool operator()(const _Tp& __lhs, const _Up& __rhs) const
noexcept(noexcept(__lhs < __rhs))
{
return __lhs < __rhs;
}
};
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_COMP_H

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_COMP_REF_TYPE_H
#define _CUDA_STD___ALGORITHM_COMP_REF_TYPE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__utility/declval.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _Compare>
struct __debug_less
{
_Compare& __comp_;
_CCCL_API constexpr __debug_less(_Compare& __c)
: __comp_(__c)
{}
template <class _Tp, class _Up>
[[nodiscard]] _CCCL_API constexpr bool operator()(const _Tp& __x, const _Up& __y)
{
bool __r = __comp_(__x, __y);
if (__r)
{
__do_compare_assert(0, __y, __x);
}
return __r;
}
template <class _Tp, class _Up>
[[nodiscard]] _CCCL_API constexpr bool operator()(_Tp& __x, _Up& __y)
{
bool __r = __comp_(__x, __y);
if (__r)
{
__do_compare_assert(0, __y, __x);
}
return __r;
}
template <class _LHS, class _RHS>
_CCCL_API constexpr decltype((void) declval<_Compare&>()(declval<_LHS&>(), declval<_RHS&>()))
__do_compare_assert(int, [[maybe_unused]] _LHS& __l, [[maybe_unused]] _RHS& __r)
{
_CCCL_ASSERT(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering");
}
template <class _LHS, class _RHS>
_CCCL_API constexpr void __do_compare_assert(long, _LHS&, _RHS&)
{}
};
// Pass the comparator by lvalue reference. Or in debug mode, using a
// debugging wrapper that stores a reference.
#ifdef _CCCL_ENABLE_DEBUG_MODE
template <class _Comp>
using __comp_ref_type = __debug_less<_Comp>;
#else // ^^^ _LIBCUDACXX_ENABLE_DEBUG_MODE ^^^ / vvv !_LIBCUDACXX_ENABLE_DEBUG_MODE vvv
template <class _Comp>
using __comp_ref_type = _Comp&;
#endif // !_LIBCUDACXX_ENABLE_DEBUG_MODE
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_COMP_REF_TYPE_H

View File

@@ -0,0 +1,152 @@
//===----------------------------------------------------------------------===//
//
// 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-24 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_COPY_H
#define _CUDA_STD___ALGORITHM_COPY_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/unwrap_iter.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_constant_evaluated.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/is_trivially_copyable.h>
#include <cuda/std/__type_traits/remove_const.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/cstdint>
#include <cuda/std/cstdlib>
#include <cuda/std/cstring> // memmove
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _InputIterator, class _OutputIterator>
_CCCL_API constexpr pair<_InputIterator, _OutputIterator>
__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
for (; __first != __last; ++__first, (void) ++__result)
{
*__result = *__first;
}
return {__last, __result};
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp, class _Up>
_CCCL_API constexpr bool
__dispatch_memmove([[maybe_unused]] _Up* __result, [[maybe_unused]] _Tp* __first, [[maybe_unused]] const size_t __n)
{
#if defined(_CCCL_BUILTIN_MEMMOVE)
_CCCL_BUILTIN_MEMMOVE(__result, __first, __n * sizeof(_Up));
return true;
#else // ^^^ _CCCL_BUILTIN_MEMMOVE ^^^ / vvv !_CCCL_BUILTIN_MEMMOVE vvv
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
{
::cuda::std::memmove(__result, __first, __n * sizeof(_Up));
return true;
}
return false;
#endif // ^^^ !_CCCL_BUILTIN_MEMMOVE ^^^
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp, class _Up>
_CCCL_API constexpr bool __constexpr_tail_overlap_fallback(_Tp* __first, _Up* __needle, _Tp* __last)
{
bool __result = false;
while (__first != __last)
{
if (__first == __needle)
{
__result = true;
break;
}
++__first;
}
return __result;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp, class _Up>
_CCCL_API constexpr bool __constexpr_tail_overlap(_Tp* __first, _Up* __needle, [[maybe_unused]] _Tp* __last)
{
if (!::cuda::std::__cccl_default_is_constant_evaluated())
{
return __first < __needle;
}
else
{
#if defined(_CCCL_BUILTIN_CONSTANT_P)
NV_IF_ELSE_TARGET(NV_IS_HOST,
(return _CCCL_BUILTIN_CONSTANT_P(__first < __needle) && __first < __needle;),
(return __constexpr_tail_overlap_fallback(__first, __needle, __last);))
#else // ^^^ _CCCL_BUILTIN_CONSTANT_P ^^^ / vvv !_CCCL_BUILTIN_CONSTANT_P vvv
return __constexpr_tail_overlap_fallback(__first, __needle, __last);
#endif // !_CCCL_BUILTIN_CONSTANT_P
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy,
class _Tp,
class _Up,
enable_if_t<is_same_v<remove_const_t<_Tp>, _Up>, int> = 0,
enable_if_t<is_trivially_copyable_v<_Up>, int> = 0>
_CCCL_API constexpr pair<_Tp*, _Up*> __copy(_Tp* __first, _Tp* __last, _Up* __result)
{
const ptrdiff_t __n = __last - __first;
if (__n > 0)
{
if (__dispatch_memmove(__result, __first, __n))
{
return pair{__last, __result + __n};
}
if (__constexpr_tail_overlap(__first, __result, __last))
{
for (ptrdiff_t __i = __n; __i > 0; --__i)
{
*(__result + __i - 1) = *(__first + __i - 1);
}
}
else
{
for (ptrdiff_t __i = 0; __i < __n; ++__i)
{
*(__result + __i) = *(__first + __i);
}
}
}
return pair{__last, __result + __n};
}
template <class _InputIterator, class _OutputIterator>
_CCCL_API constexpr _OutputIterator copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
return ::cuda::std::__copy<_ClassicAlgPolicy>(
::cuda::std::__unwrap_iter(__first), ::cuda::std::__unwrap_iter(__last), ::cuda::std::__unwrap_iter(__result))
.second;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_COPY_H

View File

@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_COPY_BACKWARD_H
#define _CUDA_STD___ALGORITHM_COPY_BACKWARD_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/copy.h>
#include <cuda/std/__algorithm/unwrap_iter.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/is_trivially_copyable.h>
#include <cuda/std/__type_traits/remove_const.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _BidirectionalIterator, class _OutputIterator>
_CCCL_API constexpr _OutputIterator
__copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
{
while (__first != __last)
{
*--__result = *--__last;
}
return __result;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp,
class _Up,
enable_if_t<is_same_v<remove_const_t<_Tp>, _Up>, int> = 0,
enable_if_t<is_trivially_copyable_v<_Up>, int> = 0>
_CCCL_API inline _CCCL_CONSTEXPR_CXX20 _Up* __copy_backward(_Tp* __first, _Tp* __last, _Up* __result)
{
const ptrdiff_t __n = __last - __first;
if (__n > 0)
{
if (__dispatch_memmove(__result - __n, __first, __n))
{
return __result - __n;
}
for (ptrdiff_t __i = 1; __i <= __n; ++__i)
{
*(__result - __i) = *(__last - __i);
}
}
return __result - __n;
}
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
_CCCL_API inline _CCCL_CONSTEXPR_CXX20 _BidirectionalIterator2
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result)
{
return ::cuda::std::__copy_backward(
::cuda::std::__unwrap_iter(__first), ::cuda::std::__unwrap_iter(__last), ::cuda::std::__unwrap_iter(__result));
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_COPY_BACKWARD_H

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_COPY_IF_H
#define _CUDA_STD___ALGORITHM_COPY_IF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _OutputIterator, class _Predicate>
_CCCL_API constexpr _OutputIterator
copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred)
{
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
*__result = *__first;
++__result;
}
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_COPY_IF_H

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_COPY_N_H
#define _CUDA_STD___ALGORITHM_COPY_N_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/copy.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__utility/convert_to_integral.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator,
class _Size,
class _OutputIterator,
enable_if_t<__has_input_traversal<_InputIterator>, int> = 0,
enable_if_t<!__has_random_access_traversal<_InputIterator>, int> = 0>
_CCCL_API inline _CCCL_CONSTEXPR_CXX20 _OutputIterator
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
{
using _IntegralSize = decltype(__convert_to_integral(__orig_n));
_IntegralSize __n = static_cast<_IntegralSize>(__orig_n);
if (__n > 0)
{
*__result = *__first;
++__result;
for (--__n; __n > 0; --__n)
{
++__first;
*__result = *__first;
++__result;
}
}
return __result;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator,
class _Size,
class _OutputIterator,
enable_if_t<__has_random_access_traversal<_InputIterator>, int> = 0>
_CCCL_API constexpr _OutputIterator copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
{
using _IntegralSize = decltype(__convert_to_integral(__orig_n));
_IntegralSize __n = static_cast<_IntegralSize>(__orig_n);
return ::cuda::std::copy(__first, __first + __n, __result);
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_COPY_N_H

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_COUNT_H
#define _CUDA_STD___ALGORITHM_COUNT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Tp>
[[nodiscard]] _CCCL_API constexpr __iter_diff_t<_InputIterator>
count(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
__iter_diff_t<_InputIterator> __r{0};
for (; __first != __last; ++__first)
{
if (*__first == __value_)
{
++__r;
}
}
return __r;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_COUNT_H

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_COUNT_IF_H
#define _CUDA_STD___ALGORITHM_COUNT_IF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Predicate>
[[nodiscard]] _CCCL_API constexpr __iter_diff_t<_InputIterator>
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
__iter_diff_t<_InputIterator> __r{0};
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
++__r;
}
}
return __r;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_COUNT_IF_H

View File

@@ -0,0 +1,132 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_EQUAL_H
#define _CUDA_STD___ALGORITHM_EQUAL_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/add_lvalue_reference.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_API constexpr bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred)
{
bool __result = true;
for (; __first1 != __last1; ++__first1, (void) ++__first2)
{
if (!__pred(*__first1, *__first2))
{
__result = false;
break;
}
}
return __result;
}
template <class _InputIterator1, class _InputIterator2>
[[nodiscard]] _CCCL_API constexpr bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2)
{
return ::cuda::std::equal(__first1, __last1, __first2, __equal_to{});
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2>
[[nodiscard]] _CCCL_API constexpr bool __equal(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_BinaryPredicate __pred,
input_iterator_tag,
input_iterator_tag)
{
bool __result = true;
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2)
{
if (!__pred(*__first1, *__first2))
{
__result = false;
break;
}
}
return __result && __first1 == __last1 && __first2 == __last2;
}
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
[[nodiscard]] _CCCL_API constexpr bool __equal(
_RandomAccessIterator1 __first1,
_RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2,
_BinaryPredicate __pred,
random_access_iterator_tag,
random_access_iterator_tag)
{
if (__last1 - __first1 != __last2 - __first2)
{
return false;
}
return ::cuda::std::equal<_RandomAccessIterator1, _RandomAccessIterator2, add_lvalue_reference_t<_BinaryPredicate>>(
__first1, __last1, __first2, __pred);
}
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_API constexpr bool
equal(_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_BinaryPredicate __pred)
{
return ::cuda::std::__equal<add_lvalue_reference_t<_BinaryPredicate>>(
__first1,
__last1,
__first2,
__last2,
__pred,
__iterator_traits_category_or_concept_t<_InputIterator1>(),
__iterator_traits_category_or_concept_t<_InputIterator2>());
}
template <class _InputIterator1, class _InputIterator2>
[[nodiscard]] _CCCL_API constexpr bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
{
return ::cuda::std::__equal(
__first1,
__last1,
__first2,
__last2,
__equal_to{},
__iterator_traits_category_or_concept_t<_InputIterator1>(),
__iterator_traits_category_or_concept_t<_InputIterator2>());
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_EQUAL_H

View File

@@ -0,0 +1,101 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_EQUAL_RANGE_H
#define _CUDA_STD___ALGORITHM_EQUAL_RANGE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/half_positive.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/lower_bound.h>
#include <cuda/std/__algorithm/upper_bound.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/advance.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__iterator/next.h>
#include <cuda/std/__type_traits/is_callable.h>
#include <cuda/std/__type_traits/is_copy_constructible.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj>
_CCCL_HOST_DEVICE_API constexpr pair<_Iter, _Iter>
__equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj)
{
auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
_Iter __end = _IterOps<_AlgPolicy>::next(__first, __last);
while (__len != 0)
{
auto __half_len = ::cuda::std::__half_positive(__len);
_Iter __mid = _IterOps<_AlgPolicy>::next(__first, __half_len);
if (::cuda::std::invoke(__comp, ::cuda::std::invoke(__proj, *__mid), __value))
{
__first = ++__mid;
__len -= __half_len + 1;
}
else if (::cuda::std::invoke(__comp, __value, ::cuda::std::invoke(__proj, *__mid)))
{
__end = __mid;
__len = __half_len;
}
else
{
_Iter __mp1 = __mid;
return pair<_Iter, _Iter>(::cuda::std::__lower_bound<_AlgPolicy>(__first, __mid, __value, __comp, __proj),
::cuda::std::__upper_bound<_AlgPolicy>(++__mp1, __end, __value, __comp, __proj));
}
}
return pair<_Iter, _Iter>(__first, __first);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Tp, class _Compare>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
{
static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
static_assert(is_copy_constructible_v<_ForwardIterator>, "Iterator has to be copy constructible");
return ::cuda::std::__equal_range<_ClassicAlgPolicy>(
::cuda::std::move(__first),
::cuda::std::move(__last),
__value,
static_cast<__comp_ref_type<_Compare>>(__comp),
::cuda::std::identity());
}
template <class _ForwardIterator, class _Tp>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
{
return ::cuda::std::equal_range(::cuda::std::move(__first), ::cuda::std::move(__last), __value, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_EQUAL_RANGE_H

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_FILL_H
#define _CUDA_STD___ALGORITHM_FILL_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/fill_n.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Tp>
_CCCL_API constexpr void
__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag)
{
for (; __first != __last; ++__first)
{
*__first = __value_;
}
}
template <class _RandomAccessIterator, class _Tp>
_CCCL_API constexpr void
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag)
{
::cuda::std::fill_n(__first, __last - __first, __value_);
}
template <class _ForwardIterator, class _Tp>
_CCCL_API constexpr void fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
::cuda::std::__fill(__first, __last, __value_, __iterator_traits_category_or_concept_t<_ForwardIterator>());
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_FILL_H

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_FILL_N_H
#define _CUDA_STD___ALGORITHM_FILL_N_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/convert_to_integral.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _OutputIterator, class _Size, class _Tp>
_CCCL_API constexpr _OutputIterator __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
{
for (; __n > 0; ++__first, (void) --__n)
{
*__first = __value_;
}
return __first;
}
template <class _OutputIterator, class _Size, class _Tp>
_CCCL_API constexpr _OutputIterator fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
{
return ::cuda::std::__fill_n(__first, __convert_to_integral(__n), __value_);
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_FILL_N_H

View File

@@ -0,0 +1,62 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_FIND_H
#define _CUDA_STD___ALGORITHM_FIND_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__functional/invoke.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
// generic implementation
template <class _Iter, class _Sent, class _Tp, class _Proj>
[[nodiscard]] _CCCL_API constexpr _Iter __find_impl(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj)
{
for (; __first != __last; ++__first)
{
if (::cuda::std::invoke(__proj, *__first) == __value)
{
break;
}
}
return __first;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Tp>
[[nodiscard]] _CCCL_API constexpr _InputIterator find(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
for (; __first != __last; ++__first)
{
if (*__first == __value_)
{
break;
}
}
return __first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_FIND_H

View File

@@ -0,0 +1,231 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_FIND_END_H
#define _CUDA_STD___ALGORITHM_FIND_END_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/add_lvalue_reference.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator1 __find_end(
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred,
forward_iterator_tag,
forward_iterator_tag)
{
// modeled after search algorithm
_ForwardIterator1 __r = __last1; // __last1 is the "default" answer
if (__first2 == __last2)
{
return __r;
}
bool __searching = true;
while (__searching)
{
while (__searching)
{
if (__first1 == __last1) // if source exhausted return last correct answer
{
// return __r; // (or __last1 if never found)
__searching = false;
break;
}
if (__pred(*__first1, *__first2))
{
break;
}
++__first1;
}
// *__first1 matches *__first2, now match elements after here
_ForwardIterator1 __m1 = __first1;
_ForwardIterator2 __m2 = __first2;
while (__searching)
{
if (++__m2 == __last2)
{ // Pattern exhausted, record answer and search for another one
__r = __first1;
++__first1;
break;
}
if (++__m1 == __last1) // Source exhausted, return last answer
{
// return __r;
__searching = false;
break;
}
if (!__pred(*__m1, *__m2)) // mismatch, restart with a new __first
{
++__first1;
break;
} // else there is a match, check next elements
}
}
return __r;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _BidirectionalIterator1, class _BidirectionalIterator2>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _BidirectionalIterator1 __find_end(
_BidirectionalIterator1 __first1,
_BidirectionalIterator1 __last1,
_BidirectionalIterator2 __first2,
_BidirectionalIterator2 __last2,
_BinaryPredicate __pred,
bidirectional_iterator_tag,
bidirectional_iterator_tag)
{
// modeled after search algorithm (in reverse)
if (__first2 == __last2)
{
return __last1; // Everything matches an empty sequence
}
_BidirectionalIterator1 __l1 = __last1;
_BidirectionalIterator2 __l2 = __last2;
--__l2;
while (true)
{
// Find last element in sequence 1 that matches *(__last2-1), with a minimum of loop checks
while (true)
{
if (__first1 == __l1) // return __last1 if no element matches *__first2
{
return __last1;
}
if (__pred(*--__l1, *__l2))
{
break;
}
}
// *__l1 matches *__l2, now match elements before here
_BidirectionalIterator1 __m1 = __l1;
_BidirectionalIterator2 __m2 = __l2;
while (true)
{
if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern)
{
return __m1;
}
if (__m1 == __first1) // Otherwise if source exhausted, pattern not found
{
return __last1;
}
if (!__pred(*--__m1, *--__m2)) // if there is a mismatch, restart with a new __l1
{
break;
} // else there is a match, check next elements
}
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _RandomAccessIterator1 __find_end(
_RandomAccessIterator1 __first1,
_RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2,
_BinaryPredicate __pred,
random_access_iterator_tag,
random_access_iterator_tag)
{
// Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
__iter_diff_t<_RandomAccessIterator2> __len2 = __last2 - __first2;
if (__len2 == 0)
{
return __last1;
}
__iter_diff_t<_RandomAccessIterator1> __len1 = __last1 - __first1;
if (__len1 < __len2)
{
return __last1;
}
const _RandomAccessIterator1 __s = __first1 + (__len2 - 1); // End of pattern match can't go before here
_RandomAccessIterator1 __l1 = __last1;
_RandomAccessIterator2 __l2 = __last2;
--__l2;
while (true)
{
while (true)
{
if (__s == __l1)
{
return __last1;
}
if (__pred(*--__l1, *__l2))
{
break;
}
}
_RandomAccessIterator1 __m1 = __l1;
_RandomAccessIterator2 __m2 = __l2;
while (true)
{
if (__m2 == __first2)
{
return __m1;
}
// no need to check range on __m1 because __s guarantees we have enough source
if (!__pred(*--__m1, *--__m2))
{
break;
}
}
}
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator1 find_end(
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred)
{
return ::cuda::std::__find_end<add_lvalue_reference_t<_BinaryPredicate>>(
__first1,
__last1,
__first2,
__last2,
__pred,
__iterator_traits_category_or_concept_t<_ForwardIterator1>{},
__iterator_traits_category_or_concept_t<_ForwardIterator2>{});
}
template <class _ForwardIterator1, class _ForwardIterator2>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator1
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
return ::cuda::std::find_end(__first1, __last1, __first2, __last2, __equal_to{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_FIND_END_H

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_FIND_FIRST_OF_H
#define _CUDA_STD___ALGORITHM_FIND_FIRST_OF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator1 __find_first_of_ce(
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred)
{
for (; __first1 != __last1; ++__first1)
{
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
{
if (__pred(*__first1, *__j))
{
return __first1;
}
}
}
return __last1;
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator1 find_first_of(
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred)
{
return ::cuda::std::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
}
template <class _ForwardIterator1, class _ForwardIterator2>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator1 find_first_of(
_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
return ::cuda::std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_FIND_FIRST_OF_H

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_FIND_IF_H
#define _CUDA_STD___ALGORITHM_FIND_IF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Predicate>
[[nodiscard]] _CCCL_API constexpr _InputIterator
find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
break;
}
}
return __first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_FIND_IF_H

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_FIND_IF_NOT_H
#define _CUDA_STD___ALGORITHM_FIND_IF_NOT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Predicate>
[[nodiscard]] _CCCL_API constexpr _InputIterator
find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
{
if (!__pred(*__first))
{
break;
}
}
return __first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_FIND_IF_NOT_H

View File

@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_FOR_EACH_H
#define _CUDA_STD___ALGORITHM_FOR_EACH_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Function>
_CCCL_API constexpr _Function for_each(_InputIterator __first, _InputIterator __last, _Function __f)
{
for (; __first != __last; ++__first)
{
__f(*__first);
}
return __f;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_FOR_EACH_H

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_FOR_EACH_N_H
#define _CUDA_STD___ALGORITHM_FOR_EACH_N_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__utility/convert_to_integral.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Size, class _Function>
_CCCL_API constexpr _InputIterator for_each_n(_InputIterator __first, _Size __orig_n, _Function __f)
{
using _IntegralSize = decltype(::cuda::std::__convert_to_integral(__orig_n));
_IntegralSize __n = __orig_n;
while (__n > 0)
{
__f(*__first);
++__first;
--__n;
}
return __first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_FOR_EACH_N_H

View File

@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_GENERATE_H
#define _CUDA_STD___ALGORITHM_GENERATE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Generator>
_CCCL_API constexpr void generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen)
{
for (; __first != __last; ++__first)
{
*__first = __gen();
}
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_GENERATE_H

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_GENERATE_N_H
#define _CUDA_STD___ALGORITHM_GENERATE_N_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__utility/convert_to_integral.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _OutputIterator, class _Size, class _Generator>
_CCCL_API constexpr _OutputIterator generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen)
{
using _IntegralSize = decltype(__convert_to_integral(__orig_n));
_IntegralSize __n = static_cast<_IntegralSize>(__orig_n);
for (; __n > 0; ++__first, (void) --__n)
{
*__first = __gen();
}
return __first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_GENERATE_N_H

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_HALF_POSITIVE_H
#define _CUDA_STD___ALGORITHM_HALF_POSITIVE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_integral.h>
#include <cuda/std/__type_traits/make_unsigned.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
// Perform division by two quickly for positive integers (llvm.org/PR39129)
template <class _Integral, enable_if_t<is_integral_v<_Integral>, int> = 0>
[[nodiscard]] _CCCL_API constexpr _Integral __half_positive(_Integral __value)
{
return static_cast<_Integral>(static_cast<make_unsigned_t<_Integral>>(__value) / 2);
}
template <class _Tp, enable_if_t<!is_integral_v<_Tp>, int> = 0>
[[nodiscard]] _CCCL_API constexpr _Tp __half_positive(_Tp __value)
{
return __value / 2;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_HALF_POSITIVE_H

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_IN_FUN_RESULT_H
#define _CUDA_STD___ALGORITHM_IN_FUN_RESULT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__concepts/convertible_to.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD_RANGES
template <class _InIter1, class _Func1>
struct in_fun_result
{
_CCCL_NO_UNIQUE_ADDRESS _InIter1 in;
_CCCL_NO_UNIQUE_ADDRESS _Func1 fun;
_CCCL_TEMPLATE(class _InIter2, class _Func2)
_CCCL_REQUIRES(convertible_to<const _InIter1&, _InIter2> _CCCL_AND convertible_to<const _Func1&, _Func2>)
_CCCL_API constexpr operator in_fun_result<_InIter2, _Func2>() const&
{
return {in, fun};
}
_CCCL_TEMPLATE(class _InIter2, class _Func2)
_CCCL_REQUIRES(convertible_to<_InIter1, _InIter2> _CCCL_AND convertible_to<_Func1, _Func2>)
_CCCL_API constexpr operator in_fun_result<_InIter2, _Func2>() &&
{
return {::cuda::std::move(in), ::cuda::std::move(fun)};
}
};
_CCCL_END_NAMESPACE_CUDA_STD_RANGES
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_IN_FUN_RESULT_H

View File

@@ -0,0 +1,92 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_INCLUDES_H
#define _CUDA_STD___ALGORITHM_INCLUDES_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_callable.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>
_CCCL_API constexpr bool __includes(
_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2)
{
bool __result = true;
for (; __first2 != __last2; ++__first1)
{
if (__first1 == __last1
|| ::cuda::std::invoke(__comp, ::cuda::std::invoke(__proj2, *__first2), ::cuda::std::invoke(__proj1, *__first1)))
{
__result = false;
break;
}
if (!::cuda::std::invoke(__comp, ::cuda::std::invoke(__proj1, *__first1), ::cuda::std::invoke(__proj2, *__first2)))
{
++__first2;
}
}
return __result;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _Compare>
[[nodiscard]] _CCCL_API constexpr bool includes(
_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
{
static_assert(__is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value,
"Comparator has to be callable");
return ::cuda::std::__includes(
::cuda::std::move(__first1),
::cuda::std::move(__last1),
::cuda::std::move(__first2),
::cuda::std::move(__last2),
static_cast<__comp_ref_type<_Compare>>(__comp),
identity(),
identity());
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2>
[[nodiscard]] _CCCL_API constexpr bool
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
{
return ::cuda::std::includes(
::cuda::std::move(__first1),
::cuda::std::move(__last1),
::cuda::std::move(__first2),
::cuda::std::move(__last2),
__less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_INCLUDES_H

View File

@@ -0,0 +1,293 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_INPLACE_MERGE_H
#define _CUDA_STD___ALGORITHM_INPLACE_MERGE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/lower_bound.h>
#include <cuda/std/__algorithm/min.h>
#include <cuda/std/__algorithm/move.h>
#include <cuda/std/__algorithm/rotate.h>
#include <cuda/std/__algorithm/upper_bound.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__iterator/reverse_iterator.h>
#include <cuda/std/__memory/construct_at.h>
#include <cuda/std/__memory/destruct_n.h>
#include <cuda/std/__memory/temporary_buffer.h>
#include <cuda/std/__memory/unique_ptr.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/cstddef>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _Predicate>
class __invert // invert the sense of a comparison
{
private:
_Predicate __p_{};
public:
_CCCL_HIDE_FROM_ABI __invert() = default;
_CCCL_API explicit __invert(_Predicate __p)
: __p_(__p)
{}
template <class _T1>
[[nodiscard]] _CCCL_API bool operator()(const _T1& __x)
{
return !__p_(__x);
}
template <class _T1, class _T2>
[[nodiscard]] _CCCL_API bool operator()(const _T1& __x, const _T2& __y)
{
return __p_(__y, __x);
}
};
template <class _AlgPolicy,
class _Compare,
class _InputIterator1,
class _Sent1,
class _InputIterator2,
class _Sent2,
class _OutputIterator>
_CCCL_API void __half_inplace_merge(
_InputIterator1 __first1,
_Sent1 __last1,
_InputIterator2 __first2,
_Sent2 __last2,
_OutputIterator __result,
_Compare&& __comp)
{
for (; __first1 != __last1; ++__result)
{
if (__first2 == __last2)
{
::cuda::std::__move<_AlgPolicy>(__first1, __last1, __result);
return;
}
if (__comp(*__first2, *__first1))
{
*__result = _IterOps<_AlgPolicy>::__iter_move(__first2);
++__first2;
}
else
{
*__result = _IterOps<_AlgPolicy>::__iter_move(__first1);
++__first1;
}
}
// __first2 through __last2 are already in the right spot.
}
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
_CCCL_API void __buffered_inplace_merge(
_BidirectionalIterator __first,
_BidirectionalIterator __middle,
_BidirectionalIterator __last,
_Compare&& __comp,
typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
typename iterator_traits<_BidirectionalIterator>::value_type* __buff)
{
using value_type = typename iterator_traits<_BidirectionalIterator>::value_type;
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
if (__len1 <= __len2)
{
value_type* __p = __buff;
for (_BidirectionalIterator __i = __first; __i != __middle;
__d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
{
::cuda::std::__construct_at(__p, _IterOps<_AlgPolicy>::__iter_move(__i));
}
::cuda::std::__half_inplace_merge<_AlgPolicy>(__buff, __p, __middle, __last, __first, __comp);
}
else
{
value_type* __p = __buff;
for (_BidirectionalIterator __i = __middle; __i != __last;
__d.template __incr<value_type>(), (void) ++__i, (void) ++__p)
{
::cuda::std::__construct_at(__p, _IterOps<_AlgPolicy>::__iter_move(__i));
}
using _RBi = reverse_iterator<_BidirectionalIterator>;
using _Rv = reverse_iterator<value_type*>;
using _Inverted = __invert<_Compare>;
::cuda::std::__half_inplace_merge<_AlgPolicy>(
_Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), _RBi(__last), _Inverted(__comp));
}
}
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
_CCCL_API void __inplace_merge(
_BidirectionalIterator __first,
_BidirectionalIterator __middle,
_BidirectionalIterator __last,
_Compare&& __comp,
typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
typename iterator_traits<_BidirectionalIterator>::value_type* __buff,
ptrdiff_t __buff_size)
{
using _Ops = _IterOps<_AlgPolicy>;
using difference_type = typename iterator_traits<_BidirectionalIterator>::difference_type;
while (true)
{
// if __middle == __last, we're done
if (__len2 == 0)
{
return;
}
if (__len1 <= __buff_size || __len2 <= __buff_size)
{
return ::cuda::std::__buffered_inplace_merge<_AlgPolicy>(
__first, __middle, __last, __comp, __len1, __len2, __buff);
}
// shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
for (; true; ++__first, (void) --__len1)
{
if (__len1 == 0)
{
return;
}
if (__comp(*__middle, *__first))
{
break;
}
}
// __first < __middle < __last
// *__first > *__middle
// partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that
// all elements in:
// [__first, __m1) <= [__middle, __m2)
// [__middle, __m2) < [__m1, __middle)
// [__m1, __middle) <= [__m2, __last)
// and __m1 or __m2 is in the middle of its range
_BidirectionalIterator __m1; // "median" of [__first, __middle)
_BidirectionalIterator __m2; // "median" of [__middle, __last)
difference_type __len11; // distance(__first, __m1)
difference_type __len21; // distance(__middle, __m2)
// binary search smaller range
if (__len1 < __len2)
{ // __len >= 1, __len2 >= 2
__len21 = __len2 / 2;
__m2 = __middle;
_Ops::advance(__m2, __len21);
__m1 = ::cuda::std::__upper_bound<_AlgPolicy>(__first, __middle, *__m2, __comp, ::cuda::std::identity{});
__len11 = _Ops::distance(__first, __m1);
}
else
{
if (__len1 == 1)
{ // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1
// It is known *__first > *__middle
_Ops::iter_swap(__first, __middle);
return;
}
// __len1 >= 2, __len2 >= 1
__len11 = __len1 / 2;
__m1 = __first;
_Ops::advance(__m1, __len11);
__m2 = ::cuda::std::lower_bound(__middle, __last, *__m1, __comp);
__len21 = _Ops::distance(__middle, __m2);
}
difference_type __len12 = __len1 - __len11; // distance(__m1, __middle)
difference_type __len22 = __len2 - __len21; // distance(__m2, __last)
// [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last)
// swap middle two partitions
__middle = ::cuda::std::__rotate<_AlgPolicy>(__m1, __middle, __m2).first;
// __len12 and __len21 now have swapped meanings
// merge smaller range with recursive call and larger with tail recursion elimination
if (__len11 + __len21 < __len12 + __len22)
{
::cuda::std::__inplace_merge<_AlgPolicy>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
__first = __middle;
__middle = __m2;
__len1 = __len12;
__len2 = __len22;
}
else
{
::cuda::std::__inplace_merge<_AlgPolicy>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
__last = __middle;
__middle = __m1;
__len1 = __len11;
__len2 = __len21;
}
}
}
template <class _AlgPolicy, class _BidirectionalIterator, class _Compare>
_CCCL_API void __inplace_merge(
_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare&& __comp)
{
using value_type = typename iterator_traits<_BidirectionalIterator>::value_type;
using difference_type = typename iterator_traits<_BidirectionalIterator>::difference_type;
difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle);
difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last);
difference_type __buf_size = ::cuda::std::min(__len1, __len2);
pair<value_type*, ptrdiff_t> __buf = ::cuda::std::get_temporary_buffer<value_type>(__buf_size);
unique_ptr<value_type, __return_temporary_buffer> __unique_buf(__buf.first);
return ::cuda::std::__inplace_merge<_AlgPolicy>(
::cuda::std::move(__first),
::cuda::std::move(__middle),
::cuda::std::move(__last),
__comp,
__len1,
__len2,
__buf.first,
__buf.second);
}
template <class _BidirectionalIterator, class _Compare>
_CCCL_API void inplace_merge(
_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp)
{
::cuda::std::__inplace_merge<_ClassicAlgPolicy>(
::cuda::std::move(__first),
::cuda::std::move(__middle),
::cuda::std::move(__last),
static_cast<__comp_ref_type<_Compare>>(__comp));
}
template <class _BidirectionalIterator>
_CCCL_API void
inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last)
{
::cuda::std::inplace_merge(
::cuda::std::move(__first), ::cuda::std::move(__middle), ::cuda::std::move(__last), __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_INPLACE_MERGE_H

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_IS_HEAP_H
#define _CUDA_STD___ALGORITHM_IS_HEAP_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/is_heap_until.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator, class _Compare>
[[nodiscard]] _CCCL_API constexpr bool
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
return ::cuda::std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare>>(__comp)) == __last;
}
template <class _RandomAccessIterator>
[[nodiscard]] _CCCL_API constexpr bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
return ::cuda::std::is_heap(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_IS_HEAP_H

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_IS_HEAP_UNTIL_H
#define _CUDA_STD___ALGORITHM_IS_HEAP_UNTIL_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Compare, class _RandomAccessIterator>
_CCCL_API constexpr _RandomAccessIterator
__is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp)
{
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
difference_type __len = __last - __first;
difference_type __p = 0;
difference_type __c = 1;
_RandomAccessIterator __pp = __first;
while (__c < __len)
{
_RandomAccessIterator __cp = __first + __c;
if (__comp(*__pp, *__cp))
{
__last = __cp;
break;
}
++__c;
++__cp;
if (__c == __len)
{
break;
}
if (__comp(*__pp, *__cp))
{
__last = __cp;
break;
}
++__p;
++__pp;
__c = 2 * __p + 1;
}
return __last;
}
template <class _RandomAccessIterator, class _Compare>
[[nodiscard]] _CCCL_API constexpr _RandomAccessIterator
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
return ::cuda::std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare>>(__comp));
}
template <class _RandomAccessIterator>
[[nodiscard]] _CCCL_API constexpr _RandomAccessIterator
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
return ::cuda::std::__is_heap_until(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_IS_HEAP_UNTIL_H

View File

@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_IS_PARTITIONED_H
#define _CUDA_STD___ALGORITHM_IS_PARTITIONED_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Predicate>
[[nodiscard]] _CCCL_API constexpr bool is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
{
if (!__pred(*__first))
{
break;
}
}
if (__first == __last)
{
return true;
}
++__first;
bool __result = true;
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
__result = false;
break;
}
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_CLAMP_H

View File

@@ -0,0 +1,258 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_IS_PERMUTATION_H
#define _CUDA_STD___ALGORITHM_IS_PERMUTATION_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__iterator/next.h>
#include <cuda/std/__type_traits/add_lvalue_reference.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_API constexpr bool is_permutation(
_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred)
{
// shorten sequences as much as possible by lopping of any equal prefix
for (; __first1 != __last1; ++__first1, (void) ++__first2)
{
if (!__pred(*__first1, *__first2))
{
break;
}
}
if (__first1 == __last1)
{
return true;
}
// __first1 != __last1 && *__first1 != *__first2
using _Diff1 = __iter_diff_t<_ForwardIterator1>;
_Diff1 __l1 = ::cuda::std::distance(__first1, __last1);
if (__l1 == _Diff1(1))
{
return false;
}
_ForwardIterator2 __last2 = ::cuda::std::next(__first2, __l1);
// For each element in [f1, l1) see if there are the same number of
// equal elements in [f2, l2)
bool __result = true;
for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
{
// Have we already counted the number of *__i in [f1, l1)?
_ForwardIterator1 __match = __first1;
for (; __match != __i; ++__match)
{
if (__pred(*__match, *__i))
{
break;
}
}
if (__match == __i)
{
// Count number of *__i in [f2, l2)
_Diff1 __c2 = 0;
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
{
if (__pred(*__i, *__j))
{
++__c2;
}
}
if (__c2 == 0)
{
__result = false;
break;
}
// Count number of *__i in [__i, l1) (we can start with 1)
_Diff1 __c1 = 1;
for (_ForwardIterator1 __j = ::cuda::std::next(__i); __j != __last1; ++__j)
{
if (__pred(*__i, *__j))
{
++__c1;
}
}
if (__c1 != __c2)
{
__result = false;
break;
}
}
}
return __result;
}
template <class _ForwardIterator1, class _ForwardIterator2>
[[nodiscard]] _CCCL_API constexpr bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
{
return ::cuda::std::is_permutation(__first1, __last1, __first2, __equal_to{});
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
[[nodiscard]] _CCCL_API constexpr bool __is_permutation(
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred,
forward_iterator_tag,
forward_iterator_tag)
{
// shorten sequences as much as possible by lopping of any equal prefix
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2)
{
if (!__pred(*__first1, *__first2))
{
break;
}
}
if (__first1 == __last1)
{
return __first2 == __last2;
}
else if (__first2 == __last2)
{
return false;
}
using _Diff1 = __iter_diff_t<_ForwardIterator1>;
_Diff1 __l1 = ::cuda::std::distance(__first1, __last1);
using _Diff2 = __iter_diff_t<_ForwardIterator2>;
_Diff2 __l2 = ::cuda::std::distance(__first2, __last2);
if (__l1 != __l2)
{
return false;
}
// For each element in [f1, l1) see if there are the same number of
// equal elements in [f2, l2)
bool __result = true;
for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
{
// Have we already counted the number of *__i in [f1, l1)?
_ForwardIterator1 __match = __first1;
for (; __match != __i; ++__match)
{
if (__pred(*__match, *__i))
{
break;
}
}
if (__match == __i)
{
// Count number of *__i in [f2, l2)
_Diff1 __c2 = 0;
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
{
if (__pred(*__i, *__j))
{
++__c2;
}
}
if (__c2 == 0)
{
__result = false;
break;
}
// Count number of *__i in [__i, l1) (we can start with 1)
_Diff1 __c1 = 1;
for (_ForwardIterator1 __j = ::cuda::std::next(__i); __j != __last1; ++__j)
{
if (__pred(*__i, *__j))
{
++__c1;
}
}
if (__c1 != __c2)
{
__result = false;
break;
}
}
}
return __result;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
[[nodiscard]] _CCCL_API constexpr bool __is_permutation(
_RandomAccessIterator1 __first1,
_RandomAccessIterator2 __last1,
_RandomAccessIterator1 __first2,
_RandomAccessIterator2 __last2,
_BinaryPredicate __pred,
random_access_iterator_tag,
random_access_iterator_tag)
{
if (__last1 - __first1 != __last2 - __first2)
{
return false;
}
return ::cuda::std::
is_permutation<_RandomAccessIterator1, _RandomAccessIterator2, add_lvalue_reference_t<_BinaryPredicate>>(
__first1, __last1, __first2, __pred);
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_API constexpr bool is_permutation(
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred)
{
return ::cuda::std::__is_permutation<add_lvalue_reference_t<_BinaryPredicate>>(
__first1,
__last1,
__first2,
__last2,
__pred,
__iterator_category_type<_ForwardIterator1>{},
__iterator_category_type<_ForwardIterator2>{});
}
template <class _ForwardIterator1, class _ForwardIterator2>
[[nodiscard]] _CCCL_API constexpr bool is_permutation(
_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
return ::cuda::std::__is_permutation(
__first1,
__last1,
__first2,
__last2,
__equal_to{},
__iterator_category_type<_ForwardIterator1>{},
__iterator_category_type<_ForwardIterator2>{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_IS_PERMUTATION_H

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_IS_SORTED_H
#define _CUDA_STD___ALGORITHM_IS_SORTED_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/is_sorted_until.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Compare>
[[nodiscard]] _CCCL_API constexpr bool is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
return ::cuda::std::__is_sorted_until<__comp_ref_type<_Compare>>(__first, __last, __comp) == __last;
}
template <class _ForwardIterator>
[[nodiscard]] _CCCL_API constexpr bool is_sorted(_ForwardIterator __first, _ForwardIterator __last)
{
return ::cuda::std::is_sorted(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_IS_SORTED_H

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_IS_SORTED_UNTIL_H
#define _CUDA_STD___ALGORITHM_IS_SORTED_UNTIL_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Compare, class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator
__is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (__comp(*__i, *__first))
{
__last = __i;
break;
}
__first = __i;
}
}
return __last;
}
template <class _ForwardIterator, class _Compare>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
return ::cuda::std::__is_sorted_until<__comp_ref_type<_Compare>>(__first, __last, __comp);
}
template <class _ForwardIterator>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
{
return ::cuda::std::is_sorted_until(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_IS_SORTED_UNTIL_H

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_ITER_SWAP_H
#define _CUDA_STD___ALGORITHM_ITER_SWAP_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__concepts/concept_macros.h>
#include <cuda/std/__utility/declval.h>
#include <cuda/std/__utility/forward.h>
#include <cuda/std/__utility/swap.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
//! Intentionally not an algorithm to avoid breaking types that pull in `::std::iter_swap` via ADL
_CCCL_BEGIN_NAMESPACE_CPO(__iter_swap)
// "Poison pill" overload to intentionally create ambiguity with the unconstrained
// `std::iter_swap` function.
template <class _ForwardIterator1, class _ForwardIterator2>
void iter_swap(_ForwardIterator1, _ForwardIterator2) = delete;
template <class _ForwardIterator1, class _ForwardIterator2>
_CCCL_CONCEPT __unqualified_iter_swap =
_CCCL_REQUIRES_EXPR((_ForwardIterator1, _ForwardIterator2), _ForwardIterator1&& __a, _ForwardIterator2&& __b)(
iter_swap(::cuda::std::forward<_ForwardIterator1>(__a), ::cuda::std::forward<_ForwardIterator2>(__b)));
template <class _ForwardIterator1, class _ForwardIterator2>
_CCCL_CONCEPT __readable_swappable =
_CCCL_REQUIRES_EXPR((_ForwardIterator1, _ForwardIterator2), _ForwardIterator1 __a, _ForwardIterator2 __b)(
requires(!__unqualified_iter_swap<_ForwardIterator1, _ForwardIterator2>), swap(*__a, *__b));
struct __fn
{
_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _ForwardIterator1, class _ForwardIterator2)
_CCCL_REQUIRES(__unqualified_iter_swap<_ForwardIterator1, _ForwardIterator2>)
_CCCL_API constexpr void operator()(_ForwardIterator1&& __a, _ForwardIterator2&& __b) const
noexcept(noexcept(iter_swap(::cuda::std::declval<_ForwardIterator1>(), ::cuda::std::declval<_ForwardIterator2>())))
{
(void) iter_swap(::cuda::std::forward<_ForwardIterator1>(__a), ::cuda::std::forward<_ForwardIterator2>(__b));
}
_CCCL_EXEC_CHECK_DISABLE
_CCCL_TEMPLATE(class _ForwardIterator1, class _ForwardIterator2)
_CCCL_REQUIRES(__readable_swappable<_ForwardIterator1, _ForwardIterator2>)
_CCCL_API constexpr void operator()(_ForwardIterator1&& __a, _ForwardIterator2&& __b) const
noexcept(noexcept(swap(*::cuda::std::declval<_ForwardIterator1>(), *::cuda::std::declval<_ForwardIterator2>())))
{
swap(*__a, *__b);
}
};
_CCCL_END_NAMESPACE_CPO
inline namespace __cpo
{
// This is a global constant to avoid breaking types that pull in `::std::iter_swap` via ADL
_CCCL_GLOBAL_CONSTANT auto iter_swap = __iter_swap::__fn{};
// We want to avoid using the CPO internally because of __tile__ access
using __iter_swap_cpo = __iter_swap::__fn;
} // namespace __cpo
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_ITER_SWAP_H

View File

@@ -0,0 +1,179 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_ITERATOR_OPERATIONS_H
#define _CUDA_STD___ALGORITHM_ITERATOR_OPERATIONS_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iter_swap.h>
#include <cuda/std/__algorithm/ranges_iterator_concept.h>
#include <cuda/std/__iterator/advance.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__iterator/incrementable_traits.h>
#include <cuda/std/__iterator/iter_move.h>
#include <cuda/std/__iterator/iter_swap.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__iterator/next.h>
#include <cuda/std/__iterator/prev.h>
#include <cuda/std/__iterator/readable_traits.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_reference.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/remove_cvref.h>
#include <cuda/std/__utility/declval.h>
#include <cuda/std/__utility/forward.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _AlgPolicy>
struct _IterOps;
struct _RangeAlgPolicy
{};
template <>
struct _IterOps<_RangeAlgPolicy>
{
template <class _Iter>
using __value_type = iter_value_t<_Iter>;
template <class _Iter>
using __difference_type = iter_difference_t<_Iter>;
static constexpr auto advance = ::cuda::std::ranges::__advance_cpo{};
static constexpr auto distance = ::cuda::std::ranges::__distance_cpo{};
static constexpr auto __iter_move = ::cuda::std::ranges::__iter_move_cpo{};
static constexpr auto iter_swap = ::cuda::std::ranges::__iter_swap_cpo{};
static constexpr auto next = ::cuda::std::ranges::__next_cpo{};
static constexpr auto prev = ::cuda::std::ranges::__prev_cpo{};
static constexpr auto __advance_to = ::cuda::std::ranges::__advance_cpo{};
};
struct _ClassicAlgPolicy
{};
template <>
struct _IterOps<_ClassicAlgPolicy>
{
template <class _Iter>
using __value_type = typename iterator_traits<_Iter>::value_type;
template <class _Iter>
using __difference_type = typename iterator_traits<_Iter>::difference_type;
// advance
template <class _Iter, class _Distance>
_CCCL_API constexpr static void advance(_Iter& __iter, _Distance __count)
{
::cuda::std::advance(__iter, __count);
}
// distance
template <class _Iter>
_CCCL_API constexpr static typename iterator_traits<_Iter>::difference_type distance(_Iter __first, _Iter __last)
{
return ::cuda::std::distance(__first, __last);
}
template <class _Iter>
using __deref_t = decltype(*::cuda::std::declval<_Iter&>());
template <class _Iter>
using __move_t = decltype(::cuda::std::move(*::cuda::std::declval<_Iter&>()));
template <class _Iter>
_CCCL_API constexpr static void __validate_iter_reference()
{
static_assert(
is_same_v<__deref_t<_Iter>, typename iterator_traits<remove_cvref_t<_Iter>>::reference>,
"It looks like your iterator's `iterator_traits<It>::reference` does not match the return type of "
"dereferencing the iterator, i.e., calling `*it`. This is undefined behavior according to [input.iterators] "
"and can lead to dangling reference issues at runtime, so we are flagging this.");
}
// iter_move
_CCCL_EXEC_CHECK_DISABLE
template <class _Iter, enable_if_t<is_reference_v<__deref_t<_Iter>>, int> = 0>
_CCCL_API constexpr static
// If the result of dereferencing `_Iter` is a reference type, deduce the result of calling `::cuda::std::move` on
// it. Note that the C++03 mode doesn't support `decltype(auto)` as the return type.
__move_t<_Iter>
__iter_move(_Iter&& __i)
{
__validate_iter_reference<_Iter>();
return ::cuda::std::move(*::cuda::std::forward<_Iter>(__i));
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Iter, enable_if_t<!is_reference_v<__deref_t<_Iter>>, int> = 0>
_CCCL_API constexpr static
// If the result of dereferencing `_Iter` is a value type, deduce the return value of this function to also be a
// value -- otherwise, after `operator*` returns a temporary, this function would return a dangling reference to
// that temporary. Note that the C++03 mode doesn't support `auto` as the return type.
__deref_t<_Iter>
__iter_move(_Iter&& __i)
{
__validate_iter_reference<_Iter>();
return *::cuda::std::forward<_Iter>(__i);
}
// iter_swap
template <class _Iter1, class _Iter2>
_CCCL_API constexpr static void iter_swap(_Iter1&& __a, _Iter2&& __b)
{
::cuda::std::__iter_swap_cpo{}(::cuda::std::forward<_Iter1>(__a), ::cuda::std::forward<_Iter2>(__b));
}
// next
template <class _Iterator>
_CCCL_API static constexpr _Iterator next(_Iterator, _Iterator __last)
{
return __last;
}
template <class _Iter>
_CCCL_API static constexpr remove_cvref_t<_Iter> next(_Iter&& __it, __difference_type<remove_cvref_t<_Iter>> __n = 1)
{
return ::cuda::std::next(::cuda::std::forward<_Iter>(__it), __n);
}
// prev
template <class _Iter>
_CCCL_API static constexpr remove_cvref_t<_Iter> prev(_Iter&& __iter, __difference_type<remove_cvref_t<_Iter>> __n = 1)
{
return ::cuda::std::prev(::cuda::std::forward<_Iter>(__iter), __n);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Iter>
_CCCL_API static constexpr void __advance_to(_Iter& __first, _Iter __last)
{
__first = __last;
}
};
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_ITERATOR_OPERATIONS_H

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
#define _CUDA_STD___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Compare, class _InputIterator1, class _InputIterator2>
[[nodiscard]] _CCCL_API constexpr bool __lexicographical_compare(
_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
{
bool __result = false;
for (; __first2 != __last2; ++__first1, (void) ++__first2)
{
if (__first1 == __last1 || __comp(*__first1, *__first2))
{
__result = true;
break;
}
if (__comp(*__first2, *__first1))
{
break;
}
}
return __result;
}
template <class _InputIterator1, class _InputIterator2, class _Compare>
[[nodiscard]] _CCCL_API constexpr bool lexicographical_compare(
_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
{
return __lexicographical_compare<__comp_ref_type<_Compare>>(__first1, __last1, __first2, __last2, __comp);
}
template <class _InputIterator1, class _InputIterator2>
[[nodiscard]] _CCCL_API constexpr bool lexicographical_compare(
_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
{
return ::cuda::std::lexicographical_compare(__first1, __last1, __first2, __last2, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H

View File

@@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_LOWER_BOUND_H
#define _CUDA_STD___ALGORITHM_LOWER_BOUND_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/half_positive.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/advance.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_callable.h>
#include <cuda/std/__type_traits/remove_reference.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Iter, class _Sent, class _Type, class _Proj, class _Comp>
_CCCL_API constexpr _Iter __lower_bound(_Iter __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj)
{
auto __len = _IterOps<_AlgPolicy>::distance(__first, __last);
while (__len != 0)
{
auto __l2 = ::cuda::std::__half_positive(__len);
_Iter __m = __first;
_IterOps<_AlgPolicy>::advance(__m, __l2);
if (::cuda::std::invoke(__comp, ::cuda::std::invoke(__proj, *__m), __value))
{
__first = ++__m;
__len -= __l2 + 1;
}
else
{
__len = __l2;
}
}
return __first;
}
template <class _ForwardIterator, class _Tp, class _Compare>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
{
static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable");
auto __proj = ::cuda::std::identity();
return ::cuda::std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj);
}
template <class _ForwardIterator, class _Tp>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
{
return ::cuda::std::lower_bound(__first, __last, __value, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_LOWER_BOUND_H

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MAKE_HEAP_H
#define _CUDA_STD___ALGORITHM_MAKE_HEAP_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/sift_down.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API constexpr void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp)
{
__comp_ref_type<_Compare> __comp_ref = __comp;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
difference_type __n = __last - __first;
if (__n > 1)
{
// start from the first parent, there is no need to consider children
for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start)
{
::cuda::std::__sift_down<_AlgPolicy>(__first, __comp_ref, __n, __first + __start);
}
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator, class _Compare>
_CCCL_API constexpr void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
::cuda::std::__make_heap<_ClassicAlgPolicy>(::cuda::std::move(__first), ::cuda::std::move(__last), __comp);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator>
_CCCL_API constexpr void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
::cuda::std::make_heap(::cuda::std::move(__first), ::cuda::std::move(__last), __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MAKE_HEAP_H

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MAKE_PROJECTED_H
#define _CUDA_STD___ALGORITHM_MAKE_PROJECTED_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__concepts/same_as.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__type_traits/decay.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/integral_constant.h>
#include <cuda/std/__type_traits/is_member_pointer.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__utility/declval.h>
#include <cuda/std/__utility/forward.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _Pred, class _Proj>
struct _ProjectedPred
{
_Pred& __pred; // Can be a unary or a binary predicate.
_Proj& __proj;
_CCCL_API constexpr _ProjectedPred(_Pred& __pred_arg, _Proj& __proj_arg)
: __pred(__pred_arg)
, __proj(__proj_arg)
{}
template <class _Tp>
invoke_result_t<_Pred&, invoke_result_t<_Proj&, _Tp>> constexpr _CCCL_API inline operator()(_Tp&& __v) const
{
return ::cuda::std::invoke(__pred, ::cuda::std::invoke(__proj, ::cuda::std::forward<_Tp>(__v)));
}
template <class _T1, class _T2>
invoke_result_t<_Pred&, invoke_result_t<_Proj&, _T1>, invoke_result_t<_Proj&, _T2>> _CCCL_API inline
operator()(_T1&& __lhs, _T2&& __rhs) const
{
return ::cuda::std::invoke(__pred,
::cuda::std::invoke(__proj, ::cuda::std::forward<_T1>(__lhs)),
::cuda::std::invoke(__proj, ::cuda::std::forward<_T2>(__rhs)));
}
};
template <class _Pred,
class _Proj,
enable_if_t<!(!is_member_pointer_v<decay_t<_Pred>> && __is_identity_v<decay_t<_Proj>>), int> = 0>
_CCCL_API constexpr _ProjectedPred<_Pred, _Proj> __make_projected(_Pred& __pred, _Proj& __proj)
{
return _ProjectedPred<_Pred, _Proj>(__pred, __proj);
}
// Avoid creating the functor and just use the pristine comparator -- for certain algorithms, this would enable
// optimizations that rely on the type of the comparator. Additionally, this results in less layers of indirection in
// the call stack when the comparator is invoked, even in an unoptimized build.
template <class _Pred,
class _Proj,
enable_if_t<!is_member_pointer_v<decay_t<_Pred>> && __is_identity_v<decay_t<_Proj>>, int> = 0>
_CCCL_API constexpr _Pred& __make_projected(_Pred& __pred, _Proj&)
{
return __pred;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MAKE_PROJECTED_H

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MAX_H
#define _CUDA_STD___ALGORITHM_MAX_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/max_element.h>
#include <cuda/std/initializer_list>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp, class _Compare>
[[nodiscard]] _CCCL_API constexpr const _Tp&
max(const _Tp& __a _CCCL_LIFETIMEBOUND, const _Tp& __b _CCCL_LIFETIMEBOUND, _Compare __comp)
{
return __comp(__a, __b) ? __b : __a;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp>
[[nodiscard]] _CCCL_API constexpr const _Tp& max(const _Tp& __a _CCCL_LIFETIMEBOUND, const _Tp& __b _CCCL_LIFETIMEBOUND)
{
return __a < __b ? __b : __a;
}
template <class _Tp, class _Compare>
[[nodiscard]] _CCCL_API constexpr _Tp max(initializer_list<_Tp> __t, _Compare __comp)
{
return *::cuda::std::__max_element<__comp_ref_type<_Compare>>(__t.begin(), __t.end(), __comp);
}
template <class _Tp>
[[nodiscard]] _CCCL_API constexpr _Tp max(initializer_list<_Tp> __t)
{
return *::cuda::std::max_element(__t.begin(), __t.end(), __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MAX_H

View File

@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MAX_ELEMENT_H
#define _CUDA_STD___ALGORITHM_MAX_ELEMENT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Compare, class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__has_forward_traversal<_ForwardIterator>, "::cuda::std::max_element requires a ForwardIterator");
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (__comp(*__first, *__i))
{
__first = __i;
}
}
}
return __first;
}
template <class _ForwardIterator, class _Compare>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
return ::cuda::std::__max_element<__comp_ref_type<_Compare>>(__first, __last, __comp);
}
template <class _ForwardIterator>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last)
{
return ::cuda::std::max_element(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MAX_ELEMENT_H

View File

@@ -0,0 +1,98 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MERGE_H
#define _CUDA_STD___ALGORITHM_MERGE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/copy.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_CCCL_API constexpr _OutputIterator __merge(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp)
{
bool __second_remains = true;
for (; __first1 != __last1; ++__result)
{
if (__first2 == __last2)
{
__second_remains = false;
break;
}
if (__comp(*__first2, *__first1))
{
*__result = *__first2;
++__first2;
}
else
{
*__result = *__first1;
++__first1;
}
}
if (__second_remains)
{
return ::cuda::std::copy(__first2, __last2, __result);
}
else
{
return ::cuda::std::copy(__first1, __last1, __result);
}
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
_CCCL_API constexpr _OutputIterator
merge(_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp)
{
return ::cuda::std::__merge<__comp_ref_type<_Compare>>(__first1, __last1, __first2, __last2, __result, __comp);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
_CCCL_API constexpr _OutputIterator
merge(_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result)
{
return ::cuda::std::merge(__first1, __last1, __first2, __last2, __result, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MERGE_H

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MIN_H
#define _CUDA_STD___ALGORITHM_MIN_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/min_element.h>
#include <cuda/std/initializer_list>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp, class _Compare>
[[nodiscard]] _CCCL_API constexpr const _Tp&
min(const _Tp& __a _CCCL_LIFETIMEBOUND, const _Tp& __b _CCCL_LIFETIMEBOUND, _Compare __comp)
{
return __comp(__b, __a) ? __b : __a;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp>
[[nodiscard]] _CCCL_API constexpr const _Tp& min(const _Tp& __a _CCCL_LIFETIMEBOUND, const _Tp& __b _CCCL_LIFETIMEBOUND)
{
return __b < __a ? __b : __a;
}
template <class _Tp, class _Compare>
[[nodiscard]] _CCCL_API constexpr _Tp min(initializer_list<_Tp> __t, _Compare __comp)
{
return *::cuda::std::__min_element<__comp_ref_type<_Compare>>(__t.begin(), __t.end(), __comp);
}
template <class _Tp>
[[nodiscard]] _CCCL_API constexpr _Tp min(initializer_list<_Tp> __t)
{
return *::cuda::std::min_element(__t.begin(), __t.end(), __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MIN_H

View File

@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MIN_ELEMENT_H
#define _CUDA_STD___ALGORITHM_MIN_ELEMENT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_callable.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Comp, class _Iter, class _Sent, class _Proj>
_CCCL_API constexpr _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp, _Proj& __proj)
{
if (__first == __last)
{
return __first;
}
_Iter __i = __first;
while (++__i != __last)
{
if (::cuda::std::invoke(__comp, ::cuda::std::invoke(__proj, *__i), ::cuda::std::invoke(__proj, *__first)))
{
__first = __i;
}
}
return __first;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Comp, class _Iter, class _Sent>
_CCCL_API constexpr _Iter __min_element(_Iter __first, _Sent __last, _Comp __comp)
{
auto __proj = identity();
return ::cuda::std::__min_element<_Comp>(::cuda::std::move(__first), ::cuda::std::move(__last), __comp, __proj);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Compare>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__has_forward_traversal<_ForwardIterator>, "std::min_element requires a ForwardIterator");
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
"The comparator has to be callable");
return ::cuda::std::__min_element<__comp_ref_type<_Compare>>(
::cuda::std::move(__first), ::cuda::std::move(__last), __comp);
}
template <class _ForwardIterator>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last)
{
return ::cuda::std::min_element(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MIN_ELEMENT_H

View File

@@ -0,0 +1,66 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MINMAX_H
#define _CUDA_STD___ALGORITHM_MINMAX_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/minmax_element.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__type_traits/is_callable.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/initializer_list>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Tp, class _Compare>
[[nodiscard]] _CCCL_API constexpr pair<const _Tp&, const _Tp&> minmax(const _Tp& __a, const _Tp& __b, _Compare __comp)
{
return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) : pair<const _Tp&, const _Tp&>(__a, __b);
}
template <class _Tp>
[[nodiscard]] _CCCL_API constexpr pair<const _Tp&, const _Tp&> minmax(const _Tp& __a, const _Tp& __b)
{
return ::cuda::std::minmax(__a, __b, __less{});
}
template <class _Tp, class _Compare>
[[nodiscard]] _CCCL_API constexpr pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp)
{
static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable");
identity __proj{};
auto __ret = ::cuda::std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj);
return pair<_Tp, _Tp>(*__ret.first, *__ret.second);
}
template <class _Tp>
[[nodiscard]] _CCCL_API constexpr pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t)
{
return ::cuda::std::minmax(__t, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MINMAX_H

View File

@@ -0,0 +1,145 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MINMAX_ELEMENT_H
#define _CUDA_STD___ALGORITHM_MINMAX_ELEMENT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_callable.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _Comp, class _Proj>
class _MinmaxElementLessFunc
{
_Comp& __comp_;
_Proj& __proj_;
public:
_CCCL_API constexpr _MinmaxElementLessFunc(_Comp& __comp, _Proj& __proj)
: __comp_(__comp)
, __proj_(__proj)
{}
template <class _Iter>
_CCCL_API constexpr bool operator()(_Iter& __it1, _Iter& __it2)
{
return ::cuda::std::invoke(__comp_, ::cuda::std::invoke(__proj_, *__it1), ::cuda::std::invoke(__proj_, *__it2));
}
};
_CCCL_EXEC_CHECK_DISABLE
template <class _Iter, class _Sent, class _Proj, class _Comp>
_CCCL_API constexpr pair<_Iter, _Iter> __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj)
{
pair<_Iter, _Iter> __result(__first, __first);
if (__first == __last)
{
return __result;
}
if (++__first == __last)
{
return __result;
}
auto __less = _MinmaxElementLessFunc<_Comp, _Proj>(__comp, __proj);
if (__less(__first, __result.first))
{
__result.first = __first;
}
else
{
__result.second = __first;
}
while (++__first != __last)
{
_Iter __i = __first;
if (++__first == __last)
{
if (__less(__i, __result.first))
{
__result.first = __i;
}
else if (!__less(__i, __result.second))
{
__result.second = __i;
}
break;
}
if (__less(__first, __i))
{
if (__less(__first, __result.first))
{
__result.first = __first;
}
if (!__less(__i, __result.second))
{
__result.second = __i;
}
}
else
{
if (__less(__i, __result.first))
{
__result.first = __i;
}
if (!__less(__first, __result.second))
{
__result.second = __first;
}
}
}
return __result;
}
template <class _ForwardIterator, class _Compare>
[[nodiscard]] _CCCL_API constexpr pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__has_forward_traversal<_ForwardIterator>, "::cuda::std::minmax_element requires a ForwardIterator");
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__first)>::value,
"The comparator has to be callable");
auto __proj = identity();
return ::cuda::std::__minmax_element_impl(__first, __last, __comp, __proj);
}
template <class _ForwardIterator>
[[nodiscard]] _CCCL_API constexpr pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last)
{
return ::cuda::std::minmax_element(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MINMAX_ELEMENT_H

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_MISMATCH_H
#define _CUDA_STD___ALGORITHM_MISMATCH_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_API constexpr pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred)
{
for (; __first1 != __last1; ++__first1, (void) ++__first2)
{
if (!__pred(*__first1, *__first2))
{
break;
}
}
return pair<_InputIterator1, _InputIterator2>{__first1, __first2};
}
template <class _InputIterator1, class _InputIterator2>
[[nodiscard]] _CCCL_API constexpr pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2)
{
return ::cuda::std::mismatch(__first1, __last1, __first2, __equal_to{});
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_API constexpr pair<_InputIterator1, _InputIterator2> mismatch(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_BinaryPredicate __pred)
{
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2)
{
if (!__pred(*__first1, *__first2))
{
break;
}
}
return pair<_InputIterator1, _InputIterator2>{__first1, __first2};
}
template <class _InputIterator1, class _InputIterator2>
[[nodiscard]] _CCCL_API constexpr pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
{
return ::cuda::std::mismatch(__first1, __last1, __first2, __last2, __equal_to{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MISMATCH_H

View File

@@ -0,0 +1,91 @@
//===----------------------------------------------------------------------===//
//
// 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-24 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MOVE_H
#define _CUDA_STD___ALGORITHM_MOVE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/copy.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/unwrap_iter.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_copy_constructible.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/is_trivially_copyable.h>
#include <cuda/std/__type_traits/remove_const.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _InputIterator, class _OutputIterator>
_CCCL_API constexpr pair<_InputIterator, _OutputIterator>
__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
for (; __first != __last; ++__first, (void) ++__result)
{
*__result = _IterOps<_AlgPolicy>::__iter_move(__first);
}
return {__last, __result};
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy,
class _Tp,
class _Up,
enable_if_t<is_same_v<remove_const_t<_Tp>, _Up>, int> = 0,
enable_if_t<is_trivially_copyable_v<_Up>, int> = 0>
_CCCL_API constexpr pair<_Tp*, _Up*> __move(_Tp* __first, _Tp* __last, _Up* __result)
{
const ptrdiff_t __n = __last - __first;
if (__n > 0)
{
if (::cuda::std::__dispatch_memmove(__result, __first, __n))
{
return {__first + __n, __result + __n};
}
for (ptrdiff_t __i = 0; __i < __n; ++__i)
{
*(__result + __i) = _IterOps<_AlgPolicy>::__iter_move((__first + __i));
}
}
return {__last, __result + __n};
}
// `requires true` overrides the imported ::std::move algorithm, this function is forward declared in
// <cuda/std/__utility/move.h>
template <class _InputIterator, class _OutputIterator>
#if _CCCL_HAS_CONCEPTS()
requires true
#endif // _CCCL_HAS_CONCEPTS()
_CCCL_API constexpr _OutputIterator move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
static_assert(is_copy_constructible_v<_InputIterator>, "Iterators has to be copy constructible.");
static_assert(is_copy_constructible_v<_OutputIterator>, "The output iterator has to be copy constructible.");
return ::cuda::std::__move<_ClassicAlgPolicy>(
::cuda::std::__unwrap_iter(__first), ::cuda::std::__unwrap_iter(__last), ::cuda::std::__unwrap_iter(__result))
.second;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MOVE_H

View File

@@ -0,0 +1,84 @@
//===----------------------------------------------------------------------===//
//
// 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-24 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_MOVE_BACKWARD_H
#define _CUDA_STD___ALGORITHM_MOVE_BACKWARD_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/copy.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/unwrap_iter.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/is_trivially_copyable.h>
#include <cuda/std/__type_traits/remove_const.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _BidirectionalIterator, class _OutputIterator>
_CCCL_API constexpr pair<_BidirectionalIterator, _OutputIterator>
__move_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
{
while (__first != __last)
{
*--__result = _IterOps<_AlgPolicy>::__iter_move(--__last);
}
return {__first, __result};
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy,
class _Tp,
class _Up,
enable_if_t<is_same_v<remove_const_t<_Tp>, _Up>, int> = 0,
enable_if_t<is_trivially_copyable_v<_Up>, int> = 0>
_CCCL_API constexpr pair<_Tp*, _Up*> __move_backward(_Tp* __first, _Tp* __last, _Up* __result)
{
const ptrdiff_t __n = __last - __first;
if (__n > 0)
{
if (::cuda::std::__dispatch_memmove(__result - __n, __first, __n))
{
return {__last, __result - __n};
}
for (ptrdiff_t __i = 1; __i <= __n; ++__i)
{
*(__result - __i) = _IterOps<_AlgPolicy>::__iter_move((__last - __i));
}
}
return {__last, __result - __n};
}
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
_CCCL_API constexpr _BidirectionalIterator2
move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result)
{
return ::cuda::std::__move_backward<_ClassicAlgPolicy>(
::cuda::std::__unwrap_iter(__first), ::cuda::std::__unwrap_iter(__last), ::cuda::std::__unwrap_iter(__result))
.second;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_MOVE_BACKWARD_H

View File

@@ -0,0 +1,92 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_NEXT_PERMUTATION_H
#define _CUDA_STD___ALGORITHM_NEXT_PERMUTATION_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/reverse.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
_CCCL_API constexpr pair<_BidirectionalIterator, bool>
__next_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp)
{
using _Result = pair<_BidirectionalIterator, bool>;
_BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
_BidirectionalIterator __i = __last_iter;
if (__first == __last || __first == --__i)
{
return _Result(::cuda::std::move(__last_iter), false);
}
bool __result = true;
while (true)
{
_BidirectionalIterator __ip1 = __i;
if (__comp(*--__i, *__ip1))
{
_BidirectionalIterator __j = __last_iter;
while (!__comp(*__i, *--__j))
;
_IterOps<_AlgPolicy>::iter_swap(__i, __j);
::cuda::std::__reverse<_AlgPolicy>(__ip1, __last_iter);
__result = true;
break;
}
if (__i == __first)
{
::cuda::std::__reverse<_AlgPolicy>(__first, __last_iter);
__result = false;
break;
}
}
return _Result(::cuda::std::move(__last_iter), __result);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BidirectionalIterator, class _Compare>
_CCCL_API constexpr bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
{
return ::cuda::std::__next_permutation<_ClassicAlgPolicy>(
::cuda::std::move(__first), ::cuda::std::move(__last), static_cast<__comp_ref_type<_Compare>>(__comp))
.second;
}
template <class _BidirectionalIterator>
_CCCL_API constexpr bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
return ::cuda::std::next_permutation(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_NEXT_PERMUTATION_H

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_NONE_OF_H
#define _CUDA_STD___ALGORITHM_NONE_OF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _Predicate>
[[nodiscard]] _CCCL_API constexpr bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
bool __result = true;
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
__result = false;
break;
}
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_NONE_OF_H

View File

@@ -0,0 +1,309 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_NTH_ELEMENT_H
#define _CUDA_STD___ALGORITHM_NTH_ELEMENT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/sort.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _Compare, class _RandomAccessIterator>
_CCCL_API constexpr bool __nth_element_find_guard(
_RandomAccessIterator& __i, _RandomAccessIterator& __j, _RandomAccessIterator __m, _Compare __comp)
{
// manually guard downward moving __j against __i
while (true)
{
if (__i == --__j)
{
return false;
}
if (__comp(*__j, *__m))
{
return true; // found guard for downward moving __j, now use unguarded partition
}
}
}
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API constexpr void
__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
{
using _Ops = _IterOps<_AlgPolicy>;
// _Compare is known to be a reference type
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
const difference_type __limit = 7;
while (true)
{
if (__nth == __last)
{
return;
}
difference_type __len = __last - __first;
switch (__len)
{
case 0:
case 1:
return;
case 2:
if (__comp(*--__last, *__first))
{
_Ops::iter_swap(__first, __last);
}
return;
case 3: {
_RandomAccessIterator __m = __first;
::cuda::std::__sort3<_AlgPolicy, _Compare>(__first, ++__m, --__last, __comp);
return;
}
}
if (__len <= __limit)
{
::cuda::std::__selection_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
return;
}
// __len > __limit >= 3
_RandomAccessIterator __m = __first + __len / 2;
_RandomAccessIterator __lm1 = __last;
unsigned __n_swaps = ::cuda::std::__sort3<_AlgPolicy, _Compare>(__first, __m, --__lm1, __comp);
// *__m is median
// partition [__first, __m) < *__m and *__m <= [__m, __last)
// (this inhibits tossing elements equivalent to __m around unnecessarily)
_RandomAccessIterator __i = __first;
_RandomAccessIterator __j = __lm1;
// j points beyond range to be tested, *__lm1 is known to be <= *__m
// The search going up is known to be guarded but the search coming down isn't.
// Prime the downward search with a guard.
if (!__comp(*__i, *__m)) // if *__first == *__m
{
// *__first == *__m, *__first doesn't go in first part
if (::cuda::std::__nth_element_find_guard<_Compare>(__i, __j, __m, __comp))
{
_Ops::iter_swap(__i, __j);
++__n_swaps;
}
else
{
// *__first == *__m, *__m <= all other elements
// Partition instead into [__first, __i) == *__first and *__first < [__i, __last)
++__i; // __first + 1
__j = __last;
if (!__comp(*__first, *--__j))
{ // we need a guard if *__first == *(__last-1)
while (true)
{
if (__i == __j)
{
return; // [__first, __last) all equivalent elements
}
else if (__comp(*__first, *__i))
{
_Ops::iter_swap(__i, __j);
++__n_swaps;
++__i;
break;
}
++__i;
}
}
// [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
if (__i == __j)
{
return;
}
while (true)
{
while (!__comp(*__first, *__i))
{
++__i;
_CCCL_ASSERT(__i != __last,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering "
"requirement?");
}
do
{
_CCCL_ASSERT(__j != __first,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering "
"requirement?");
--__j;
} while (__comp(*__first, *__j));
if (__i >= __j)
{
break;
}
_Ops::iter_swap(__i, __j);
++__n_swaps;
++__i;
}
// [__first, __i) == *__first and *__first < [__i, __last)
// The first part is sorted,
if (__nth < __i)
{
return;
}
// __nth_element the second part
// ::cuda::std::__nth_element<_Compare>(__i, __nth, __last, __comp);
__first = __i;
continue;
}
}
++__i;
// j points beyond range to be tested, *__lm1 is known to be <= *__m
// if not yet partitioned...
if (__i < __j)
{
// known that *(__i - 1) < *__m
while (true)
{
// __m still guards upward moving __i
while (__comp(*__i, *__m))
{
++__i;
_CCCL_ASSERT(__i != __last,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
}
// It is now known that a guard exists for downward moving __j
do
{
_CCCL_ASSERT(__j != __first,
"Would read out of bounds, does your comparator satisfy the strict-weak ordering requirement?");
--__j;
} while (!__comp(*__j, *__m));
if (__i >= __j)
{
break;
}
_Ops::iter_swap(__i, __j);
++__n_swaps;
// It is known that __m != __j
// If __m just moved, follow it
if (__m == __i)
{
__m = __j;
}
++__i;
}
}
// [__first, __i) < *__m and *__m <= [__i, __last)
if (__i != __m && __comp(*__m, *__i))
{
_Ops::iter_swap(__i, __m);
++__n_swaps;
}
// [__first, __i) < *__i and *__i <= [__i+1, __last)
if (__nth == __i)
{
return;
}
if (__n_swaps == 0)
{
// We were given a perfectly partitioned sequence. Coincidence?
if (__nth < __i)
{
// Check for [__first, __i) already sorted
__j = __m = __first;
while (true)
{
if (++__j == __i)
{
// [__first, __i) sorted
return;
}
if (__comp(*__j, *__m))
{
// not yet sorted, so sort
break;
}
__m = __j;
}
}
else
{
// Check for [__i, __last) already sorted
__j = __m = __i;
while (true)
{
if (++__j == __last)
{
// [__i, __last) sorted
return;
}
if (__comp(*__j, *__m))
{
// not yet sorted, so sort
break;
}
__m = __j;
}
}
}
// __nth_element on range containing __nth
if (__nth < __i)
{
// ::cuda::std::__nth_element<_Compare>(__first, __nth, __i, __comp);
__last = __i;
}
else
{
// ::cuda::std::__nth_element<_Compare>(__i+1, __nth, __last, __comp);
__first = ++__i;
}
}
}
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
_CCCL_API constexpr void __nth_element_impl(
_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare& __comp)
{
if (__nth == __last)
{
return;
}
::cuda::std::__nth_element<_AlgPolicy, __comp_ref_type<_Compare>>(__first, __nth, __last, __comp);
}
template <class _RandomAccessIterator, class _Compare>
_CCCL_API constexpr void
nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
{
::cuda::std::__nth_element_impl<_ClassicAlgPolicy>(
::cuda::std::move(__first), ::cuda::std::move(__nth), ::cuda::std::move(__last), __comp);
}
template <class _RandomAccessIterator>
_CCCL_API constexpr void
nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last)
{
::cuda::std::nth_element(::cuda::std::move(__first), ::cuda::std::move(__nth), ::cuda::std::move(__last), __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_NTH_ELEMENT_H

View File

@@ -0,0 +1,102 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_PARTIAL_SORT_H
#define _CUDA_STD___ALGORITHM_PARTIAL_SORT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/make_heap.h>
#include <cuda/std/__algorithm/sift_down.h>
#include <cuda/std/__algorithm/sort_heap.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_copy_assignable.h>
#include <cuda/std/__type_traits/is_copy_constructible.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
_CCCL_API constexpr _RandomAccessIterator
__partial_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare&& __comp)
{
if (__first == __middle)
{
return _IterOps<_AlgPolicy>::next(__middle, __last);
}
::cuda::std::__make_heap<_AlgPolicy>(__first, __middle, __comp);
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
_RandomAccessIterator __i = __middle;
for (; __i != __last; ++__i)
{
if (__comp(*__i, *__first))
{
_IterOps<_AlgPolicy>::iter_swap(__i, __first);
::cuda::std::__sift_down<_AlgPolicy>(__first, __comp, __len, __first);
}
}
::cuda::std::__sort_heap<_AlgPolicy>(::cuda::std::move(__first), ::cuda::std::move(__middle), __comp);
return __i;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
_CCCL_API constexpr _RandomAccessIterator
__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Sentinel __last, _Compare& __comp)
{
if (__first == __middle)
{
return _IterOps<_AlgPolicy>::next(__middle, __last);
}
return ::cuda::std::__partial_sort_impl<_AlgPolicy>(
__first, __middle, __last, static_cast<__comp_ref_type<_Compare>>(__comp));
}
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator, class _Compare>
_CCCL_API constexpr void partial_sort(
_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp)
{
static_assert(is_copy_constructible_v<_RandomAccessIterator>, "Iterators must be copy constructible.");
static_assert(is_copy_assignable_v<_RandomAccessIterator>, "Iterators must be copy assignable.");
(void) ::cuda::std::__partial_sort<_ClassicAlgPolicy>(
::cuda::std::move(__first), ::cuda::std::move(__middle), ::cuda::std::move(__last), __comp);
}
template <class _RandomAccessIterator>
_CCCL_API constexpr void
partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
{
::cuda::std::partial_sort(__first, __middle, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_PARTIAL_SORT_H

View File

@@ -0,0 +1,122 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_PARTIAL_SORT_COPY_H
#define _CUDA_STD___ALGORITHM_PARTIAL_SORT_COPY_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/make_heap.h>
#include <cuda/std/__algorithm/make_projected.h>
#include <cuda/std/__algorithm/sift_down.h>
#include <cuda/std/__algorithm/sort_heap.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_callable.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy,
class _Compare,
class _InputIterator,
class _Sentinel1,
class _RandomAccessIterator,
class _Sentinel2,
class _Proj1,
class _Proj2>
_CCCL_API constexpr pair<_InputIterator, _RandomAccessIterator> __partial_sort_copy(
_InputIterator __first,
_Sentinel1 __last,
_RandomAccessIterator __result_first,
_Sentinel2 __result_last,
_Compare&& __comp,
_Proj1&& __proj1,
_Proj2&& __proj2)
{
_RandomAccessIterator __r = __result_first;
auto&& __projected_comp = ::cuda::std::__make_projected(__comp, __proj2);
if (__r != __result_last)
{
for (; __first != __last && __r != __result_last; ++__first, (void) ++__r)
{
*__r = *__first;
}
::cuda::std::__make_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
for (; __first != __last; ++__first)
{
if (::cuda::std::invoke(
__comp, ::cuda::std::invoke(__proj1, *__first), ::cuda::std::invoke(__proj2, *__result_first)))
{
*__result_first = *__first;
::cuda::std::__sift_down<_AlgPolicy>(__result_first, __projected_comp, __len, __result_first);
}
}
::cuda::std::__sort_heap<_AlgPolicy>(__result_first, __r, __projected_comp);
}
return pair<_InputIterator, _RandomAccessIterator>(
_IterOps<_AlgPolicy>::next(::cuda::std::move(__first), ::cuda::std::move(__last)), ::cuda::std::move(__r));
}
template <class _InputIterator, class _RandomAccessIterator, class _Compare>
_CCCL_API constexpr _RandomAccessIterator partial_sort_copy(
_InputIterator __first,
_InputIterator __last,
_RandomAccessIterator __result_first,
_RandomAccessIterator __result_last,
_Compare __comp)
{
static_assert(__is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value,
"Comparator has to be callable");
auto __result = ::cuda::std::__partial_sort_copy<_ClassicAlgPolicy>(
__first,
__last,
__result_first,
__result_last,
static_cast<__comp_ref_type<_Compare>>(__comp),
identity(),
identity());
return __result.second;
}
template <class _InputIterator, class _RandomAccessIterator>
_CCCL_API constexpr _RandomAccessIterator partial_sort_copy(
_InputIterator __first,
_InputIterator __last,
_RandomAccessIterator __result_first,
_RandomAccessIterator __result_last)
{
return ::cuda::std::partial_sort_copy(__first, __last, __result_first, __result_last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_PARTIAL_SORT_COPY_H

View File

@@ -0,0 +1,121 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_PARTITION_H
#define _CUDA_STD___ALGORITHM_PARTITION_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/remove_cvref.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _Predicate, class _AlgPolicy, class _ForwardIterator, class _Sentinel>
_CCCL_HOST_DEVICE_API constexpr pair<_ForwardIterator, _ForwardIterator>
__partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag)
{
while (true)
{
if (__first == __last)
{
return ::cuda::std::make_pair(::cuda::std::move(__first), ::cuda::std::move(__first));
}
if (!__pred(*__first))
{
break;
}
++__first;
}
_ForwardIterator __p = __first;
while (++__p != __last)
{
if (__pred(*__p))
{
_IterOps<_AlgPolicy>::iter_swap(__first, __p);
++__first;
}
}
return ::cuda::std::make_pair(::cuda::std::move(__first), ::cuda::std::move(__p));
}
_CCCL_EXEC_CHECK_DISABLE
template <class _Predicate, class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
_CCCL_HOST_DEVICE_API constexpr pair<_BidirectionalIterator, _BidirectionalIterator>
__partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred, bidirectional_iterator_tag)
{
_BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel);
_BidirectionalIterator __last = __original_last;
while (true)
{
while (true)
{
if (__first == __last)
{
return ::cuda::std::make_pair(::cuda::std::move(__first), ::cuda::std::move(__original_last));
}
if (!__pred(*__first))
{
break;
}
++__first;
}
do
{
if (__first == --__last)
{
return ::cuda::std::make_pair(::cuda::std::move(__first), ::cuda::std::move(__original_last));
}
} while (!__pred(*__last));
_IterOps<_AlgPolicy>::iter_swap(__first, __last);
++__first;
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _ForwardIterator, class _Sentinel, class _Predicate, class _IterCategory>
_CCCL_HOST_DEVICE_API constexpr pair<_ForwardIterator, _ForwardIterator>
__partition(_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category)
{
return ::cuda::std::__partition_impl<remove_cvref_t<_Predicate>&, _AlgPolicy>(
::cuda::std::move(__first), ::cuda::std::move(__last), __pred, __iter_category);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Predicate>
_CCCL_HOST_DEVICE_API constexpr _ForwardIterator
partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
using _IterCategory = __iterator_traits_category_or_concept_t<_ForwardIterator>;
auto __result = ::cuda::std::__partition<_ClassicAlgPolicy>(
::cuda::std::move(__first), ::cuda::std::move(__last), __pred, _IterCategory());
return __result.first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_PARTITION_H

View File

@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_PARTITION_COPY_H
#define _CUDA_STD___ALGORITHM_PARTITION_COPY_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _OutputIterator1, class _OutputIterator2, class _Predicate>
_CCCL_API constexpr pair<_OutputIterator1, _OutputIterator2> partition_copy(
_InputIterator __first,
_InputIterator __last,
_OutputIterator1 __out_true,
_OutputIterator2 __out_false,
_Predicate __pred)
{
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
*__out_true = *__first;
++__out_true;
}
else
{
*__out_false = *__first;
++__out_false;
}
}
return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_PARTITION_COPY_H

View File

@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_PARTITION_POINT_H
#define _CUDA_STD___ALGORITHM_PARTITION_POINT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/half_positive.h>
#include <cuda/std/__iterator/advance.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Predicate>
_CCCL_API constexpr _ForwardIterator
partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
using difference_type = typename iterator_traits<_ForwardIterator>::difference_type;
difference_type __len = ::cuda::std::distance(__first, __last);
while (__len != 0)
{
difference_type __l2 = ::cuda::std::__half_positive(__len);
_ForwardIterator __m = __first;
::cuda::std::advance(__m, __l2);
if (__pred(*__m))
{
__first = ++__m;
__len -= __l2 + 1;
}
else
{
__len = __l2;
}
}
return __first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_PARTITION_POINT_H

View File

@@ -0,0 +1,93 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_POP_HEAP_H
#define _CUDA_STD___ALGORITHM_POP_HEAP_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/push_heap.h>
#include <cuda/std/__algorithm/sift_down.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_copy_assignable.h>
#include <cuda/std/__type_traits/is_copy_constructible.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API constexpr void __pop_heap(
_RandomAccessIterator __first,
_RandomAccessIterator __last,
_Compare& __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len)
{
// Calling `pop_heap` on an empty range is undefined behavior, but in practice it will be a no-op.
_CCCL_ASSERT(__len > 0, "The heap given to pop_heap must be non-empty");
__comp_ref_type<_Compare> __comp_ref = __comp;
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
if (__len > 1)
{
value_type __top = _IterOps<_AlgPolicy>::__iter_move(__first); // create a hole at __first
_RandomAccessIterator __hole = ::cuda::std::__floyd_sift_down<_AlgPolicy>(__first, __comp_ref, __len);
--__last;
if (__hole == __last)
{
*__hole = ::cuda::std::move(__top);
}
else
{
*__hole = _IterOps<_AlgPolicy>::__iter_move(__last);
++__hole;
*__last = ::cuda::std::move(__top);
::cuda::std::__sift_up<_AlgPolicy>(__first, __hole, __comp_ref, __hole - __first);
}
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator, class _Compare>
_CCCL_API constexpr void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
static_assert(::cuda::std::is_copy_constructible_v<_RandomAccessIterator>, "Iterators must be copy constructible.");
static_assert(::cuda::std::is_copy_assignable_v<_RandomAccessIterator>, "Iterators must be copy assignable.");
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first;
::cuda::std::__pop_heap<_ClassicAlgPolicy>(::cuda::std::move(__first), ::cuda::std::move(__last), __comp, __len);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator>
_CCCL_API constexpr void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
::cuda::std::pop_heap(::cuda::std::move(__first), ::cuda::std::move(__last), __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_POP_HEAP_H

View File

@@ -0,0 +1,92 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_PREV_PERMUTATION_H
#define _CUDA_STD___ALGORITHM_PREV_PERMUTATION_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/reverse.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
_CCCL_API constexpr pair<_BidirectionalIterator, bool>
__prev_permutation(_BidirectionalIterator __first, _Sentinel __last, _Compare&& __comp)
{
using _Result = pair<_BidirectionalIterator, bool>;
_BidirectionalIterator __last_iter = _IterOps<_AlgPolicy>::next(__first, __last);
_BidirectionalIterator __i = __last_iter;
if (__first == __last || __first == --__i)
{
return _Result(::cuda::std::move(__last_iter), false);
}
bool __result = true;
while (true)
{
_BidirectionalIterator __ip1 = __i;
if (__comp(*__ip1, *--__i))
{
_BidirectionalIterator __j = __last_iter;
while (!__comp(*--__j, *__i))
;
_IterOps<_AlgPolicy>::iter_swap(__i, __j);
::cuda::std::__reverse<_AlgPolicy>(__ip1, __last_iter);
__result = true;
break;
}
if (__i == __first)
{
::cuda::std::__reverse<_AlgPolicy>(__first, __last_iter);
__result = false;
break;
}
}
return _Result(::cuda::std::move(__last_iter), __result);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BidirectionalIterator, class _Compare>
_CCCL_API constexpr bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
{
return ::cuda::std::__prev_permutation<_ClassicAlgPolicy>(
::cuda::std::move(__first), ::cuda::std::move(__last), static_cast<__comp_ref_type<_Compare>>(__comp))
.second;
}
template <class _BidirectionalIterator>
_CCCL_API constexpr bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
return ::cuda::std::prev_permutation(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_PREV_PERMUTATION_H

View File

@@ -0,0 +1,100 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_PUSH_HEAP_H
#define _CUDA_STD___ALGORITHM_PUSH_HEAP_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_copy_assignable.h>
#include <cuda/std/__type_traits/is_copy_constructible.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API constexpr void
__sift_up(_RandomAccessIterator __first,
_RandomAccessIterator __last,
_Compare&& __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len)
{
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
if (__len > 1)
{
__len = (__len - 2) / 2;
_RandomAccessIterator __ptr = __first + __len;
if (__comp(*__ptr, *--__last))
{
value_type __t(_IterOps<_AlgPolicy>::__iter_move(__last));
do
{
*__last = _IterOps<_AlgPolicy>::__iter_move(__ptr);
__last = __ptr;
if (__len == 0)
{
break;
}
__len = (__len - 1) / 2;
__ptr = __first + __len;
} while (__comp(*__ptr, __t));
*__last = ::cuda::std::move(__t);
}
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
_CCCL_API constexpr void __push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp)
{
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first;
::cuda::std::__sift_up<_AlgPolicy, __comp_ref_type<_Compare>>(
::cuda::std::move(__first), ::cuda::std::move(__last), __comp, __len);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator, class _Compare>
_CCCL_API constexpr void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
static_assert(::cuda::std::is_copy_constructible_v<_RandomAccessIterator>, "Iterators must be copy constructible.");
static_assert(::cuda::std::is_copy_assignable_v<_RandomAccessIterator>, "Iterators must be copy assignable.");
::cuda::std::__push_heap<_ClassicAlgPolicy>(::cuda::std::move(__first), ::cuda::std::move(__last), __comp);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator>
_CCCL_API constexpr void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
::cuda::std::push_heap(::cuda::std::move(__first), ::cuda::std::move(__last), __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_PUSH_HEAP_H

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_RANGES_FIND_IF_H
#define _CUDA_STD___ALGORITHM_RANGES_FIND_IF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__functional/ranges_operations.h>
#include <cuda/std/__iterator/concepts.h>
#include <cuda/std/__iterator/projected.h>
#include <cuda/std/__ranges/access.h>
#include <cuda/std/__ranges/concepts.h>
#include <cuda/std/__ranges/dangling.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD_RANGES
_CCCL_BEGIN_NAMESPACE_CPO(__find_if)
struct __fn
{
template <class _Ip, class _Sp, class _Pred, class _Proj>
_CCCL_API static constexpr _Ip __find_if_impl(_Ip __first, _Sp __last, _Pred& __pred, _Proj& __proj)
{
for (; __first != __last; ++__first)
{
if (::cuda::std::invoke(__pred, ::cuda::std::invoke(__proj, *__first)))
{
break;
}
}
return __first;
}
_CCCL_TEMPLATE(class _Ip, class _Sp, class _Pred, class _Proj = identity)
_CCCL_REQUIRES(input_iterator<_Ip> _CCCL_AND sentinel_for<_Sp, _Ip> _CCCL_AND
indirect_unary_predicate<_Pred, projected<_Ip, _Proj>>)
[[nodiscard]] _CCCL_API constexpr _Ip operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const
{
return __find_if_impl(::cuda::std::move(__first), ::cuda::std::move(__last), __pred, __proj);
}
_CCCL_TEMPLATE(class _Rp, class _Pred, class _Proj = identity)
_CCCL_REQUIRES(input_range<_Rp> _CCCL_AND indirect_unary_predicate<_Pred, projected<iterator_t<_Rp>, _Proj>>)
[[nodiscard]] _CCCL_API constexpr borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const
{
return __find_if_impl(
::cuda::std::ranges::__begin_cpo{}(__r), ::cuda::std::ranges::__end_cpo{}(__r), __pred, __proj);
}
};
_CCCL_END_NAMESPACE_CPO
inline namespace __cpo
{
_CCCL_GLOBAL_CONSTANT auto find_if = __find_if::__fn{};
} // namespace __cpo
_CCCL_END_NAMESPACE_CUDA_STD_RANGES
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_RANGES_FIND_IF_H

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_RANGES_FIND_IF_NOT_H
#define _CUDA_STD___ALGORITHM_RANGES_FIND_IF_NOT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/ranges_find_if.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__functional/ranges_operations.h>
#include <cuda/std/__iterator/concepts.h>
#include <cuda/std/__iterator/projected.h>
#include <cuda/std/__ranges/access.h>
#include <cuda/std/__ranges/concepts.h>
#include <cuda/std/__ranges/dangling.h>
#include <cuda/std/__utility/forward.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD_RANGES
_CCCL_BEGIN_NAMESPACE_CPO(__find_if_not)
template <class _Pred>
struct __not_pred
{
_CCCL_API constexpr __not_pred(_Pred& __pred) noexcept
: __pred_(__pred)
{}
_Pred& __pred_;
template <class _Tp>
_CCCL_API constexpr auto operator()(_Tp&& __e) const
{
return !::cuda::std::invoke(__pred_, ::cuda::std::forward<_Tp>(__e));
}
};
struct __fn
{
_CCCL_TEMPLATE(class _Ip, class _Sp, class _Pred, class _Proj = identity)
_CCCL_REQUIRES(input_iterator<_Ip> _CCCL_AND sentinel_for<_Sp, _Ip> _CCCL_AND
indirect_unary_predicate<_Pred, projected<_Ip, _Proj>>)
[[nodiscard]] _CCCL_API constexpr _Ip operator()(_Ip __first, _Sp __last, _Pred __pred, _Proj __proj = {}) const
{
return ::cuda::std::ranges::find_if(
::cuda::std::move(__first), ::cuda::std::move(__last), __not_pred{__pred}, ::cuda::std::move(__proj));
}
_CCCL_TEMPLATE(class _Rp, class _Pred, class _Proj = identity)
_CCCL_REQUIRES(input_range<_Rp> _CCCL_AND indirect_unary_predicate<_Pred, projected<iterator_t<_Rp>, _Proj>>)
[[nodiscard]] _CCCL_API constexpr borrowed_iterator_t<_Rp> operator()(_Rp&& __r, _Pred __pred, _Proj __proj = {}) const
{
return ::cuda::std::ranges::find_if(::cuda::std::forward<_Rp>(__r), __not_pred{__pred}, ::cuda::std::move(__proj));
}
};
_CCCL_END_NAMESPACE_CPO
inline namespace __cpo
{
_CCCL_GLOBAL_CONSTANT auto find_if_not = __find_if_not::__fn{};
} // namespace __cpo
_CCCL_END_NAMESPACE_CUDA_STD_RANGES
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_RANGES_FIND_IF_NOT_H

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_RANGES_FOR_EACH_H
#define _CUDA_STD___ALGORITHM_RANGES_FOR_EACH_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/in_fun_result.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/concepts.h>
#include <cuda/std/__iterator/projected.h>
#include <cuda/std/__ranges/access.h>
#include <cuda/std/__ranges/concepts.h>
#include <cuda/std/__ranges/dangling.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD_RANGES
template <class _Iter, class _Func>
using for_each_result = in_fun_result<_Iter, _Func>;
_CCCL_BEGIN_NAMESPACE_CPO(__for_each)
struct __fn
{
private:
template <class _Iter, class _Sent, class _Proj, class _Func>
_CCCL_API constexpr static for_each_result<_Iter, _Func>
__for_each_impl(_Iter __first, _Sent __last, _Func& __func, _Proj& __proj)
{
for (; __first != __last; ++__first)
{
::cuda::std::invoke(__func, ::cuda::std::invoke(__proj, *__first));
}
return {::cuda::std::move(__first), ::cuda::std::move(__func)};
}
public:
_CCCL_TEMPLATE(class _Iter, class _Sent, class _Func, class _Proj = identity)
_CCCL_REQUIRES(input_iterator<_Iter> _CCCL_AND sentinel_for<_Sent, _Iter> _CCCL_AND
indirectly_unary_invocable<_Func, projected<_Iter, _Proj>>)
_CCCL_API constexpr for_each_result<_Iter, _Func>
operator()(_Iter __first, _Sent __last, _Func __func, _Proj __proj = {}) const
{
return __for_each_impl(::cuda::std::move(__first), ::cuda::std::move(__last), __func, __proj);
}
_CCCL_TEMPLATE(class _Range, class _Func, class _Proj = identity)
_CCCL_REQUIRES(input_range<_Range> _CCCL_AND indirectly_unary_invocable<_Func, projected<iterator_t<_Range>, _Proj>>)
_CCCL_API constexpr for_each_result<borrowed_iterator_t<_Range>, _Func>
operator()(_Range&& __range, _Func __func, _Proj __proj = {}) const
{
return __for_each_impl(
::cuda::std::ranges::__begin_cpo{}(__range), ::cuda::std::ranges::__end_cpo{}(__range), __func, __proj);
}
};
_CCCL_END_NAMESPACE_CPO
inline namespace __cpo
{
_CCCL_GLOBAL_CONSTANT auto for_each = __for_each::__fn{};
} // namespace __cpo
_CCCL_END_NAMESPACE_CUDA_STD_RANGES
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_RANGES_FOR_EACH_H

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_RANGES_FOR_EACH_N_H
#define _CUDA_STD___ALGORITHM_RANGES_FOR_EACH_N_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/in_fun_result.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/concepts.h>
#include <cuda/std/__iterator/incrementable_traits.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__iterator/projected.h>
#include <cuda/std/__ranges/concepts.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD_RANGES
template <class _Iter, class _Func>
using for_each_n_result = in_fun_result<_Iter, _Func>;
_CCCL_BEGIN_NAMESPACE_CPO(__for_each_n)
struct __fn
{
_CCCL_TEMPLATE(class _Iter, class _Func, class _Proj = identity)
_CCCL_REQUIRES(input_iterator<_Iter> _CCCL_AND indirectly_unary_invocable<_Func, projected<_Iter, _Proj>>)
_CCCL_API constexpr for_each_n_result<_Iter, _Func>
operator()(_Iter __first, iter_difference_t<_Iter> __count, _Func __func, _Proj __proj = {}) const
{
while (__count-- > 0)
{
::cuda::std::invoke(__func, ::cuda::std::invoke(__proj, *__first));
++__first;
}
return {::cuda::std::move(__first), ::cuda::std::move(__func)};
}
};
_CCCL_END_NAMESPACE_CPO
inline namespace __cpo
{
_CCCL_GLOBAL_CONSTANT auto for_each_n = __for_each_n::__fn{};
} // namespace __cpo
_CCCL_END_NAMESPACE_CUDA_STD_RANGES
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_RANGES_FOR_EACH_N_H

View File

@@ -0,0 +1,65 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_RANGES_ITERATOR_CONCEPT_H
#define _CUDA_STD___ALGORITHM_RANGES_ITERATOR_CONCEPT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__iterator/concepts.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/remove_cvref.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD_RANGES
template <class _IterMaybeQualified>
_CCCL_API constexpr auto __get_iterator_concept()
{
using _Iter = remove_cvref_t<_IterMaybeQualified>;
if constexpr (contiguous_iterator<_Iter>)
{
return contiguous_iterator_tag();
}
else if constexpr (random_access_iterator<_Iter>)
{
return random_access_iterator_tag();
}
else if constexpr (bidirectional_iterator<_Iter>)
{
return bidirectional_iterator_tag();
}
else if constexpr (forward_iterator<_Iter>)
{
return forward_iterator_tag();
}
else if constexpr (input_iterator<_Iter>)
{
return input_iterator_tag();
}
}
template <class _Iter>
using __iterator_concept = decltype(__get_iterator_concept<_Iter>());
_CCCL_END_NAMESPACE_CUDA_STD_RANGES
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_RANGES_ITERATOR_CONCEPT_H

View File

@@ -0,0 +1,100 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_RANGES_MIN_H
#define _CUDA_STD___ALGORITHM_RANGES_MIN_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/min_element.h>
#include <cuda/std/__concepts/copyable.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__functional/ranges_operations.h>
#include <cuda/std/__iterator/concepts.h>
#include <cuda/std/__iterator/projected.h>
#include <cuda/std/__ranges/access.h>
#include <cuda/std/__ranges/concepts.h>
#include <cuda/std/initializer_list>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD_RANGES
_CCCL_BEGIN_NAMESPACE_CPO(__min)
struct __fn
{
_CCCL_TEMPLATE(class _Tp, class _Proj = identity, class _Comp = ::cuda::std::ranges::less)
_CCCL_REQUIRES(indirect_strict_weak_order<_Comp, projected<const _Tp*, _Proj>>)
[[nodiscard]] _CCCL_API constexpr const _Tp& operator()(
const _Tp& __a _CCCL_LIFETIMEBOUND, const _Tp& __b _CCCL_LIFETIMEBOUND, _Comp __comp = {}, _Proj __proj = {}) const
{
return ::cuda::std::invoke(__comp, ::cuda::std::invoke(__proj, __b), ::cuda::std::invoke(__proj, __a)) ? __b : __a;
}
_CCCL_TEMPLATE(class _Tp, class _Proj = identity, class _Comp = ::cuda::std::ranges::less)
_CCCL_REQUIRES(indirect_strict_weak_order<_Comp, projected<const _Tp*, _Proj>>)
[[nodiscard]] _CCCL_API constexpr _Tp
operator()(initializer_list<_Tp> __il, _Comp __comp = {}, _Proj __proj = {}) const
{
_CCCL_ASSERT(__il.begin() != __il.end(), "initializer_list must contain at least one element");
return *::cuda::std::__min_element(__il.begin(), __il.end(), __comp, __proj);
}
_CCCL_TEMPLATE(class _Rp, class _Proj = identity, class _Comp = ::cuda::std::ranges::less)
_CCCL_REQUIRES(input_range<_Rp> _CCCL_AND indirect_strict_weak_order<_Comp, projected<iterator_t<_Rp>, _Proj>>
_CCCL_AND indirectly_copyable_storable<iterator_t<_Rp>, range_value_t<_Rp>*>)
[[nodiscard]] _CCCL_API constexpr range_value_t<_Rp> operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const
{
auto __first = ::cuda::std::ranges::__begin_cpo{}(__r);
auto __last = ::cuda::std::ranges::__end_cpo{}(__r);
_CCCL_ASSERT(__first != __last, "range must contain at least one element");
if constexpr (forward_range<_Rp>)
{
return *::cuda::std::__min_element(__first, __last, __comp, __proj);
}
else
{
range_value_t<_Rp> __result = *__first;
while (++__first != __last)
{
if (::cuda::std::invoke(__comp, ::cuda::std::invoke(__proj, *__first), ::cuda::std::invoke(__proj, __result)))
{
__result = *__first;
}
}
return __result;
}
}
};
_CCCL_END_NAMESPACE_CPO
inline namespace __cpo
{
_CCCL_GLOBAL_CONSTANT auto min = __min::__fn{};
// We want to avoid using the CPO internally because of __tile__ access
using __min_cpo = __min::__fn;
} // namespace __cpo
_CCCL_END_NAMESPACE_CUDA_STD_RANGES
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_RANGES_MIN_H

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_RANGES_MIN_ELEMENT_H
#define _CUDA_STD___ALGORITHM_RANGES_MIN_ELEMENT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/min_element.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__functional/ranges_operations.h>
#include <cuda/std/__iterator/concepts.h>
#include <cuda/std/__iterator/projected.h>
#include <cuda/std/__ranges/access.h>
#include <cuda/std/__ranges/concepts.h>
#include <cuda/std/__ranges/dangling.h>
#include <cuda/std/__utility/forward.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD_RANGES
_CCCL_BEGIN_NAMESPACE_CPO(__min_element)
struct __fn
{
_CCCL_TEMPLATE(class _Ip, class _Sp, class _Proj = identity, class _Comp = ::cuda::std::ranges::less)
_CCCL_REQUIRES(forward_iterator<_Ip> _CCCL_AND sentinel_for<_Sp, _Ip> _CCCL_AND
indirect_strict_weak_order<_Comp, projected<_Ip, _Proj>>)
[[nodiscard]] _CCCL_API constexpr _Ip operator()(_Ip __first, _Sp __last, _Comp __comp = {}, _Proj __proj = {}) const
{
return ::cuda::std::__min_element(__first, __last, __comp, __proj);
}
_CCCL_TEMPLATE(class _Rp, class _Proj = identity, class _Comp = ::cuda::std::ranges::less)
_CCCL_REQUIRES(forward_range<_Rp> _CCCL_AND indirect_strict_weak_order<_Comp, projected<iterator_t<_Rp>, _Proj>>)
[[nodiscard]] _CCCL_API constexpr borrowed_iterator_t<_Rp>
operator()(_Rp&& __r, _Comp __comp = {}, _Proj __proj = {}) const
{
return ::cuda::std::__min_element(
::cuda::std::ranges::__begin_cpo{}(__r), ::cuda::std::ranges::__end_cpo{}(__r), __comp, __proj);
}
};
_CCCL_END_NAMESPACE_CPO
inline namespace __cpo
{
_CCCL_GLOBAL_CONSTANT auto min_element = __min_element::__fn{};
using __min_element_cpo = __min_element::__fn;
} // namespace __cpo
_CCCL_END_NAMESPACE_CUDA_STD_RANGES
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_RANGES_MIN_ELEMENT_H

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_REMOVE_H
#define _CUDA_STD___ALGORITHM_REMOVE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/find.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Tp>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator
remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
__first = ::cuda::std::find(__first, __last, __value_);
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (!(*__i == __value_))
{
*__first = ::cuda::std::move(*__i);
++__first;
}
}
}
return __first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REMOVE_H

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_REMOVE_COPY_H
#define _CUDA_STD___ALGORITHM_REMOVE_COPY_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _OutputIterator, class _Tp>
_CCCL_API constexpr _OutputIterator
remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value_)
{
for (; __first != __last; ++__first)
{
if (!(*__first == __value_))
{
*__result = *__first;
++__result;
}
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REMOVE_COPY_H

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_REMOVE_COPY_IF_H
#define _CUDA_STD___ALGORITHM_REMOVE_COPY_IF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _OutputIterator, class _Predicate>
_CCCL_API constexpr _OutputIterator
remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred)
{
for (; __first != __last; ++__first)
{
if (!__pred(*__first))
{
*__result = *__first;
++__result;
}
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REMOVE_COPY_IF_H

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_REMOVE_IF_H
#define _CUDA_STD___ALGORITHM_REMOVE_IF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/find_if.h>
#include <cuda/std/__type_traits/add_lvalue_reference.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Predicate>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator
remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
__first = ::cuda::std::find_if<_ForwardIterator, add_lvalue_reference_t<_Predicate>>(__first, __last, __pred);
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (!__pred(*__i))
{
*__first = ::cuda::std::move(*__i);
++__first;
}
}
}
return __first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REMOVE_IF_H

View File

@@ -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) 2023 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_REPLACE_H
#define _CUDA_STD___ALGORITHM_REPLACE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Tp>
_CCCL_API constexpr void
replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value)
{
for (; __first != __last; ++__first)
{
if (*__first == __old_value)
{
*__first = __new_value;
}
}
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REPLACE_H

View File

@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_REPLACE_COPY_H
#define _CUDA_STD___ALGORITHM_REPLACE_COPY_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _OutputIterator, class _Tp>
_CCCL_API constexpr _OutputIterator replace_copy(
_InputIterator __first,
_InputIterator __last,
_OutputIterator __result,
const _Tp& __old_value,
const _Tp& __new_value)
{
for (; __first != __last; ++__first, (void) ++__result)
{
if (*__first == __old_value)
{
*__result = __new_value;
}
else
{
*__result = *__first;
}
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REPLACE_COPY_H

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_REPLACE_COPY_IF_H
#define _CUDA_STD___ALGORITHM_REPLACE_COPY_IF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _OutputIterator, class _Predicate, class _Tp>
_CCCL_API constexpr _OutputIterator replace_copy_if(
_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred, const _Tp& __new_value)
{
for (; __first != __last; ++__first, (void) ++__result)
{
if (__pred(*__first))
{
*__result = __new_value;
}
else
{
*__result = *__first;
}
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REPLACE_COPY_IF_H

View File

@@ -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) 2023 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_REPLACE_IF_H
#define _CUDA_STD___ALGORITHM_REPLACE_IF_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _Predicate, class _Tp>
_CCCL_API constexpr void
replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value)
{
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
*__first = __new_value;
}
}
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REPLACE_IF_H

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_REVERSE_H
#define _CUDA_STD___ALGORITHM_REVERSE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iter_swap.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _BidirectionalIterator>
_CCCL_API constexpr void
__reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
{
while (__first != __last)
{
if (__first == --__last)
{
break;
}
_IterOps<_AlgPolicy>::iter_swap(__first, __last);
++__first;
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _RandomAccessIterator>
_CCCL_API constexpr void
__reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag)
{
if (__first != __last)
{
for (; __first < --__last; ++__first)
{
_IterOps<_AlgPolicy>::iter_swap(__first, __last);
}
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
_CCCL_API constexpr void __reverse(_BidirectionalIterator __first, _Sentinel __last)
{
using _IterCategory = __iterator_traits_category_or_concept_t<_BidirectionalIterator>;
::cuda::std::__reverse_impl<_AlgPolicy>(::cuda::std::move(__first), ::cuda::std::move(__last), _IterCategory());
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BidirectionalIterator>
_CCCL_API constexpr void reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
::cuda::std::__reverse<_ClassicAlgPolicy>(::cuda::std::move(__first), ::cuda::std::move(__last));
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REVERSE_H

View File

@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_REVERSE_COPY_H
#define _CUDA_STD___ALGORITHM_REVERSE_COPY_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _BidirectionalIterator, class _OutputIterator>
_CCCL_API constexpr _OutputIterator
reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
{
for (; __first != __last; ++__result)
{
*__result = *--__last;
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_REVERSE_COPY_H

View File

@@ -0,0 +1,261 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_ROTATE_H
#define _CUDA_STD___ALGORITHM_ROTATE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/move.h>
#include <cuda/std/__algorithm/move_backward.h>
#include <cuda/std/__algorithm/swap_ranges.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_trivially_move_assignable.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator __rotate_left(_ForwardIterator __first, _ForwardIterator __last)
{
using value_type = typename iterator_traits<_ForwardIterator>::value_type;
using _Ops = _IterOps<_AlgPolicy>;
value_type __tmp = _Ops::__iter_move(__first);
_ForwardIterator __lm1 = ::cuda::std::__move<_AlgPolicy>(_Ops::next(__first), __last, __first).second;
*__lm1 = ::cuda::std::move(__tmp);
return __lm1;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _BidirectionalIterator>
_CCCL_API constexpr _BidirectionalIterator __rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
using value_type = typename iterator_traits<_BidirectionalIterator>::value_type;
using _Ops = _IterOps<_AlgPolicy>;
_BidirectionalIterator __lm1 = _Ops::prev(__last);
value_type __tmp = _Ops::__iter_move(__lm1);
_BidirectionalIterator __fp1 =
::cuda::std::__move_backward<_AlgPolicy>(__first, __lm1, ::cuda::std::move(__last)).second;
*__first = ::cuda::std::move(__tmp);
return __fp1;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator
__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
{
_ForwardIterator __i = __middle;
while (true)
{
_IterOps<_AlgPolicy>::iter_swap(__first, __i);
++__first;
if (++__i == __last)
{
break;
}
if (__first == __middle)
{
__middle = __i;
}
}
_ForwardIterator __r = __first;
if (__first != __middle)
{
__i = __middle;
while (true)
{
_IterOps<_AlgPolicy>::iter_swap(__first, __i);
++__first;
if (++__i == __last)
{
if (__first == __middle)
{
break;
}
__i = __middle;
}
else if (__first == __middle)
{
__middle = __i;
}
}
}
return __r;
}
_CCCL_EXEC_CHECK_DISABLE
template <typename _Integral>
_CCCL_API constexpr _Integral __algo_gcd(_Integral __x, _Integral __y)
{
do
{
_Integral __t = __x % __y;
__x = __y;
__y = __t;
} while (__y);
return __x;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, typename _RandomAccessIterator>
_CCCL_API constexpr _RandomAccessIterator
__rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
{
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
using _Ops = _IterOps<_AlgPolicy>;
const difference_type __m1 = __middle - __first;
const difference_type __m2 = _Ops::distance(__middle, __last);
if (__m1 == __m2)
{
::cuda::std::__swap_ranges<_AlgPolicy>(__first, __middle, __middle, __last);
return __middle;
}
const difference_type __g = ::cuda::std::__algo_gcd(__m1, __m2);
for (_RandomAccessIterator __p = __first + __g; __p != __first;)
{
value_type __t(_Ops::__iter_move(--__p));
_RandomAccessIterator __p1 = __p;
_RandomAccessIterator __p2 = __p1 + __m1;
do
{
*__p1 = _Ops::__iter_move(__p2);
__p1 = __p2;
const difference_type __d = _Ops::distance(__p2, __last);
if (__m1 < __d)
{
__p2 += __m1;
}
else
{
__p2 = __first + (__m1 - __d);
}
} while (__p2 != __p);
*__p1 = ::cuda::std::move(__t);
}
return __first + __m2;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator __rotate_impl(
_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, ::cuda::std::forward_iterator_tag)
{
using value_type = typename iterator_traits<_ForwardIterator>::value_type;
if (is_trivially_move_assignable_v<value_type>)
{
if (_IterOps<_AlgPolicy>::next(__first) == __middle)
{
return ::cuda::std::__rotate_left<_AlgPolicy>(__first, __last);
}
}
return ::cuda::std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _BidirectionalIterator>
_CCCL_API constexpr _BidirectionalIterator __rotate_impl(
_BidirectionalIterator __first,
_BidirectionalIterator __middle,
_BidirectionalIterator __last,
bidirectional_iterator_tag)
{
using value_type = typename iterator_traits<_BidirectionalIterator>::value_type;
if (is_trivially_move_assignable_v<value_type>)
{
if (_IterOps<_AlgPolicy>::next(__first) == __middle)
{
return ::cuda::std::__rotate_left<_AlgPolicy>(__first, __last);
}
if (_IterOps<_AlgPolicy>::next(__middle) == __last)
{
return ::cuda::std::__rotate_right<_AlgPolicy>(__first, __last);
}
}
return ::cuda::std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _RandomAccessIterator>
_CCCL_API constexpr _RandomAccessIterator __rotate_impl(
_RandomAccessIterator __first,
_RandomAccessIterator __middle,
_RandomAccessIterator __last,
random_access_iterator_tag)
{
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
if (is_trivially_move_assignable_v<value_type>)
{
if (_IterOps<_AlgPolicy>::next(__first) == __middle)
{
return ::cuda::std::__rotate_left<_AlgPolicy>(__first, __last);
}
if (_IterOps<_AlgPolicy>::next(__middle) == __last)
{
return ::cuda::std::__rotate_right<_AlgPolicy>(__first, __last);
}
return ::cuda::std::__rotate_gcd<_AlgPolicy>(__first, __middle, __last);
}
return ::cuda::std::__rotate_forward<_AlgPolicy>(__first, __middle, __last);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Iterator, class _Sentinel>
_CCCL_API constexpr pair<_Iterator, _Iterator> __rotate(_Iterator __first, _Iterator __middle, _Sentinel __last)
{
using _Ret = pair<_Iterator, _Iterator>;
_Iterator __last_iter = _IterOps<_AlgPolicy>::next(__middle, __last);
if (__first == __middle)
{
return _Ret(__last_iter, __last_iter);
}
if (__middle == __last)
{
return _Ret(::cuda::std::move(__first), ::cuda::std::move(__last_iter));
}
using _IterCategory = __iterator_traits_category_or_concept_t<_Iterator>;
auto __result = ::cuda::std::__rotate_impl<_AlgPolicy>(
::cuda::std::move(__first), ::cuda::std::move(__middle), __last_iter, _IterCategory());
return _Ret(::cuda::std::move(__result), ::cuda::std::move(__last_iter));
}
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
{
return ::cuda::std::__rotate<_ClassicAlgPolicy>(
::cuda::std::move(__first), ::cuda::std::move(__middle), ::cuda::std::move(__last))
.first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_ROTATE_H

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_ROTATE_COPY_H
#define _CUDA_STD___ALGORITHM_ROTATE_COPY_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/copy.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _ForwardIterator, class _OutputIterator>
_CCCL_API constexpr _OutputIterator
rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result)
{
return ::cuda::std::copy(__first, __middle, ::cuda::std::copy(__middle, __last, __result));
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_ROTATE_COPY_H

View File

@@ -0,0 +1,116 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_SAMPLE_H
#define _CUDA_STD___ALGORITHM_SAMPLE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/min.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__random/uniform_int_distribution.h>
#include <cuda/std/__type_traits/common_type.h>
#include <cuda/std/__type_traits/is_signed.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _PopulationIterator, class _SampleIterator, class _Distance, class _UniformRandomNumberGenerator>
_CCCL_API _SampleIterator __sample(
_PopulationIterator __first,
_PopulationIterator __last,
_SampleIterator __output_iter,
_Distance __n,
_UniformRandomNumberGenerator& __g,
input_iterator_tag)
{
_Distance __k = 0;
for (; __first != __last && __k < __n; ++__first, (void) ++__k)
{
__output_iter[__k] = *__first;
}
_Distance __sz = __k;
for (; __first != __last; ++__first, (void) ++__k)
{
_Distance __r = ::cuda::std::uniform_int_distribution<_Distance>(0, __k)(__g);
if (__r < __sz)
{
__output_iter[__r] = *__first;
}
}
return __output_iter + ::cuda::std::min(__n, __k);
}
template <class _PopulationIterator, class _SampleIterator, class _Distance, class _UniformRandomNumberGenerator>
_CCCL_API _SampleIterator __sample(
_PopulationIterator __first,
_PopulationIterator __last,
_SampleIterator __output_iter,
_Distance __n,
_UniformRandomNumberGenerator& __g,
forward_iterator_tag)
{
_Distance __unsampled_sz = ::cuda::std::distance(__first, __last);
for (__n = ::cuda::std::min(__n, __unsampled_sz); __n != 0; ++__first)
{
_Distance __r = ::cuda::std::uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g);
if (__r < __n)
{
*__output_iter++ = *__first;
--__n;
}
}
return __output_iter;
}
template <class _PopulationIterator, class _SampleIterator, class _Distance, class _UniformRandomNumberGenerator>
_CCCL_API _SampleIterator __sample(
_PopulationIterator __first,
_PopulationIterator __last,
_SampleIterator __output_iter,
_Distance __n,
_UniformRandomNumberGenerator& __g)
{
using _PopCategory = __iterator_traits_category_or_concept_t<_PopulationIterator>;
using _Difference = typename iterator_traits<_PopulationIterator>::difference_type;
static_assert(__has_forward_traversal<_PopulationIterator> || __has_random_access_traversal<_SampleIterator>,
"SampleIterator must meet the requirements of RandomAccessIterator");
using _CommonType = typename common_type<_Distance, _Difference>::type;
_CCCL_ASSERT(!is_signed_v<_Distance> || __n >= 0, "N must be a positive number.");
return ::cuda::std::__sample(__first, __last, __output_iter, _CommonType(__n), __g, _PopCategory());
}
template <class _PopulationIterator, class _SampleIterator, class _Distance, class _UniformRandomNumberGenerator>
_CCCL_API _SampleIterator sample(
_PopulationIterator __first,
_PopulationIterator __last,
_SampleIterator __output_iter,
_Distance __n,
_UniformRandomNumberGenerator&& __g)
{
return ::cuda::std::__sample(__first, __last, __output_iter, __n, __g);
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SAMPLE_H

View File

@@ -0,0 +1,185 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_SEARCH_H
#define _CUDA_STD___ALGORITHM_SEARCH_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/advance.h>
#include <cuda/std/__iterator/concepts.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/add_lvalue_reference.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr pair<_ForwardIterator1, _ForwardIterator1> __search(
_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred,
forward_iterator_tag,
forward_iterator_tag)
{
if (__first2 == __last2)
{
return ::cuda::std::make_pair(__first1, __first1); // Everything matches an empty sequence
}
while (true)
{
// Find first element in sequence 1 that matches *__first2, with a minimum of loop checks
while (true)
{
if (__first1 == __last1) // return __last1 if no element matches *__first2
{
return ::cuda::std::make_pair(__last1, __last1);
}
if (__pred(*__first1, *__first2))
{
break;
}
++__first1;
}
// *__first1 matches *__first2, now match elements after here
_ForwardIterator1 __m1 = __first1;
_ForwardIterator2 __m2 = __first2;
while (true)
{
if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
{
return ::cuda::std::make_pair(__first1, __m1);
}
if (++__m1 == __last1) // Otherwise if source exhausted, pattern not found
{
return ::cuda::std::make_pair(__last1, __last1);
}
if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
{
++__first1;
break;
} // else there is a match, check next elements
}
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr pair<_RandomAccessIterator1, _RandomAccessIterator1> __search(
_RandomAccessIterator1 __first1,
_RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2,
_RandomAccessIterator2 __last2,
_BinaryPredicate __pred,
random_access_iterator_tag,
random_access_iterator_tag)
{
using _Diff1 = typename iterator_traits<_RandomAccessIterator1>::difference_type;
using _Diff2 = typename iterator_traits<_RandomAccessIterator2>::difference_type;
// Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
const _Diff2 __len2 = __last2 - __first2;
if (__len2 == 0)
{
return ::cuda::std::make_pair(__first1, __first1);
}
const _Diff1 __len1 = __last1 - __first1;
if (__len1 < __len2)
{
return ::cuda::std::make_pair(__last1, __last1);
}
const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
while (true)
{
while (true)
{
if (__first1 == __s)
{
return ::cuda::std::make_pair(__last1, __last1);
}
if (__pred(*__first1, *__first2))
{
break;
}
++__first1;
}
_RandomAccessIterator1 __m1 = __first1;
_RandomAccessIterator2 __m2 = __first2;
while (true)
{
if (++__m2 == __last2)
{
return ::cuda::std::make_pair(__first1, __first1 + __len2);
}
++__m1; // no need to check range on __m1 because __s guarantees we have enough source
if (!__pred(*__m1, *__m2))
{
++__first1;
break;
}
}
}
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator1
search(_ForwardIterator1 __first1,
_ForwardIterator1 __last1,
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate __pred)
{
return ::cuda::std::__search<add_lvalue_reference_t<_BinaryPredicate>>(
__first1,
__last1,
__first2,
__last2,
__pred,
__iterator_traits_category_or_concept_t<_ForwardIterator1>(),
__iterator_traits_category_or_concept_t<_ForwardIterator2>())
.first;
}
template <class _ForwardIterator1, class _ForwardIterator2>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator1
search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
return ::cuda::std::search(__first1, __last1, __first2, __last2, __equal_to{});
}
template <class _ForwardIterator, class _Searcher>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator
search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher& __s)
{
return __s(__f, __l).first;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SEARCH_H

View File

@@ -0,0 +1,163 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_SEARCH_N_H
#define _CUDA_STD___ALGORITHM_SEARCH_N_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/add_lvalue_reference.h>
#include <cuda/std/__utility/convert_to_integral.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _ForwardIterator, class _Size, class _Tp>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator __search_n(
_ForwardIterator __first,
_ForwardIterator __last,
_Size __count,
const _Tp& __value_,
_BinaryPredicate __pred,
forward_iterator_tag)
{
if (__count <= 0)
{
return __first;
}
while (true)
{
// Find first element in sequence that matches __value_, with a minimum of loop checks
while (true)
{
if (__first == __last) // return __last if no element matches __value_
{
return __last;
}
if (__pred(*__first, __value_))
{
break;
}
++__first;
}
// *__first matches __value_, now match elements after here
_ForwardIterator __m = __first;
_Size __c(0);
while (true)
{
if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern)
{
return __first;
}
if (++__m == __last) // Otherwise if source exhausted, pattern not found
{
return __last;
}
if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first
{
__first = __m;
++__first;
break;
} // else there is a match, check next elements
}
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _BinaryPredicate, class _RandomAccessIterator, class _Size, class _Tp>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _RandomAccessIterator __search_n(
_RandomAccessIterator __first,
_RandomAccessIterator __last,
_Size __count,
const _Tp& __value_,
_BinaryPredicate __pred,
random_access_iterator_tag)
{
if (__count <= 0)
{
return __first;
}
_Size __len = static_cast<_Size>(__last - __first);
if (__len < __count)
{
return __last;
}
const _RandomAccessIterator __s = __last - (__count - 1); // Start of pattern match can't go beyond here
while (true)
{
// Find first element in sequence that matches __value_, with a minimum of loop checks
while (true)
{
if (__first >= __s) // return __last if no element matches __value_
{
return __last;
}
if (__pred(*__first, __value_))
{
break;
}
++__first;
}
// *__first matches __value_, now match elements after here
_RandomAccessIterator __m = __first;
_Size __c(0);
while (true)
{
if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern)
{
return __first;
}
++__m; // no need to check range on __m because __s guarantees we have enough source
if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first
{
__first = __m;
++__first;
break;
} // else there is a match, check next elements
}
}
}
template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator
search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred)
{
return ::cuda::std::__search_n<add_lvalue_reference_t<_BinaryPredicate>>(
__first,
__last,
__convert_to_integral(__count),
__value_,
__pred,
__iterator_traits_category_or_concept_t<_ForwardIterator>());
}
template <class _ForwardIterator, class _Size, class _Tp>
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr _ForwardIterator
search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_)
{
return ::cuda::std::search_n(__first, __last, __convert_to_integral(__count), __value_, __equal_to{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SEARCH_N_H

View File

@@ -0,0 +1,95 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_SET_DIFFERENCE_H
#define _CUDA_STD___ALGORITHM_SET_DIFFERENCE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/copy.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__functional/identity.h>
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/remove_cvref.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Comp, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
_CCCL_API constexpr pair<remove_cvref_t<_InIter1>, remove_cvref_t<_OutIter>> __set_difference(
_InIter1&& __first1, _Sent1&& __last1, _InIter2&& __first2, _Sent2&& __last2, _OutIter&& __result, _Comp&& __comp)
{
while (__first1 != __last1 && __first2 != __last2)
{
if (__comp(*__first1, *__first2))
{
*__result = *__first1;
++__first1;
++__result;
}
else if (__comp(*__first2, *__first1))
{
++__first2;
}
else
{
++__first1;
++__first2;
}
}
return ::cuda::std::__copy<_AlgPolicy>(
::cuda::std::move(__first1), ::cuda::std::move(__last1), ::cuda::std::move(__result));
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
_CCCL_API constexpr _OutputIterator set_difference(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp)
{
return ::cuda::std::__set_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare>>(
__first1, __last1, __first2, __last2, __result, __comp)
.second;
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
_CCCL_API constexpr _OutputIterator set_difference(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result)
{
return ::cuda::std::__set_difference<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __result, __less{})
.second;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SET_DIFFERENCE_H

View File

@@ -0,0 +1,122 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_SET_INTERSECTION_H
#define _CUDA_STD___ALGORITHM_SET_INTERSECTION_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__iterator/next.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InIter1, class _InIter2, class _OutIter>
struct __set_intersection_result
{
_InIter1 __in1_;
_InIter2 __in2_;
_OutIter __out_;
// need a constructor as C++03 aggregate init is hard
_CCCL_API constexpr __set_intersection_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter)
: __in1_(::cuda::std::move(__in_iter1))
, __in2_(::cuda::std::move(__in_iter2))
, __out_(::cuda::std::move(__out_iter))
{}
};
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
_CCCL_API constexpr __set_intersection_result<_InIter1, _InIter2, _OutIter> __set_intersection(
_InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp)
{
while (__first1 != __last1 && __first2 != __last2)
{
if (__comp(*__first1, *__first2))
{
++__first1;
}
else
{
if (!__comp(*__first2, *__first1))
{
*__result = *__first1;
++__result;
++__first1;
}
++__first2;
}
}
return __set_intersection_result<_InIter1, _InIter2, _OutIter>(
_IterOps<_AlgPolicy>::next(::cuda::std::move(__first1), ::cuda::std::move(__last1)),
_IterOps<_AlgPolicy>::next(::cuda::std::move(__first2), ::cuda::std::move(__last2)),
::cuda::std::move(__result));
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
_CCCL_API constexpr _OutputIterator set_intersection(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp)
{
return ::cuda::std::__set_intersection<_ClassicAlgPolicy, __comp_ref_type<_Compare>>(
::cuda::std::move(__first1),
::cuda::std::move(__last1),
::cuda::std::move(__first2),
::cuda::std::move(__last2),
::cuda::std::move(__result),
__comp)
.__out_;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
_CCCL_API constexpr _OutputIterator set_intersection(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result)
{
return ::cuda::std::__set_intersection<_ClassicAlgPolicy>(
::cuda::std::move(__first1),
::cuda::std::move(__last1),
::cuda::std::move(__first2),
::cuda::std::move(__last2),
::cuda::std::move(__result),
__less{})
.__out_;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SET_INTERSECTION_H

View File

@@ -0,0 +1,144 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
#define _CUDA_STD___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/copy.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InIter1, class _InIter2, class _OutIter>
struct __set_symmetric_difference_result
{
_InIter1 __in1_;
_InIter2 __in2_;
_OutIter __out_;
// need a constructor as C++03 aggregate init is hard
_CCCL_API constexpr __set_symmetric_difference_result(
_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter)
: __in1_(::cuda::std::move(__in_iter1))
, __in2_(::cuda::std::move(__in_iter2))
, __out_(::cuda::std::move(__out_iter))
{}
};
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
_CCCL_API constexpr __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter> __set_symmetric_difference(
_InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp)
{
bool __first_end_reached = true;
while (__first1 != __last1)
{
if (__first2 == __last2)
{
__first_end_reached = false;
break;
}
if (__comp(*__first1, *__first2))
{
*__result = *__first1;
++__result;
++__first1;
}
else
{
if (__comp(*__first2, *__first1))
{
*__result = *__first2;
++__result;
}
else
{
++__first1;
}
++__first2;
}
}
if (__first_end_reached)
{
auto __ret2 = ::cuda::std::__copy<_AlgPolicy>(
::cuda::std::move(__first2), ::cuda::std::move(__last2), ::cuda::std::move(__result));
return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>(
::cuda::std::move(__first1), ::cuda::std::move(__ret2.first), ::cuda::std::move((__ret2.second)));
}
else
{
auto __ret1 = ::cuda::std::__copy<_AlgPolicy>(
::cuda::std::move(__first1), ::cuda::std::move(__last1), ::cuda::std::move(__result));
return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>(
::cuda::std::move(__ret1.first), ::cuda::std::move(__first2), ::cuda::std::move((__ret1.second)));
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
_CCCL_API constexpr _OutputIterator set_symmetric_difference(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp)
{
return ::cuda::std::__set_symmetric_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare>>(
::cuda::std::move(__first1),
::cuda::std::move(__last1),
::cuda::std::move(__first2),
::cuda::std::move(__last2),
::cuda::std::move(__result),
__comp)
.__out_;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
_CCCL_API constexpr _OutputIterator set_symmetric_difference(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result)
{
return ::cuda::std::set_symmetric_difference(
::cuda::std::move(__first1),
::cuda::std::move(__last1),
::cuda::std::move(__first2),
::cuda::std::move(__last2),
::cuda::std::move(__result),
__less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H

View File

@@ -0,0 +1,138 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_SET_UNION_H
#define _CUDA_STD___ALGORITHM_SET_UNION_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/copy.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InIter1, class _InIter2, class _OutIter>
struct __set_union_result
{
_InIter1 __in1_;
_InIter2 __in2_;
_OutIter __out_;
// need a constructor as C++03 aggregate init is hard
_CCCL_API constexpr __set_union_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter)
: __in1_(::cuda::std::move(__in_iter1))
, __in2_(::cuda::std::move(__in_iter2))
, __out_(::cuda::std::move(__out_iter))
{}
};
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
_CCCL_API constexpr __set_union_result<_InIter1, _InIter2, _OutIter>
__set_union(_InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp)
{
bool __first_end_reached = true;
for (; __first1 != __last1; ++__result)
{
if (__first2 == __last2)
{
__first_end_reached = false;
break;
}
if (__comp(*__first2, *__first1))
{
*__result = *__first2;
++__first2;
}
else
{
if (!__comp(*__first1, *__first2))
{
++__first2;
}
*__result = *__first1;
++__first1;
}
}
if (__first_end_reached)
{
auto __ret2 = ::cuda::std::__copy<_AlgPolicy>(
::cuda::std::move(__first2), ::cuda::std::move(__last2), ::cuda::std::move(__result));
return __set_union_result<_InIter1, _InIter2, _OutIter>(
::cuda::std::move(__first1), ::cuda::std::move(__ret2.first), ::cuda::std::move((__ret2.second)));
}
else
{
auto __ret1 = ::cuda::std::__copy<_AlgPolicy>(
::cuda::std::move(__first1), ::cuda::std::move(__last1), ::cuda::std::move(__result));
return __set_union_result<_InIter1, _InIter2, _OutIter>(
::cuda::std::move(__ret1.first), ::cuda::std::move(__first2), ::cuda::std::move((__ret1.second)));
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
_CCCL_API constexpr _OutputIterator set_union(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp)
{
return ::cuda::std::__set_union<_ClassicAlgPolicy, __comp_ref_type<_Compare>>(
::cuda::std::move(__first1),
::cuda::std::move(__last1),
::cuda::std::move(__first2),
::cuda::std::move(__last2),
::cuda::std::move(__result),
__comp)
.__out_;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
_CCCL_API constexpr _OutputIterator set_union(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result)
{
return ::cuda::std::set_union(
::cuda::std::move(__first1),
::cuda::std::move(__last1),
::cuda::std::move(__first2),
::cuda::std::move(__last2),
::cuda::std::move(__result),
__less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SET_UNION_H

View File

@@ -0,0 +1,84 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_SHIFT_LEFT_H
#define _CUDA_STD___ALGORITHM_SHIFT_LEFT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/move.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator __shift_left(
_ForwardIterator __first,
_ForwardIterator __last,
typename iterator_traits<_ForwardIterator>::difference_type __n,
random_access_iterator_tag)
{
_ForwardIterator __m = __first;
if (__n >= __last - __first)
{
return __first;
}
__m += __n;
return ::cuda::std::move(__m, __last, __first);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator __shift_left(
_ForwardIterator __first,
_ForwardIterator __last,
typename iterator_traits<_ForwardIterator>::difference_type __n,
forward_iterator_tag)
{
_ForwardIterator __m = __first;
for (; __n > 0; --__n)
{
if (__m == __last)
{
return __first;
}
++__m;
}
return ::cuda::std::move(__m, __last, __first);
}
template <class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator shift_left(
_ForwardIterator __first, _ForwardIterator __last, typename iterator_traits<_ForwardIterator>::difference_type __n)
{
if (__n == 0)
{
return __last;
}
using _IterCategory = __iterator_traits_category_or_concept_t<_ForwardIterator>;
return __shift_left(__first, __last, __n, _IterCategory());
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SHIFT_LEFT_H

View File

@@ -0,0 +1,144 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_SHIFT_RIGHT_H
#define _CUDA_STD___ALGORITHM_SHIFT_RIGHT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/move.h>
#include <cuda/std/__algorithm/move_backward.h>
#include <cuda/std/__algorithm/swap_ranges.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/swap.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator __shift_right(
_ForwardIterator __first,
_ForwardIterator __last,
typename iterator_traits<_ForwardIterator>::difference_type __n,
random_access_iterator_tag)
{
decltype(__n) __d = __last - __first;
if (__n >= __d)
{
return __last;
}
_ForwardIterator __m = __first + (__d - __n);
return ::cuda::std::move_backward(__first, __m, __last);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator __shift_right(
_ForwardIterator __first,
_ForwardIterator __last,
typename iterator_traits<_ForwardIterator>::difference_type __n,
bidirectional_iterator_tag)
{
_ForwardIterator __m = __last;
for (; __n > 0; --__n)
{
if (__m == __first)
{
return __last;
}
--__m;
}
return ::cuda::std::move_backward(__first, __m, __last);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator __shift_right(
_ForwardIterator __first,
_ForwardIterator __last,
typename iterator_traits<_ForwardIterator>::difference_type __n,
forward_iterator_tag)
{
_ForwardIterator __ret = __first;
for (; __n > 0; --__n)
{
if (__ret == __last)
{
return __last;
}
++__ret;
}
// We have an __n-element scratch space from __first to __ret.
// Slide an __n-element window [__trail, __lead) from left to right.
// We're essentially doing swap_ranges(__first, __ret, __trail, __lead)
// over and over; but once __lead reaches __last we needn't bother
// to save the values of elements [__trail, __last).
auto __trail = __first;
auto __lead = __ret;
while (__trail != __ret)
{
if (__lead == __last)
{
::cuda::std::move(__first, __trail, __ret);
return __ret;
}
++__trail;
++__lead;
}
_ForwardIterator __mid = __first;
while (true)
{
if (__lead == __last)
{
__trail = ::cuda::std::move(__mid, __ret, __trail);
::cuda::std::move(__first, __mid, __trail);
return __ret;
}
swap(*__mid, *__trail);
++__mid;
++__trail;
++__lead;
if (__mid == __ret)
{
__mid = __first;
}
}
}
template <class _ForwardIterator>
_CCCL_API constexpr _ForwardIterator shift_right(
_ForwardIterator __first, _ForwardIterator __last, typename iterator_traits<_ForwardIterator>::difference_type __n)
{
if (__n == 0)
{
return __first;
}
using _IterCategory = __iterator_traits_category_or_concept_t<_ForwardIterator>;
return __shift_right(__first, __last, __n, _IterCategory());
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SHIFT_RIGHT_H

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_SHUFFLE_H
#define _CUDA_STD___ALGORITHM_SHUFFLE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__random/uniform_int_distribution.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _AlgPolicy, class _RandomAccessIterator, class _Sentinel, class _UniformRandomNumberGenerator>
_CCCL_API inline _RandomAccessIterator
__shuffle(_RandomAccessIterator __first, _Sentinel __last_sentinel, _UniformRandomNumberGenerator&& __g)
{
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
using _Dp = uniform_int_distribution<ptrdiff_t>;
using _Pp = typename _Dp::param_type;
auto __original_last = _IterOps<_AlgPolicy>::next(__first, __last_sentinel);
auto __last = __original_last;
difference_type __d = __last - __first;
if (__d > 1)
{
_Dp __uid;
for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d)
{
difference_type __i = __uid(__g, _Pp(0, __d));
if (__i != difference_type(0))
{
_IterOps<_AlgPolicy>::iter_swap(__first, __first + __i);
}
}
}
return __original_last;
}
template <class _RandomAccessIterator, class _UniformRandomNumberGenerator>
_CCCL_API inline void
shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, _UniformRandomNumberGenerator&& __g)
{
(void) ::cuda::std::__shuffle<_ClassicAlgPolicy>(
::cuda::std::move(__first), ::cuda::std::move(__last), ::cuda::std::forward<_UniformRandomNumberGenerator>(__g));
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SHUFFLE_H

View File

@@ -0,0 +1,140 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_SIFT_DOWN_H
#define _CUDA_STD___ALGORITHM_SIFT_DOWN_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API constexpr void __sift_down(
_RandomAccessIterator __first,
_Compare&& __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len,
_RandomAccessIterator __start)
{
using _Ops = _IterOps<_AlgPolicy>;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
// left-child of __start is at 2 * __start + 1
// right-child of __start is at 2 * __start + 2
difference_type __child = __start - __first;
if (__len < 2 || (__len - 2) / 2 < __child)
{
return;
}
__child = 2 * __child + 1;
_RandomAccessIterator __child_i = __first + __child;
if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1))))
{
// right-child exists and is greater than left-child
++__child_i;
++__child;
}
// check if we are in heap-order
if (__comp(*__child_i, *__start))
{
// we are, __start is larger than its largest child
return;
}
value_type __top(_Ops::__iter_move(__start));
do
{
// we are not in heap-order, swap the parent with its largest child
*__start = _Ops::__iter_move(__child_i);
__start = __child_i;
if ((__len - 2) / 2 < __child)
{
break;
}
// recompute the child based off of the updated parent
__child = 2 * __child + 1;
__child_i = __first + __child;
if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1))))
{
// right-child exists and is greater than left-child
++__child_i;
++__child;
}
// check if we are in heap-order
} while (!__comp(*__child_i, __top));
*__start = ::cuda::std::move(__top);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API constexpr _RandomAccessIterator __floyd_sift_down(
_RandomAccessIterator __first,
_Compare&& __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len)
{
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
_CCCL_ASSERT(__len >= 2, "shouldn't be called unless __len >= 2");
_RandomAccessIterator __hole = __first;
_RandomAccessIterator __child_i = __first;
difference_type __child = 0;
while (true)
{
__child_i += difference_type(__child + 1);
__child = 2 * __child + 1;
if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + difference_type(1))))
{
// right-child exists and is greater than left-child
++__child_i;
++__child;
}
// swap __hole with its largest child
*__hole = _IterOps<_AlgPolicy>::__iter_move(__child_i);
__hole = __child_i;
// if __hole is now a leaf, we're done
if (__child > (__len - 2) / 2)
{
break;
}
}
return __hole;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SIFT_DOWN_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_SORT_HEAP_H
#define _CUDA_STD___ALGORITHM_SORT_HEAP_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/pop_heap.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_copy_assignable.h>
#include <cuda/std/__type_traits/is_copy_constructible.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API constexpr void __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp)
{
__comp_ref_type<_Compare> __comp_ref = __comp;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n)
{
::cuda::std::__pop_heap<_AlgPolicy>(__first, __last, __comp_ref, __n);
}
}
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator, class _Compare>
_CCCL_API constexpr void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
static_assert(is_copy_constructible_v<_RandomAccessIterator>, "Iterators must be copy constructible.");
static_assert(is_copy_assignable_v<_RandomAccessIterator>, "Iterators must be copy assignable.");
::cuda::std::__sort_heap<_ClassicAlgPolicy>(::cuda::std::move(__first), ::cuda::std::move(__last), __comp);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _RandomAccessIterator>
_CCCL_API constexpr void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
::cuda::std::sort_heap(::cuda::std::move(__first), ::cuda::std::move(__last), __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SORT_HEAP_H

View File

@@ -0,0 +1,359 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_STABLE_PARTITION_H
#define _CUDA_STD___ALGORITHM_STABLE_PARTITION_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/rotate.h>
#include <cuda/std/__iterator/advance.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__memory/destruct_n.h>
#include <cuda/std/__memory/temporary_buffer.h>
#include <cuda/std/__memory/unique_ptr.h>
#include <cuda/std/__new_>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
_CCCL_API _ForwardIterator __stable_partition_impl(
_ForwardIterator __first,
_ForwardIterator __last,
_Predicate __pred,
_Distance __len,
_Pair __p,
forward_iterator_tag __fit)
{
using _Ops = _IterOps<_AlgPolicy>;
// *__first is known to be false
// __len >= 1
if (__len == 1)
{
return __first;
}
if (__len == 2)
{
_ForwardIterator __m = __first;
if (__pred(*++__m))
{
_Ops::iter_swap(__first, __m);
return __m;
}
return __first;
}
if (__len <= __p.second)
{ // The buffer is big enough to use
using value_type = typename iterator_traits<_ForwardIterator>::value_type;
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
// Move the falses into the temporary buffer, and the trues to the front of the line
// Update __first to always point to the end of the trues
value_type* __t = __p.first;
::new ((void*) __t) value_type(_Ops::__iter_move(__first));
__d.template __incr<value_type>();
++__t;
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (__pred(*__i))
{
*__first = _Ops::__iter_move(__i);
++__first;
}
else
{
::new ((void*) __t) value_type(_Ops::__iter_move(__i));
__d.template __incr<value_type>();
++__t;
}
}
// All trues now at start of range, all falses in buffer
// Move falses back into range, but don't mess up __first which points to first false
__i = __first;
for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
{
*__i = _Ops::__iter_move(__t2);
}
// __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
return __first;
}
// Else not enough buffer, do in place
// __len >= 3
_ForwardIterator __m = __first;
_Distance __len2 = __len / 2; // __len2 >= 2
_Ops::advance(__m, __len2);
// recurse on [__first, __m), *__first know to be false
// F?????????????????
// f m l
_ForwardIterator __first_false =
::cuda::std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m, __pred, __len2, __p, __fit);
// TTTFFFFF??????????
// f ff m l
// recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
_ForwardIterator __m1 = __m;
_ForwardIterator __second_false = __last;
_Distance __len_half = __len - __len2;
while (__pred(*__m1))
{
if (++__m1 == __last)
{
goto __second_half_done;
}
--__len_half;
}
// TTTFFFFFTTTF??????
// f ff m m1 l
__second_false =
::cuda::std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __fit);
__second_half_done:
// TTTFFFFFTTTTTFFFFF
// f ff m sf l
return ::cuda::std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first;
// TTTTTTTTFFFFFFFFFF
// |
}
template <class _AlgPolicy, class _Predicate, class _ForwardIterator>
_CCCL_API _ForwardIterator
__stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag)
{
using difference_type = typename iterator_traits<_ForwardIterator>::difference_type;
using value_type = typename iterator_traits<_ForwardIterator>::value_type;
const difference_type __alloc_limit = 3; // might want to make this a function of trivial assignment
// Either prove all true and return __first or point to first false
while (true)
{
if (__first == __last)
{
return __first;
}
if (!__pred(*__first))
{
break;
}
++__first;
}
// We now have a reduced range [__first, __last)
// *__first is known to be false
difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last);
pair<value_type*, ptrdiff_t> __p(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len >= __alloc_limit)
{
__p = ::cuda::std::get_temporary_buffer<value_type>(__len);
__h.reset(__p.first);
}
return ::cuda::std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
::cuda::std::move(__first), ::cuda::std::move(__last), __pred, __len, __p, forward_iterator_tag());
}
template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
_CCCL_API _BidirectionalIterator __stable_partition_impl(
_BidirectionalIterator __first,
_BidirectionalIterator __last,
_Predicate __pred,
_Distance __len,
_Pair __p,
bidirectional_iterator_tag __bit)
{
using _Ops = _IterOps<_AlgPolicy>;
// *__first is known to be false
// *__last is known to be true
// __len >= 2
if (__len == 2)
{
_Ops::iter_swap(__first, __last);
return __last;
}
if (__len == 3)
{
_BidirectionalIterator __m = __first;
if (__pred(*++__m))
{
_Ops::iter_swap(__first, __m);
_Ops::iter_swap(__m, __last);
return __last;
}
_Ops::iter_swap(__m, __last);
_Ops::iter_swap(__first, __m);
return __m;
}
if (__len <= __p.second)
{ // The buffer is big enough to use
using value_type = typename iterator_traits<_BidirectionalIterator>::value_type;
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
// Move the falses into the temporary buffer, and the trues to the front of the line
// Update __first to always point to the end of the trues
value_type* __t = __p.first;
::new ((void*) __t) value_type(_Ops::__iter_move(__first));
__d.template __incr<value_type>();
++__t;
_BidirectionalIterator __i = __first;
while (++__i != __last)
{
if (__pred(*__i))
{
*__first = _Ops::__iter_move(__i);
++__first;
}
else
{
::new ((void*) __t) value_type(_Ops::__iter_move(__i));
__d.template __incr<value_type>();
++__t;
}
}
// move *__last, known to be true
*__first = _Ops::__iter_move(__i);
__i = ++__first;
// All trues now at start of range, all falses in buffer
// Move falses back into range, but don't mess up __first which points to first false
for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
{
*__i = _Ops::__iter_move(__t2);
}
// __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
return __first;
}
// Else not enough buffer, do in place
// __len >= 4
_BidirectionalIterator __m = __first;
_Distance __len2 = __len / 2; // __len2 >= 2
_Ops::advance(__m, __len2);
// recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false
// F????????????????T
// f m l
_BidirectionalIterator __m1 = __m;
_BidirectionalIterator __first_false = __first;
_Distance __len_half = __len2;
while (!__pred(*--__m1))
{
if (__m1 == __first)
{
goto __first_half_done;
}
--__len_half;
}
// F???TFFF?????????T
// f m1 m l
__first_false =
::cuda::std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__first, __m1, __pred, __len_half, __p, __bit);
__first_half_done:
// TTTFFFFF?????????T
// f ff m l
// recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
__m1 = __m;
_BidirectionalIterator __second_false = __last;
++__second_false;
__len_half = __len - __len2;
while (__pred(*__m1))
{
if (++__m1 == __last)
{
goto __second_half_done;
}
--__len_half;
}
// TTTFFFFFTTTF?????T
// f ff m m1 l
__second_false =
::cuda::std::__stable_partition_impl<_AlgPolicy, _Predicate&>(__m1, __last, __pred, __len_half, __p, __bit);
__second_half_done:
// TTTFFFFFTTTTTFFFFF
// f ff m sf l
return ::cuda::std::__rotate<_AlgPolicy>(__first_false, __m, __second_false).first;
// TTTTTTTTFFFFFFFFFF
// |
}
template <class _AlgPolicy, class _Predicate, class _BidirectionalIterator>
_CCCL_API _BidirectionalIterator __stable_partition_impl(
_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred, bidirectional_iterator_tag)
{
using difference_type = typename iterator_traits<_BidirectionalIterator>::difference_type;
using value_type = typename iterator_traits<_BidirectionalIterator>::value_type;
const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment
// Either prove all true and return __first or point to first false
while (true)
{
if (__first == __last)
{
return __first;
}
if (!__pred(*__first))
{
break;
}
++__first;
}
// __first points to first false, everything prior to __first is already set.
// Either prove [__first, __last) is all false and return __first, or point __last to last true
do
{
if (__first == --__last)
{
return __first;
}
} while (!__pred(*__last));
// We now have a reduced range [__first, __last]
// *__first is known to be false
// *__last is known to be true
// __len >= 2
difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1;
pair<value_type*, ptrdiff_t> __p(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len >= __alloc_limit)
{
__p = ::cuda::std::get_temporary_buffer<value_type>(__len);
__h.reset(__p.first);
}
return ::cuda::std::__stable_partition_impl<_AlgPolicy, _Predicate&>(
::cuda::std::move(__first), ::cuda::std::move(__last), __pred, __len, __p, bidirectional_iterator_tag());
}
template <class _AlgPolicy, class _Predicate, class _ForwardIterator, class _IterCategory>
_CCCL_API _ForwardIterator __stable_partition(
_ForwardIterator __first, _ForwardIterator __last, _Predicate&& __pred, _IterCategory __iter_category)
{
return ::cuda::std::__stable_partition_impl<_AlgPolicy, remove_cvref_t<_Predicate>&>(
::cuda::std::move(__first), ::cuda::std::move(__last), __pred, __iter_category);
}
template <class _ForwardIterator, class _Predicate>
_CCCL_API _ForwardIterator stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
using _IterCategory = __iterator_traits_category_or_concept_t<_ForwardIterator>;
return ::cuda::std::__stable_partition<_ClassicAlgPolicy, _Predicate&>(
::cuda::std::move(__first), ::cuda::std::move(__last), __pred, _IterCategory());
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_STABLE_PARTITION_H

View File

@@ -0,0 +1,321 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_STABLE_SORT_H
#define _CUDA_STD___ALGORITHM_STABLE_SORT_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/comp_ref_type.h>
#include <cuda/std/__algorithm/inplace_merge.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__algorithm/sort.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__memory/construct_at.h>
#include <cuda/std/__memory/destruct_n.h>
#include <cuda/std/__memory/temporary_buffer.h>
#include <cuda/std/__memory/unique_ptr.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_integral.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/is_trivially_copy_assignable.h>
#include <cuda/std/__type_traits/remove_cvref.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/cstddef>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator>
_CCCL_API void __insertion_sort_move(
_BidirectionalIterator __first1,
_BidirectionalIterator __last1,
typename iterator_traits<_BidirectionalIterator>::value_type* __first2,
_Compare __comp)
{
using _Ops = _IterOps<_AlgPolicy>;
using value_type = typename iterator_traits<_BidirectionalIterator>::value_type;
if (__first1 != __last1)
{
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__first2, __d);
value_type* __last2 = __first2;
::cuda::std::__construct_at(__last2, _Ops::__iter_move(__first1));
__d.template __incr<value_type>();
for (++__last2; ++__first1 != __last1; ++__last2)
{
value_type* __j2 = __last2;
value_type* __i2 = __j2;
if (__comp(*__first1, *--__i2))
{
::cuda::std::__construct_at(__j2, ::cuda::std::move(*__i2));
__d.template __incr<value_type>();
for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2)
{
*__j2 = ::cuda::std::move(*__i2);
}
*__j2 = _Ops::__iter_move(__first1);
}
else
{
::cuda::std::__construct_at(__j2, _Ops::__iter_move(__first1));
__d.template __incr<value_type>();
}
}
__h.release();
}
}
template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2>
_CCCL_API void __merge_move_construct(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
typename iterator_traits<_InputIterator1>::value_type* __result,
_Compare __comp)
{
using _Ops = _IterOps<_AlgPolicy>;
using value_type = typename iterator_traits<_InputIterator1>::value_type;
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__result, __d);
for (; true; ++__result)
{
if (__first1 == __last1)
{
for (; __first2 != __last2; ++__first2, (void) ++__result, __d.template __incr<value_type>())
{
::cuda::std::__construct_at(__result, _Ops::__iter_move(__first2));
}
__h.release();
return;
}
if (__first2 == __last2)
{
for (; __first1 != __last1; ++__first1, (void) ++__result, __d.template __incr<value_type>())
{
::cuda::std::__construct_at(__result, _Ops::__iter_move(__first1));
}
__h.release();
return;
}
if (__comp(*__first2, *__first1))
{
::cuda::std::__construct_at(__result, _Ops::__iter_move(__first2));
__d.template __incr<value_type>();
++__first2;
}
else
{
::cuda::std::__construct_at(__result, _Ops::__iter_move(__first1));
__d.template __incr<value_type>();
++__first1;
}
}
}
template <class _AlgPolicy, class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_CCCL_API void __merge_move_assign(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp)
{
using _Ops = _IterOps<_AlgPolicy>;
for (; __first1 != __last1; ++__result)
{
if (__first2 == __last2)
{
for (; __first1 != __last1; ++__first1, (void) ++__result)
{
*__result = _Ops::__iter_move(__first1);
}
return;
}
if (__comp(*__first2, *__first1))
{
*__result = _Ops::__iter_move(__first2);
++__first2;
}
else
{
*__result = _Ops::__iter_move(__first1);
++__first1;
}
}
for (; __first2 != __last2; ++__first2, (void) ++__result)
{
*__result = _Ops::__iter_move(__first2);
}
}
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API void __stable_sort(
_RandomAccessIterator __first,
_RandomAccessIterator __last,
_Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len,
typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
ptrdiff_t __buff_size);
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API void __stable_sort_move(
_RandomAccessIterator __first1,
_RandomAccessIterator __last1,
_Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len,
typename iterator_traits<_RandomAccessIterator>::value_type* __first2)
{
using _Ops = _IterOps<_AlgPolicy>;
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
switch (__len)
{
case 0:
return;
case 1:
::cuda::std::__construct_at(__first2, _Ops::__iter_move(__first1));
return;
case 2:
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h2(__first2, __d);
if (__comp(*--__last1, *__first1))
{
::cuda::std::__construct_at(__first2, _Ops::__iter_move(__last1));
__d.template __incr<value_type>();
++__first2;
::cuda::std::__construct_at(__first2, _Ops::__iter_move(__first1));
}
else
{
::cuda::std::__construct_at(__first2, _Ops::__iter_move(__first1));
__d.template __incr<value_type>();
++__first2;
::cuda::std::__construct_at(__first2, _Ops::__iter_move(__last1));
}
__h2.release();
return;
}
if (__len <= 8)
{
::cuda::std::__insertion_sort_move<_AlgPolicy, _Compare>(__first1, __last1, __first2, __comp);
return;
}
typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
_RandomAccessIterator __m = __first1 + __l2;
::cuda::std::__stable_sort<_AlgPolicy, _Compare>(__first1, __m, __comp, __l2, __first2, __l2);
::cuda::std::__stable_sort<_AlgPolicy, _Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2);
::cuda::std::__merge_move_construct<_AlgPolicy, _Compare>(__first1, __m, __m, __last1, __first2, __comp);
}
template <class _Tp>
struct __stable_sort_switch
{
static const unsigned value = 128 * is_trivially_copy_assignable_v<_Tp>;
};
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
_CCCL_API void __stable_sort(
_RandomAccessIterator __first,
_RandomAccessIterator __last,
_Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len,
typename iterator_traits<_RandomAccessIterator>::value_type* __buff,
ptrdiff_t __buff_size)
{
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
switch (__len)
{
case 0:
case 1:
return;
case 2:
if (__comp(*--__last, *__first))
{
_IterOps<_AlgPolicy>::iter_swap(__first, __last);
}
return;
}
if (__len <= static_cast<difference_type>(__stable_sort_switch<value_type>::value))
{
::cuda::std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp);
return;
}
typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
_RandomAccessIterator __m = __first + __l2;
if (__len <= __buff_size)
{
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
::cuda::std::__stable_sort_move<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff);
__d.__set(__l2, (value_type*) nullptr);
::cuda::std::__stable_sort_move<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff + __l2);
__d.__set(__len, (value_type*) nullptr);
::cuda::std::__merge_move_assign<_AlgPolicy, _Compare>(
__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp);
return;
}
::cuda::std::__stable_sort<_AlgPolicy, _Compare>(__first, __m, __comp, __l2, __buff, __buff_size);
::cuda::std::__stable_sort<_AlgPolicy, _Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size);
::cuda::std::__inplace_merge<_AlgPolicy>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size);
}
template <class _AlgPolicy, class _RandomAccessIterator, class _Compare>
_CCCL_API void __stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp)
{
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
difference_type __len = __last - __first;
pair<value_type*, ptrdiff_t> __buf(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value))
{
__buf = ::cuda::std::get_temporary_buffer<value_type>(__len);
__h.reset(__buf.first);
}
::cuda::std::__stable_sort<_AlgPolicy, __comp_ref_type<_Compare>>(
__first, __last, __comp, __len, __buf.first, __buf.second);
}
template <class _RandomAccessIterator, class _Compare>
_CCCL_API void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
::cuda::std::__stable_sort_impl<_ClassicAlgPolicy>(::cuda::std::move(__first), ::cuda::std::move(__last), __comp);
}
template <class _RandomAccessIterator>
_CCCL_API void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
::cuda::std::stable_sort(__first, __last, __less{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_STABLE_SORT_H

View File

@@ -0,0 +1,78 @@
// -*- 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_STD___ALGORITHM_SWAP_RANGES_H
#define _CUDA_STD___ALGORITHM_SWAP_RANGES_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
// 2+2 iterators: the shorter size will be used.
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2, class _Sentinel2>
_CCCL_API constexpr pair<_ForwardIterator1, _ForwardIterator2>
__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _Sentinel2 __last2)
{
while (__first1 != __last1 && __first2 != __last2)
{
_IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
++__first1;
++__first2;
}
return pair<_ForwardIterator1, _ForwardIterator2>(::cuda::std::move(__first1), ::cuda::std::move(__first2));
}
// 2+1 iterators: size2 >= size1.
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _ForwardIterator1, class _Sentinel1, class _ForwardIterator2>
_CCCL_API constexpr pair<_ForwardIterator1, _ForwardIterator2>
__swap_ranges(_ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2)
{
while (__first1 != __last1)
{
_IterOps<_AlgPolicy>::iter_swap(__first1, __first2);
++__first1;
++__first2;
}
return pair<_ForwardIterator1, _ForwardIterator2>(::cuda::std::move(__first1), ::cuda::std::move(__first2));
}
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator1, class _ForwardIterator2>
_CCCL_API constexpr _ForwardIterator2
swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
{
return ::cuda::std::__swap_ranges<_ClassicAlgPolicy>(
::cuda::std::move(__first1), ::cuda::std::move(__last1), ::cuda::std::move(__first2))
.second;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_SWAP_RANGES_H

View File

@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// 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_STD___ALGORITHM_TRANSFORM_H
#define _CUDA_STD___ALGORITHM_TRANSFORM_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator, class _OutputIterator, class _UnaryOperation>
_CCCL_API constexpr _OutputIterator
transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op)
{
for (; __first != __last; ++__first, (void) ++__result)
{
*__result = __op(*__first);
}
return __result;
}
_CCCL_EXEC_CHECK_DISABLE
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _BinaryOperation>
_CCCL_API constexpr _OutputIterator transform(
_InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_OutputIterator __result,
_BinaryOperation __binary_op)
{
for (; __first1 != __last1; ++__first1, (void) ++__first2, ++__result)
{
*__result = __binary_op(*__first1, *__first2);
}
return __result;
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_TRANSFORM_H

View File

@@ -0,0 +1,76 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _CUDA_STD___ALGORITHM_UNIQUE_H
#define _CUDA_STD___ALGORITHM_UNIQUE_H
#include <cuda/std/detail/__config>
#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 <cuda/std/__algorithm/adjacent_find.h>
#include <cuda/std/__algorithm/comp.h>
#include <cuda/std/__algorithm/iterator_operations.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/__cccl/prologue.h>
_CCCL_BEGIN_NAMESPACE_CUDA_STD
_CCCL_EXEC_CHECK_DISABLE
template <class _AlgPolicy, class _Iter, class _Sent, class _BinaryPredicate>
[[nodiscard]] _CCCL_API constexpr ::cuda::std::pair<_Iter, _Iter>
__unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred)
{
__first = ::cuda::std::adjacent_find(__first, __last, __pred);
if (__first != __last)
{
// ... a a ? ...
// f i
_Iter __i = __first;
for (++__i; ++__i != __last;)
{
if (!__pred(*__first, *__i))
{
*++__first = _IterOps<_AlgPolicy>::__iter_move(__i);
}
}
++__first;
return ::cuda::std::pair<_Iter, _Iter>(::cuda::std::move(__first), ::cuda::std::move(__i));
}
return ::cuda::std::pair<_Iter, _Iter>(__first, __first);
}
_CCCL_EXEC_CHECK_DISABLE
template <class _ForwardIterator, class _BinaryPredicate>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator
unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
{
return ::cuda::std::__unique<_ClassicAlgPolicy>(::cuda::std::move(__first), ::cuda::std::move(__last), __pred).first;
}
template <class _ForwardIterator>
[[nodiscard]] _CCCL_API constexpr _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last)
{
return ::cuda::std::unique(__first, __last, __equal_to{});
}
_CCCL_END_NAMESPACE_CUDA_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _CUDA_STD___ALGORITHM_UNIQUE_H

Some files were not shown because too many files have changed in this diff Show More