feat(CCCL): device-level CUB algorithms for MoE dispatch

Add complete CCCL CUB header tree (1394 files) to cccl_preload/include/:
- cub/device/ — DeviceRadixSort, DeviceScan, DeviceHistogram, DeviceReduce, DeviceSelect
- cub/agent/ — all agent implementations (sort, scan, reduce, histogram, etc)
- cub/block/ — BlockScan, BlockReduce, BlockExchange, BlockLoad, BlockStore, etc
- cub/warp/ — WarpScan, WarpReduce, WarpExchange, WarpMergeSort
- cub/thread/ — thread-level operators
- thrust/ — sort_by_key, iterator utilities
- cuda/ — execution, stream, memory_resource, functional

New kernel: cccl_moe_sort_scatter.cu
- Uses CUB DeviceRadixSort::SortPairs to sort (expert_id, token_idx) pairs
- O(n) radix sort replaces O(n log n) torch.argsort in MoE prefill path
- Boundary detection + fill for expert offsets/sizes
- Compiled against CCCL upstream headers (not corex CUB) to avoid BI-V100 bugs

Previously only 288 CCCL headers (CachingDeviceAllocator only).
Now 1394 headers — full CUB device-level algorithm stack available for
all future kernels.
This commit is contained in:
project6-dev
2026-08-13 11:18:52 +00:00
parent 7ba97f7977
commit 4c365b8c03
1108 changed files with 294533 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/adjacent_difference.h>
#include <thrust/system/detail/sequential/adjacent_difference.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(adjacent_difference.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(adjacent_difference.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/adjacent_difference.h>
# include <thrust/system/cuda/detail/adjacent_difference.h>
# include <thrust/system/omp/detail/adjacent_difference.h>
# include <thrust/system/tbb/detail/adjacent_difference.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator adjacent_difference(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::adjacent_difference");
using thrust::system::detail::generic::adjacent_difference;
return adjacent_difference(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result);
} // end adjacent_difference()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename BinaryFunction>
_CCCL_HOST_DEVICE OutputIterator adjacent_difference(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::adjacent_difference");
using thrust::system::detail::generic::adjacent_difference;
return adjacent_difference(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, binary_op);
} // end adjacent_difference()
template <typename InputIterator, typename OutputIterator>
OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::adjacent_difference");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::adjacent_difference(select_system(system1, system2), first, last, result);
} // end adjacent_difference()
template <typename InputIterator, typename OutputIterator, typename BinaryFunction>
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::adjacent_difference");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::adjacent_difference(select_system(system1, system2), first, last, result, binary_op);
} // end adjacent_difference()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/// \file alignment.h
/// \brief Type-alignment utilities.
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
THRUST_NAMESPACE_BEGIN
namespace detail
{
/// \p aligned_reinterpret_cast `reinterpret_cast`s \p u of type \p U to `void*`
/// and then `reinterpret_cast`s the result to \p T. The indirection through
/// `void*` suppresses compiler warnings when the alignment requirement of \p *u
/// is less than the alignment requirement of \p *t. The caller of
/// \p aligned_reinterpret_cast is responsible for ensuring that the alignment
/// requirements are actually satisfied.
template <typename T, typename U>
_CCCL_HOST_DEVICE T aligned_reinterpret_cast(U u)
{
// NOLINTNEXTLINE(bugprone-casting-through-void)
return reinterpret_cast<T>(reinterpret_cast<void*>(u));
}
} // end namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,93 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// allocator_traits::rebind_alloc and allocator::rebind_traits are from libc++,
// dual licensed under the MIT and the University of Illinois Open Source
// Licenses.
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/type_traits.h>
#include <thrust/iterator/iterator_traits.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__memory/allocator_traits.h>
#include <cuda/std/__type_traits/add_lvalue_reference.h>
#include <cuda/std/__type_traits/conditional.h>
#include <cuda/std/__type_traits/integral_constant.h>
#include <cuda/std/__type_traits/type_identity.h>
#include <cuda/std/__type_traits/void_t.h>
#include <cuda/std/__utility/declval.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
// forward declaration for has_member_system
template <typename Alloc>
struct allocator_system;
namespace allocator_traits_detail
{
template <class T, class = void>
inline constexpr bool has_system_type = false;
template <class T>
inline constexpr bool has_system_type<T, ::cuda::std::void_t<typename T::system_type>> = true;
template <class T>
struct nested_system_type
{
using type = typename T::system_type;
};
template <class T, class = void>
inline constexpr bool has_member_system = false;
template <class T>
inline constexpr bool has_member_system<T, ::cuda::std::void_t<decltype(::cuda::std::declval<T>().system())>> =
::cuda::std::is_same_v<decltype(::cuda::std::declval<T>().system()), typename allocator_system<T>::type&>;
template <typename Alloc>
[[nodiscard]] _CCCL_HOST_DEVICE_API decltype(auto) system(Alloc& a)
{
if constexpr (has_member_system<Alloc>)
{ // return the allocator's system
return a.system();
}
else
{ // return a copy of a value-initialized system
return typename allocator_system<Alloc>::type{};
}
}
} // namespace allocator_traits_detail
// XXX consider moving this non-standard functionality inside allocator_traits
template <typename Alloc>
struct allocator_system
{
// the type of the allocator's system
using type = typename eval_if<allocator_traits_detail::has_system_type<Alloc>,
allocator_traits_detail::nested_system_type<Alloc>,
thrust::iterator_system<typename ::cuda::std::allocator_traits<Alloc>::pointer>>::type;
// the type that get returns
using get_result_type =
typename eval_if<allocator_traits_detail::has_member_system<Alloc>,
::cuda::std::add_lvalue_reference<type>,
::cuda::std::type_identity<type>>::type;
_CCCL_HOST_DEVICE inline static get_result_type get(Alloc& a)
{
return allocator_traits_detail::system(a);
}
};
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,182 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/allocator/allocator_system.h>
#include <thrust/detail/copy.h>
#include <thrust/detail/execution_policy.h>
#include <thrust/for_each.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/iterator/zip_iterator.h>
#include <cuda/std/__host_stdlib/memory>
#include <cuda/std/__iterator/advance.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__memory/allocator_traits.h>
#include <cuda/std/__memory/pointer_traits.h>
#include <cuda/std/__type_traits/is_convertible.h>
#include <cuda/std/__type_traits/is_trivially_copy_constructible.h>
#include <cuda/std/tuple>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename Allocator, typename InputType, typename OutputType>
struct copy_construct_with_allocator
{
Allocator& a;
template <typename Tuple>
inline _CCCL_HOST_DEVICE void operator()(Tuple t)
{
const InputType& in = ::cuda::std::get<0>(t);
OutputType& out = ::cuda::std::get<1>(t);
::cuda::std::allocator_traits<Allocator>::construct(a, &out, in);
}
};
// we need to use ::cuda::std::allocator_traits<Allocator>::construct() to
// copy construct a T if either:
// 1. Allocator has a 2-argument construct() member or
// 2. T has a non-trivial copy constructor
template <typename Allocator, typename T>
inline constexpr bool needs_copy_construct_via_allocator =
::cuda::std::__has_construct<Allocator, T*, T> || !::cuda::std::is_trivially_copy_constructible_v<T>;
// we know that std::allocator::construct's only effect is to call T's
// copy constructor, so we needn't consider or use its construct() member for copy construction
template <typename U, typename T>
inline constexpr bool needs_copy_construct_via_allocator<std::allocator<U>, T> =
!::cuda::std::is_trivially_copy_constructible_v<T>;
// XXX it's regrettable that this implementation is copied almost
// exactly from system::detail::generic::uninitialized_copy
// perhaps generic::uninitialized_copy could call this routine
// with a default allocator
template <typename Allocator, typename FromSystem, typename ToSystem, typename InputIterator, typename Pointer>
_CCCL_HOST_DEVICE Pointer uninitialized_copy_with_allocator(
Allocator& a,
const thrust::execution_policy<FromSystem>& from_system,
const thrust::execution_policy<ToSystem>& to_system,
InputIterator first,
InputIterator last,
Pointer result)
{
if constexpr (::cuda::std::is_convertible_v<FromSystem, ToSystem>)
{
// zip up the iterators
using IteratorTuple = ::cuda::std::tuple<InputIterator, Pointer>;
using ZipIterator = thrust::zip_iterator<IteratorTuple>;
ZipIterator begin = thrust::make_zip_iterator(first, result);
ZipIterator end = begin;
// get a zip_iterator pointing to the end
const thrust::detail::it_difference_t<InputIterator> n = ::cuda::std::distance(first, last);
::cuda::std::advance(end, n);
// create a functor
using InputType = it_value_t<InputIterator>;
using OutputType = it_value_t<Pointer>;
// do the for_each
// note we use to_system to dispatch the for_each
thrust::for_each(to_system, begin, end, copy_construct_with_allocator<Allocator, InputType, OutputType>{a});
// return the end of the output range
return ::cuda::std::get<1>(end.get_iterator_tuple());
}
else
{
// the systems aren't trivially interoperable
// just call two_system_copy and hope for the best
return thrust::detail::two_system_copy(from_system, to_system, first, last, result);
}
}
// XXX it's regrettable that this implementation is copied almost
// exactly from system::detail::generic::uninitialized_copy_n
// perhaps generic::uninitialized_copy_n could call this routine
// with a default allocator
template <typename Allocator, typename FromSystem, typename ToSystem, typename InputIterator, typename Size, typename Pointer>
_CCCL_HOST_DEVICE Pointer uninitialized_copy_with_allocator_n(
Allocator& a,
const thrust::execution_policy<FromSystem>& from_system,
const thrust::execution_policy<ToSystem>& to_system,
InputIterator first,
Size n,
Pointer result)
{
if constexpr (::cuda::std::is_convertible_v<FromSystem, ToSystem>)
{
// zip up the iterators
using IteratorTuple = ::cuda::std::tuple<InputIterator, Pointer>;
using ZipIterator = thrust::zip_iterator<IteratorTuple>;
ZipIterator begin = thrust::make_zip_iterator(first, result);
// create a functor
using InputType = it_value_t<InputIterator>;
using OutputType = it_value_t<Pointer>;
// do the for_each_n
// note we use to_system to dispatch the for_each_n
ZipIterator end =
thrust::for_each_n(to_system, begin, n, copy_construct_with_allocator<Allocator, InputType, OutputType>(a));
// return the end of the output range
return ::cuda::std::get<1>(end.get_iterator_tuple());
}
else
{
// the systems aren't trivially interoperable
// just call two_system_copy_n and hope for the best
return thrust::detail::two_system_copy_n(from_system, to_system, first, n, result);
}
}
template <typename System, typename Allocator, typename InputIterator, typename Pointer>
_CCCL_HOST_DEVICE Pointer copy_construct_range(
thrust::execution_policy<System>& from_system, Allocator& a, InputIterator first, InputIterator last, Pointer result)
{
if constexpr (needs_copy_construct_via_allocator<Allocator,
typename ::cuda::std::pointer_traits<Pointer>::element_type>)
{
return uninitialized_copy_with_allocator(a, from_system, allocator_system<Allocator>::get(a), first, last, result);
}
else
{
// just call two_system_copy
return thrust::detail::two_system_copy(from_system, allocator_system<Allocator>::get(a), first, last, result);
}
}
template <typename System, typename Allocator, typename InputIterator, typename Size, typename Pointer>
_CCCL_HOST_DEVICE Pointer copy_construct_range_n(
thrust::execution_policy<System>& from_system, Allocator& a, InputIterator first, Size n, Pointer result)
{
if constexpr (needs_copy_construct_via_allocator<Allocator,
typename ::cuda::std::pointer_traits<Pointer>::element_type>)
{
return uninitialized_copy_with_allocator_n(a, from_system, allocator_system<Allocator>::get(a), first, n, result);
}
else
{
// just call two_system_copy_n
return thrust::detail::two_system_copy_n(from_system, allocator_system<Allocator>::get(a), first, n, result);
}
}
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,83 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/allocator/allocator_system.h>
#include <thrust/detail/allocator/destroy_range.h>
#include <thrust/for_each.h>
#include <cuda/std/__host_stdlib/memory>
#include <cuda/std/__memory/allocator_traits.h>
#include <cuda/std/__memory/pointer_traits.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
// destroy_range has three cases:
// if Allocator has an effectful member function destroy:
// 1. destroy via the allocator
// else
// 2. if T has a non-trivial destructor, destroy the range without using the allocator
// 3. if T has a trivial destructor, do a no-op
template <typename Allocator, typename T>
inline constexpr bool has_effectful_member_destroy = ::cuda::std::__has_destroy<Allocator, T*>;
// std::allocator::destroy's only effect is to invoke its argument's destructor
template <typename U, typename T>
inline constexpr bool has_effectful_member_destroy<std::allocator<U>, T> = false;
template <typename Allocator>
struct destroy_via_allocator
{
Allocator& a;
template <typename T>
_CCCL_HOST_DEVICE void operator()(T& x) noexcept
{
::cuda::std::allocator_traits<Allocator>::destroy(a, &x);
}
};
// we must prepare for His coming
struct gozer
{
_CCCL_EXEC_CHECK_DISABLE
template <typename T>
inline _CCCL_HOST_DEVICE void operator()(T& x) noexcept
{
x.~T();
}
};
template <typename Allocator, typename Pointer, typename Size>
_CCCL_HOST_DEVICE void
destroy_range([[maybe_unused]] Allocator& a, [[maybe_unused]] Pointer p, [[maybe_unused]] Size n) noexcept
{
using pe_t = typename ::cuda::std::pointer_traits<Pointer>::element_type;
// case 1: destroy via allocator
if constexpr (has_effectful_member_destroy<Allocator, pe_t>)
{
thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, destroy_via_allocator<Allocator>{a});
}
// case 2: destroy without the allocator
else if constexpr (!::cuda::std::is_trivially_destructible_v<pe_t>)
{
thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, gozer());
}
// case 3: Allocator has no member function "destroy", and T has a trivial destructor, nothing to be done
}
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/allocator/allocator_system.h>
#include <thrust/detail/type_traits.h>
#include <thrust/for_each.h>
#include <thrust/uninitialized_fill.h>
#include <cuda/std/__host_stdlib/memory>
#include <cuda/std/__memory/allocator_traits.h>
#include <cuda/std/__memory/pointer_traits.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
// fill_construct_range has 2 cases:
// if Allocator has an effectful member function construct:
// 1. construct via the allocator
// else
// 2. construct via uninitialized_fill
template <typename Allocator, typename T, typename Arg1>
inline constexpr bool has_effectful_member_construct2 = ::cuda::std::__has_construct<Allocator, T*, Arg1>;
// std::allocator::construct's only effect is to invoke placement new
template <typename U, typename T, typename Arg1>
inline constexpr bool has_effectful_member_construct2<std::allocator<U>, T, Arg1> = false;
template <typename Allocator, typename Arg1>
struct construct2_via_allocator
{
Allocator& a;
Arg1 arg;
template <typename T>
inline _CCCL_HOST_DEVICE void operator()(T& x)
{
::cuda::std::allocator_traits<Allocator>::construct(a, &x, arg);
}
};
template <typename Allocator, typename Pointer, typename Size, typename T>
_CCCL_HOST_DEVICE void fill_construct_range(Allocator& a, Pointer p, Size n, const T& value)
{
if constexpr (has_effectful_member_construct2<Allocator, typename ::cuda::std::pointer_traits<Pointer>::element_type, T>)
{
thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, construct2_via_allocator<Allocator, T>{a, value});
}
else
{
thrust::uninitialized_fill_n(allocator_system<Allocator>::get(a), p, n, value);
}
}
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <nv/target>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename BaseAllocator>
struct no_throw_allocator : BaseAllocator
{
private:
using super_t = BaseAllocator;
public:
inline _CCCL_HOST_DEVICE no_throw_allocator(const BaseAllocator& other = BaseAllocator())
: super_t(other)
{}
template <typename U>
struct rebind
{
using other = no_throw_allocator<typename super_t::template rebind<U>::other>;
}; // end rebind
_CCCL_HOST_DEVICE void deallocate(typename super_t::pointer p, typename super_t::size_type n) noexcept
{
NV_IF_TARGET(
NV_IS_HOST,
(try { super_t::deallocate(p, n); } // end try
catch (...){
// catch anything
} // end catch
),
(super_t::deallocate(p, n);));
} // end deallocate()
inline _CCCL_HOST_DEVICE bool operator==(no_throw_allocator const& other)
{
return super_t::operator==(other);
}
inline _CCCL_HOST_DEVICE bool operator!=(no_throw_allocator const& other)
{
return super_t::operator!=(other);
}
}; // end no_throw_allocator
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,103 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/allocator/tagged_allocator.h>
#include <thrust/detail/type_traits/pointer_traits.h>
#include <thrust/iterator/iterator_traits.h>
#include <cuda/std/limits>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename T, typename Tag, typename Pointer>
class tagged_allocator;
template <typename Tag, typename Pointer>
class tagged_allocator<void, Tag, Pointer>
{
public:
using value_type = void;
using pointer = typename ::cuda::std::pointer_traits<Pointer>::template rebind<void>;
using const_pointer = typename ::cuda::std::pointer_traits<Pointer>::template rebind<const void>;
using size_type = std::size_t;
using difference_type = typename ::cuda::std::pointer_traits<Pointer>::difference_type;
using system_type = Tag;
template <typename U>
struct rebind
{
using other = tagged_allocator<U, Tag, Pointer>;
}; // end rebind
};
template <typename T, typename Tag, typename Pointer>
class tagged_allocator
{
public:
using value_type = T;
using pointer = typename ::cuda::std::pointer_traits<Pointer>::template rebind<T>;
using const_pointer = typename ::cuda::std::pointer_traits<Pointer>::template rebind<const T>;
using reference = thrust::detail::it_reference_t<pointer>;
using const_reference = thrust::detail::it_reference_t<const_pointer>;
using size_type = std::size_t;
using difference_type = typename ::cuda::std::pointer_traits<pointer>::difference_type;
using system_type = Tag;
template <typename U>
struct rebind
{
using other = tagged_allocator<U, Tag, Pointer>;
}; // end rebind
tagged_allocator() = default;
tagged_allocator(const tagged_allocator&) = default;
template <typename U, typename OtherPointer>
_CCCL_HOST_DEVICE tagged_allocator(const tagged_allocator<U, Tag, OtherPointer>&)
{}
~tagged_allocator() = default;
_CCCL_HOST_DEVICE pointer address(reference x) const
{
return &x;
}
_CCCL_HOST_DEVICE const_pointer address(const_reference x) const
{
return &x;
}
// Workaround for cudafe++ < 13.1 + gcc < 13 replacing `numeric_limits<size_t>` with
// `numeric_limits<conditional<is_void_v<void>, __common_type2_imp<uint64_t, uint64_t>::type, void>::type>`
template <class SizeType = size_type>
size_type max_size() const
{
return (::cuda::std::numeric_limits<SizeType>::max)() / sizeof(T);
}
_CCCL_HOST_DEVICE friend bool operator==(const tagged_allocator&, const tagged_allocator&)
{
return true;
}
_CCCL_HOST_DEVICE friend bool operator!=(const tagged_allocator&, const tagged_allocator&)
{
return false;
}
};
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,129 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/allocator/tagged_allocator.h>
#include <thrust/detail/allocator/temporary_allocator.h>
#include <thrust/detail/execution_policy.h>
#include <thrust/detail/temporary_buffer.h>
#include <thrust/memory.h>
#include <thrust/system/detail/bad_alloc.h>
#include <cuda/std/__exception/exception_macros.h>
#include <cuda/std/__memory/allocator_traits.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/cassert>
#include <nv/target>
#include <cstdio>
#if _CCCL_CUDA_COMPILATION() && _CCCL_DEVICE_COMPILATION()
# include <thrust/system/cuda/detail/terminate.h>
#endif // _CCCL_CUDA_COMPILATION() && _CCCL_DEVICE_COMPILATION()
THRUST_NAMESPACE_BEGIN
namespace detail
{
// XXX the pointer parameter given to tagged_allocator should be related to
// the type of the expression get_temporary_buffer(system, n).first
// without decltype, compromise on pointer<T,System>
template <typename T, typename System>
class temporary_allocator : public thrust::detail::tagged_allocator<T, System, thrust::pointer<T, System>>
{
private:
using super_t = thrust::detail::tagged_allocator<T, System, thrust::pointer<T, System>>;
System& m_system;
public:
using pointer = typename super_t::pointer;
using size_type = typename super_t::size_type;
inline _CCCL_HOST_DEVICE temporary_allocator(const temporary_allocator& other)
: super_t()
, m_system(other.m_system)
{}
inline _CCCL_HOST_DEVICE explicit temporary_allocator(thrust::execution_policy<System>& system)
: super_t()
, m_system(thrust::detail::derived_cast(system))
{}
_CCCL_HOST_DEVICE pointer allocate(size_type cnt)
{
pointer_and_size result = thrust::get_temporary_buffer<T>(system(), cnt);
// handle failure
if (result.second < cnt)
{
// deallocate and throw
// note that we pass cnt to deallocate, not a value derived from result.second
deallocate(result.first, cnt);
#if _CCCL_CUDA_COMPILATION()
NV_IF_TARGET(
NV_IS_HOST,
(throw thrust::system::detail::bad_alloc("temporary_buffer::allocate: get_temporary_buffer failed");),
( // NV_IS_DEVICE
thrust::system::cuda::detail::terminate_with_message("temporary_buffer::allocate: "
"get_temporary_buffer failed");));
#else
throw thrust::system::detail::bad_alloc("temporary_buffer::allocate: get_temporary_buffer failed");
#endif
} // end if
return result.first;
}
_CCCL_HOST_DEVICE void deallocate(pointer p, size_type n) noexcept // NOLINT(bugprone-exception-escape)
{
_CCCL_TRY
{
thrust::return_temporary_buffer(system(), p, n);
}
// Swallow all exceptions to maintain noexcept contract per C++ allocator requirements.
// Deallocate must be noexcept to be safe in destructors and during exception unwinding.
// Clear CUDA error state and leak the memory rather than propagating exception.
// Memory is leaked, but this matches standard allocator behavior when deallocation fails.
_CCCL_CATCH (std::exception & e)
{
// if we have some context about the thrown exception, log it
NV_IF_TARGET(NV_IS_HOST, {
::fprintf(stderr, "Exception thrown in thrust::detail::temporary_allocator::deallocate: %s\n", e.what());
})
_CCCL_ASSERT(false, "Exception thrown in thrust::detail::temporary_allocator::deallocate");
#if _CCCL_CUDA_COMPILATION()
NV_IF_TARGET(NV_IS_HOST, cudaGetLastError();)
#endif // _CCCL_CUDA_COMPILATION()
}
_CCCL_CATCH_ALL
{
_CCCL_ASSERT(false, "Exception thrown in thrust::detail::temporary_allocator::deallocate");
#if _CCCL_CUDA_COMPILATION()
NV_IF_TARGET(NV_IS_HOST, cudaGetLastError();)
#endif // _CCCL_CUDA_COMPILATION()
}
}
_CCCL_HOST_DEVICE inline System& system()
{
return m_system;
} // end system()
private:
using pointer_and_size = ::cuda::std::pair<pointer, size_type>;
}; // end temporary_allocator
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,68 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/allocator/allocator_system.h>
#include <thrust/detail/type_traits.h>
#include <thrust/for_each.h>
#include <thrust/uninitialized_fill.h>
#include <cuda/std/__memory/allocator_traits.h>
#include <cuda/std/__memory/pointer_traits.h>
#include <cuda/std/__type_traits/is_trivially_default_constructible.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename Allocator>
struct construct1_via_allocator
{
Allocator& a;
template <typename T>
inline _CCCL_HOST_DEVICE void operator()(T& x)
{
::cuda::std::allocator_traits<Allocator>::construct(a, &x);
}
};
// we need to construct T via the allocator if the Allocator does something interesting or if T's default constructor
// does something interesting
template <typename Allocator, typename T>
inline constexpr bool needs_default_construct_via_allocator =
::cuda::std::__has_construct<Allocator, T*> || !::cuda::std::is_trivially_default_constructible_v<T>;
// we know that std::allocator::construct's only effect is to call T's
// default constructor, so we needn't use it for default construction
// unless T's constructor does something interesting
template <typename U, typename T>
inline constexpr bool needs_default_construct_via_allocator<std::allocator<U>, T> =
!::cuda::std::is_trivially_default_constructible_v<T>;
template <typename Allocator, typename Pointer, typename Size>
_CCCL_HOST_DEVICE void value_initialize_range(Allocator& a, Pointer p, Size n)
{
if constexpr (needs_default_construct_via_allocator<Allocator,
typename ::cuda::std::pointer_traits<Pointer>::element_type>)
{
thrust::for_each_n(allocator_system<Allocator>::get(a), p, n, construct1_via_allocator<Allocator>{a});
}
else
{
thrust::uninitialized_fill_n(
allocator_system<Allocator>::get(a), p, n, typename ::cuda::std::pointer_traits<Pointer>::element_type());
}
}
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,80 @@
// SPDX-FileCopyrightText: Copyright (c) 2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/alignment.h>
#include <thrust/detail/execute_with_allocator_fwd.h>
#include <cuda/std/__cstddef/types.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_reference.h>
#include <cuda/std/__utility/forward.h>
THRUST_NAMESPACE_BEGIN
namespace mr
{
template <typename T, class MR>
class allocator;
}
namespace detail
{
template <template <typename> class ExecutionPolicyCRTPBase>
struct allocator_aware_execution_policy
{
template <typename MemoryResource>
struct execute_with_memory_resource_type
{
using type = thrust::detail::execute_with_allocator<thrust::mr::allocator<::cuda::std::max_align_t, MemoryResource>,
ExecutionPolicyCRTPBase>;
};
template <typename Allocator>
struct execute_with_allocator_type
{
using type = thrust::detail::execute_with_allocator<Allocator, ExecutionPolicyCRTPBase>;
};
_CCCL_EXEC_CHECK_DISABLE
template <typename MemoryResource>
_CCCL_HOST_DEVICE typename execute_with_memory_resource_type<MemoryResource>::type
operator()(MemoryResource* mem_res) const
{
return typename execute_with_memory_resource_type<MemoryResource>::type(mem_res);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename Allocator>
_CCCL_HOST_DEVICE typename execute_with_allocator_type<Allocator&>::type operator()(Allocator& alloc) const
{
return typename execute_with_allocator_type<Allocator&>::type(alloc);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename Allocator>
_CCCL_HOST_DEVICE typename execute_with_allocator_type<Allocator>::type operator()(const Allocator& alloc) const
{
return typename execute_with_allocator_type<Allocator>::type(alloc);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename Allocator, ::cuda::std::enable_if_t<!::cuda::std::is_lvalue_reference_v<Allocator>>* = nullptr>
_CCCL_HOST_DEVICE typename execute_with_allocator_type<Allocator>::type operator()(Allocator&& alloc) const
{
return typename execute_with_allocator_type<Allocator>::type(::cuda::std::forward<Allocator>(alloc));
}
};
} // end namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,524 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/binary_search.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/binary_search.h>
#include <thrust/system/detail/sequential/binary_search.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(binary_search.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(binary_search.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/binary_search.h>
# include <thrust/system/cuda/detail/binary_search.h>
# include <thrust/system/omp/detail/binary_search.h>
# include <thrust/system/tbb/detail/binary_search.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
_CCCL_HOST_DEVICE ForwardIterator lower_bound(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const LessThanComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::lower_bound");
using thrust::system::detail::generic::lower_bound;
return lower_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
_CCCL_HOST_DEVICE ForwardIterator lower_bound(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const T& value,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::lower_bound");
using thrust::system::detail::generic::lower_bound;
return lower_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value, comp);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
_CCCL_HOST_DEVICE ForwardIterator upper_bound(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const LessThanComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::upper_bound");
using thrust::system::detail::generic::upper_bound;
return upper_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
_CCCL_HOST_DEVICE ForwardIterator upper_bound(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const T& value,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::upper_bound");
using thrust::system::detail::generic::upper_bound;
return upper_bound(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value, comp);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
_CCCL_HOST_DEVICE bool binary_search(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const LessThanComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::binary_search");
using thrust::system::detail::generic::binary_search;
return binary_search(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
_CCCL_HOST_DEVICE bool binary_search(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const T& value,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::binary_search");
using thrust::system::detail::generic::binary_search;
return binary_search(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value, comp);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T, typename StrictWeakOrdering>
_CCCL_HOST_DEVICE ::cuda::std::pair<ForwardIterator, ForwardIterator> equal_range(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const T& value,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::equal_range");
using thrust::system::detail::generic::equal_range;
return equal_range(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value, comp);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename LessThanComparable>
_CCCL_HOST_DEVICE ::cuda::std::pair<ForwardIterator, ForwardIterator> equal_range(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const LessThanComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::equal_range");
using thrust::system::detail::generic::equal_range;
return equal_range(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator lower_bound(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::lower_bound");
using thrust::system::detail::generic::lower_bound;
return lower_bound(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, values_first, values_last, output);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename ForwardIterator,
typename InputIterator,
typename OutputIterator,
typename StrictWeakOrdering>
_CCCL_HOST_DEVICE OutputIterator lower_bound(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::lower_bound");
using thrust::system::detail::generic::lower_bound;
return lower_bound(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
first,
last,
values_first,
values_last,
output,
comp);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator upper_bound(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::upper_bound");
using thrust::system::detail::generic::upper_bound;
return upper_bound(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, values_first, values_last, output);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename ForwardIterator,
typename InputIterator,
typename OutputIterator,
typename StrictWeakOrdering>
_CCCL_HOST_DEVICE OutputIterator upper_bound(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::upper_bound");
using thrust::system::detail::generic::upper_bound;
return upper_bound(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
first,
last,
values_first,
values_last,
output,
comp);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator binary_search(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::binary_search");
using thrust::system::detail::generic::binary_search;
return binary_search(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, values_first, values_last, output);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename ForwardIterator,
typename InputIterator,
typename OutputIterator,
typename StrictWeakOrdering>
_CCCL_HOST_DEVICE OutputIterator binary_search(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::binary_search");
using thrust::system::detail::generic::binary_search;
return binary_search(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
first,
last,
values_first,
values_last,
output,
comp);
}
//////////////////////
// Scalar Functions //
//////////////////////
template <typename ForwardIterator, typename LessThanComparable>
ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const LessThanComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::lower_bound");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::lower_bound(select_system(system), first, last, value);
}
template <typename ForwardIterator, typename T, typename StrictWeakOrdering>
ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::lower_bound");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::lower_bound(select_system(system), first, last, value, comp);
}
template <typename ForwardIterator, typename LessThanComparable>
ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const LessThanComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::upper_bound");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::upper_bound(select_system(system), first, last, value);
}
template <typename ForwardIterator, typename T, typename StrictWeakOrdering>
ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::upper_bound");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::upper_bound(select_system(system), first, last, value, comp);
}
template <typename ForwardIterator, typename LessThanComparable>
bool binary_search(ForwardIterator first, ForwardIterator last, const LessThanComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::binary_search");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::binary_search(select_system(system), first, last, value);
}
template <typename ForwardIterator, typename T, typename StrictWeakOrdering>
bool binary_search(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::binary_search");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::binary_search(select_system(system), first, last, value, comp);
}
template <typename ForwardIterator, typename LessThanComparable>
::cuda::std::pair<ForwardIterator, ForwardIterator>
equal_range(ForwardIterator first, ForwardIterator last, const LessThanComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::equal_range");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::equal_range(select_system(system), first, last, value);
}
template <typename ForwardIterator, typename T, typename StrictWeakOrdering>
::cuda::std::pair<ForwardIterator, ForwardIterator>
equal_range(ForwardIterator first, ForwardIterator last, const T& value, StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::equal_range");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::equal_range(select_system(system), first, last, value, comp);
}
//////////////////////
// Vector Functions //
//////////////////////
template <typename ForwardIterator, typename InputIterator, typename OutputIterator>
OutputIterator lower_bound(
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::lower_bound");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::lower_bound(select_system(system1, system2, system3), first, last, values_first, values_last, output);
}
template <typename ForwardIterator, typename InputIterator, typename OutputIterator, typename StrictWeakOrdering>
OutputIterator lower_bound(
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::lower_bound");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::lower_bound(
select_system(system1, system2, system3), first, last, values_first, values_last, output, comp);
}
template <typename ForwardIterator, typename InputIterator, typename OutputIterator>
OutputIterator upper_bound(
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::upper_bound");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::upper_bound(select_system(system1, system2, system3), first, last, values_first, values_last, output);
}
template <typename ForwardIterator, typename InputIterator, typename OutputIterator, typename StrictWeakOrdering>
OutputIterator upper_bound(
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::upper_bound");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::upper_bound(
select_system(system1, system2, system3), first, last, values_first, values_last, output, comp);
}
template <typename ForwardIterator, typename InputIterator, typename OutputIterator>
OutputIterator binary_search(
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::binary_search");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::binary_search(select_system(system1, system2, system3), first, last, values_first, values_last, output);
}
template <typename ForwardIterator, typename InputIterator, typename OutputIterator, typename StrictWeakOrdering>
OutputIterator binary_search(
ForwardIterator first,
ForwardIterator last,
InputIterator values_first,
InputIterator values_last,
OutputIterator output,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::binary_search");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::binary_search(
select_system(system1, system2, system3), first, last, values_first, values_last, output, comp);
}
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file config.h
* \brief Defines platform configuration.
*/
#pragma once
#include <thrust/detail/config/config.h> // IWYU pragma: export
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/version.h> // IWYU pragma: export
#if _CCCL_HOSTED()
# include <cuda/__nvtx/nvtx.h>
#endif // _CCCL_HOSTED()

View File

@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file compiler.h
* \brief Compiler-specific configuration
*/
#pragma once
// Internal config header that is only included through thrust/detail/config/config.h
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
// is the device compiler capable of compiling omp?
#if defined(_OPENMP) || defined(_NVHPC_STDPAR_OPENMP)
# define THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE THRUST_TRUE
#else
# define THRUST_DEVICE_COMPILER_IS_OMP_CAPABLE THRUST_FALSE
#endif // _OPENMP

View File

@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file config.h
* \brief Defines platform configuration.
*/
#pragma once
// For _CCCL_IMPLICIT_SYSTEM_HEADER
#include <cuda/__cccl_config> // IWYU pragma: export
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
// NOTE: The order of these #includes matters.
#include <thrust/detail/config/compiler.h> // IWYU pragma: export
#include <thrust/detail/config/cpp_dialect.h> // IWYU pragma: export
#include <thrust/detail/config/simple_defines.h> // IWYU pragma: export
// host_system.h & device_system.h must be #included as early as possible because other config headers depend on it
#include <thrust/detail/config/host_system.h> // IWYU pragma: export
#include <thrust/detail/config/device_system.h> // IWYU pragma: export
#include <thrust/detail/config/namespace.h> // IWYU pragma: export

View File

@@ -0,0 +1,65 @@
// SPDX-FileCopyrightText: Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file cpp_dialect.h
* \brief Detect the version of the C++ standard used by the compiler.
*/
#pragma once
#include <thrust/detail/config/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/config/compiler.h> // IWYU pragma: export
// Deprecation warnings may be silenced by defining the following macros. These
// may be combined.
// - CCCL_IGNORE_DEPRECATED_COMPILER
// Ignore deprecation warnings when using deprecated compilers. Compiling
// with deprecated C++ dialects will still issue warnings.
#define THRUST_CPP_DIALECT _CCCL_STD_VER
// Define THRUST_COMPILER_DEPRECATION macro:
#define THRUST_COMP_DEPR_IMPL(msg) _CCCL_WARNING(#msg)
// Compiler checks:
// clang-format off
#define THRUST_COMPILER_DEPRECATION(REQ) \
THRUST_COMP_DEPR_IMPL(Thrust requires at least REQ. Define CCCL_IGNORE_DEPRECATED_COMPILER to suppress this message.)
#define THRUST_COMPILER_DEPRECATION_SOFT(REQ, CUR) \
THRUST_COMP_DEPR_IMPL( \
Thrust requires at least REQ. CUR is deprecated but still supported. CUR support will be removed in a \
future release. Define CCCL_IGNORE_DEPRECATED_COMPILER to suppress this message.)
// clang-format on
#ifndef CCCL_IGNORE_DEPRECATED_COMPILER
# if _CCCL_COMPILER(GCC, <, 7)
THRUST_COMPILER_DEPRECATION(GCC 7.0);
# elif _CCCL_COMPILER(CLANG, <, 7)
THRUST_COMPILER_DEPRECATION(Clang 7.0);
# elif _CCCL_COMPILER(MSVC, <, 19, 10)
// <2017. Hard upgrade message:
THRUST_COMPILER_DEPRECATION(MSVC 2019(19.20 / 16.0 / 14.20));
# endif
#endif // CCCL_IGNORE_DEPRECATED_COMPILER
#undef THRUST_COMPILER_DEPRECATION_SOFT
#undef THRUST_COMPILER_DEPRECATION
// C++17 dialect check:
#ifndef CCCL_IGNORE_DEPRECATED_CPP_DIALECT
# if _CCCL_STD_VER < 2017
# error Thrust requires at least C++17. Define CCCL_IGNORE_DEPRECATED_CPP_DIALECT to suppress this message.
# endif // _CCCL_STD_VER < 2017
#endif
#undef THRUST_COMP_DEPR_IMPL

View File

@@ -0,0 +1,44 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
// Internal config header that is only included through thrust/detail/config/config.h
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
// reserve 0 for undefined
#define THRUST_DEVICE_SYSTEM_CUDA 1
#define THRUST_DEVICE_SYSTEM_OMP 2
#define THRUST_DEVICE_SYSTEM_TBB 3
#define THRUST_DEVICE_SYSTEM_CPP 4
#ifndef THRUST_DEVICE_SYSTEM
# define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_CUDA
#endif // THRUST_DEVICE_SYSTEM
#ifdef THRUST_DEVICE_BACKEND
# error THRUST_DEVICE_BACKEND is no longer supported; use THRUST_DEVICE_SYSTEM instead.
#endif // THRUST_DEVICE_BACKEND
#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
# define __THRUST_DEVICE_SYSTEM_NAMESPACE cuda
#elif THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_OMP
# define __THRUST_DEVICE_SYSTEM_NAMESPACE omp
#elif THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_TBB
# define __THRUST_DEVICE_SYSTEM_NAMESPACE tbb
#elif THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CPP
# define __THRUST_DEVICE_SYSTEM_NAMESPACE cpp
#endif
// clang-format off
#define __THRUST_DEVICE_SYSTEM_ROOT thrust/system/__THRUST_DEVICE_SYSTEM_NAMESPACE
#define __THRUST_DEVICE_SYSTEM_ALGORITH_HEADER_INCLUDE(filename) <__THRUST_DEVICE_SYSTEM_ROOT/filename>
#define __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(filename) <__THRUST_DEVICE_SYSTEM_ROOT/detail/filename>
// clang-format on

View File

@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
// Internal config header that is only included through thrust/detail/config/config.h
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
// reserve 0 for undefined
#define THRUST_HOST_SYSTEM_CPP 1
#define THRUST_HOST_SYSTEM_OMP 2
#define THRUST_HOST_SYSTEM_TBB 3
#ifndef THRUST_HOST_SYSTEM
# define THRUST_HOST_SYSTEM THRUST_HOST_SYSTEM_CPP
#endif // THRUST_HOST_SYSTEM
#if THRUST_HOST_SYSTEM == THRUST_HOST_SYSTEM_CPP
# define __THRUST_HOST_SYSTEM_NAMESPACE cpp
#elif THRUST_HOST_SYSTEM == THRUST_HOST_SYSTEM_OMP
# define __THRUST_HOST_SYSTEM_NAMESPACE omp
#elif THRUST_HOST_SYSTEM == THRUST_HOST_SYSTEM_TBB
# define __THRUST_HOST_SYSTEM_NAMESPACE tbb
#endif
// clang-format off
#define __THRUST_HOST_SYSTEM_ROOT thrust/system/__THRUST_HOST_SYSTEM_NAMESPACE
#define __THRUST_HOST_SYSTEM_ALGORITH_HEADER_INCLUDE(filename) <__THRUST_HOST_SYSTEM_ROOT/filename>
#define __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(filename) <__THRUST_HOST_SYSTEM_ROOT/detail/filename>
// clang-format on

View File

@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: Copyright (c) 2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <cuda/std/__cstddef/types.h>
#include <cuda/std/cstddef>
#define THRUST_MR_DEFAULT_ALIGNMENT alignof(::cuda::std::max_align_t)
#if __has_include(<memory_resource>)
# define THRUST_MR_STD_MR_HEADER <memory_resource>
# define THRUST_MR_STD_MR_NS std::pmr
#elif __has_include(<experimental/memory_resource>)
# define THRUST_MR_STD_MR_HEADER <experimental/memory_resource>
# define THRUST_MR_STD_MR_NS std::experimental::pmr
#endif

View File

@@ -0,0 +1,151 @@
// SPDX-FileCopyrightText: Copyright (c) 2021, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
// Internal config header that is only included through thrust/detail/config/config.h
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/config/device_system.h>
#include <thrust/version.h>
/**
* \file namespace.h
* \brief Utilities that allow `thrust::` to be placed inside an
* application-specific namespace.
*/
/**
* \def THRUST_CUB_WRAPPED_NAMESPACE
* If defined, this value will be used as the name of a namespace that wraps the
* `thrust::` and `cub::` namespaces.
* This macro should not be used with any other Thrust namespace macros.
*/
#ifdef THRUST_CUB_WRAPPED_NAMESPACE
# define THRUST_WRAPPED_NAMESPACE THRUST_CUB_WRAPPED_NAMESPACE
#endif
/**
* \def THRUST_WRAPPED_NAMESPACE
* If defined, this value will be used as the name of a namespace that wraps the
* `thrust::` namespace.
* If THRUST_CUB_WRAPPED_NAMESPACE is set, this will inherit that macro's value.
* This macro should not be used with any other Thrust namespace macros.
*/
#ifdef THRUST_WRAPPED_NAMESPACE
# define THRUST_NS_PREFIX \
namespace THRUST_WRAPPED_NAMESPACE \
{
# define THRUST_NS_POSTFIX }
# define THRUST_NS_QUALIFIER ::THRUST_WRAPPED_NAMESPACE::thrust
#endif
/**
* \def THRUST_NS_PREFIX
* This macro is inserted prior to all `namespace thrust { ... }` blocks. It is
* derived from THRUST_WRAPPED_NAMESPACE, if set, and will be empty otherwise.
* It may be defined by users, in which case THRUST_NS_PREFIX,
* THRUST_NS_POSTFIX, and THRUST_NS_QUALIFIER must all be set consistently.
*/
#ifndef THRUST_NS_PREFIX
# define THRUST_NS_PREFIX
#endif
/**
* \def THRUST_NS_POSTFIX
* This macro is inserted following the closing braces of all
* `namespace thrust { ... }` block. It is defined appropriately when
* THRUST_WRAPPED_NAMESPACE is set, and will be empty otherwise. It may be
* defined by users, in which case THRUST_NS_PREFIX, THRUST_NS_POSTFIX, and
* THRUST_NS_QUALIFIER must all be set consistently.
*/
#ifndef THRUST_NS_POSTFIX
# define THRUST_NS_POSTFIX
#endif
/**
* \def THRUST_NS_QUALIFIER
* This macro is used to qualify members of thrust:: when accessing them from
* outside of their namespace. By default, this is just `::thrust`, and will be
* set appropriately when THRUST_WRAPPED_NAMESPACE is defined. This macro may be
* defined by users, in which case THRUST_NS_PREFIX, THRUST_NS_POSTFIX, and
* THRUST_NS_QUALIFIER must all be set consistently.
*/
#ifndef THRUST_NS_QUALIFIER
# define THRUST_NS_QUALIFIER ::thrust
#endif
#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
# if defined(THRUST_DISABLE_ABI_NAMESPACE) || defined(THRUST_WRAPPED_NAMESPACE)
# if !defined(THRUST_WRAPPED_NAMESPACE)
# if !defined(THRUST_IGNORE_ABI_NAMESPACE_ERROR)
# error "Disabling ABI namespace is unsafe without wrapping namespace"
# endif // !defined(THRUST_IGNORE_ABI_NAMESPACE_ERROR)
# endif // !defined(THRUST_WRAPPED_NAMESPACE)
# define THRUST_DETAIL_ABI_NS_BEGIN
# define THRUST_DETAIL_ABI_NS_END
# else // not defined(THRUST_DISABLE_ABI_NAMESPACE)
# if defined(_NVHPC_CUDA)
# define THRUST_DETAIL_ABI_NS_BEGIN \
inline namespace _CCCL_PP_CAT( \
_CCCL_PP_CAT(_CCCL_PP_CAT(_V_, THRUST_VERSION), _CCCL_PP_SPLICE_WITH(_, _SM, NV_TARGET_SM_INTEGER_LIST)), \
_NVHPC) \
{
# define THRUST_DETAIL_ABI_NS_END }
# else // not defined(_NVHPC_CUDA)
# define THRUST_DETAIL_ABI_NS_BEGIN \
inline namespace _CCCL_PP_CAT( \
_CCCL_PP_CAT(_V_, THRUST_VERSION), _CCCL_PP_SPLICE_WITH(_, _SM, __CUDA_ARCH_LIST__)) \
{
# define THRUST_DETAIL_ABI_NS_END }
# endif // not defined(_NVHPC_CUDA)
# endif // not defined(THRUST_DISABLE_ABI_NAMESPACE)
#else // THRUST_DEVICE_SYSTEM != THRUST_DEVICE_SYSTEM_CUDA
# define THRUST_DETAIL_ABI_NS_BEGIN
# define THRUST_DETAIL_ABI_NS_END
#endif // THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
/**
* \def THRUST_NAMESPACE_BEGIN
* This macro is used to open a `thrust::` namespace block, along with any
* enclosing namespaces requested by THRUST_WRAPPED_NAMESPACE, etc.
* This macro is defined by Thrust and may not be overridden.
*/
#define THRUST_NAMESPACE_BEGIN \
THRUST_NS_PREFIX \
namespace thrust \
{ \
THRUST_DETAIL_ABI_NS_BEGIN
/**
* \def THRUST_NAMESPACE_END
* This macro is used to close a `thrust::` namespace block, along with any
* enclosing namespaces requested by THRUST_WRAPPED_NAMESPACE, etc.
* This macro is defined by Thrust and may not be overridden.
*/
#define THRUST_NAMESPACE_END \
THRUST_DETAIL_ABI_NS_END \
} /* end namespace thrust */ \
THRUST_NS_POSTFIX
// The following is just here to add docs for the thrust namespace:
THRUST_NS_PREFIX
/*! \namespace thrust
* \brief \p thrust is the top-level namespace which contains all Thrust
* functions and types.
*/
namespace thrust
{
}
THRUST_NS_POSTFIX

View File

@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file simple_defines.h
* \brief Primitive macros without dependencies.
*/
#pragma once
// Internal config header that is only included through thrust/detail/config/config.h
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
//! Deprecated [Since 3.0]
#define THRUST_UNKNOWN 0
//! Deprecated [Since 3.0]
#define THRUST_FALSE 0
//! Deprecated [Since 3.0]
#define THRUST_TRUE 1
//! Deprecated [Since 3.0]
#define THRUST_UNUSED_VAR(expr) \
do \
{ \
(void) (expr); \
} while (0)
//! Deprecated [Since 3.0]
#define THRUST_PREVENT_MACRO_SUBSTITUTION

View File

@@ -0,0 +1,236 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/execution_policy.h>
#include <thrust/iterator/detail/normal_iterator.h>
#include <cuda/std/__host_stdlib/stdexcept>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__memory/allocator_traits.h>
#include <cuda/std/__type_traits/is_swappable.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/swap.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
struct copy_allocator_t
{};
struct allocator_mismatch_on_swap : std::runtime_error
{
allocator_mismatch_on_swap()
: std::runtime_error("swap called on containers with allocators that propagate on swap, but compare non-equal")
{}
};
// XXX parameter T is redundant with parameter Alloc
template <typename T, typename Alloc>
class contiguous_storage
{
private:
using alloc_traits = ::cuda::std::allocator_traits<Alloc>;
public:
using allocator_type = Alloc;
using value_type = T;
using pointer = typename alloc_traits::pointer;
using const_pointer = typename alloc_traits::const_pointer;
using size_type = typename alloc_traits::size_type;
using difference_type = typename alloc_traits::difference_type;
using reference = typename ::cuda::std::iterator_traits<pointer>::reference;
using const_reference = typename ::cuda::std::iterator_traits<const_pointer>::reference;
using iterator = thrust::detail::normal_iterator<pointer>;
using const_iterator = thrust::detail::normal_iterator<const_pointer>;
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE explicit contiguous_storage(allocator_type alloc = allocator_type());
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE explicit contiguous_storage(size_type n, allocator_type alloc = allocator_type());
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE explicit contiguous_storage(copy_allocator_t, const contiguous_storage& other);
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE explicit contiguous_storage(copy_allocator_t, const contiguous_storage& other, size_type n);
contiguous_storage& operator=(const contiguous_storage& x) = delete;
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE ~contiguous_storage();
_CCCL_HOST_DEVICE size_type size() const;
_CCCL_HOST_DEVICE size_type max_size() const;
_CCCL_HOST_DEVICE pointer data();
_CCCL_HOST_DEVICE const_pointer data() const;
_CCCL_HOST_DEVICE iterator begin();
_CCCL_HOST_DEVICE const_iterator begin() const;
_CCCL_HOST_DEVICE iterator end();
_CCCL_HOST_DEVICE const_iterator end() const;
_CCCL_HOST_DEVICE reference operator[](size_type n);
_CCCL_HOST_DEVICE const_reference operator[](size_type n) const;
_CCCL_HOST_DEVICE allocator_type get_allocator() const;
// note that allocate does *not* automatically call deallocate
_CCCL_HOST_DEVICE void allocate(size_type n);
_CCCL_HOST_DEVICE void deallocate() noexcept;
private:
static constexpr bool is_swap_noexcept()
{
if (!::cuda::std::is_nothrow_swappable_v<iterator>)
{
return false;
}
if (!::cuda::std::is_nothrow_swappable_v<size_type>)
{
return false;
}
if (::cuda::std::allocator_traits<Alloc>::propagate_on_container_swap::value)
{
return ::cuda::std::is_nothrow_swappable_v<allocator_type>;
}
return ::cuda::std::allocator_traits<Alloc>::is_always_equal::value;
}
public:
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE void
swap(contiguous_storage& other) noexcept(is_swap_noexcept()) // NOLINT(bugprone-exception-escape)
{
using ::cuda::std::swap;
swap(m_begin, other.m_begin);
swap(m_size, other.m_size);
// From C++ standard [container.reqmts]
// If ::cuda::std::allocator_traits<allocator_type>::propagate_on_container_swap::value is true, then
// allocator_type shall meet the Cpp17Swappable requirements and the allocators of a and b shall also be exchanged
// by calling swap as described in [swappable.requirements]. Otherwise, the allocators shall not be swapped, and
// the behavior is undefined unless a.get_allocator() == b.get_allocator().
if constexpr (::cuda::std::allocator_traits<Alloc>::propagate_on_container_swap::value)
{
swap(m_allocator, other.m_allocator);
}
else if constexpr (!::cuda::std::allocator_traits<Alloc>::is_always_equal::value)
{
NV_IF_TARGET(NV_IS_DEVICE, (assert(m_allocator == other.m_allocator);), (if (m_allocator != other.m_allocator) {
throw allocator_mismatch_on_swap();
}));
}
}
_CCCL_HOST_DEVICE void value_initialize_n(iterator first, size_type n);
_CCCL_HOST_DEVICE void uninitialized_fill_n(iterator first, size_type n, const value_type& value);
template <typename InputIterator>
_CCCL_HOST_DEVICE iterator uninitialized_copy(InputIterator first, InputIterator last, iterator result);
template <typename System, typename InputIterator>
_CCCL_HOST_DEVICE iterator uninitialized_copy(
thrust::execution_policy<System>& from_system, InputIterator first, InputIterator last, iterator result);
template <typename InputIterator, typename Size>
_CCCL_HOST_DEVICE iterator uninitialized_copy_n(InputIterator first, Size n, iterator result);
template <typename System, typename InputIterator, typename Size>
_CCCL_HOST_DEVICE iterator
uninitialized_copy_n(thrust::execution_policy<System>& from_system, InputIterator first, Size n, iterator result);
_CCCL_HOST_DEVICE void destroy(iterator first, iterator last) noexcept;
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE void deallocate_on_allocator_mismatch(const contiguous_storage& other) noexcept
{
if constexpr (::cuda::std::allocator_traits<Alloc>::propagate_on_container_copy_assignment::value)
{
if (m_allocator != other.m_allocator)
{
deallocate();
}
}
}
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE void destroy_on_allocator_mismatch(
const contiguous_storage& other, [[maybe_unused]] iterator first, [[maybe_unused]] iterator last) noexcept
{
if constexpr (::cuda::std::allocator_traits<Alloc>::propagate_on_container_copy_assignment::value)
{
if (m_allocator != other.m_allocator)
{
destroy(first, last);
}
}
}
_CCCL_HOST_DEVICE void set_allocator(const allocator_type& alloc);
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE void propagate_allocator(const contiguous_storage& other)
{
if constexpr (::cuda::std::allocator_traits<Alloc>::propagate_on_container_copy_assignment::value)
{
m_allocator = other.m_allocator;
}
}
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE void propagate_allocator(contiguous_storage& other)
{
if constexpr (::cuda::std::allocator_traits<Alloc>::propagate_on_container_move_assignment::value)
{
m_allocator = ::cuda::std::move(other.m_allocator);
}
}
// allow move assignment for a sane implementation of allocator propagation
_CCCL_HOST_DEVICE contiguous_storage& operator=(contiguous_storage&& other) noexcept;
_CCCL_SYNTHESIZE_SEQUENCE_ACCESS(contiguous_storage, const_iterator)
private:
// XXX we could inherit from this to take advantage of empty base class optimization
allocator_type m_allocator;
iterator m_begin;
size_type m_size;
// NOLINTNEXTLINE(bugprone-exception-escape)
friend _CCCL_HOST_DEVICE void swap(contiguous_storage& lhs, contiguous_storage& rhs) noexcept(noexcept(lhs.swap(rhs)))
{
lhs.swap(rhs);
}
}; // end contiguous_storage
} // namespace detail
THRUST_NAMESPACE_END
#include <thrust/detail/contiguous_storage.inl>

View File

@@ -0,0 +1,259 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/allocator/copy_construct_range.h>
#include <thrust/detail/allocator/destroy_range.h>
#include <thrust/detail/allocator/fill_construct_range.h>
#include <thrust/detail/allocator/value_initialize_range.h>
#include <thrust/detail/contiguous_storage.h>
#include <cuda/std/__host_stdlib/stdexcept>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/swap.h>
#include <nv/target>
THRUST_NAMESPACE_BEGIN
namespace detail
{
_CCCL_EXEC_CHECK_DISABLE
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE contiguous_storage<T, Alloc>::contiguous_storage(Alloc alloc)
: m_allocator(::cuda::std::move(alloc))
, m_begin(pointer(static_cast<T*>(nullptr)))
, m_size(0)
{
;
} // end contiguous_storage::contiguous_storage()
_CCCL_EXEC_CHECK_DISABLE
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE contiguous_storage<T, Alloc>::contiguous_storage(size_type n, Alloc alloc)
: m_allocator(::cuda::std::move(alloc))
, m_begin(pointer(static_cast<T*>(nullptr)))
, m_size(0)
{
allocate(n);
} // end contiguous_storage::contiguous_storage()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE contiguous_storage<T, Alloc>::contiguous_storage(copy_allocator_t, const contiguous_storage& other)
: m_allocator(other.m_allocator)
, m_begin(pointer(static_cast<T*>(nullptr)))
, m_size(0)
{} // end contiguous_storage::contiguous_storage()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE
contiguous_storage<T, Alloc>::contiguous_storage(copy_allocator_t, const contiguous_storage& other, size_type n)
: m_allocator(other.m_allocator)
, m_begin(pointer(static_cast<T*>(nullptr)))
, m_size(0)
{
allocate(n);
} // end contiguous_storage::contiguous_storage()
_CCCL_EXEC_CHECK_DISABLE
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE contiguous_storage<T, Alloc>::~contiguous_storage()
{
deallocate();
} // end contiguous_storage::~contiguous_storage()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::size_type contiguous_storage<T, Alloc>::size() const
{
return m_size;
} // end contiguous_storage::size()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::size_type contiguous_storage<T, Alloc>::max_size() const
{
return alloc_traits::max_size(m_allocator);
} // end contiguous_storage::max_size()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::iterator contiguous_storage<T, Alloc>::begin()
{
return m_begin;
} // end contiguous_storage::begin()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::const_iterator contiguous_storage<T, Alloc>::begin() const
{
return m_begin;
} // end contiguous_storage::begin()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::iterator contiguous_storage<T, Alloc>::end()
{
return m_begin + size();
} // end contiguous_storage::end()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::const_iterator contiguous_storage<T, Alloc>::end() const
{
return m_begin + size();
} // end contiguous_storage::end()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::pointer contiguous_storage<T, Alloc>::data()
{
return &*m_begin;
} // end contiguous_storage::data()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::const_pointer contiguous_storage<T, Alloc>::data() const
{
return &*m_begin;
} // end contiguous_storage::data()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::reference contiguous_storage<T, Alloc>::operator[](size_type n)
{
return m_begin[n];
} // end contiguous_storage::operator[]()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::const_reference
contiguous_storage<T, Alloc>::operator[](size_type n) const
{
return m_begin[n];
} // end contiguous_storage::operator[]()
_CCCL_EXEC_CHECK_DISABLE
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::allocator_type
contiguous_storage<T, Alloc>::get_allocator() const
{
return m_allocator;
} // end contiguous_storage::get_allocator()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE void contiguous_storage<T, Alloc>::allocate(size_type n)
{
if (n > 0)
{
m_begin = iterator(alloc_traits::allocate(m_allocator, n));
m_size = n;
} // end if
else
{
m_begin = iterator(pointer(static_cast<T*>(nullptr)));
m_size = 0;
} // end else
} // end contiguous_storage::allocate()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE void contiguous_storage<T, Alloc>::deallocate() noexcept
{
if (size() > 0)
{
alloc_traits::deallocate(m_allocator, m_begin.base(), size());
m_begin = iterator(pointer(static_cast<T*>(nullptr)));
m_size = 0;
} // end if
} // end contiguous_storage::deallocate()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE void contiguous_storage<T, Alloc>::value_initialize_n(iterator first, size_type n)
{
value_initialize_range(m_allocator, first.base(), n);
} // end contiguous_storage::value_initialize_n()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE void
contiguous_storage<T, Alloc>::uninitialized_fill_n(iterator first, size_type n, const value_type& x)
{
fill_construct_range(m_allocator, first.base(), n, x);
} // end contiguous_storage::uninitialized_fill()
template <typename T, typename Alloc>
template <typename System, typename InputIterator>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::iterator contiguous_storage<T, Alloc>::uninitialized_copy(
thrust::execution_policy<System>& from_system, InputIterator first, InputIterator last, iterator result)
{
return iterator(copy_construct_range(from_system, m_allocator, first, last, result.base()));
} // end contiguous_storage::uninitialized_copy()
template <typename T, typename Alloc>
template <typename InputIterator>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::iterator
contiguous_storage<T, Alloc>::uninitialized_copy(InputIterator first, InputIterator last, iterator result)
{
// XXX assumes InputIterator's associated System is default-constructible
typename thrust::iterator_system<InputIterator>::type from_system;
return iterator(copy_construct_range(from_system, m_allocator, first, last, result.base()));
} // end contiguous_storage::uninitialized_copy()
template <typename T, typename Alloc>
template <typename System, typename InputIterator, typename Size>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::iterator contiguous_storage<T, Alloc>::uninitialized_copy_n(
thrust::execution_policy<System>& from_system, InputIterator first, Size n, iterator result)
{
return iterator(copy_construct_range_n(from_system, m_allocator, first, n, result.base()));
} // end contiguous_storage::uninitialized_copy_n()
template <typename T, typename Alloc>
template <typename InputIterator, typename Size>
_CCCL_HOST_DEVICE typename contiguous_storage<T, Alloc>::iterator
contiguous_storage<T, Alloc>::uninitialized_copy_n(InputIterator first, Size n, iterator result)
{
// XXX assumes InputIterator's associated System is default-constructible
typename thrust::iterator_system<InputIterator>::type from_system;
return iterator(copy_construct_range_n(from_system, m_allocator, first, n, result.base()));
} // end contiguous_storage::uninitialized_copy_n()
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE void contiguous_storage<T, Alloc>::destroy(iterator first, iterator last) noexcept
{
destroy_range(m_allocator, first.base(), last - first);
} // end contiguous_storage::destroy()
_CCCL_EXEC_CHECK_DISABLE
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE void contiguous_storage<T, Alloc>::set_allocator(const Alloc& alloc)
{
m_allocator = alloc;
} // end contiguous_storage::set_allocator()
_CCCL_EXEC_CHECK_DISABLE
template <typename T, typename Alloc>
_CCCL_HOST_DEVICE contiguous_storage<T, Alloc>&
contiguous_storage<T, Alloc>::operator=(contiguous_storage&& other) noexcept
{
if (size() > 0)
{
deallocate();
}
if constexpr (::cuda::std::allocator_traits<Alloc>::propagate_on_container_move_assignment::value)
{
m_allocator = ::cuda::std::move(other.m_allocator);
}
m_begin = ::cuda::std::move(other.m_begin);
m_size = ::cuda::std::move(other.m_size);
other.m_begin = pointer(static_cast<T*>(nullptr));
other.m_size = 0;
return *this;
}
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,57 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/execution_policy.h>
THRUST_NAMESPACE_BEGIN
template <typename System, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator
copy(const thrust::detail::execution_policy_base<System>& system,
InputIterator first,
InputIterator last,
OutputIterator result);
template <typename System, typename InputIterator, typename Size, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator
copy_n(const thrust::detail::execution_policy_base<System>& system, InputIterator first, Size n, OutputIterator result);
template <typename InputIterator, typename OutputIterator>
OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result);
template <typename InputIterator, typename Size, typename OutputIterator>
OutputIterator copy_n(InputIterator first, Size n, OutputIterator result);
namespace detail
{
template <typename FromSystem, typename ToSystem, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator two_system_copy(
const thrust::execution_policy<FromSystem>& from_system,
const thrust::execution_policy<ToSystem>& two_system,
InputIterator first,
InputIterator last,
OutputIterator result);
template <typename FromSystem, typename ToSystem, typename InputIterator, typename Size, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator two_system_copy_n(
const thrust::execution_policy<FromSystem>& from_system,
const thrust::execution_policy<ToSystem>& two_system,
InputIterator first,
Size n,
OutputIterator result);
} // namespace detail
THRUST_NAMESPACE_END
#include <thrust/detail/copy.inl>

View File

@@ -0,0 +1,133 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/copy.h>
#include <thrust/detail/nvtx_policy.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/copy.h>
#include <thrust/system/detail/sequential/copy.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(copy.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(copy.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/copy.h>
# include <thrust/system/cuda/detail/copy.h>
# include <thrust/system/omp/detail/copy.h>
# include <thrust/system/tbb/detail/copy.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator
copy(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "thrust::copy");
using thrust::system::detail::generic::copy;
return copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result);
} // end copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename Size, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator copy_n(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, InputIterator first, Size n, OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "thrust::copy_n");
using thrust::system::detail::generic::copy_n;
return copy_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, result);
} // end copy_n()
namespace detail
{
_CCCL_EXEC_CHECK_DISABLE // because we might call e.g. std::ostream_iterator's constructor
template <typename System1, typename System2, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator two_system_copy(
const thrust::execution_policy<System1>& system1,
const thrust::execution_policy<System2>& system2,
InputIterator first,
InputIterator last,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE_IF(should_enable_nvtx_for_policy<System1>() || should_enable_nvtx_for_policy<System2>(),
"thrust::two_system_copy");
using thrust::system::detail::generic::select_system;
return thrust::copy(
select_system(thrust::detail::derived_cast(thrust::detail::strip_const(system1)),
thrust::detail::derived_cast(thrust::detail::strip_const(system2))),
first,
last,
result);
} // end two_system_copy()
_CCCL_EXEC_CHECK_DISABLE // because we might call e.g. std::ostream_iterator's constructor
template <typename System1, typename System2, typename InputIterator, typename Size, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator two_system_copy_n(
const thrust::execution_policy<System1>& system1,
const thrust::execution_policy<System2>& system2,
InputIterator first,
Size n,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE_IF(should_enable_nvtx_for_policy<System1>() || should_enable_nvtx_for_policy<System2>(),
"thrust::two_system_copy_n");
using thrust::system::detail::generic::select_system;
return thrust::copy_n(
select_system(thrust::detail::derived_cast(thrust::detail::strip_const(system1)),
thrust::detail::derived_cast(thrust::detail::strip_const(system2))),
first,
n,
result);
} // end two_system_copy_n()
} // namespace detail
template <typename InputIterator, typename OutputIterator>
OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
{
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(
detail::should_enable_nvtx_for_policy<System1>() || detail::should_enable_nvtx_for_policy<System2>(),
"thrust::copy");
System1 system1;
System2 system2;
return thrust::detail::two_system_copy(system1, system2, first, last, result);
} // end copy()
template <typename InputIterator, typename Size, typename OutputIterator>
OutputIterator copy_n(InputIterator first, Size n, OutputIterator result)
{
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(
detail::should_enable_nvtx_for_policy<System1>() || detail::should_enable_nvtx_for_policy<System2>(),
"thrust::copy_n");
System1 system1;
System2 system2;
return thrust::detail::two_system_copy_n(system1, system2, first, n, result);
} // end copy_n()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/execution_policy.h>
THRUST_NAMESPACE_BEGIN
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename Predicate>
_CCCL_HOST_DEVICE OutputIterator copy_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
Predicate pred);
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename Predicate>
_CCCL_HOST_DEVICE OutputIterator copy_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first,
InputIterator1 last,
InputIterator2 stencil,
OutputIterator result,
Predicate pred);
template <typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
template <typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
OutputIterator
copy_if(InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred);
THRUST_NAMESPACE_END
#include <thrust/detail/copy_if.inl>

View File

@@ -0,0 +1,101 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/copy_if.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/copy_if.h>
#include <thrust/system/detail/sequential/copy_if.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(copy_if.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(copy_if.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/copy_if.h>
# include <thrust/system/cuda/detail/copy_if.h>
# include <thrust/system/omp/detail/copy_if.h>
# include <thrust/system/tbb/detail/copy_if.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename Predicate>
_CCCL_HOST_DEVICE OutputIterator copy_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::copy_if");
using thrust::system::detail::generic::copy_if;
return copy_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, pred);
} // end copy_if()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename Predicate>
_CCCL_HOST_DEVICE OutputIterator copy_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first,
InputIterator1 last,
InputIterator2 stencil,
OutputIterator result,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::copy_if");
using thrust::system::detail::generic::copy_if;
return copy_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, result, pred);
} // end copy_if()
template <typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::copy_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::copy_if(select_system(system1, system2), first, last, result, pred);
} // end copy_if()
template <typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
OutputIterator
copy_if(InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::copy_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::copy_if(select_system(system1, system2, system3), first, last, stencil, result, pred);
} // end copy_if()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,42 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/execution_policy.h>
THRUST_NAMESPACE_BEGIN
template <typename DerivedPolicy, typename InputIterator, typename EqualityComparable>
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
const EqualityComparable& value);
template <typename DerivedPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count_if(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Predicate pred);
template <typename InputIterator, typename EqualityComparable>
thrust::detail::it_difference_t<InputIterator>
count(InputIterator first, InputIterator last, const EqualityComparable& value);
template <typename InputIterator, typename Predicate>
thrust::detail::it_difference_t<InputIterator> count_if(InputIterator first, InputIterator last, Predicate pred);
THRUST_NAMESPACE_END
#include <thrust/detail/count.inl>

View File

@@ -0,0 +1,88 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/count.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/count.h>
#include <thrust/system/detail/sequential/count.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(count.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(count.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/count.h>
# include <thrust/system/cuda/detail/count.h>
# include <thrust/system/omp/detail/count.h>
# include <thrust/system/tbb/detail/count.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename EqualityComparable>
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
const EqualityComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::count");
using thrust::system::detail::generic::count;
return count(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value);
} // end count()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<InputIterator>
count_if(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::count_if");
using thrust::system::detail::generic::count_if;
return count_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred);
} // end count_if()
template <typename InputIterator, typename EqualityComparable>
thrust::detail::it_difference_t<InputIterator>
count(InputIterator first, InputIterator last, const EqualityComparable& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::count");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::count(select_system(system), first, last, value);
} // end count()
template <typename InputIterator, typename Predicate>
thrust::detail::it_difference_t<InputIterator> count_if(InputIterator first, InputIterator last, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::count_if");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::count_if(select_system(system), first, last, pred);
} // end count_if()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/type_traits.h>
#include <thrust/device_ptr.h>
#include <thrust/device_reference.h>
#include <thrust/iterator/iterator_traits.h>
THRUST_NAMESPACE_BEGIN
template <typename T>
_CCCL_HOST_DEVICE device_ptr<T> device_pointer_cast(T* ptr)
{
return device_ptr<T>(ptr);
} // end device_pointer_cast()
template <typename T>
_CCCL_HOST_DEVICE device_ptr<T> device_pointer_cast(const device_ptr<T>& ptr)
{
return ptr;
} // end device_pointer_cast()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,92 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/equal.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/equal.h>
#include <thrust/system/detail/sequential/equal.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(equal.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(equal.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/equal.h>
# include <thrust/system/cuda/detail/equal.h>
# include <thrust/system/omp/detail/equal.h>
# include <thrust/system/tbb/detail/equal.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename System, typename InputIterator1, typename InputIterator2>
_CCCL_HOST_DEVICE bool
equal(const thrust::detail::execution_policy_base<System>& system,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::equal");
using thrust::system::detail::generic::equal;
return equal(thrust::detail::derived_cast(thrust::detail::strip_const(system)), first1, last1, first2);
} // end equal()
_CCCL_EXEC_CHECK_DISABLE
template <typename System, typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
_CCCL_HOST_DEVICE bool
equal(const thrust::detail::execution_policy_base<System>& system,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::equal");
using thrust::system::detail::generic::equal;
return equal(thrust::detail::derived_cast(thrust::detail::strip_const(system)), first1, last1, first2, binary_pred);
} // end equal()
template <typename InputIterator1, typename InputIterator2>
bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::equal");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
System1 system1;
System2 system2;
return thrust::equal(select_system(system1, system2), first1, last1, first2);
}
template <typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::equal");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
System1 system1;
System2 system2;
return thrust::equal(select_system(system1, system2), first1, last1, first2, binary_pred);
}
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/execute_with_allocator_fwd.h>
#include <thrust/detail/raw_pointer_cast.h>
#include <cuda/__cmath/ceil_div.h>
#include <cuda/std/__memory/allocator_traits.h>
#include <cuda/std/__memory/pointer_traits.h>
#include <cuda/std/__utility/pair.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename T, typename Allocator, template <typename> class BaseSystem>
_CCCL_HOST ::cuda::std::pair<T*, std::ptrdiff_t>
get_temporary_buffer(thrust::detail::execute_with_allocator<Allocator, BaseSystem>& system, std::ptrdiff_t n)
{
using naked_allocator = ::cuda::std::remove_reference_t<Allocator>;
using alloc_traits = typename ::cuda::std::allocator_traits<naked_allocator>;
using void_pointer = typename alloc_traits::void_pointer;
using size_type = typename alloc_traits::size_type;
using value_type = typename alloc_traits::value_type;
// How many elements of type value_type do we need to accommodate n elements
// of type T?
const size_type num_elements = static_cast<size_type>(::cuda::ceil_div(sizeof(T) * n, sizeof(value_type)));
void_pointer ptr = alloc_traits::allocate(system.get_allocator(), num_elements);
// Return the pointer and the number of elements of type T allocated.
return ::cuda::std::make_pair(thrust::reinterpret_pointer_cast<T*>(ptr), n);
}
template <typename Pointer, typename Allocator, template <typename> class BaseSystem>
_CCCL_HOST void return_temporary_buffer(
thrust::detail::execute_with_allocator<Allocator, BaseSystem>& system, Pointer p, std::ptrdiff_t n)
{
using naked_allocator = ::cuda::std::remove_reference_t<Allocator>;
using alloc_traits = typename ::cuda::std::allocator_traits<naked_allocator>;
using pointer = typename alloc_traits::pointer;
using size_type = typename alloc_traits::size_type;
using value_type = typename alloc_traits::value_type;
using T = typename ::cuda::std::pointer_traits<Pointer>::element_type;
size_type num_elements = ::cuda::ceil_div(sizeof(T) * n, sizeof(value_type));
pointer to_ptr = thrust::reinterpret_pointer_cast<pointer>(p);
alloc_traits::deallocate(system.get_allocator(), to_ptr, num_elements);
}
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/type_traits.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename Allocator, template <typename> class BaseSystem>
struct execute_with_allocator : BaseSystem<execute_with_allocator<Allocator, BaseSystem>>
{
private:
using super_t = BaseSystem<execute_with_allocator<Allocator, BaseSystem>>;
Allocator alloc;
public:
_CCCL_HOST_DEVICE execute_with_allocator(super_t const& super, Allocator alloc_)
: super_t(super)
, alloc(alloc_)
{}
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE execute_with_allocator(Allocator alloc_)
: alloc(alloc_)
{}
_CCCL_HOST_DEVICE ::cuda::std::remove_reference_t<Allocator>& get_allocator()
{
return alloc;
}
};
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,120 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
THRUST_NAMESPACE_BEGIN
namespace detail
{
struct execution_policy_marker
{};
// execution_policy_base serves as a guard against infinite recursion in thrust entry points:
//
// template<typename DerivedPolicy>
// void foo(const thrust::detail::execution_policy_base<DerivedPolicy> &s)
// {
// using thrust::system::detail::generic::foo;
//
// foo(thrust::detail::derived_cast(thrust::detail::strip_const(s));
// }
//
// foo is not recursive when
// 1. DerivedPolicy is derived from thrust::execution_policy below
// 2. generic::foo takes thrust::execution_policy as a parameter
template <typename DerivedPolicy>
struct execution_policy_base : execution_policy_marker
{};
template <typename DerivedPolicy>
constexpr _CCCL_HOST_DEVICE execution_policy_base<DerivedPolicy>&
strip_const(const execution_policy_base<DerivedPolicy>& x)
{
return const_cast<execution_policy_base<DerivedPolicy>&>(x);
}
template <typename DerivedPolicy>
constexpr _CCCL_HOST_DEVICE DerivedPolicy& derived_cast(execution_policy_base<DerivedPolicy>& x)
{
return static_cast<DerivedPolicy&>(x);
}
template <typename DerivedPolicy>
constexpr _CCCL_HOST_DEVICE const DerivedPolicy& derived_cast(const execution_policy_base<DerivedPolicy>& x)
{
return static_cast<const DerivedPolicy&>(x);
}
} // namespace detail
//! \addtogroup execution_policies
//! \{
//! \p execution_policy is the base class for all Thrust parallel execution policies like \p thrust::host, \p
//! thrust::device, and each backend system's tag type.
//!
//! Custom user-defined backends should derive a policy from this type in order to interoperate with Thrust algorithm
//! dispatch.
//!
//! The following code snippet demonstrates how to derive a standalone custom execution policy from \p
//! thrust::execution_policy to implement a backend which only implements \p for_each:
//!
//! \code
//! #include <thrust/execution_policy.h>
//! #include <iostream>
//!
//! // define a type derived from thrust::execution_policy to distinguish our custom execution policy:
//! struct my_policy : thrust::execution_policy<my_policy> {};
//!
//! // overload for_each on my_policy
//! template<typename Iterator, typename Function>
//! Iterator for_each(my_policy, Iterator first, Iterator last, Function f)
//! {
//! std::cout << "Hello, world from for_each(my_policy)!" << '\n';
//!
//! for(; first < last; ++first)
//! {
//! f(*first);
//! }
//!
//! return first;
//! }
//!
//! struct ignore_argument
//! {
//! void operator()(int) {}
//! };
//!
//! int main()
//! {
//! int data[4];
//!
//! // dispatch thrust::for_each using our custom policy:
//! my_policy exec;
//! thrust::for_each(exec, data, data + 4, ignore_argument());
//!
//! // can't dispatch thrust::transform because no overload exists for my_policy:
//! //thrust::transform(exec, data, data, + 4, data, ::cuda::std::identity{}); // error!
//!
//! return 0;
//! }
//! \endcode
//!
//! \see host_execution_policy
//! \see device_execution_policy
template <typename DerivedPolicy>
struct execution_policy : detail::execution_policy_base<DerivedPolicy>
{};
//! \}
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,183 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/extrema.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/extrema.h>
#include <thrust/system/detail/sequential/extrema.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(extrema.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(extrema.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/extrema.h>
# include <thrust/system/cuda/detail/extrema.h>
# include <thrust/system/omp/detail/extrema.h>
# include <thrust/system/tbb/detail/extrema.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator>
_CCCL_HOST_DEVICE ForwardIterator min_element(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("min_element");
using thrust::system::detail::generic::min_element;
return min_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end min_element()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
_CCCL_HOST_DEVICE ForwardIterator min_element(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
BinaryPredicate comp)
{
_CCCL_NVTX_RANGE_SCOPE("min_element");
using thrust::system::detail::generic::min_element;
return min_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp);
} // end min_element()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator>
_CCCL_HOST_DEVICE ForwardIterator max_element(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("max_element");
using thrust::system::detail::generic::max_element;
return max_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end max_element()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
_CCCL_HOST_DEVICE ForwardIterator max_element(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
BinaryPredicate comp)
{
_CCCL_NVTX_RANGE_SCOPE("max_element");
using thrust::system::detail::generic::max_element;
return max_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp);
} // end max_element()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator>
_CCCL_HOST_DEVICE ::cuda::std::pair<ForwardIterator, ForwardIterator> minmax_element(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("minmax_element");
using thrust::system::detail::generic::minmax_element;
return minmax_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end minmax_element()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<ForwardIterator, ForwardIterator> minmax_element(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
BinaryPredicate comp)
{
_CCCL_NVTX_RANGE_SCOPE("minmax_element");
using thrust::system::detail::generic::minmax_element;
return minmax_element(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp);
} // end minmax_element()
template <typename ForwardIterator>
ForwardIterator min_element(ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("min_element");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::min_element(select_system(system), first, last);
} // end min_element()
template <typename ForwardIterator, typename BinaryPredicate>
ForwardIterator min_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp)
{
_CCCL_NVTX_RANGE_SCOPE("min_element");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::min_element(select_system(system), first, last, comp);
} // end min_element()
template <typename ForwardIterator>
ForwardIterator max_element(ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("max_element");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::max_element(select_system(system), first, last);
} // end max_element()
template <typename ForwardIterator, typename BinaryPredicate>
ForwardIterator max_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp)
{
_CCCL_NVTX_RANGE_SCOPE("max_element");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::max_element(select_system(system), first, last, comp);
} // end max_element()
template <typename ForwardIterator>
::cuda::std::pair<ForwardIterator, ForwardIterator> minmax_element(ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("minmax_element");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::minmax_element(select_system(system), first, last);
} // end minmax_element()
template <typename ForwardIterator, typename BinaryPredicate>
::cuda::std::pair<ForwardIterator, ForwardIterator>
minmax_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp)
{
_CCCL_NVTX_RANGE_SCOPE("minmax_element");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::minmax_element(select_system(system), first, last, comp);
} // end minmax_element()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/nvtx_policy.h>
#include <thrust/fill.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/fill.h>
#include <thrust/system/detail/sequential/fill.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(fill.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(fill.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/fill.h>
# include <thrust/system/cuda/detail/fill.h>
# include <thrust/system/omp/detail/fill.h>
# include <thrust/system/tbb/detail/fill.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T>
_CCCL_HOST_DEVICE void
fill(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const T& value)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "thrust::fill");
using thrust::system::detail::generic::fill;
return fill(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value);
} // end fill()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename OutputIterator, typename Size, typename T>
_CCCL_HOST_DEVICE OutputIterator
fill_n(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, OutputIterator first, Size n, const T& value)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "thrust::fill_n");
using thrust::system::detail::generic::fill_n;
return fill_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, value);
} // end fill_n()
template <typename ForwardIterator, typename T>
_CCCL_HOST_DEVICE void fill(ForwardIterator first, ForwardIterator last, const T& value)
{
using System = typename thrust::iterator_system<ForwardIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<System>(), "thrust::fill");
using thrust::system::detail::generic::select_system;
System system;
thrust::fill(select_system(system), first, last, value);
} // end fill()
template <typename OutputIterator, typename Size, typename T>
_CCCL_HOST_DEVICE OutputIterator fill_n(OutputIterator first, Size n, const T& value)
{
using System = typename thrust::iterator_system<OutputIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<System>(), "thrust::fill_n");
using thrust::system::detail::generic::select_system;
System system;
return thrust::fill_n(select_system(system), first, n, value);
} // end fill()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,112 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/find.h>
#include <thrust/system/detail/sequential/find.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(find.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(find.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/find.h>
# include <thrust/system/cuda/detail/find.h>
# include <thrust/system/omp/detail/find.h>
# include <thrust/system/tbb/detail/find.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename T>
_CCCL_HOST_DEVICE InputIterator
find(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
const T& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::find");
using thrust::system::detail::generic::find;
return find(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value);
} // end find()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE InputIterator find_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::find_if");
using thrust::system::detail::generic::find_if;
return find_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred);
} // end find_if()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE InputIterator find_if_not(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::find_if_not");
using thrust::system::detail::generic::find_if_not;
return find_if_not(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred);
} // end find_if_not()
template <typename InputIterator, typename T>
InputIterator find(InputIterator first, InputIterator last, const T& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::find");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::find(select_system(system), first, last, value);
}
template <typename InputIterator, typename Predicate>
InputIterator find_if(InputIterator first, InputIterator last, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::find_if");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::find_if(select_system(system), first, last, pred);
}
template <typename InputIterator, typename Predicate>
InputIterator find_if_not(InputIterator first, InputIterator last, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::find_if_not");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::find_if_not(select_system(system), first, last, pred);
}
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,83 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/nvtx_policy.h>
#include <thrust/for_each.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/for_each.h>
#include <thrust/system/detail/sequential/for_each.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(for_each.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(for_each.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/for_each.h>
# include <thrust/system/cuda/detail/for_each.h>
# include <thrust/system/omp/detail/for_each.h>
# include <thrust/system/tbb/detail/for_each.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename UnaryFunction>
_CCCL_HOST_DEVICE InputIterator for_each(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
UnaryFunction f)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "thrust::for_each");
using thrust::system::detail::generic::for_each;
return for_each(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, f);
}
template <typename InputIterator, typename UnaryFunction>
InputIterator for_each(InputIterator first, InputIterator last, UnaryFunction f)
{
using System = typename thrust::iterator_system<InputIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<System>(), "thrust::for_each");
using thrust::system::detail::generic::select_system;
System system;
return thrust::for_each(select_system(system), first, last, f);
} // end for_each()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename Size, typename UnaryFunction>
_CCCL_HOST_DEVICE InputIterator for_each_n(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, InputIterator first, Size n, UnaryFunction f)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "thrust::for_each_n");
using thrust::system::detail::generic::for_each_n;
return for_each_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, f);
} // end for_each_n()
template <typename InputIterator, typename Size, typename UnaryFunction>
InputIterator for_each_n(InputIterator first, Size n, UnaryFunction f)
{
using System = typename thrust::iterator_system<InputIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<System>(), "thrust::for_each_n");
using thrust::system::detail::generic::select_system;
System system;
return thrust::for_each_n(select_system(system), first, n, f);
} // end for_each_n()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/raw_reference_cast.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename Function, typename Result>
struct wrapped_function
{
// mutable because Function::operator() might be const
mutable Function m_f;
_CCCL_EXEC_CHECK_DISABLE
template <typename... Ts>
inline _CCCL_HOST_DEVICE Result operator()(Ts&&... args) const
{
return static_cast<Result>(m_f(thrust::raw_reference_cast(::cuda::std::forward<Ts>(args))...));
}
}; // end wrapped_function
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,201 @@
// SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// Portions of this code are derived from
//
// Manjunath Kudlur's Carbon library
//
// and
//
// Based on Boost.Phoenix v1.2
// Copyright (c) 2001-2002 Joel de Guzman
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/type_deduction.h>
#include <cuda/std/__type_traits/decay.h>
#include <cuda/std/__type_traits/integral_constant.h>
#include <cuda/std/__utility/declval.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/tuple>
THRUST_NAMESPACE_BEGIN
namespace detail::functional
{
// An actor is a node in an expression template
template <typename Eval>
struct actor : Eval
{
constexpr actor() = default;
_CCCL_HOST_DEVICE actor(const Eval& base)
: Eval(base)
{}
template <typename... Ts>
_CCCL_HOST_DEVICE auto operator()(Ts&&... ts) const -> decltype(Eval::eval(THRUST_FWD(ts)...))
{
return Eval::eval(THRUST_FWD(ts)...);
}
template <typename T>
_CCCL_HOST_DEVICE auto operator=(const T& _1) const -> decltype(do_assign(*this, _1))
{
return do_assign(*this, _1);
}
};
template <typename T>
struct is_actor : ::cuda::std::false_type
{};
template <typename T>
struct is_actor<actor<T>> : ::cuda::std::true_type
{};
// a node selecting and returning one of the arguments to the entire expression template
template <unsigned int Pos>
struct argument
{
template <typename... Ts>
_CCCL_HOST_DEVICE auto eval(Ts&&... args) const
-> decltype(::cuda::std::get<Pos>(::cuda::std::tuple<Ts&&...>{THRUST_FWD(args)...}))
{
return ::cuda::std::get<Pos>(::cuda::std::tuple<Ts&&...>{THRUST_FWD(args)...});
}
};
template <unsigned int Pos>
struct placeholder
{
using type = actor<argument<Pos>>;
};
// composition of actors/nodes
template <typename...>
struct composite;
template <typename Eval, typename SubExpr>
struct composite<Eval, SubExpr>
{
constexpr composite() = default;
// TODO(bgruber): drop ctor and use aggregate initialization in C++17
_CCCL_HOST_DEVICE composite(const Eval& eval, const SubExpr& subexpr)
: m_eval(eval)
, m_subexpr(subexpr)
{}
template <typename... Ts>
_CCCL_HOST_DEVICE auto eval(Ts&&... args) const
-> decltype(::cuda::std::declval<Eval>().eval(::cuda::std::declval<SubExpr>().eval(THRUST_FWD(args)...)))
{
return m_eval.eval(m_subexpr.eval(THRUST_FWD(args)...));
}
private:
Eval m_eval;
SubExpr m_subexpr;
};
template <typename Eval, typename SubExpr1, typename SubExpr2>
struct composite<Eval, SubExpr1, SubExpr2>
{
constexpr composite() = default;
// TODO(bgruber): drop ctor and use aggregate initialization in C++17
_CCCL_HOST_DEVICE composite(const Eval& eval, const SubExpr1& subexpr1, const SubExpr2& subexpr2)
: m_eval(eval)
, m_subexpr1(subexpr1)
, m_subexpr2(subexpr2)
{}
template <typename... Ts>
_CCCL_HOST_DEVICE auto eval(Ts&&... args) const
-> decltype(::cuda::std::declval<Eval>().eval(::cuda::std::declval<SubExpr1>().eval(THRUST_FWD(args)...),
::cuda::std::declval<SubExpr2>().eval(THRUST_FWD(args)...)))
{
// NOLINTNEXTLINE(bugprone-use-after-move)
return m_eval.eval(m_subexpr1.eval(THRUST_FWD(args)...), m_subexpr2.eval(THRUST_FWD(args)...));
}
private:
Eval m_eval;
SubExpr1 m_subexpr1;
SubExpr2 m_subexpr2;
};
template <typename Eval>
struct actor;
// Adapts a transparent unary functor from functional.h (e.g. ::cuda::std::negate<>) into the Eval interface.
template <typename F>
struct operator_adaptor : F
{
constexpr operator_adaptor() = default;
_CCCL_HOST_DEVICE operator_adaptor(F f)
: F(::cuda::std::move(f))
{}
template <typename... Ts>
_CCCL_HOST_DEVICE auto eval(Ts&&... args) const -> decltype(F{}(THRUST_FWD(args)...))
{
return static_cast<const F&>(*this)(THRUST_FWD(args)...);
}
};
// a node returning a fixed value
template <typename T>
struct value
{
T m_val;
template <typename... Ts>
_CCCL_HOST_DEVICE T eval(Ts&&...) const
{
return m_val;
}
};
template <typename T>
_CCCL_HOST_DEVICE auto make_actor(T&& x) -> actor<value<::cuda::std::decay_t<T>>>
{
return {{THRUST_FWD(x)}};
}
template <typename Eval>
_CCCL_HOST_DEVICE auto make_actor(actor<Eval> x) -> actor<Eval>
{
return x;
}
template <typename Eval, typename SubExpr>
_CCCL_HOST_DEVICE auto compose(Eval e, const SubExpr& subexpr)
-> decltype(actor<composite<operator_adaptor<Eval>, decltype(make_actor(subexpr))>>{
{{::cuda::std::move(e)}, make_actor(subexpr)}})
{
return actor<composite<operator_adaptor<Eval>, decltype(make_actor(subexpr))>>{
{{::cuda::std::move(e)}, make_actor(subexpr)}};
}
template <typename Eval, typename SubExpr1, typename SubExpr2>
_CCCL_HOST_DEVICE auto compose(Eval e, const SubExpr1& subexpr1, const SubExpr2& subexpr2)
-> decltype(actor<composite<operator_adaptor<Eval>, decltype(make_actor(subexpr1)), decltype(make_actor(subexpr2))>>{
{{::cuda::std::move(e)}, make_actor(subexpr1), make_actor(subexpr2)}})
{
return actor<composite<operator_adaptor<Eval>, decltype(make_actor(subexpr1)), decltype(make_actor(subexpr2))>>{
{{::cuda::std::move(e)}, make_actor(subexpr1), make_actor(subexpr2)}};
}
} // namespace detail::functional
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,370 @@
// SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// Portions of this code are derived from
//
// Manjunath Kudlur's Carbon library
//
// and
//
// Based on Boost.Phoenix v1.2
// Copyright (c) 2001-2002 Joel de Guzman
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/functional.h>
#include <cuda/std/__functional/operations.h>
#include <cuda/std/__type_traits/enable_if.h>
THRUST_NAMESPACE_BEGIN
namespace detail::functional
{
// there's no standard plus_equal functional, so roll an ad hoc one here
struct plus_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) += THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) += THRUST_FWD(t2))
{
return THRUST_FWD(t1) += THRUST_FWD(t2);
}
};
// there's no standard minus_equal functional, so roll an ad hoc one here
struct minus_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) -= THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) -= THRUST_FWD(t2))
{
return THRUST_FWD(t1) -= THRUST_FWD(t2);
}
};
// there's no standard multiplies_equal functional, so roll an ad hoc one here
struct multiplies_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) *= THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) *= THRUST_FWD(t2))
{
return THRUST_FWD(t1) *= THRUST_FWD(t2);
}
};
// there's no standard divides_equal functional, so roll an ad hoc one here
struct divides_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) /= THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) /= THRUST_FWD(t2))
{
return THRUST_FWD(t1) /= THRUST_FWD(t2);
}
};
// there's no standard modulus_equal functional, so roll an ad hoc one here
struct modulus_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) %= THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) %= THRUST_FWD(t2))
{
return THRUST_FWD(t1) %= THRUST_FWD(t2);
}
};
// there's no standard bit_and_equal functional, so roll an ad hoc one here
struct bit_and_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) &= THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) &= THRUST_FWD(t2))
{
return THRUST_FWD(t1) &= THRUST_FWD(t2);
}
};
// there's no standard bit_or_equal functional, so roll an ad hoc one here
struct bit_or_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) |= THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) |= THRUST_FWD(t2))
{
return THRUST_FWD(t1) |= THRUST_FWD(t2);
}
};
// there's no standard bit_xor_equal functional, so roll an ad hoc one here
struct bit_xor_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) ^= THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) ^= THRUST_FWD(t2))
{
return THRUST_FWD(t1) ^= THRUST_FWD(t2);
}
};
// there's no standard bit_lshift_equal functional, so roll an ad hoc one here
struct bit_lshift_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) <<= THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) <<= THRUST_FWD(t2))
{
return THRUST_FWD(t1) <<= THRUST_FWD(t2);
}
};
// there's no standard bit_rshift_equal functional, so roll an ad hoc one here
struct bit_rshift_equal
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) >>= THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) >>= THRUST_FWD(t2))
{
return THRUST_FWD(t1) >>= THRUST_FWD(t2);
}
};
// there's no standard bit_lshift functional, so roll an ad hoc one here
struct bit_lshift
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) << THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) << THRUST_FWD(t2))
{
return THRUST_FWD(t1) << THRUST_FWD(t2);
}
};
// there's no standard bit_rshift functional, so roll an ad hoc one here
struct bit_rshift
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1& t1, T2&& t2) const
noexcept(noexcept(THRUST_FWD(t1) >> THRUST_FWD(t2))) -> decltype(THRUST_FWD(t1) >> THRUST_FWD(t2))
{
return THRUST_FWD(t1) >> THRUST_FWD(t2);
}
};
#define MAKE_BINARY_COMPOSITE(op, functor) \
template <typename A, typename B, ::cuda::std::enable_if_t<is_actor<A>::value || is_actor<B>::value, int> = 0> \
_CCCL_HOST_DEVICE auto operator op(const A& a, const B& b)->decltype(compose(functor{}, a, b)) \
{ \
return compose(functor{}, a, b); \
}
MAKE_BINARY_COMPOSITE(==, ::cuda::std::equal_to<>)
MAKE_BINARY_COMPOSITE(!=, ::cuda::std::not_equal_to<>)
MAKE_BINARY_COMPOSITE(<, ::cuda::std::less<>)
MAKE_BINARY_COMPOSITE(<=, ::cuda::std::less_equal<>)
MAKE_BINARY_COMPOSITE(>, ::cuda::std::greater<>)
MAKE_BINARY_COMPOSITE(>=, ::cuda::std::greater_equal<>)
MAKE_BINARY_COMPOSITE(+, ::cuda::std::plus<>)
MAKE_BINARY_COMPOSITE(-, ::cuda::std::minus<>)
MAKE_BINARY_COMPOSITE(*, ::cuda::std::multiplies<>)
MAKE_BINARY_COMPOSITE(/, ::cuda::std::divides<>)
MAKE_BINARY_COMPOSITE(%, ::cuda::std::modulus<>)
MAKE_BINARY_COMPOSITE(+=, plus_equal)
MAKE_BINARY_COMPOSITE(-=, minus_equal)
MAKE_BINARY_COMPOSITE(*=, multiplies_equal)
MAKE_BINARY_COMPOSITE(/=, divides_equal)
MAKE_BINARY_COMPOSITE(%=, modulus_equal)
MAKE_BINARY_COMPOSITE(&&, ::cuda::std::logical_and<>)
MAKE_BINARY_COMPOSITE(||, ::cuda::std::logical_or<>)
MAKE_BINARY_COMPOSITE(&, ::cuda::std::bit_and<>)
MAKE_BINARY_COMPOSITE(|, ::cuda::std::bit_or<>)
MAKE_BINARY_COMPOSITE(^, ::cuda::std::bit_xor<>)
MAKE_BINARY_COMPOSITE(<<, bit_lshift)
MAKE_BINARY_COMPOSITE(>>, bit_rshift)
MAKE_BINARY_COMPOSITE(&=, bit_and_equal)
MAKE_BINARY_COMPOSITE(|=, bit_or_equal)
MAKE_BINARY_COMPOSITE(^=, bit_xor_equal)
MAKE_BINARY_COMPOSITE(<<=, bit_lshift_equal)
MAKE_BINARY_COMPOSITE(>>=, bit_rshift_equal)
#undef MAKE_BINARY_COMPOSITE
// there's no standard unary_plus functional, so roll an ad hoc one here
struct unary_plus
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1) const noexcept(noexcept(+THRUST_FWD(t1)))
-> decltype(+THRUST_FWD(t1))
{
return +THRUST_FWD(t1);
}
};
// there's no standard prefix_increment functional, so roll an ad hoc one here
struct prefix_increment
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1) const noexcept(noexcept(++THRUST_FWD(t1)))
-> decltype(++THRUST_FWD(t1))
{
return ++THRUST_FWD(t1);
}
}; // end prefix_increment
// there's no standard postfix_increment functional, so roll an ad hoc one here
struct postfix_increment
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1) const noexcept(noexcept(THRUST_FWD(t1)++))
-> decltype(THRUST_FWD(t1)++)
{
return THRUST_FWD(t1)++;
}
}; // end postfix_increment
// there's no standard prefix_decrement functional, so roll an ad hoc one here
struct prefix_decrement
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1) const noexcept(noexcept(--THRUST_FWD(t1)))
-> decltype(--THRUST_FWD(t1))
{
return --THRUST_FWD(t1);
}
}; // end prefix_decrement
// there's no standard postfix_decrement functional, so roll an ad hoc one here
struct postfix_decrement
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1) const noexcept(noexcept(THRUST_FWD(t1)--))
-> decltype(THRUST_FWD(t1)--)
{
return THRUST_FWD(t1)--;
}
}; // end prefix_increment
// there's no standard bit_not functional, so roll an ad hoc one here
struct bit_not
{
using is_transparent = void;
_CCCL_EXEC_CHECK_DISABLE
template <typename T1>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1) const noexcept(noexcept(~THRUST_FWD(t1)))
-> decltype(~THRUST_FWD(t1))
{
return ~THRUST_FWD(t1);
}
}; // end prefix_increment
#define MAKE_UNARY_COMPOSITE(op, functor) \
template <typename A, ::cuda::std::enable_if_t<is_actor<A>::value, int> = 0> \
_CCCL_HOST_DEVICE auto operator op(const A& a)->decltype(compose(functor{}, a)) \
{ \
return compose(functor{}, a); \
}
MAKE_UNARY_COMPOSITE(+, unary_plus)
MAKE_UNARY_COMPOSITE(-, ::cuda::std::negate<>)
MAKE_UNARY_COMPOSITE(++, prefix_increment)
MAKE_UNARY_COMPOSITE(--, prefix_decrement)
MAKE_UNARY_COMPOSITE(!, ::cuda::std::logical_not<>)
MAKE_UNARY_COMPOSITE(~, bit_not)
#undef MAKE_UNARY_COMPOSITE
#define MAKE_UNARY_COMPOSITE_POSTFIX(op, functor) \
template <typename A, ::cuda::std::enable_if_t<is_actor<A>::value, int> = 0> \
_CCCL_HOST_DEVICE auto operator op(const A& a, int)->decltype(compose(functor{}, a)) \
{ \
return compose(functor{}, a); \
}
MAKE_UNARY_COMPOSITE_POSTFIX(++, postfix_increment)
MAKE_UNARY_COMPOSITE_POSTFIX(--, postfix_decrement)
#undef MAKE_UNARY_COMPOSITE_POSTFIX
// there's no standard assign functional, so roll an ad hoc one here
struct assign
{
_CCCL_EXEC_CHECK_DISABLE
template <typename T1, typename T2>
_CCCL_HOST_DEVICE constexpr auto operator()(T1&& t1, T2&& t2) const
THRUST_DECLTYPE_RETURNS(THRUST_FWD(t1) = THRUST_FWD(t2))
};
template <typename Eval, typename T>
_CCCL_HOST_DEVICE auto do_assign(const actor<Eval>& _1, const T& _2) -> decltype(compose(assign{}, _1, _2))
{
return compose(assign{}, _1, _2);
}
} // namespace detail::functional
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/nvtx_policy.h>
#include <thrust/generate.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/generate.h>
#include <thrust/system/detail/sequential/generate.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(generate.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(generate.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/generate.h>
# include <thrust/system/cuda/detail/generate.h>
# include <thrust/system/omp/detail/generate.h>
# include <thrust/system/tbb/detail/generate.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename Generator>
_CCCL_HOST_DEVICE void
generate(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
Generator gen)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "thrust::generate");
using thrust::system::detail::generic::generate;
return generate(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, gen);
} // end generate()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename OutputIterator, typename Size, typename Generator>
_CCCL_HOST_DEVICE OutputIterator generate_n(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, OutputIterator first, Size n, Generator gen)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "thrust::generate_n");
using thrust::system::detail::generic::generate_n;
return generate_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, gen);
} // end generate_n()
template <typename ForwardIterator, typename Generator>
void generate(ForwardIterator first, ForwardIterator last, Generator gen)
{
using System = typename thrust::iterator_system<ForwardIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<System>(), "thrust::generate");
using thrust::system::detail::generic::select_system;
System system;
return thrust::generate(select_system(system), first, last, gen);
} // end generate()
template <typename OutputIterator, typename Size, typename Generator>
OutputIterator generate_n(OutputIterator first, Size n, Generator gen)
{
using System = typename thrust::iterator_system<OutputIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<System>(), "thrust::generate_n");
using thrust::system::detail::generic::select_system;
System system;
return thrust::generate_n(select_system(system), first, n, gen);
} // end generate_n()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2016, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/execution_policy.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/memory.h> // for get_value()
#include <cuda/std/__memory/pointer_traits.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
// get_iterator_value specialization on iterators
// --------------------------------------------------
// it is okay to dereference iterator in the usual way
template <typename DerivedPolicy, typename Iterator>
_CCCL_HOST_DEVICE it_value_t<Iterator> get_iterator_value(thrust::execution_policy<DerivedPolicy>&, Iterator it)
{
return *it;
} // get_iterator_value(exec,Iterator);
// get_iterator_value specialization on pointer
// ----------------------------------------------
// we can't just dereference a pointer in the usual way, because
// it may point to a location in the device memory.
// we use get_value(exec,pointer*) function
// to perform a dereferencing consistent with the execution policy
template <typename DerivedPolicy, typename Pointer>
_CCCL_HOST_DEVICE typename ::cuda::std::pointer_traits<Pointer*>::element_type
get_iterator_value(thrust::execution_policy<DerivedPolicy>& exec, Pointer* ptr)
{
return get_value(derived_cast(exec), ptr);
} // get_iterator_value(exec,Pointer*)
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,304 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file internal_functional.inl
* \brief Non-public functionals used to implement algorithm internals.
*/
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/raw_reference_cast.h>
#include <thrust/detail/static_assert.h>
#include <thrust/detail/type_traits.h>
#include <thrust/iterator/detail/tuple_of_iterator_references.h>
#include <thrust/iterator/iterator_traits.h>
#include <cuda/__functional/address_stability.h>
#include <cuda/__functional/equal_to_value.h>
#include <cuda/__iterator/discard_iterator.h>
#include <cuda/__iterator/tabulate_output_iterator.h>
#include <cuda/__iterator/transform_input_output_iterator.h>
#include <cuda/__iterator/transform_output_iterator.h>
#include <cuda/std/__host_stdlib/memory>
#include <cuda/std/__new/device_new.h>
#include <cuda/std/__tuple_dir/get.h>
#include <cuda/std/__tuple_dir/tuple_element.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_const.h>
#include <cuda/std/__type_traits/is_convertible.h>
#include <cuda/std/__type_traits/is_reference.h>
#include <cuda/std/__type_traits/type_identity.h>
#include <cuda/std/tuple>
THRUST_NAMESPACE_BEGIN
namespace detail
{
// convert a predicate to a 0 or 1 integral value
template <typename Predicate, typename IntegralType>
struct predicate_to_integral
{
Predicate pred;
template <typename T>
_CCCL_HOST_DEVICE IntegralType operator()(const T& x)
{
return pred(x) ? IntegralType(1) : IntegralType(0);
}
};
template <typename Predicate>
struct tuple_binary_predicate
{
template <typename Tuple>
_CCCL_HOST_DEVICE bool operator()(const Tuple& t) const
{
return pred(::cuda::std::get<0>(t), ::cuda::std::get<1>(t));
}
mutable Predicate pred;
};
template <class Predicate, class NewType, class OutputType>
struct new_value_if_f
{
Predicate pred;
NewType new_value;
template <class T>
_CCCL_DEVICE_API OutputType operator()(T const& x)
{
return pred(x) ? new_value : x;
}
template <class T, class P>
_CCCL_DEVICE_API OutputType operator()(T const& x, P const& y)
{
return pred(y) ? new_value : x;
}
};
// We need to mark proxy iterators as such
template <>
inline constexpr bool is_proxy_reference_v<::cuda::discard_iterator::__discard_proxy> = true;
template <class Fn, class Index>
inline constexpr bool is_proxy_reference_v<::cuda::__tabulate_proxy<Fn, Index>> = true;
template <class Iter, class Fn>
inline constexpr bool is_proxy_reference_v<::cuda::__transform_output_proxy<Iter, Fn>> = true;
template <class Iter, class InputFn, class OutputFn>
inline constexpr bool is_proxy_reference_v<::cuda::__transform_input_output_proxy<Iter, InputFn, OutputFn>> = true;
template <typename T>
inline constexpr bool is_non_const_reference_v =
!::cuda::std::is_const_v<T> && (::cuda::std::is_reference_v<T> || detail::is_proxy_reference_v<T>);
template <typename T>
inline constexpr bool is_tuple_of_iterator_references_v = false;
template <typename... Ts>
inline constexpr bool is_tuple_of_iterator_references_v<tuple_of_iterator_references<Ts...>> = true;
// use this enable_if to avoid assigning to temporaries in the transform functors below
// XXX revisit this problem with c++11 perfect forwarding
template <typename T>
using enable_if_assignable_ref =
::cuda::std::enable_if_t<is_non_const_reference_v<T> || is_tuple_of_iterator_references_v<T>, int>;
template <typename UnaryFunction>
struct unary_transform_functor
{
UnaryFunction f;
_CCCL_EXEC_CHECK_DISABLE
template <typename Tuple, enable_if_assignable_ref<::cuda::std::tuple_element_t<1, Tuple>> = 0>
_CCCL_HOST_DEVICE void operator()(Tuple t)
{
::cuda::std::get<1>(t) = f(::cuda::std::get<0>(t));
}
};
template <typename BinaryFunction>
struct binary_transform_functor
{
BinaryFunction f;
_CCCL_EXEC_CHECK_DISABLE
template <typename Tuple, enable_if_assignable_ref<::cuda::std::tuple_element_t<2, Tuple>> = 0>
_CCCL_HOST_DEVICE void operator()(Tuple t)
{
::cuda::std::get<2>(t) = f(::cuda::std::get<0>(t), ::cuda::std::get<1>(t));
}
};
template <typename UnaryFunction, typename Predicate>
struct unary_transform_if_functor
{
UnaryFunction unary_op;
Predicate pred;
_CCCL_EXEC_CHECK_DISABLE
template <typename Tuple, enable_if_assignable_ref<::cuda::std::tuple_element_t<1, Tuple>> = 0>
_CCCL_HOST_DEVICE void operator()(Tuple t)
{
if (pred(::cuda::std::get<0>(t)))
{
::cuda::std::get<1>(t) = unary_op(::cuda::std::get<0>(t));
}
}
}; // end unary_transform_if_functor
template <typename UnaryFunction, typename Predicate>
struct unary_transform_if_with_stencil_functor
{
UnaryFunction unary_op;
Predicate pred;
_CCCL_EXEC_CHECK_DISABLE
template <typename Tuple, enable_if_assignable_ref<::cuda::std::tuple_element_t<2, Tuple>> = 0>
_CCCL_HOST_DEVICE void operator()(Tuple t)
{
if (pred(::cuda::std::get<1>(t)))
{
::cuda::std::get<2>(t) = unary_op(::cuda::std::get<0>(t));
}
}
}; // end unary_transform_if_with_stencil_functor
template <typename BinaryFunction, typename Predicate>
struct binary_transform_if_functor
{
BinaryFunction binary_op;
Predicate pred;
_CCCL_EXEC_CHECK_DISABLE
template <typename Tuple, enable_if_assignable_ref<::cuda::std::tuple_element_t<3, Tuple>> = 0>
_CCCL_HOST_DEVICE void operator()(Tuple t)
{
if (pred(::cuda::std::get<2>(t)))
{
::cuda::std::get<3>(t) = binary_op(::cuda::std::get<0>(t), ::cuda::std::get<1>(t));
}
}
}; // end binary_transform_if_functor
template <typename T>
struct host_destroy_functor
{
_CCCL_HOST void operator()(T& x) const
{
x.~T();
} // end operator()()
}; // end host_destroy_functor
template <typename T>
struct device_destroy_functor
{
// add __host__ to allow the omp backend to compile with nvcc
_CCCL_HOST_DEVICE void operator()(T& x) const
{
x.~T();
} // end operator()()
}; // end device_destroy_functor
template <typename System, typename T>
struct destroy_functor
: thrust::detail::eval_if<::cuda::std::is_convertible_v<System, thrust::host_system_tag>,
::cuda::std::type_identity<host_destroy_functor<T>>,
::cuda::std::type_identity<device_destroy_functor<T>>>
{};
template <typename T>
struct fill_functor
{
T exemplar;
// explicit declaration is needed to avoid an exec check warning
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE fill_functor(const T& _exemplar)
: exemplar(_exemplar)
{}
// explicit declaration is needed to avoid an exec check warning
_CCCL_EXEC_CHECK_DISABLE
fill_functor(const fill_functor& other) = default;
// explicit declaration is needed to avoid an exec check warning
_CCCL_EXEC_CHECK_DISABLE
~fill_functor() = default;
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE T operator()() const
{
return exemplar;
}
};
template <typename T>
struct uninitialized_fill_functor
{
T exemplar;
// explicit declaration is needed to avoid an exec check warning
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE uninitialized_fill_functor(const T& x)
: exemplar(x)
{}
// explicit declaration is needed to avoid an exec check warning
_CCCL_EXEC_CHECK_DISABLE
uninitialized_fill_functor(const uninitialized_fill_functor& other) = default;
// explicit declaration is needed to avoid an exec check warning
_CCCL_EXEC_CHECK_DISABLE
~uninitialized_fill_functor() = default;
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE void operator()(T& x)
{
::new (static_cast<void*>(&x)) T(exemplar);
} // end operator()()
}; // end uninitialized_fill_functor
template <typename Compare>
struct compare_first
{
Compare comp;
template <typename Tuple1, typename Tuple2>
_CCCL_HOST_DEVICE bool operator()(const Tuple1& x, const Tuple2& y)
{
return comp(thrust::raw_reference_cast(::cuda::std::get<0>(x)), thrust::raw_reference_cast(::cuda::std::get<0>(y)));
}
}; // end compare_first
} // end namespace detail
THRUST_NAMESPACE_END
_CCCL_BEGIN_NAMESPACE_CUDA
template <typename Predicate, typename IntegralType>
struct proclaims_copyable_arguments<THRUST_NS_QUALIFIER::detail::predicate_to_integral<Predicate, IntegralType>>
: proclaims_copyable_arguments<Predicate>
{};
template <typename Predicate>
struct proclaims_copyable_arguments<THRUST_NS_QUALIFIER::detail::tuple_binary_predicate<Predicate>>
: proclaims_copyable_arguments<Predicate>
{};
template <class Predicate, class NewType, class OutputType>
struct proclaims_copyable_arguments<THRUST_NS_QUALIFIER::detail::new_value_if_f<Predicate, NewType, OutputType>>
: proclaims_copyable_arguments<Predicate>
{};
_CCCL_END_NAMESPACE_CUDA

View File

@@ -0,0 +1,76 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/execution_policy.h>
#include <thrust/detail/malloc_and_free_fwd.h>
#include <thrust/detail/pointer.h>
#include <thrust/detail/raw_pointer_cast.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/memory.h>
#include <thrust/system/detail/sequential/malloc_and_free.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(malloc_and_free.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(malloc_and_free.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/malloc_and_free.h>
# include <thrust/system/cuda/detail/malloc_and_free.h>
# include <thrust/system/omp/detail/malloc_and_free.h>
# include <thrust/system/tbb/detail/malloc_and_free.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy>
_CCCL_HOST_DEVICE pointer<void, DerivedPolicy>
malloc(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, std::size_t n)
{
using thrust::system::detail::generic::malloc;
// XXX should use a hypothetical thrust::static_pointer_cast here
void* raw_ptr = static_cast<void*>(
thrust::raw_pointer_cast(malloc(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), n)));
return pointer<void, DerivedPolicy>(raw_ptr);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename T, typename DerivedPolicy>
_CCCL_HOST_DEVICE pointer<T, DerivedPolicy>
malloc(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, std::size_t n)
{
using thrust::system::detail::generic::malloc;
T* raw_ptr = static_cast<T*>(
thrust::raw_pointer_cast(malloc<T>(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), n)));
return pointer<T, DerivedPolicy>(raw_ptr);
}
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename Pointer>
_CCCL_HOST_DEVICE void free(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, Pointer ptr)
{
using thrust::system::detail::generic::free;
free(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), ptr);
}
// XXX consider another form of free which does not take a system argument and
// instead infers the system from the pointer
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2024, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/execution_policy.h>
#include <thrust/detail/pointer.h>
THRUST_NAMESPACE_BEGIN
template <typename DerivedPolicy>
_CCCL_HOST_DEVICE pointer<void, DerivedPolicy>
malloc(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, std::size_t n);
template <typename T, typename DerivedPolicy>
_CCCL_HOST_DEVICE pointer<T, DerivedPolicy>
malloc(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, std::size_t n);
template <typename DerivedPolicy, typename Pointer>
_CCCL_HOST_DEVICE void free(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, Pointer ptr);
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,275 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/merge.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/merge.h>
#include <thrust/system/detail/sequential/merge.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(merge.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(merge.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/merge.h>
# include <thrust/system/cuda/detail/merge.h>
# include <thrust/system/omp/detail/merge.h>
# include <thrust/system/tbb/detail/merge.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator merge(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::merge");
using thrust::system::detail::generic::merge;
return merge(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result);
} // end merge()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename StrictWeakCompare>
_CCCL_HOST_DEVICE OutputIterator merge(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2,
OutputIterator result,
StrictWeakCompare comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::merge");
using thrust::system::detail::generic::merge;
return merge(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, result, comp);
} // end merge()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename InputIterator3,
typename InputIterator4,
typename OutputIterator1,
typename OutputIterator2>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> merge_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 keys_first1,
InputIterator1 keys_last1,
InputIterator2 keys_first2,
InputIterator2 keys_last2,
InputIterator3 values_first1,
InputIterator4 values_first2,
OutputIterator1 keys_result,
OutputIterator2 values_result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::merge_by_key");
using thrust::system::detail::generic::merge_by_key;
return merge_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
keys_first1,
keys_last1,
keys_first2,
keys_last2,
values_first1,
values_first2,
keys_result,
values_result);
} // end merge_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename InputIterator3,
typename InputIterator4,
typename OutputIterator1,
typename OutputIterator2,
typename Compare>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> merge_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 keys_first1,
InputIterator1 keys_last1,
InputIterator2 keys_first2,
InputIterator2 keys_last2,
InputIterator3 values_first1,
InputIterator4 values_first2,
OutputIterator1 keys_result,
OutputIterator2 values_result,
Compare comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::merge_by_key");
using thrust::system::detail::generic::merge_by_key;
return merge_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
keys_first1,
keys_last1,
keys_first2,
keys_last2,
values_first1,
values_first2,
keys_result,
values_result,
comp);
} // end merge_by_key()
template <typename InputIterator1, typename InputIterator2, typename OutputIterator, typename StrictWeakOrdering>
OutputIterator
merge(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2,
OutputIterator result,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::merge");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::merge(select_system(system1, system2, system3), first1, last1, first2, last2, result, comp);
} // end merge()
template <typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator
merge(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::merge");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::merge(select_system(system1, system2, system3), first1, last1, first2, last2, result);
} // end merge()
template <typename InputIterator1,
typename InputIterator2,
typename InputIterator3,
typename InputIterator4,
typename OutputIterator1,
typename OutputIterator2,
typename StrictWeakOrdering>
::cuda::std::pair<OutputIterator1, OutputIterator2> merge_by_key(
InputIterator1 keys_first1,
InputIterator1 keys_last1,
InputIterator2 keys_first2,
InputIterator2 keys_last2,
InputIterator3 values_first1,
InputIterator4 values_first2,
OutputIterator1 keys_result,
OutputIterator2 values_result,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::merge_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<InputIterator3>::type;
using System4 = typename thrust::iterator_system<InputIterator4>::type;
using System5 = typename thrust::iterator_system<OutputIterator1>::type;
using System6 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
System5 system5;
System6 system6;
return thrust::merge_by_key(
select_system(system1, system2, system3, system4, system5, system6),
keys_first1,
keys_last1,
keys_first2,
keys_last2,
values_first1,
values_first2,
keys_result,
values_result,
comp);
} // end merge_by_key()
template <typename InputIterator1,
typename InputIterator2,
typename InputIterator3,
typename InputIterator4,
typename OutputIterator1,
typename OutputIterator2>
::cuda::std::pair<OutputIterator1, OutputIterator2> merge_by_key(
InputIterator1 keys_first1,
InputIterator1 keys_last1,
InputIterator2 keys_first2,
InputIterator2 keys_last2,
InputIterator3 values_first1,
InputIterator4 values_first2,
OutputIterator1 keys_result,
OutputIterator2 values_result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::merge_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<InputIterator3>::type;
using System4 = typename thrust::iterator_system<InputIterator4>::type;
using System5 = typename thrust::iterator_system<OutputIterator1>::type;
using System6 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
System5 system5;
System6 system6;
return thrust::merge_by_key(
select_system(system1, system2, system3, system4, system5, system6),
keys_first1,
keys_last1,
keys_first2,
keys_last2,
values_first1,
values_first2,
keys_result,
values_result);
} // end merge_by_key()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,155 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/mismatch.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/mismatch.h>
#include <thrust/system/detail/sequential/mismatch.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(mismatch.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(mismatch.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/mismatch.h>
# include <thrust/system/cuda/detail/mismatch.h>
# include <thrust/system/omp/detail/mismatch.h>
# include <thrust/system/tbb/detail/mismatch.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2>
_CCCL_HOST_DEVICE ::cuda::std::pair<InputIterator1, InputIterator2>
mismatch(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::mismatch");
using thrust::system::detail::generic::mismatch;
return mismatch(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2);
} // end mismatch()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<InputIterator1, InputIterator2> mismatch(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
BinaryPredicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::mismatch");
using thrust::system::detail::generic::mismatch;
return mismatch(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, pred);
} // end mismatch()
template <typename InputIterator1, typename InputIterator2>
::cuda::std::pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::mismatch");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
System1 system1;
System2 system2;
return thrust::mismatch(select_system(system1, system2), first1, last1, first2);
} // end mismatch()
template <typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
::cuda::std::pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::mismatch");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
System1 system1;
System2 system2;
return thrust::mismatch(select_system(system1, system2), first1, last1, first2, pred);
} // end mismatch()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2>
_CCCL_HOST_DEVICE ::cuda::std::pair<InputIterator1, InputIterator2> mismatch(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::mismatch");
using thrust::system::detail::generic::mismatch;
return mismatch(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2);
} // end mismatch()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<InputIterator1, InputIterator2> mismatch(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2,
BinaryPredicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::mismatch");
using thrust::system::detail::generic::mismatch;
return mismatch(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, last2, pred);
} // end mismatch()
template <typename InputIterator1, typename InputIterator2>
::cuda::std::pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::mismatch");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
System1 system1;
System2 system2;
return thrust::mismatch(select_system(system1, system2), first1, last1, first2, last2);
} // end mismatch()
template <typename InputIterator1, typename InputIterator2, typename BinaryPredicate>
::cuda::std::pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::mismatch");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
System1 system1;
System2 system2;
return thrust::mismatch(select_system(system1, system2), first1, last1, first2, last2, pred);
} // end mismatch()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <cuda/std/__type_traits/decay.h>
#include <cuda/std/__type_traits/is_base_of.h>
THRUST_NAMESPACE_BEGIN
// Forward declarations
namespace system::detail::sequential
{
template <class>
struct execution_policy;
} // namespace system::detail::sequential
namespace detail
{
// Helper to determine if NVTX should be enabled for a given policy
// NVTX is DISABLED only for thrust::seq and any policy derived from sequential::execution_policy
// ENABLED for all other policies (CUDA, OMP, TBB, etc.)
template <typename DerivedPolicy>
inline constexpr bool should_enable_nvtx_for_policy()
{
using Policy = ::cuda::std::decay_t<DerivedPolicy>;
// This catches thrust::seq, cpp::tag, and any other sequential-based policy
return !::cuda::std::is_base_of_v<thrust::system::detail::sequential::execution_policy<Policy>, Policy>;
}
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,107 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/copy.h>
#include <thrust/detail/temporary_array.h>
#include <thrust/iterator/detail/minimum_system.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/cpp/detail/execution_policy.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename InputIterator, typename OutputIterator>
OutputIterator sequential_copy(InputIterator first, InputIterator last, OutputIterator result)
{
for (; first != last; ++first, ++result)
{
*result = *first;
} // end for
return result;
} // end sequential_copy()
template <typename BidirectionalIterator1, typename BidirectionalIterator2>
BidirectionalIterator2
sequential_copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result)
{
// yes, we preincrement
// the ranges are open on the right, i.e. [first, last)
while (first != last)
{
*--result = *--last;
} // end while
return result;
} // end sequential_copy_backward()
namespace dispatch
{
template <typename DerivedPolicy, typename RandomAccessIterator1, typename RandomAccessIterator2>
RandomAccessIterator2 overlapped_copy(
cpp::execution_policy<DerivedPolicy>&,
RandomAccessIterator1 first,
RandomAccessIterator1 last,
RandomAccessIterator2 result)
{
if (first < last && first <= result && result < last)
{
// result lies in [first, last)
// it's safe to use std::copy_backward here
thrust::detail::sequential_copy_backward(first, last, result + (last - first));
result += (last - first);
} // end if
else
{
// result + (last - first) lies in [first, last)
// it's safe to use sequential_copy here
result = thrust::detail::sequential_copy(first, last, result);
} // end else
return result;
} // end overlapped_copy()
template <typename DerivedPolicy, typename RandomAccessIterator1, typename RandomAccessIterator2>
RandomAccessIterator2 overlapped_copy(
thrust::execution_policy<DerivedPolicy>& exec,
RandomAccessIterator1 first,
RandomAccessIterator1 last,
RandomAccessIterator2 result)
{
using value_type = thrust::detail::it_value_t<RandomAccessIterator1>;
// make a temporary copy of [first,last), and copy into it first
thrust::detail::temporary_array<value_type, DerivedPolicy> temp(exec, first, last);
return thrust::copy(exec, temp.begin(), temp.end(), result);
} // end overlapped_copy()
} // namespace dispatch
template <typename RandomAccessIterator1, typename RandomAccessIterator2>
RandomAccessIterator2
overlapped_copy(RandomAccessIterator1 first, RandomAccessIterator1 last, RandomAccessIterator2 result)
{
using System1 = typename thrust::iterator_system<RandomAccessIterator2>::type;
using System2 = typename thrust::iterator_system<RandomAccessIterator2>::type;
using System = minimum_system_t<System1, System2>;
// XXX presumes System is default constructible
System system;
return thrust::detail::dispatch::overlapped_copy(system, first, last, result);
} // end overlapped_copy()
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,377 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/partition.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/partition.h>
#include <thrust/system/detail/sequential/partition.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(partition.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(partition.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/partition.h>
# include <thrust/system/cuda/detail/partition.h>
# include <thrust/system/omp/detail/partition.h>
# include <thrust/system/tbb/detail/partition.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename Predicate>
_CCCL_HOST_DEVICE ForwardIterator partition(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition");
using thrust::system::detail::generic::partition;
return partition(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred);
} // end partition()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE ForwardIterator partition(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator stencil,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition");
using thrust::system::detail::generic::partition;
return partition(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, pred);
} // end partition()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator,
typename OutputIterator1,
typename OutputIterator2,
typename Predicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> partition_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator1 out_true,
OutputIterator2 out_false,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition_copy");
using thrust::system::detail::generic::partition_copy;
return partition_copy(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, out_true, out_false, pred);
} // end partition_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename Predicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> partition_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first,
InputIterator1 last,
InputIterator2 stencil,
OutputIterator1 out_true,
OutputIterator2 out_false,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition_copy");
using thrust::system::detail::generic::partition_copy;
return partition_copy(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, out_true, out_false, pred);
} // end partition_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename Predicate>
_CCCL_HOST_DEVICE ForwardIterator stable_partition(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_partition");
using thrust::system::detail::generic::stable_partition;
return stable_partition(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred);
} // end stable_partition()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE ForwardIterator stable_partition(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator stencil,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_partition");
using thrust::system::detail::generic::stable_partition;
return stable_partition(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, pred);
} // end stable_partition()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator,
typename OutputIterator1,
typename OutputIterator2,
typename Predicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> stable_partition_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator1 out_true,
OutputIterator2 out_false,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_partition_copy");
using thrust::system::detail::generic::stable_partition_copy;
return stable_partition_copy(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, out_true, out_false, pred);
} // end stable_partition_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename Predicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> stable_partition_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first,
InputIterator1 last,
InputIterator2 stencil,
OutputIterator1 out_true,
OutputIterator2 out_false,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_partition_copy");
using thrust::system::detail::generic::stable_partition_copy;
return stable_partition_copy(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, out_true, out_false, pred);
} // end stable_partition_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename Predicate>
_CCCL_HOST_DEVICE ForwardIterator partition_point(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition_point");
using thrust::system::detail::generic::partition_point;
return partition_point(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred);
} // end partition_point()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE bool is_partitioned(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_partitioned");
using thrust::system::detail::generic::is_partitioned;
return is_partitioned(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred);
} // end is_partitioned()
template <typename ForwardIterator, typename Predicate>
ForwardIterator partition(ForwardIterator first, ForwardIterator last, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::partition(select_system(system), first, last, pred);
} // end partition()
template <typename ForwardIterator, typename InputIterator, typename Predicate>
ForwardIterator partition(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
System1 system1;
System2 system2;
return thrust::partition(select_system(system1, system2), first, last, stencil, pred);
} // end partition()
template <typename ForwardIterator, typename Predicate>
ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_partition");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::stable_partition(select_system(system), first, last, pred);
} // end stable_partition()
template <typename ForwardIterator, typename InputIterator, typename Predicate>
ForwardIterator stable_partition(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_partition");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
System1 system1;
System2 system2;
return thrust::stable_partition(select_system(system1, system2), first, last, stencil, pred);
} // end stable_partition()
template <typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> partition_copy(
InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator1>::type;
using System3 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::partition_copy(select_system(system1, system2, system3), first, last, out_true, out_false, pred);
} // end partition_copy()
template <typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename Predicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> partition_copy(
InputIterator1 first,
InputIterator1 last,
InputIterator2 stencil,
OutputIterator1 out_true,
OutputIterator2 out_false,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator1>::type;
using System3 = typename thrust::iterator_system<OutputIterator1>::type;
using System4 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
return thrust::partition_copy(
select_system(system1, system2, system3, system4), first, last, stencil, out_true, out_false, pred);
} // end partition_copy()
template <typename InputIterator, typename OutputIterator1, typename OutputIterator2, typename Predicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> stable_partition_copy(
InputIterator first, InputIterator last, OutputIterator1 out_true, OutputIterator2 out_false, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_partition_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator1>::type;
using System3 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::stable_partition_copy(select_system(system1, system2, system3), first, last, out_true, out_false, pred);
} // end stable_partition_copy()
template <typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename Predicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> stable_partition_copy(
InputIterator1 first,
InputIterator1 last,
InputIterator2 stencil,
OutputIterator1 out_true,
OutputIterator2 out_false,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_partition_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator1>::type;
using System4 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
return thrust::stable_partition_copy(
select_system(system1, system2, system3, system4), first, last, stencil, out_true, out_false, pred);
} // end stable_partition_copy()
template <typename ForwardIterator, typename Predicate>
ForwardIterator partition_point(ForwardIterator first, ForwardIterator last, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::partition_point");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::partition_point(select_system(system), first, last, pred);
} // end partition_point()
template <typename InputIterator, typename Predicate>
bool is_partitioned(InputIterator first, InputIterator last, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_partitioned");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::is_partitioned(select_system(system), first, last, pred);
} // end is_partitioned()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,428 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2021, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file
* \brief A pointer to a variable which resides in memory associated with a
* system.
*/
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/reference_forward_declaration.h>
#include <thrust/detail/type_traits.h>
#include <thrust/detail/type_traits/pointer_traits.h>
#include <thrust/iterator/iterator_adaptor.h>
#include <thrust/iterator/iterator_traversal_tags.h>
#include <cuda/std/__host_stdlib/ostream>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__memory/addressof.h>
#include <cuda/std/__memory/pointer_traits.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_comparable.h>
#include <cuda/std/__type_traits/is_reference.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/is_void.h>
#include <cuda/std/__type_traits/remove_cv.h>
#include <cuda/std/__type_traits/remove_cvref.h>
#include <cuda/std/__type_traits/remove_pointer.h>
#include <cuda/std/__type_traits/type_identity.h>
#include <cuda/std/cstddef>
THRUST_NAMESPACE_BEGIN
template <typename Element, typename Tag, typename Reference = use_default, typename Derived = use_default>
class pointer;
THRUST_NAMESPACE_END
// Specialize `std::iterator_traits` (picked up by cuda::std::iterator_traits) to avoid problems with the name of
// pointer's constructor shadowing its nested pointer type. We do this before pointer is defined so the specialization
// is correctly used inside the definition.
template <typename Element, typename Tag, typename Reference, typename Derived>
struct std::iterator_traits<THRUST_NS_QUALIFIER::pointer<Element, Tag, Reference, Derived>>
{
using pointer = THRUST_NS_QUALIFIER::pointer<Element, Tag, Reference, Derived>;
using iterator_category = typename pointer::iterator_category;
using value_type = typename pointer::value_type;
using difference_type = typename pointer::difference_type;
using reference = typename pointer::reference;
};
THRUST_NAMESPACE_BEGIN
namespace detail
{
// this metafunction computes the type of iterator_adaptor thrust::pointer should inherit from
template <typename Element, typename Tag, typename Reference, typename Derived>
struct pointer_base
{
// void pointers should have no element type
// note that we remove_cv from the Element type to get the value_type
using value_type = typename eval_if<::cuda::std::is_void_v<::cuda::std::remove_cvref_t<Element>>,
::cuda::std::type_identity<void>,
::cuda::std::remove_cv<Element>>::type;
// if no Derived type is given, just use pointer
using derived_type =
typename eval_if<::cuda::std::is_same_v<Derived, use_default>,
::cuda::std::type_identity<pointer<Element, Tag, Reference, Derived>>,
::cuda::std::type_identity<Derived>>::type;
// void pointers should have no reference type
// if no Reference type is given, just use reference
using reference_type =
typename eval_if<::cuda::std::is_void_v<::cuda::std::remove_cvref_t<Element>>,
::cuda::std::type_identity<void>,
eval_if<::cuda::std::is_same_v<Reference, use_default>,
::cuda::std::type_identity<reference<Element, derived_type>>,
::cuda::std::type_identity<Reference>>>::type;
using type =
iterator_adaptor<derived_type, Element*, value_type, Tag, random_access_traversal_tag, reference_type, std::ptrdiff_t>;
};
} // namespace detail
/*! \addtogroup memory_management Memory Management
* \{
*/
// the base type for all of thrust's tagged pointers.
// for reasonable pointer-like semantics, derived types should reimplement the following:
// 1. no-argument constructor
// 2. constructor from OtherElement *
// 3. constructor from OtherPointer related by convertibility
// 4. constructor from OtherPointer to void
// 5. assignment from OtherPointer related by convertibility
// These should just call the corresponding members of pointer.
/*! \p pointer stores a pointer to an object allocated in memory. Like \p device_ptr, this
* type ensures type safety when dispatching standard algorithms on ranges resident in memory.
*
* \p pointer generalizes \p device_ptr by relaxing the backend system associated with the \p pointer.
* Instead of the backend system specified by \p THRUST_DEVICE_SYSTEM, \p pointer's
* system is given by its second template parameter, \p Tag. For the purpose of Thrust dispatch,
* <tt>device_ptr<Element></tt> and <tt>pointer<Element,device_system_tag></tt> are considered equivalent.
*
* The raw pointer encapsulated by a \p pointer may be obtained through its <tt>get</tt> member function
* or the \p raw_pointer_cast free function.
*
* \tparam Element specifies the type of the pointed-to object.
*
* \tparam Tag specifies the system with which this \p pointer is associated. This may be any Thrust
* backend system, or a user-defined tag.
*
* \tparam Reference allows the client to specify the reference type returned upon derereference.
* By default, this type is <tt>reference<Element,pointer></tt>.
*
* \tparam Derived allows the client to specify the name of the derived type when \p pointer is used as
* a base class. This is useful to ensure that arithmetic on values of the derived type return
* values of the derived type as a result. By default, this type is <tt>pointer<Element,Tag,Reference></tt>.
*
* \note \p pointer is not a smart pointer; it is the client's responsibility to deallocate memory
* pointer to by \p pointer.
*
* \see device_ptr
* \see reference
* \see raw_pointer_cast
*/
template <typename Element, typename Tag, typename Reference, typename Derived>
class pointer : public detail::pointer_base<Element, Tag, Reference, Derived>::type
{
private:
using super_t = typename detail::pointer_base<Element, Tag, Reference, Derived>::type;
using derived_type = typename detail::pointer_base<Element, Tag, Reference, Derived>::derived_type;
// friend iterator_core_access to give it access to dereference
friend class iterator_core_access;
template <typename SuperRef = typename super_t::reference>
_CCCL_HOST_DEVICE SuperRef dereference() const
{
const auto& derived_ptr = static_cast<const derived_type&>(*this);
if constexpr (::cuda::std::is_reference_v<SuperRef>)
{
// Implementation for dereference() when Reference is Element&, e.g. cuda's managed_memory_pointer
return *derived_ptr.get();
}
else
{
// Implementation for pointers with proxy references:
return SuperRef(derived_ptr);
}
}
// don't provide access to this part of super_t's interface
using super_t::base;
using typename super_t::base_type;
public:
/*! The type of the raw pointer
*/
using raw_pointer = typename super_t::base_type;
/*! \p pointer's default constructor initializes its encapsulated pointer to \c 0
*/
_CCCL_HOST_DEVICE pointer()
: super_t(static_cast<Element*>(nullptr))
{}
// NOTE: This is needed so that Thrust smart pointers can be used in `std::unique_ptr`.
_CCCL_HOST_DEVICE pointer(::cuda::std::nullptr_t)
: super_t(static_cast<Element*>(nullptr))
{}
/*! This constructor allows construction of a <tt>pointer<const T, ...></tt> from a <tt>T*</tt>.
*
* \param ptr A raw pointer to copy from, presumed to point to a location in \p Tag's memory.
* \tparam OtherElement \p OtherElement shall be convertible to \p Element.
*/
// XXX consider making the pointer implementation a template parameter which defaults to Element *
template <typename OtherElement>
_CCCL_HOST_DEVICE explicit pointer(OtherElement* ptr)
: super_t(ptr)
{}
/*! This constructor allows initialization from another pointer-like object.
*
* \param other The \p OtherPointer to copy.
*
* \tparam OtherPointer The tag associated with \p OtherPointer shall be convertible to \p Tag,
* and its element type shall be convertible to \p Element.
*/
template <typename OtherPointer, detail::enable_if_pointer_is_convertible_t<OtherPointer, pointer>* = nullptr>
_CCCL_HOST_DEVICE pointer(const OtherPointer& other)
: super_t(static_cast<Element*>(::cuda::std::to_address(other)))
{}
#ifndef _CCCL_DOXYGEN_INVOKED // Doxygen cannot handle this constructor and creates a duplicate ID with the ctor above
// OtherPointer's element_type shall be void
// OtherPointer's system shall be convertible to Tag
template <typename OtherPointer,
detail::enable_if_void_pointer_is_system_convertible_t<OtherPointer, pointer>* = nullptr>
_CCCL_HOST_DEVICE explicit pointer(const OtherPointer& other)
: super_t(static_cast<Element*>(::cuda::std::to_address(other)))
{}
#endif
// assignment
// NOTE: This is needed so that Thrust smart pointers can be used in `std::unique_ptr`.
_CCCL_HOST_DEVICE derived_type& operator=(::cuda::std::nullptr_t)
{
super_t::base_reference() = nullptr;
return static_cast<derived_type&>(*this);
}
/*! Assignment operator allows assigning from another pointer-like object whose element type
* is convertible to \c Element.
*
* \param other The other pointer-like object to assign from.
* \return <tt>*this</tt>
*
* \tparam OtherPointer The tag associated with \p OtherPointer shall be convertible to \p Tag,
* and its element type shall be convertible to \p Element.
*/
template <typename OtherPointer>
_CCCL_HOST_DEVICE detail::enable_if_pointer_is_convertible_t<OtherPointer, pointer, derived_type&>
operator=(const OtherPointer& other)
{
super_t::base_reference() = ::cuda::std::to_address(other);
return static_cast<derived_type&>(*this);
}
// observers
/*! \p get returns this \p pointer's encapsulated raw pointer.
* \return This \p pointer's raw pointer.
*/
_CCCL_HOST_DEVICE Element* get() const
{
return super_t::base();
}
_CCCL_HOST_DEVICE Element* operator->() const
{
return super_t::base();
}
// NOTE: This is needed so that Thrust smart pointers can be used in `std::unique_ptr`.
_CCCL_HOST_DEVICE explicit operator bool() const
{
return bool(get());
}
template <class T,
::cuda::std::enable_if_t<(::cuda::std::is_void_v<Element> || ::cuda::std::is_same_v<T, Element>), int> = 0>
_CCCL_HOST_DEVICE static derived_type pointer_to(T& r)
{
return static_cast<derived_type>(::cuda::std::addressof(r));
}
#if _CCCL_HOSTED()
template <typename charT, typename traits>
_CCCL_HOST friend std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const pointer& p)
{
return os << p.get();
}
#endif // _CCCL_HOSTED()
// NOTE: This is needed so that Thrust smart pointers can be used in `std::unique_ptr`.
_CCCL_HOST_DEVICE friend bool operator==(::cuda::std::nullptr_t, pointer p)
{
return nullptr == p.get();
}
_CCCL_HOST_DEVICE friend bool operator==(pointer p, ::cuda::std::nullptr_t)
{
return nullptr == p.get();
}
_CCCL_HOST_DEVICE friend bool operator!=(::cuda::std::nullptr_t, pointer p)
{
return !(nullptr == p);
}
_CCCL_HOST_DEVICE friend bool operator!=(pointer p, ::cuda::std::nullptr_t)
{
return !(nullptr == p);
}
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
detail::ptr_can_compare_equal<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool> operator==(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs)
{
return lhs.get() == rhs.get();
}
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
!detail::ptr_can_compare_equal<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator==(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
detail::ptr_can_compare_equal<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator!=(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs)
{
return !(lhs.get() == rhs.get());
}
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
!detail::ptr_can_compare_equal<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator!=(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
detail::ptr_can_compare_less_than<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator<(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs)
{
return lhs.get() < rhs.get();
}
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
!detail::ptr_can_compare_less_than<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator<(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
detail::ptr_can_compare_less_than<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator>=(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs)
{
return !(lhs.get() < rhs.get());
}
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
!detail::ptr_can_compare_less_than<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator>=(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
detail::ptr_can_compare_less_than<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator>(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs)
{
return rhs.get() < lhs.get();
}
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
!detail::ptr_can_compare_less_than<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator>(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
detail::ptr_can_compare_less_than<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator<=(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs)
{
return !(rhs.get() < lhs.get());
}
template <typename OtherElement, typename OtherTag, typename OtherReference, typename OtherDerived>
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<
!detail::ptr_can_compare_less_than<pointer, pointer<OtherElement, OtherTag, OtherReference, OtherDerived>>,
bool>
operator<=(pointer const& lhs, pointer<OtherElement, OtherTag, OtherReference, OtherDerived> const& rhs) = delete;
};
/*! \} // memory_management
*/
THRUST_NAMESPACE_END
_CCCL_BEGIN_NAMESPACE_CUDA_STD
// Specialize pointer traits for everything that has the raw_pointer alias
template <typename Pointer>
struct pointer_traits<Pointer, void_t<typename Pointer::raw_pointer>>
{
using pointer = Pointer;
using element_type = remove_pointer_t<typename Pointer::raw_pointer>;
using difference_type = ptrdiff_t;
template <typename U>
using rebind = typename THRUST_NS_QUALIFIER::detail::rebind_pointer<pointer, U>::type;
// Backwards compatibility with thrust::detail::pointer_traits
using raw_pointer = typename pointer::raw_pointer;
// Thrust historically provided a non-standard pointer_to for pointer<void>
template <class T, enable_if_t<(is_void_v<element_type> || is_same_v<T, element_type>), int> = 0>
[[nodiscard]] _CCCL_HOST_DEVICE_API inline static pointer
pointer_to(T& r) noexcept(noexcept(::cuda::std::addressof(r)))
{
return static_cast<element_type*>(::cuda::std::addressof(r));
}
//! @brief Retrieve the address of the element pointed at by an thrust pointer
//! @param iter A thrust::pointer
//! @return A pointer to the element pointed to by the thrust pointer
[[nodiscard]] _CCCL_HOST_DEVICE_API static constexpr raw_pointer to_address(const pointer iter) noexcept
{
return iter.get();
}
};
_CCCL_END_NAMESPACE_CUDA_STD

View File

@@ -0,0 +1,650 @@
// SPDX-FileCopyrightText: Copyright (c) 2017-2018, NVIDIA Corporation
// SPDX-FileCopyrightText: Copyright (c) 2014-2018, Bryce Adelstein Lelbach
// SPDX-FileCopyrightText: Copyright (c) 2001-2015, Housemarque Oy (housemarque.com)
// SPDX-FileCopyrightText: Copyright (c) 2007-2015, Hartmut Kaiser
// SPDX-FileCopyrightText: Copyright (c) 2002, Peter Dimov and Multi Media Ltd (`THRUST_CURRENT_FUNCTION`)
// SPDX-License-Identifier: BSL-1.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <cuda/std/__cccl/preprocessor.h>
///////////////////////////////////////////////////////////////////////////////
/// \def THRUST_PP_STRINGIZE(expr)
/// \brief Stringizes the expression \a expr.
///
/// \par <b>Example</b>:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << THRUST_PP_STRINGIZE(foo) << "\n";
/// }
/// \endcode
///
/// The above code expands to:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << "foo" << "\n";
/// }
/// \endcode
///
#define THRUST_PP_STRINGIZE(expr) THRUST_PP_STRINGIZE_IMPL0(expr)
#define THRUST_PP_STRINGIZE_IMPL0(expr) #expr
///////////////////////////////////////////////////////////////////////////////
/// \def THRUST_PP_CAT2(a, b)
/// \brief Concatenates the tokens \a a and \b b.
///
/// \par <b>Example</b>:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << THRUST_PP_CAT2(1, THRUST_PP_CAT2(2, 3)) << "\n";
/// }
/// \endcode
///
/// The above code expands to:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << 123 << "\n";
/// }
/// \endcode
///
#define THRUST_PP_CAT2(a, b) THRUST_PP_CAT2_IMPL0(a, b)
#if defined(_MSC_VER) && (defined(__EDG__) || defined(__EDG_VERSION__)) \
&& (defined(__INTELLISENSE__) || __EDG_VERSION__ >= 308)
# define THRUST_PP_CAT2_IMPL0(a, b) THRUST_PP_CAT2_IMPL1(~, a##b)
# define THRUST_PP_CAT2_IMPL1(p, res) res
#else
# define THRUST_PP_CAT2_IMPL0(a, b) a##b
#endif
#define THRUST_PP_CAT3(a, b, c) \
THRUST_PP_CAT2(a, THRUST_PP_CAT2(b, c)) \
/**/
#define THRUST_PP_CAT4(a, b, c, d) \
THRUST_PP_CAT2(a, THRUST_PP_CAT2(b, THRUST_PP_CAT2(c, d))) \
/**/
#define THRUST_PP_CAT5(a, b, c, d, e) \
THRUST_PP_CAT2(a, THRUST_PP_CAT2(b, THRUST_PP_CAT2(c, THRUST_PP_CAT2(d, e)))) \
/**/
///////////////////////////////////////////////////////////////////////////////
/// \def THRUST_PP_EXPAND(x)
/// \brief Performs macro expansion on \a x.
///
/// \par <b>Example</b>:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// #define FOO_BAR() "foo_bar"
/// #define BUZZ() THRUST_PP_EXPAND(THRUST_PP_CAT2(FOO_, BAR)())
///
/// int main()
/// {
/// std::cout << BUZZ() << "\n";
/// }
/// \endcode
///
/// The above code expands to:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << "foo_bar" << "\n";
/// }
/// \endcode
///
#define THRUST_PP_EXPAND(x) THRUST_PP_EXPAND_IMPL0(x)
#define THRUST_PP_EXPAND_IMPL0(x) x
#define THRUST_PP_EXPAND_ARGS(...) THRUST_PP_EXPAND_ARGS_IMPL0(__VA_ARGS__)
#define THRUST_PP_EXPAND_ARGS_IMPL0(...) __VA_ARGS__
#define THRUST_PP_HEAD(x, ...) x
#define THRUST_PP_TAIL(x, ...) __VA_ARGS__
///////////////////////////////////////////////////////////////////////////////
#define THRUST_PP_EMPTY()
#define THRUST_PP_COMMA() ,
#define THRUST_PP_INC _CCCL_PP_INC
#define THRUST_PP_DEC _CCCL_PP_DEC
#define THRUST_PP_BOOL(x) THRUST_PP_BOOL_IMPL0(x)
#define THRUST_PP_BOOL_IMPL0(x) THRUST_PP_CAT2(THRUST_PP_BOOL_IMPL_TAG, x)
#define THRUST_PP_BOOL_IMPL_TAG0 0
#define THRUST_PP_BOOL_IMPL_TAG1 1
#define THRUST_PP_BOOL_IMPL_TAG2 1
#define THRUST_PP_BOOL_IMPL_TAG3 1
#define THRUST_PP_BOOL_IMPL_TAG4 1
#define THRUST_PP_BOOL_IMPL_TAG5 1
#define THRUST_PP_BOOL_IMPL_TAG6 1
#define THRUST_PP_BOOL_IMPL_TAG7 1
#define THRUST_PP_BOOL_IMPL_TAG8 1
#define THRUST_PP_BOOL_IMPL_TAG9 1
#define THRUST_PP_BOOL_IMPL_TAG10 1
#define THRUST_PP_BOOL_IMPL_TAG11 1
#define THRUST_PP_BOOL_IMPL_TAG12 1
#define THRUST_PP_BOOL_IMPL_TAG13 1
#define THRUST_PP_BOOL_IMPL_TAG14 1
#define THRUST_PP_BOOL_IMPL_TAG15 1
#define THRUST_PP_BOOL_IMPL_TAG16 1
#define THRUST_PP_BOOL_IMPL_TAG17 1
#define THRUST_PP_BOOL_IMPL_TAG18 1
#define THRUST_PP_BOOL_IMPL_TAG19 1
#define THRUST_PP_BOOL_IMPL_TAG20 1
#define THRUST_PP_BOOL_IMPL_TAG21 1
#define THRUST_PP_BOOL_IMPL_TAG22 1
#define THRUST_PP_BOOL_IMPL_TAG23 1
#define THRUST_PP_BOOL_IMPL_TAG24 1
#define THRUST_PP_BOOL_IMPL_TAG25 1
#define THRUST_PP_BOOL_IMPL_TAG26 1
#define THRUST_PP_BOOL_IMPL_TAG27 1
#define THRUST_PP_BOOL_IMPL_TAG28 1
#define THRUST_PP_BOOL_IMPL_TAG29 1
#define THRUST_PP_BOOL_IMPL_TAG30 1
#define THRUST_PP_BOOL_IMPL_TAG31 1
#define THRUST_PP_BOOL_IMPL_TAG32 1
#define THRUST_PP_BOOL_IMPL_TAG33 1
#define THRUST_PP_BOOL_IMPL_TAG34 1
#define THRUST_PP_BOOL_IMPL_TAG35 1
#define THRUST_PP_BOOL_IMPL_TAG36 1
#define THRUST_PP_BOOL_IMPL_TAG37 1
#define THRUST_PP_BOOL_IMPL_TAG38 1
#define THRUST_PP_BOOL_IMPL_TAG39 1
#define THRUST_PP_BOOL_IMPL_TAG40 1
#define THRUST_PP_BOOL_IMPL_TAG41 1
#define THRUST_PP_BOOL_IMPL_TAG42 1
#define THRUST_PP_BOOL_IMPL_TAG43 1
#define THRUST_PP_BOOL_IMPL_TAG44 1
#define THRUST_PP_BOOL_IMPL_TAG45 1
#define THRUST_PP_BOOL_IMPL_TAG46 1
#define THRUST_PP_BOOL_IMPL_TAG47 1
#define THRUST_PP_BOOL_IMPL_TAG48 1
#define THRUST_PP_BOOL_IMPL_TAG49 1
#define THRUST_PP_BOOL_IMPL_TAG50 1
#define THRUST_PP_BOOL_IMPL_TAG51 1
#define THRUST_PP_BOOL_IMPL_TAG52 1
#define THRUST_PP_BOOL_IMPL_TAG53 1
#define THRUST_PP_BOOL_IMPL_TAG54 1
#define THRUST_PP_BOOL_IMPL_TAG55 1
#define THRUST_PP_BOOL_IMPL_TAG56 1
#define THRUST_PP_BOOL_IMPL_TAG57 1
#define THRUST_PP_BOOL_IMPL_TAG58 1
#define THRUST_PP_BOOL_IMPL_TAG59 1
#define THRUST_PP_BOOL_IMPL_TAG60 1
#define THRUST_PP_BOOL_IMPL_TAG61 1
#define THRUST_PP_BOOL_IMPL_TAG62 1
#define THRUST_PP_BOOL_IMPL_TAG63 1
#define THRUST_PP_BOOL_IMPL_TAG64 1
#define THRUST_PP_BOOL_IMPL_TAG65 1
#define THRUST_PP_BOOL_IMPL_TAG66 1
#define THRUST_PP_BOOL_IMPL_TAG67 1
#define THRUST_PP_BOOL_IMPL_TAG68 1
#define THRUST_PP_BOOL_IMPL_TAG69 1
#define THRUST_PP_BOOL_IMPL_TAG70 1
#define THRUST_PP_BOOL_IMPL_TAG71 1
#define THRUST_PP_BOOL_IMPL_TAG72 1
#define THRUST_PP_BOOL_IMPL_TAG73 1
#define THRUST_PP_BOOL_IMPL_TAG74 1
#define THRUST_PP_BOOL_IMPL_TAG75 1
#define THRUST_PP_BOOL_IMPL_TAG76 1
#define THRUST_PP_BOOL_IMPL_TAG77 1
#define THRUST_PP_BOOL_IMPL_TAG78 1
#define THRUST_PP_BOOL_IMPL_TAG79 1
#define THRUST_PP_BOOL_IMPL_TAG80 1
#define THRUST_PP_BOOL_IMPL_TAG81 1
#define THRUST_PP_BOOL_IMPL_TAG82 1
#define THRUST_PP_BOOL_IMPL_TAG83 1
#define THRUST_PP_BOOL_IMPL_TAG84 1
#define THRUST_PP_BOOL_IMPL_TAG85 1
#define THRUST_PP_BOOL_IMPL_TAG86 1
#define THRUST_PP_BOOL_IMPL_TAG87 1
#define THRUST_PP_BOOL_IMPL_TAG88 1
#define THRUST_PP_BOOL_IMPL_TAG89 1
#define THRUST_PP_BOOL_IMPL_TAG90 1
#define THRUST_PP_BOOL_IMPL_TAG91 1
#define THRUST_PP_BOOL_IMPL_TAG92 1
#define THRUST_PP_BOOL_IMPL_TAG93 1
#define THRUST_PP_BOOL_IMPL_TAG94 1
#define THRUST_PP_BOOL_IMPL_TAG95 1
#define THRUST_PP_BOOL_IMPL_TAG96 1
#define THRUST_PP_BOOL_IMPL_TAG97 1
#define THRUST_PP_BOOL_IMPL_TAG98 1
#define THRUST_PP_BOOL_IMPL_TAG99 1
#define THRUST_PP_BOOL_IMPL_TAG100 1
#define THRUST_PP_BOOL_IMPL_TAG101 1
#define THRUST_PP_BOOL_IMPL_TAG102 1
#define THRUST_PP_BOOL_IMPL_TAG103 1
#define THRUST_PP_BOOL_IMPL_TAG104 1
#define THRUST_PP_BOOL_IMPL_TAG105 1
#define THRUST_PP_BOOL_IMPL_TAG106 1
#define THRUST_PP_BOOL_IMPL_TAG107 1
#define THRUST_PP_BOOL_IMPL_TAG108 1
#define THRUST_PP_BOOL_IMPL_TAG109 1
#define THRUST_PP_BOOL_IMPL_TAG110 1
#define THRUST_PP_BOOL_IMPL_TAG111 1
#define THRUST_PP_BOOL_IMPL_TAG112 1
#define THRUST_PP_BOOL_IMPL_TAG113 1
#define THRUST_PP_BOOL_IMPL_TAG114 1
#define THRUST_PP_BOOL_IMPL_TAG115 1
#define THRUST_PP_BOOL_IMPL_TAG116 1
#define THRUST_PP_BOOL_IMPL_TAG117 1
#define THRUST_PP_BOOL_IMPL_TAG118 1
#define THRUST_PP_BOOL_IMPL_TAG119 1
#define THRUST_PP_BOOL_IMPL_TAG120 1
#define THRUST_PP_BOOL_IMPL_TAG121 1
#define THRUST_PP_BOOL_IMPL_TAG122 1
#define THRUST_PP_BOOL_IMPL_TAG123 1
#define THRUST_PP_BOOL_IMPL_TAG124 1
#define THRUST_PP_BOOL_IMPL_TAG125 1
#define THRUST_PP_BOOL_IMPL_TAG126 1
#define THRUST_PP_BOOL_IMPL_TAG127 1
#define THRUST_PP_BOOL_IMPL_TAG128 1
#define THRUST_PP_BOOL_IMPL_TAG129 1
#define THRUST_PP_BOOL_IMPL_TAG130 1
#define THRUST_PP_BOOL_IMPL_TAG131 1
#define THRUST_PP_BOOL_IMPL_TAG132 1
#define THRUST_PP_BOOL_IMPL_TAG133 1
#define THRUST_PP_BOOL_IMPL_TAG134 1
#define THRUST_PP_BOOL_IMPL_TAG135 1
#define THRUST_PP_BOOL_IMPL_TAG136 1
#define THRUST_PP_BOOL_IMPL_TAG137 1
#define THRUST_PP_BOOL_IMPL_TAG138 1
#define THRUST_PP_BOOL_IMPL_TAG139 1
#define THRUST_PP_BOOL_IMPL_TAG140 1
#define THRUST_PP_BOOL_IMPL_TAG141 1
#define THRUST_PP_BOOL_IMPL_TAG142 1
#define THRUST_PP_BOOL_IMPL_TAG143 1
#define THRUST_PP_BOOL_IMPL_TAG144 1
#define THRUST_PP_BOOL_IMPL_TAG145 1
#define THRUST_PP_BOOL_IMPL_TAG146 1
#define THRUST_PP_BOOL_IMPL_TAG147 1
#define THRUST_PP_BOOL_IMPL_TAG148 1
#define THRUST_PP_BOOL_IMPL_TAG149 1
#define THRUST_PP_BOOL_IMPL_TAG150 1
#define THRUST_PP_BOOL_IMPL_TAG151 1
#define THRUST_PP_BOOL_IMPL_TAG152 1
#define THRUST_PP_BOOL_IMPL_TAG153 1
#define THRUST_PP_BOOL_IMPL_TAG154 1
#define THRUST_PP_BOOL_IMPL_TAG155 1
#define THRUST_PP_BOOL_IMPL_TAG156 1
#define THRUST_PP_BOOL_IMPL_TAG157 1
#define THRUST_PP_BOOL_IMPL_TAG158 1
#define THRUST_PP_BOOL_IMPL_TAG159 1
#define THRUST_PP_BOOL_IMPL_TAG160 1
#define THRUST_PP_BOOL_IMPL_TAG161 1
#define THRUST_PP_BOOL_IMPL_TAG162 1
#define THRUST_PP_BOOL_IMPL_TAG163 1
#define THRUST_PP_BOOL_IMPL_TAG164 1
#define THRUST_PP_BOOL_IMPL_TAG165 1
#define THRUST_PP_BOOL_IMPL_TAG166 1
#define THRUST_PP_BOOL_IMPL_TAG167 1
#define THRUST_PP_BOOL_IMPL_TAG168 1
#define THRUST_PP_BOOL_IMPL_TAG169 1
#define THRUST_PP_BOOL_IMPL_TAG170 1
#define THRUST_PP_BOOL_IMPL_TAG171 1
#define THRUST_PP_BOOL_IMPL_TAG172 1
#define THRUST_PP_BOOL_IMPL_TAG173 1
#define THRUST_PP_BOOL_IMPL_TAG174 1
#define THRUST_PP_BOOL_IMPL_TAG175 1
#define THRUST_PP_BOOL_IMPL_TAG176 1
#define THRUST_PP_BOOL_IMPL_TAG177 1
#define THRUST_PP_BOOL_IMPL_TAG178 1
#define THRUST_PP_BOOL_IMPL_TAG179 1
#define THRUST_PP_BOOL_IMPL_TAG180 1
#define THRUST_PP_BOOL_IMPL_TAG181 1
#define THRUST_PP_BOOL_IMPL_TAG182 1
#define THRUST_PP_BOOL_IMPL_TAG183 1
#define THRUST_PP_BOOL_IMPL_TAG184 1
#define THRUST_PP_BOOL_IMPL_TAG185 1
#define THRUST_PP_BOOL_IMPL_TAG186 1
#define THRUST_PP_BOOL_IMPL_TAG187 1
#define THRUST_PP_BOOL_IMPL_TAG188 1
#define THRUST_PP_BOOL_IMPL_TAG189 1
#define THRUST_PP_BOOL_IMPL_TAG190 1
#define THRUST_PP_BOOL_IMPL_TAG191 1
#define THRUST_PP_BOOL_IMPL_TAG192 1
#define THRUST_PP_BOOL_IMPL_TAG193 1
#define THRUST_PP_BOOL_IMPL_TAG194 1
#define THRUST_PP_BOOL_IMPL_TAG195 1
#define THRUST_PP_BOOL_IMPL_TAG196 1
#define THRUST_PP_BOOL_IMPL_TAG197 1
#define THRUST_PP_BOOL_IMPL_TAG198 1
#define THRUST_PP_BOOL_IMPL_TAG199 1
#define THRUST_PP_BOOL_IMPL_TAG200 1
#define THRUST_PP_BOOL_IMPL_TAG201 1
#define THRUST_PP_BOOL_IMPL_TAG202 1
#define THRUST_PP_BOOL_IMPL_TAG203 1
#define THRUST_PP_BOOL_IMPL_TAG204 1
#define THRUST_PP_BOOL_IMPL_TAG205 1
#define THRUST_PP_BOOL_IMPL_TAG206 1
#define THRUST_PP_BOOL_IMPL_TAG207 1
#define THRUST_PP_BOOL_IMPL_TAG208 1
#define THRUST_PP_BOOL_IMPL_TAG209 1
#define THRUST_PP_BOOL_IMPL_TAG210 1
#define THRUST_PP_BOOL_IMPL_TAG211 1
#define THRUST_PP_BOOL_IMPL_TAG212 1
#define THRUST_PP_BOOL_IMPL_TAG213 1
#define THRUST_PP_BOOL_IMPL_TAG214 1
#define THRUST_PP_BOOL_IMPL_TAG215 1
#define THRUST_PP_BOOL_IMPL_TAG216 1
#define THRUST_PP_BOOL_IMPL_TAG217 1
#define THRUST_PP_BOOL_IMPL_TAG218 1
#define THRUST_PP_BOOL_IMPL_TAG219 1
#define THRUST_PP_BOOL_IMPL_TAG220 1
#define THRUST_PP_BOOL_IMPL_TAG221 1
#define THRUST_PP_BOOL_IMPL_TAG222 1
#define THRUST_PP_BOOL_IMPL_TAG223 1
#define THRUST_PP_BOOL_IMPL_TAG224 1
#define THRUST_PP_BOOL_IMPL_TAG225 1
#define THRUST_PP_BOOL_IMPL_TAG226 1
#define THRUST_PP_BOOL_IMPL_TAG227 1
#define THRUST_PP_BOOL_IMPL_TAG228 1
#define THRUST_PP_BOOL_IMPL_TAG229 1
#define THRUST_PP_BOOL_IMPL_TAG230 1
#define THRUST_PP_BOOL_IMPL_TAG231 1
#define THRUST_PP_BOOL_IMPL_TAG232 1
#define THRUST_PP_BOOL_IMPL_TAG233 1
#define THRUST_PP_BOOL_IMPL_TAG234 1
#define THRUST_PP_BOOL_IMPL_TAG235 1
#define THRUST_PP_BOOL_IMPL_TAG236 1
#define THRUST_PP_BOOL_IMPL_TAG237 1
#define THRUST_PP_BOOL_IMPL_TAG238 1
#define THRUST_PP_BOOL_IMPL_TAG239 1
#define THRUST_PP_BOOL_IMPL_TAG240 1
#define THRUST_PP_BOOL_IMPL_TAG241 1
#define THRUST_PP_BOOL_IMPL_TAG242 1
#define THRUST_PP_BOOL_IMPL_TAG243 1
#define THRUST_PP_BOOL_IMPL_TAG244 1
#define THRUST_PP_BOOL_IMPL_TAG245 1
#define THRUST_PP_BOOL_IMPL_TAG246 1
#define THRUST_PP_BOOL_IMPL_TAG247 1
#define THRUST_PP_BOOL_IMPL_TAG248 1
#define THRUST_PP_BOOL_IMPL_TAG249 1
#define THRUST_PP_BOOL_IMPL_TAG250 1
#define THRUST_PP_BOOL_IMPL_TAG251 1
#define THRUST_PP_BOOL_IMPL_TAG252 1
#define THRUST_PP_BOOL_IMPL_TAG253 1
#define THRUST_PP_BOOL_IMPL_TAG254 1
#define THRUST_PP_BOOL_IMPL_TAG255 1
#define THRUST_PP_BOOL_IMPL_TAG256 1
///////////////////////////////////////////////////////////////////////////////
#define THRUST_PP_IIF(bit, t, f) THRUST_PP_IIF_IMPL0(bit, t, f)
#if defined(_MSC_VER)
# define THRUST_PP_IIF_IMPL0(bit, t, f) \
THRUST_PP_IIF_IMPL1(THRUST_PP_CAT2(THRUST_PP_IIF_IMPL_TAG, bit(t, f))) \
/**/
# define THRUST_PP_IIF_IMPL1(id) id
#else
# define THRUST_PP_IIF_IMPL0(bit, t, f) THRUST_PP_CAT2(THRUST_PP_IIF_IMPL_TAG, bit(t, f))
/**/
#endif
#define THRUST_PP_IIF_IMPL_TAG0(t, f) f
#define THRUST_PP_IIF_IMPL_TAG1(t, f) t
#if defined(__EDG__)
# define THRUST_PP_IF(cond, t, f) THRUST_PP_IF_IMPL0(cond, t, f)
# define THRUST_PP_IF_IMPL0(cond, t, f) \
THRUST_PP_IIF(THRUST_PP_BOOL(cond), t, f) \
/**/
#else
# define THRUST_PP_IF(cond, t, f) THRUST_PP_IIF(THRUST_PP_BOOL(cond), t, f)
#endif
/// \def THRUST_COMMA_IF(cond)
/// \brief If \a cond is true, expands to a comma. Otherwise, expands to nothing.
///
/// \par <b>Example</b>:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << THRUST_PP_STRINGIZE(THRUST_COMMA_IF(0)) << "\n"
/// << THRUST_PP_STRINGIZE(THRUST_COMMA_IF(1)) << "\n";
/// }
/// \endcode
///
/// The above code expands to:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << "" << "\n"
/// << "," << "\n";
/// }
/// \endcode
///
#if defined(__EDG__)
# define THRUST_PP_COMMA_IF(cond) THRUST_PP_COMMA_IF_IMPL0(cond)
# define THRUST_PP_COMMA_IF_IMPL0(cond) THRUST_PP_IF(cond, THRUST_PP_COMMA, THRUST_PP_EMPTY)() /**/
#else
# define THRUST_PP_COMMA_IF(cond) THRUST_PP_IF(cond, THRUST_PP_COMMA, THRUST_PP_EMPTY)() /**/
#endif
///////////////////////////////////////////////////////////////////////////////
// http://gustedt.wordpress.com/2010/06/08/detect-empty-macro-arguments
// clang-format off
#define THRUST_PP_64TH_ARG( \
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10,_11,_12,_13,_14,_15,_16 \
, _17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32 \
, _33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48 \
, _49,_50,_51,_52,_53,_54,_55,_56,_57,_58,_59,_60,_61,_62,_63, N \
, ... \
) N \
/**/
#define THRUST_PP_HAS_COMMA(...) \
THRUST_PP_EXPAND(THRUST_PP_64TH_ARG( \
__VA_ARGS__ \
, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 \
, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 \
, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 \
, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 \
)) \
/**/
// clang-format on
#define THRUST_PP_TRIGGER_PAREN(...) ,
#define THRUST_PP_IS_VARIADIC_NULLARY(...) \
THRUST_PP_IS_VARIADIC_NULLARY_IMPL0( \
/* Test if there is just one argument, eventually an empty one. */ \
THRUST_PP_HAS_COMMA(__VA_ARGS__), \
/* Test if THRUST_PP_TRIGGER_PAREN together with the argument adds a */ \
/* comma. */ \
THRUST_PP_HAS_COMMA(THRUST_PP_TRIGGER_PAREN __VA_ARGS__), \
/* Test if the argument together with a parenthesis adds a comma. */ \
THRUST_PP_HAS_COMMA(__VA_ARGS__ (/*empty*/)), \
/* Test if placing it between THRUST_PP_TRIGGER_PAREN and the */ \
/* parenthesis adds a comma. */ \
THRUST_PP_HAS_COMMA(THRUST_PP_TRIGGER_PAREN __VA_ARGS__ (/*empty*/)) \
) \
/**/
#define THRUST_PP_IS_VARIADIC_NULLARY_IMPL0(_0, _1, _2, _3) \
THRUST_PP_HAS_COMMA(THRUST_PP_CAT5(THRUST_PP_IS_VARIADIC_NULLARY_IMPL_TAG, _0, _1, _2, _3))
#define THRUST_PP_IS_VARIADIC_NULLARY_IMPL_TAG0001 ,
///////////////////////////////////////////////////////////////////////////////
/// \def THRUST_PP_ARITY(...)
/// \brief Returns the number of arguments that it was called with. Must be
/// called with less than 64 arguments.
///
/// \par <b>Example</b>:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << THRUST_PP_ARITY() << "\n"
/// << THRUST_PP_ARITY(x) << "\n"
/// << THRUST_PP_ARITY(x, y) << "\n"
/// << THRUST_PP_ARITY(x, y, z) << "\n";
/// }
/// \endcode
///
/// The above code expands to:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << 0 << "\n"
/// << 1 << "\n"
/// << 2 << "\n"
/// << 3 << "\n";
/// }
/// \endcode
///
// clang-format off
#define THRUST_PP_ARITY(...) \
THRUST_PP_EXPAND( \
THRUST_PP_IF( \
THRUST_PP_IS_VARIADIC_NULLARY(__VA_ARGS__) \
, 0 \
, THRUST_PP_64TH_ARG( \
__VA_ARGS__ \
, 63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48 \
, 47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32 \
, 31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16 \
, 15,14,13,12,11,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 \
) \
) \
) \
/**/
// clang-format on
/// \def THRUST_PP_DISPATCH(basename, ...)
/// \brief Expands to <tt>basenameN(...)</tt>, where <tt>N</tt> is the
/// number of variadic arguments that \a THRUST_PP_DISPATCH was called
/// with. This macro can be used to implement "macro overloading".
///
/// \par <b>Example</b>:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// #define PLUS(...) THRUST_PP_DISPATCH(PLUS, __VA_ARGS__)
/// #define PLUS0() 0
/// #define PLUS1(x) x
/// #define PLUS2(x, y) x + y
/// #define PLUS3(x, y, z) x + y + z
///
/// int main()
/// {
/// std::cout << PLUS() << "\n"
/// << PLUS(1) << "\n"
/// << PLUS(1, 2) << "\n"
/// << PLUS(1, 2, 3) << "\n";
/// }
/// \endcode
///
/// The above code expands to:
///
/// \code
/// #include <thrust/detail/preprocessor.h>
/// #include <iostream>
///
/// int main()
/// {
/// std::cout << 0 << "\n"
/// << 1 << "\n"
/// << 1 + 2 << "\n"
/// << 1 + 2 + 3 << "\n";
/// }
/// \endcode
///
#define THRUST_PP_DISPATCH(basename, ...) \
THRUST_PP_EXPAND(THRUST_PP_CAT2(basename, THRUST_PP_ARITY(__VA_ARGS__))(__VA_ARGS__)) \
/**/
///////////////////////////////////////////////////////////////////////////////
/// \def THRUST_CURRENT_FUNCTION
/// \brief The name of the current function as a string.
///
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || defined(__ghs__)
# define THRUST_CURRENT_FUNCTION __PRETTY_FUNCTION__
#elif defined(__DMC__) && (__DMC__ >= 0x810)
# define THRUST_CURRENT_FUNCTION __PRETTY_FUNCTION__
#elif defined(__FUNCSIG__)
# define THRUST_CURRENT_FUNCTION __FUNCSIG__
#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) \
|| (defined(__IBMCTHRUST_PP__) && (__IBMCTHRUST_PP__ >= 500))
# define THRUST_CURRENT_FUNCTION __FUNCTION__
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
# define THRUST_CURRENT_FUNCTION __FUNC__
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
# define THRUST_CURRENT_FUNCTION __func__
#elif defined(__cplusplus) && (__cplusplus >= 201103)
# define THRUST_CURRENT_FUNCTION __func__
#else
# define THRUST_CURRENT_FUNCTION "(unknown)"
#endif
///////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,100 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/functional.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename RandomAccessIterator,
typename BinaryPredicate = ::cuda::std::equal_to<it_value_t<RandomAccessIterator>>,
typename ValueType = bool,
typename IndexType = it_difference_t<RandomAccessIterator>>
class head_flags
{
public:
struct head_flag_functor
{
BinaryPredicate binary_pred; // this must be the first member for performance reasons
RandomAccessIterator iter;
using result_type = ValueType;
_CCCL_HOST_DEVICE head_flag_functor(RandomAccessIterator iter, BinaryPredicate binary_pred = {})
: binary_pred(binary_pred)
, iter(iter)
{}
_CCCL_HOST_DEVICE _CCCL_FORCEINLINE result_type operator()(const IndexType i)
{
// note that we do not dereference the iterators i <= 0
// and therefore do not dereference a bad location at the boundary
if (i <= 0)
{
return true;
}
return !binary_pred(thrust::raw_reference_cast(iter[i]), thrust::raw_reference_cast(iter[i - 1]));
}
};
public:
using iterator = thrust::transform_iterator<head_flag_functor, thrust::counting_iterator<IndexType>>;
_CCCL_HOST_DEVICE head_flags(RandomAccessIterator first, RandomAccessIterator last, BinaryPredicate binary_pred = {})
: m_begin(thrust::make_transform_iterator(
thrust::counting_iterator<IndexType>(0), head_flag_functor(first, binary_pred)))
, m_count(last - first)
{}
_CCCL_HOST_DEVICE iterator begin() const
{
return m_begin;
}
_CCCL_HOST_DEVICE iterator end() const
{
return m_begin + m_count;
}
template <typename OtherIndex>
_CCCL_HOST_DEVICE typename iterator::reference operator[](OtherIndex i)
{
return *(begin() + i);
}
_CCCL_SYNTHESIZE_SEQUENCE_ACCESS(head_flags, iterator)
private:
iterator m_begin;
IndexType m_count;
};
template <typename RandomAccessIterator, typename BinaryPredicate>
_CCCL_HOST_DEVICE head_flags<RandomAccessIterator, BinaryPredicate>
make_head_flags(RandomAccessIterator first, RandomAccessIterator last, BinaryPredicate binary_pred)
{
return head_flags<RandomAccessIterator, BinaryPredicate>(first, last, binary_pred);
}
template <typename RandomAccessIterator>
_CCCL_HOST_DEVICE head_flags<RandomAccessIterator> make_head_flags(RandomAccessIterator first, RandomAccessIterator last)
{
return head_flags<RandomAccessIterator>(first, last);
}
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,114 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/functional.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/iterator/zip_iterator.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename RandomAccessIterator,
typename BinaryPredicate = ::cuda::std::equal_to<detail::it_value_t<RandomAccessIterator>>,
typename ValueType = bool,
typename IndexType = detail::it_difference_t<RandomAccessIterator>>
class tail_flags
{
// XXX WAR cudafe bug
// private:
public:
struct tail_flag_functor
{
BinaryPredicate binary_pred; // this must be the first member for performance reasons
RandomAccessIterator iter;
IndexType n;
using result_type = ValueType;
_CCCL_HOST_DEVICE tail_flag_functor(RandomAccessIterator first, RandomAccessIterator last)
: binary_pred()
, iter(first)
, n(last - first)
{}
_CCCL_HOST_DEVICE
tail_flag_functor(RandomAccessIterator first, RandomAccessIterator last, BinaryPredicate binary_pred)
: binary_pred(binary_pred)
, iter(first)
, n(last - first)
{}
_CCCL_HOST_DEVICE _CCCL_FORCEINLINE result_type operator()(const IndexType& i)
{
return (i == (n - 1) || !binary_pred(iter[i], iter[i + 1]));
}
};
using counting_iterator = thrust::counting_iterator<IndexType>;
public:
using iterator = thrust::transform_iterator<tail_flag_functor, counting_iterator>;
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE tail_flags(RandomAccessIterator first, RandomAccessIterator last)
: m_begin(
thrust::make_transform_iterator(thrust::counting_iterator<IndexType>(0), tail_flag_functor(first, last)))
, m_end(m_begin + (last - first))
{}
_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE tail_flags(RandomAccessIterator first, RandomAccessIterator last, BinaryPredicate binary_pred)
: m_begin(thrust::make_transform_iterator(
thrust::counting_iterator<IndexType>(0), tail_flag_functor(first, last, binary_pred)))
, m_end(m_begin + (last - first))
{}
_CCCL_HOST_DEVICE iterator begin() const
{
return m_begin;
}
_CCCL_HOST_DEVICE iterator end() const
{
return m_end;
}
template <typename OtherIndex>
_CCCL_HOST_DEVICE typename iterator::reference operator[](OtherIndex i)
{
return *(begin() + i);
}
_CCCL_SYNTHESIZE_SEQUENCE_ACCESS(tail_flags, iterator)
private:
iterator m_begin, m_end;
};
template <typename RandomAccessIterator, typename BinaryPredicate>
_CCCL_HOST_DEVICE tail_flags<RandomAccessIterator, BinaryPredicate>
make_tail_flags(RandomAccessIterator first, RandomAccessIterator last, BinaryPredicate binary_pred)
{
return tail_flags<RandomAccessIterator, BinaryPredicate>(first, last, binary_pred);
}
template <typename RandomAccessIterator>
_CCCL_HOST_DEVICE tail_flags<RandomAccessIterator> make_tail_flags(RandomAccessIterator first, RandomAccessIterator last)
{
return tail_flags<RandomAccessIterator>(first, last);
}
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <cuda/std/__memory/pointer_traits.h>
THRUST_NAMESPACE_BEGIN
template <typename Pointer>
_CCCL_HOST_DEVICE auto* raw_pointer_cast(Pointer ptr)
{
return ::cuda::std::to_address(ptr);
}
template <typename ToPointer, typename FromPointer>
_CCCL_HOST_DEVICE ToPointer reinterpret_pointer_cast(FromPointer ptr)
{
using to_element = typename ::cuda::std::pointer_traits<ToPointer>::element_type;
return ToPointer(reinterpret_cast<to_element*>(::cuda::std::to_address(ptr)));
}
template <typename ToPointer, typename FromPointer>
_CCCL_HOST_DEVICE ToPointer static_pointer_cast(FromPointer ptr)
{
using to_element = typename ::cuda::std::pointer_traits<ToPointer>::element_type;
return ToPointer(static_cast<to_element*>(::cuda::std::to_address(ptr)));
}
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,180 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/raw_pointer_cast.h>
#include <thrust/detail/type_traits.h>
#include <thrust/detail/type_traits/has_nested_type.h>
#include <cuda/std/__memory/pointer_traits.h>
#include <cuda/std/__tuple_dir/apply.h>
#include <cuda/std/__type_traits/add_lvalue_reference.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/remove_cv.h>
#include <cuda/std/__type_traits/type_identity.h>
#include <cuda/std/__utility/forward.h>
#include <cuda/std/tuple>
// the order of declarations and definitions in this file is totally goofy
// this header defines raw_reference_cast, which has a few overloads towards the bottom of the file
// raw_reference_cast depends on metafunctions such as is_unwrappable and raw_reference
// we need to be sure that these metafunctions are completely defined (including specializations) before they are
// instantiated by raw_reference_cast
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename... Ts>
class tuple_of_iterator_references;
__THRUST_DEFINE_HAS_NESTED_TYPE(is_wrapped_reference, wrapped_reference_hint)
// wrapped reference-like things which aren't strictly wrapped references
// (e.g. tuples of wrapped references) are considered unwrappable
template <typename T>
inline constexpr bool can_unwrap = is_wrapped_reference<T>::value;
// specialize is_unwrappable
// a tuple is_unwrappable if any of its elements is_unwrappable
template <typename... Ts>
inline constexpr bool can_unwrap<::cuda::std::tuple<Ts...>> = (can_unwrap<Ts> || ...);
// specialize is_unwrappable
// a tuple_of_iterator_references is_unwrappable if any of its elements is_unwrappable
template <typename... Ts>
inline constexpr bool can_unwrap<tuple_of_iterator_references<Ts...>> = (can_unwrap<Ts> || ...);
namespace raw_reference_detail
{
template <typename T, typename SFINAE = void>
struct raw_reference_impl : ::cuda::std::add_lvalue_reference<T>
{};
template <typename T>
struct raw_reference_impl<T, ::cuda::std::enable_if_t<is_wrapped_reference<::cuda::std::remove_cv_t<T>>::value>>
: ::cuda::std::add_lvalue_reference<typename ::cuda::std::pointer_traits<typename T::pointer>::element_type>
{};
template <typename T>
struct raw_reference_impl<T, ::cuda::std::enable_if_t<is_proxy_reference_v<::cuda::std::remove_cv_t<T>>>>
{
using type = T;
};
} // namespace raw_reference_detail
template <typename T>
struct raw_reference : raw_reference_detail::raw_reference_impl<T>
{};
template <typename T>
using raw_reference_t = typename raw_reference<T>::type;
namespace raw_reference_detail
{
// unlike raw_reference,
// raw_reference_tuple_helper needs to return a value
// when it encounters one, rather than a reference
// upon encountering tuple, recurse
//
// we want the following behavior:
// 1. T -> T
// 2. T& -> T&
// 3. null_type -> null_type
// 4. reference<T> -> T&
// 5. tuple_of_iterator_references<T> -> tuple_of_iterator_references<raw_reference_tuple_helper<T>::type>
// wrapped references are unwrapped using raw_reference, otherwise, return T
template <typename T>
struct raw_reference_tuple_helper
: eval_if<can_unwrap<::cuda::std::remove_cv_t<T>>, raw_reference<T>, ::cuda::std::type_identity<T>>
{};
// recurse on tuples
template <typename... Ts>
struct raw_reference_tuple_helper<::cuda::std::tuple<Ts...>>
{
using type = ::cuda::std::tuple<typename raw_reference_tuple_helper<Ts>::type...>;
};
template <typename... Ts>
struct raw_reference_tuple_helper<tuple_of_iterator_references<Ts...>>
{
using type = tuple_of_iterator_references<typename raw_reference_tuple_helper<Ts>::type...>;
};
} // namespace raw_reference_detail
// a couple of specializations of raw_reference for tuples follow
// if a tuple "tuple_type" is_unwrappable,
// then the raw_reference of tuple_type is a tuple of its members' raw_references
// else the raw_reference of tuple_type is tuple_type &
template <typename... Ts>
struct raw_reference<::cuda::std::tuple<Ts...>>
{
private:
using tuple_type = ::cuda::std::tuple<Ts...>;
public:
using type = typename eval_if<can_unwrap<tuple_type>,
raw_reference_detail::raw_reference_tuple_helper<tuple_type>,
::cuda::std::add_lvalue_reference<tuple_type>>::type;
};
template <typename... Ts>
struct raw_reference<tuple_of_iterator_references<Ts...>>
{
using type = typename raw_reference_detail::raw_reference_tuple_helper<tuple_of_iterator_references<Ts...>>::type;
};
} // namespace detail
// provide declarations of raw_reference_cast's overloads for raw_reference_caster below
template <typename T>
_CCCL_HOST_DEVICE typename detail::raw_reference<T>::type raw_reference_cast(T& ref)
{
return *thrust::raw_pointer_cast(&ref);
}
template <typename T>
_CCCL_HOST_DEVICE typename detail::raw_reference<const T>::type raw_reference_cast(const T& ref)
{
return *thrust::raw_pointer_cast(&ref);
}
template <typename T, ::cuda::std::enable_if_t<detail::is_proxy_reference_v<::cuda::std::remove_cv_t<T>>, int> = 0>
_CCCL_HOST_DEVICE typename detail::raw_reference<T>::type raw_reference_cast(T&& t)
{
return t;
}
template <typename... Ts>
_CCCL_HOST_DEVICE auto raw_reference_cast(detail::tuple_of_iterator_references<Ts...> t) ->
typename detail::raw_reference<detail::tuple_of_iterator_references<Ts...>>::type
{
if constexpr (detail::can_unwrap<detail::tuple_of_iterator_references<Ts...>>)
{
using ResultTuple =
::cuda::std::tuple<typename detail::raw_reference_detail::raw_reference_tuple_helper<Ts>::type...>;
return ::cuda::std::apply(
[](auto&&... refs) {
return ResultTuple{raw_reference_cast(::cuda::std::forward<decltype(refs)>(refs))...};
},
static_cast<::cuda::std::tuple<Ts...>&>(t));
}
else
{
return t;
}
}
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,383 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/nvtx_policy.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/reduce.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/reduce.h>
#include <thrust/system/detail/generic/reduce_by_key.h>
#include <thrust/system/detail/sequential/reduce.h>
#include <thrust/system/detail/sequential/reduce_by_key.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(reduce.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(reduce.h)
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(reduce_by_key.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(reduce_by_key.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/reduce.h>
# include <thrust/system/cpp/detail/reduce_by_key.h>
# include <thrust/system/cuda/detail/reduce.h>
# include <thrust/system/cuda/detail/reduce_by_key.h>
# include <thrust/system/omp/detail/reduce.h>
# include <thrust/system/omp/detail/reduce_by_key.h>
# include <thrust/system/tbb/detail/reduce.h>
# include <thrust/system/tbb/detail/reduce_by_key.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator>
_CCCL_HOST_DEVICE detail::it_value_t<InputIterator>
reduce(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, InputIterator first, InputIterator last)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "thrust::reduce");
using thrust::system::detail::generic::reduce;
return reduce(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end reduce()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename T>
_CCCL_HOST_DEVICE T reduce(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, InputIterator first, InputIterator last, T init)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce");
using thrust::system::detail::generic::reduce;
return reduce(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, init);
} // end reduce()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename T, typename BinaryFunction>
_CCCL_HOST_DEVICE T reduce(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
T init,
BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce");
using thrust::system::detail::generic::reduce;
return reduce(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, init, binary_op);
} // end reduce()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE void reduce_into(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator output)
{
using thrust::system::detail::generic::reduce_into;
reduce_into(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, output);
} // end reduce_into()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename T>
_CCCL_HOST_DEVICE void reduce_into(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator output,
T init)
{
using thrust::system::detail::generic::reduce_into;
reduce_into(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, output, init);
} // end reduce_into()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename T, typename BinaryFunction>
_CCCL_HOST_DEVICE void reduce_into(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator output,
T init,
BinaryFunction binary_op)
{
using thrust::system::detail::generic::reduce_into;
reduce_into(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, output, init, binary_op);
} // end reduce_into()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> reduce_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce_by_key");
using thrust::system::detail::generic::reduce_by_key;
return reduce_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
keys_first,
keys_last,
values_first,
keys_output,
values_output);
} // end reduce_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename BinaryPredicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> reduce_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce_by_key");
using thrust::system::detail::generic::reduce_by_key;
return reduce_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
keys_first,
keys_last,
values_first,
keys_output,
values_output,
binary_pred);
} // end reduce_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename BinaryPredicate,
typename BinaryFunction>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> reduce_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output,
BinaryPredicate binary_pred,
BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce_by_key");
using thrust::system::detail::generic::reduce_by_key;
return reduce_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
keys_first,
keys_last,
values_first,
keys_output,
values_output,
binary_pred,
binary_op);
} // end reduce_by_key()
template <typename InputIterator>
detail::it_value_t<InputIterator> reduce(InputIterator first, InputIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::reduce(select_system(system), first, last);
}
template <typename InputIterator, typename T>
T reduce(InputIterator first, InputIterator last, T init)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::reduce(select_system(system), first, last, init);
}
template <typename InputIterator, typename T, typename BinaryFunction>
T reduce(InputIterator first, InputIterator last, T init, BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::reduce(select_system(system), first, last, init, binary_op);
}
template <typename InputIterator, typename OutputIterator>
void reduce_into(InputIterator first, InputIterator last, OutputIterator output)
{
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
thrust::reduce_into(select_system(system1, system2), first, last, output);
}
template <typename InputIterator, typename OutputIterator, typename T>
void reduce_into(InputIterator first, InputIterator last, OutputIterator output, T init)
{
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
thrust::reduce_into(select_system(system1, system2), first, last, output, init);
}
template <typename InputIterator, typename OutputIterator, typename T, typename BinaryFunction>
void reduce_into(InputIterator first, InputIterator last, OutputIterator output, T init, BinaryFunction binary_op)
{
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
thrust::reduce_into(select_system(system1, system2), first, last, output, init, binary_op);
}
template <typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2>
::cuda::std::pair<OutputIterator1, OutputIterator2> reduce_by_key(
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator1>::type;
using System4 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
return thrust::reduce_by_key(
select_system(system1, system2, system3, system4), keys_first, keys_last, values_first, keys_output, values_output);
}
template <typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename BinaryPredicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> reduce_by_key(
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator1>::type;
using System4 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
return thrust::reduce_by_key(
select_system(system1, system2, system3, system4),
keys_first,
keys_last,
values_first,
keys_output,
values_output,
binary_pred);
}
template <typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename BinaryPredicate,
typename BinaryFunction>
::cuda::std::pair<OutputIterator1, OutputIterator2> reduce_by_key(
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output,
BinaryPredicate binary_pred,
BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reduce_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator1>::type;
using System4 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
return thrust::reduce_by_key(
select_system(system1, system2, system3, system4),
keys_first,
keys_last,
values_first,
keys_output,
values_output,
binary_pred,
binary_op);
}
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,604 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file
* \brief A pointer to a variable which resides in memory associated with a
* system.
*/
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/reference_forward_declaration.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/memory.h>
#include <thrust/system/detail/generic/select_system.h>
#include <cuda/std/__host_stdlib/ostream>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_comparable.h>
#include <cuda/std/__type_traits/is_convertible.h>
#include <cuda/std/__type_traits/remove_cvref.h>
#include <cuda/std/__utility/move.h>
// Include all active backend system implementations (sequential, host and device) (there is no generic implementation)
#include <thrust/system/detail/sequential/assign_value.h>
#include <thrust/system/detail/sequential/get_value.h>
#include <thrust/system/detail/sequential/iter_swap.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(assign_value.h)
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(get_value.h)
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(iter_swap.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(assign_value.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(get_value.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(iter_swap.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/assign_value.h>
# include <thrust/system/cpp/detail/get_value.h>
# include <thrust/system/cpp/detail/iter_swap.h>
# include <thrust/system/cuda/detail/assign_value.h>
# include <thrust/system/cuda/detail/get_value.h>
# include <thrust/system/cuda/detail/iter_swap.h>
# include <thrust/system/omp/detail/assign_value.h>
# include <thrust/system/omp/detail/get_value.h>
# include <thrust/system/omp/detail/iter_swap.h>
# include <thrust/system/tbb/detail/assign_value.h>
# include <thrust/system/tbb/detail/get_value.h>
# include <thrust/system/tbb/detail/iter_swap.h>
#endif
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename>
struct is_wrapped_reference;
}
/*! \p reference acts as a reference-like wrapper for an object residing in
* memory that a \p pointer refers to.
*/
template <typename Element, typename Pointer, typename Derived>
class reference
{
private:
using derived_type = std::conditional_t<std::is_same_v<Derived, use_default>, reference, Derived>;
public:
using pointer = Pointer;
using value_type = ::cuda::std::remove_cvref_t<Element>;
reference(reference const&) = default;
reference(reference&&) = default;
/*! Construct a \p reference from another \p reference whose pointer type is
* convertible to \p pointer. After this \p reference is constructed, it
* shall refer to the same object as \p other.
*
* \tparam OtherElement The element type of the other \p reference.
* \tparam OtherPointer The pointer type of the other \p reference.
* \tparam OtherDerived The derived type of the other \p reference.
* \param other A \p reference to copy from.
*/
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
_CCCL_HOST_DEVICE reference(
reference<OtherElement, OtherPointer, OtherDerived> const& other
/*! \cond
*/
,
std::enable_if_t<
std::is_convertible_v<typename reference<OtherElement, OtherPointer, OtherDerived>::pointer, pointer>>* = nullptr
/*! \endcond
*/
)
: ptr(other.ptr)
{}
/*! Construct a \p reference that refers to an object pointed to by the given
* \p pointer. After this \p reference is constructed, it shall refer to the
* object pointed to by \p ptr.
*
* \param ptr A \p pointer to construct from.
*/
_CCCL_HOST_DEVICE explicit reference(pointer const& p)
: ptr(p)
{}
/*! Assign the object referred to \p other to the object referred to by
* this \p reference.
*
* \param other The other \p reference to assign from.
*
* \return <tt>*this</tt>.
*/
_CCCL_HOST_DEVICE const derived_type& operator=(reference const& other) const
{
assign_from(&other);
return derived();
}
/*! Assign the object referred to by this \p reference with the object
* referred to by another \p reference whose pointer type is convertible to
* \p pointer.
*
* \tparam OtherElement The element type of the other \p reference.
* \tparam OtherPointer The pointer type of the other \p reference.
* \tparam OtherDerived The derived type of the other \p reference.
* \param other The other \p reference to assign from.
*
* \return <tt>*this</tt>.
*/
template <
typename OtherElement,
typename OtherPointer,
typename OtherDerived,
::cuda::std::enable_if_t<
::cuda::std::is_convertible_v<typename reference<OtherElement, OtherPointer, OtherDerived>::pointer, pointer>,
int> = 0>
_CCCL_HOST_DEVICE const derived_type& operator=(reference<OtherElement, OtherPointer, OtherDerived> const& other) const
{
assign_from(&other);
return derived();
}
/*! Assign \p rhs to the object referred to by this \p tagged_reference.
*
* \param rhs The \p value_type to assign from.
*
* \return <tt>*this</tt>.
*/
_CCCL_HOST_DEVICE const derived_type& operator=(value_type const& rhs) const
{
assign_from(&rhs);
return derived();
}
/*! Exchanges the value of the object referred to by this \p tagged_reference
* with the object referred to by \p other.
*
* \param other The \p tagged_reference to swap with.
*/
_CCCL_HOST_DEVICE void swap(derived_type other)
{
// we cannot construct a system solely from its type, since it may be stateful, so just use the system's tag
typename iterator_system_t<pointer>::tag_type tag;
swap(&tag, other);
}
_CCCL_HOST_DEVICE pointer operator&() const
{
return ptr;
}
// This is inherently hazardous, as it discards the strong type information
// about what system the object is on.
_CCCL_HOST_DEVICE operator value_type() const
{
// we cannot construct a system solely from its type, since it may be stateful, so just use the system's tag
typename iterator_system_t<pointer>::tag_type tag;
return convert_to_value_type(&tag);
}
_CCCL_HOST_DEVICE derived_type& operator++()
{
// Sadly, this has to make a copy. The only mechanism we have for
// modifying the value, which may be in memory inaccessible to this
// system, is to get a copy of it, modify the copy, and then update it.
value_type tmp = *this;
++tmp;
*this = tmp;
return derived();
}
_CCCL_HOST_DEVICE value_type operator++(int)
{
value_type tmp = *this;
value_type result = tmp++;
*this = ::cuda::std::move(tmp);
return result;
}
derived_type& operator--()
{
// Sadly, this has to make a copy. The only mechanism we have for
// modifying the value, which may be in memory inaccessible to this
// system, is to get a copy of it, modify the copy, and then update it.
value_type tmp = *this;
--tmp;
*this = ::cuda::std::move(tmp);
return derived();
}
value_type operator--(int)
{
value_type tmp = *this;
value_type result = tmp--;
*this = ::cuda::std::move(tmp);
return derived();
}
_CCCL_HOST_DEVICE derived_type& operator+=(value_type const& rhs)
{
value_type tmp = *this;
tmp += rhs;
*this = tmp;
return derived();
}
derived_type& operator-=(value_type const& rhs)
{
value_type tmp = *this;
tmp -= rhs;
*this = tmp;
return derived();
}
derived_type& operator*=(value_type const& rhs)
{
value_type tmp = *this;
tmp *= rhs;
*this = tmp;
return derived();
}
derived_type& operator/=(value_type const& rhs)
{
value_type tmp = *this;
tmp /= rhs;
*this = tmp;
return derived();
}
derived_type& operator%=(value_type const& rhs)
{
value_type tmp = *this;
tmp %= rhs;
*this = tmp;
return derived();
}
derived_type& operator<<=(value_type const& rhs)
{
value_type tmp = *this;
tmp <<= rhs;
*this = tmp;
return derived();
}
derived_type& operator>>=(value_type const& rhs)
{
value_type tmp = *this;
tmp >>= rhs;
*this = tmp;
return derived();
}
derived_type& operator&=(value_type const& rhs)
{
value_type tmp = *this;
tmp &= rhs;
*this = tmp;
return derived();
}
derived_type& operator|=(value_type const& rhs)
{
value_type tmp = *this;
tmp |= rhs;
*this = tmp;
return derived();
}
derived_type& operator^=(value_type const& rhs)
{
value_type tmp = *this;
tmp ^= rhs;
*this = tmp;
return derived();
}
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<detail::ref_can_compare_equal<Pointer, OtherPointer>, bool>
operator==(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) noexcept(
::cuda::std::__is_cpp17_nothrow_equality_comparable_v<value_type, ::cuda::std::remove_cvref_t<OtherElement>>)
{ // MSVC cannot directly compare the references thinking its a recursive function call
const value_type& lhs_ref = *&lhs;
const ::cuda::std::remove_cvref_t<OtherElement>& rhs_ref = *&rhs;
return lhs_ref == rhs_ref;
}
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<!detail::ref_can_compare_equal<Pointer, OtherPointer>, bool>
operator==(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<detail::ref_can_compare_equal<Pointer, OtherPointer>, bool>
operator!=(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) noexcept(
::cuda::std::__is_cpp17_nothrow_equality_comparable_v<value_type, ::cuda::std::remove_cvref_t<OtherElement>>)
{
const value_type& lhs_ref = *&lhs;
const ::cuda::std::remove_cvref_t<OtherElement>& rhs_ref = *&rhs;
return !(lhs_ref == rhs_ref);
}
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<!detail::ref_can_compare_equal<Pointer, OtherPointer>, bool>
operator!=(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<detail::ref_can_compare_less_than<Pointer, OtherPointer>, bool>
operator<(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) noexcept(
::cuda::std::__is_cpp17_nothrow_less_than_comparable_v<value_type, ::cuda::std::remove_cvref_t<OtherElement>>)
{ // MSVC cannot directly compare the references thinking its a recursive function call
const value_type& lhs_ref = *&lhs;
const ::cuda::std::remove_cvref_t<OtherElement>& rhs_ref = *&rhs;
return lhs_ref < rhs_ref;
}
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<!detail::ref_can_compare_less_than<Pointer, OtherPointer>, bool>
operator<(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<detail::ref_can_compare_less_than<Pointer, OtherPointer>, bool>
operator>=(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) noexcept(
::cuda::std::__is_cpp17_nothrow_less_than_comparable_v<value_type, ::cuda::std::remove_cvref_t<OtherElement>>)
{ // MSVC cannot directly compare the references thinking its a recursive function call
const value_type& lhs_ref = *&lhs;
const ::cuda::std::remove_cvref_t<OtherElement>& rhs_ref = *&rhs;
return !(lhs_ref < rhs_ref);
}
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<!detail::ref_can_compare_less_than<Pointer, OtherPointer>, bool>
operator>=(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<detail::ref_can_compare_less_than<Pointer, OtherPointer>, bool>
operator>(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) noexcept(
::cuda::std::__is_cpp17_nothrow_less_than_comparable_v<value_type, ::cuda::std::remove_cvref_t<OtherElement>>)
{ // MSVC cannot directly compare the references thinking its a recursive function call
const value_type& lhs_ref = *&lhs;
const ::cuda::std::remove_cvref_t<OtherElement>& rhs_ref = *&rhs;
return rhs_ref < lhs_ref;
}
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<!detail::ref_can_compare_less_than<Pointer, OtherPointer>, bool>
operator>(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) = delete;
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<detail::ref_can_compare_less_than<Pointer, OtherPointer>, bool>
operator<=(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) noexcept(
::cuda::std::__is_cpp17_nothrow_less_than_comparable_v<value_type, ::cuda::std::remove_cvref_t<OtherElement>>)
{ // MSVC cannot directly compare the references thinking its a recursive function call
const value_type& lhs_ref = *&lhs;
const ::cuda::std::remove_cvref_t<OtherElement>& rhs_ref = *&rhs;
return !(rhs_ref < lhs_ref);
}
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
[[nodiscard]]
_CCCL_HOST_DEVICE friend ::cuda::std::enable_if_t<!detail::ref_can_compare_less_than<Pointer, OtherPointer>, bool>
operator<=(reference const& lhs, reference<OtherElement, OtherPointer, OtherDerived> const& rhs) = delete;
private:
pointer const ptr;
// `thrust::detail::is_wrapped_reference` is a trait that indicates whether
// a type is a fancy reference. It detects such types by looking for a
// nested `wrapped_reference_hint` type.
struct wrapped_reference_hint
{};
template <typename>
friend struct thrust::detail::is_wrapped_reference;
template <typename OtherElement, typename OtherPointer, typename OtherDerived>
friend class reference;
_CCCL_HOST_DEVICE derived_type& derived()
{
return static_cast<derived_type&>(*this);
}
_CCCL_HOST_DEVICE const derived_type& derived() const
{
return static_cast<const derived_type&>(*this);
}
template <typename System>
_CCCL_HOST_DEVICE value_type convert_to_value_type(System* system) const
{
using thrust::system::detail::generic::select_system;
return strip_const_get_value(select_system(*system));
}
template <typename System>
_CCCL_HOST_DEVICE value_type strip_const_get_value(System const& system) const
{
System& non_const_system = const_cast<System&>(system);
using thrust::system::detail::generic::get_value;
return get_value(thrust::detail::derived_cast(non_const_system), ptr);
}
template <typename System0, typename System1, typename OtherPointer>
_CCCL_HOST_DEVICE void assign_from(System0* system0, System1* system1, OtherPointer src) const
{
using thrust::system::detail::generic::select_system;
strip_const_assign_value(select_system(*system0, *system1), src);
}
template <typename OtherPointer>
_CCCL_HOST_DEVICE void assign_from(OtherPointer src) const
{
// we cannot construct a system solely from its type, since it may be stateful, so just use the system's tag
typename iterator_system_t<pointer>::tag_type tag0;
typename iterator_system_t<OtherPointer>::tag_type tag1;
assign_from(&tag0, &tag1, src);
}
template <typename System, typename OtherPointer>
_CCCL_HOST_DEVICE void strip_const_assign_value(System const& system, OtherPointer src) const
{
System& non_const_system = const_cast<System&>(system);
using thrust::system::detail::generic::assign_value;
assign_value(thrust::detail::derived_cast(non_const_system), ptr, src);
}
template <typename System>
_CCCL_HOST_DEVICE void swap(System* system, derived_type other)
{
using thrust::system::detail::generic::iter_swap;
using thrust::system::detail::generic::select_system;
iter_swap(select_system(*system, *system), ptr, other.ptr);
}
};
template <typename Pointer, typename Derived>
class reference<void, Pointer, Derived>
{};
template <typename Pointer, typename Derived>
class reference<void const, Pointer, Derived>
{};
template <typename Element, typename Pointer, typename Derived, typename CharT, typename Traits>
std::basic_ostream<CharT, Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, reference<Element, Pointer, Derived> const& r)
{
using value_type = typename reference<Element, Pointer, Derived>::value_type;
return os << static_cast<value_type>(r); // NOLINT(bugprone-unintended-char-ostream-output)
}
template <typename Element, typename Tag>
class tagged_reference;
/*! \p tagged_reference acts as a reference-like wrapper for an object residing
* in memory associated with system \p Tag that a \p pointer refers to.
*/
template <typename Element, typename Tag>
class tagged_reference
: public thrust::
reference<Element, thrust::pointer<Element, Tag, tagged_reference<Element, Tag>>, tagged_reference<Element, Tag>>
{
private:
using base_type = thrust::
reference<Element, thrust::pointer<Element, Tag, tagged_reference<Element, Tag>>, tagged_reference<Element, Tag>>;
public:
using value_type = typename base_type::value_type;
using pointer = typename base_type::pointer;
tagged_reference(tagged_reference const&) = default;
tagged_reference(tagged_reference&&) = default;
/*! Construct a \p tagged_reference from another \p tagged_reference whose
* pointer type is convertible to \p pointer. After this \p tagged_reference
* is constructed, it shall refer to the same object as \p other.
*
* \tparam OtherElement The element type of the other \p tagged_reference.
* \tparam OtherTag The tag type of the other \p tagged_reference.
* \param other A \p tagged_reference to copy from.
*/
template <typename OtherElement, typename OtherTag>
_CCCL_HOST_DEVICE tagged_reference(tagged_reference<OtherElement, OtherTag> const& other)
: base_type(other)
{}
/*! Construct a \p tagged_reference that refers to an object pointed to by
* the given \p pointer. After this \p tagged_reference is constructed, it
* shall refer to the object pointed to by \p ptr.
*
* \param ptr A \p pointer to construct from.
*/
_CCCL_HOST_DEVICE explicit tagged_reference(pointer const& p)
: base_type(p)
{}
/*! Assign the object referred to \p other to the object referred to by
* this \p tagged_reference.
*
* \param other The other \p tagged_reference to assign from.
*
* \return <tt>*this</tt>.
*/
_CCCL_HOST_DEVICE const tagged_reference& operator=(tagged_reference const& other) const
{
return base_type::operator=(other);
}
/*! Assign the object referred to by this \p tagged_reference with the object
* referred to by another \p tagged_reference whose pointer type is
* convertible to \p pointer.
*
* \tparam OtherElement The element type of the other \p tagged_reference.
* \tparam OtherTag The tag type of the other \p tagged_reference.
* \param other The other \p tagged_reference to assign from.
*
* \return <tt>*this</tt>.
*/
template <typename OtherElement, typename OtherTag>
_CCCL_HOST_DEVICE const tagged_reference& operator=(tagged_reference<OtherElement, OtherTag> const& other) const
{
return base_type::operator=(other);
}
/*! Assign \p rhs to the object referred to by this \p tagged_reference.
*
* \param rhs The \p value_type to assign from.
*
* \return <tt>*this</tt>.
*/
_CCCL_HOST_DEVICE const tagged_reference& operator=(value_type const& rhs) const
{
return base_type::operator=(rhs);
}
};
template <typename Tag>
class tagged_reference<void, Tag>
{};
template <typename Tag>
class tagged_reference<void const, Tag>
{};
/*! Exchanges the values of two objects referred to by \p tagged_reference.
*
* \param x The first \p tagged_reference of interest.
* \param y The second \p tagged_reference of interest.
*/
// note: this is not a hidden friend, because we have template specializations of tagged_reference
template <typename Element, typename Tag>
_CCCL_HOST_DEVICE void
swap(tagged_reference<Element, Tag> x, tagged_reference<Element, Tag> y) noexcept(noexcept(x.swap(y)))
{
x.swap(y);
}
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2020, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/use_default.h>
THRUST_NAMESPACE_BEGIN
template <typename Element, typename Pointer, typename Derived = use_default>
class reference;
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,212 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/remove.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/remove.h>
#include <thrust/system/detail/sequential/remove.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(remove.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(remove.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/remove.h>
# include <thrust/system/cuda/detail/remove.h>
# include <thrust/system/omp/detail/remove.h>
# include <thrust/system/tbb/detail/remove.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T>
_CCCL_HOST_DEVICE ForwardIterator remove(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const T& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove");
using thrust::system::detail::generic::remove;
return remove(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, value);
} // end remove()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename T>
_CCCL_HOST_DEVICE OutputIterator remove_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
const T& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_copy");
using thrust::system::detail::generic::remove_copy;
return remove_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, value);
} // end remove_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename Predicate>
_CCCL_HOST_DEVICE ForwardIterator remove_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_if");
using thrust::system::detail::generic::remove_if;
return remove_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred);
} // end remove_if()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename Predicate>
_CCCL_HOST_DEVICE OutputIterator remove_copy_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_copy_if");
using thrust::system::detail::generic::remove_copy_if;
return remove_copy_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, pred);
} // end remove_copy_if()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename Predicate>
_CCCL_HOST_DEVICE ForwardIterator remove_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator stencil,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_if");
using thrust::system::detail::generic::remove_if;
return remove_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, pred);
} // end remove_if()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename Predicate>
_CCCL_HOST_DEVICE OutputIterator remove_copy_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first,
InputIterator1 last,
InputIterator2 stencil,
OutputIterator result,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_copy_if");
using thrust::system::detail::generic::remove_copy_if;
return remove_copy_if(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, result, pred);
} // end remove_copy_if()
template <typename ForwardIterator, typename T>
ForwardIterator remove(ForwardIterator first, ForwardIterator last, const T& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::remove(select_system(system), first, last, value);
} // end remove()
template <typename InputIterator, typename OutputIterator, typename T>
OutputIterator remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::remove_copy(select_system(system1, system2), first, last, result, value);
} // end remove_copy()
template <typename ForwardIterator, typename Predicate>
ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_if");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::remove_if(select_system(system), first, last, pred);
} // end remove_if()
template <typename ForwardIterator, typename InputIterator, typename Predicate>
ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
System1 system1;
System2 system2;
return thrust::remove_if(select_system(system1, system2), first, last, stencil, pred);
} // end remove_if()
template <typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_copy_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::remove_copy_if(select_system(system1, system2), first, last, result, pred);
} // end remove_copy_if()
template <typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
OutputIterator
remove_copy_if(InputIterator1 first, InputIterator1 last, InputIterator2 stencil, OutputIterator result, Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::remove_copy_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::remove_copy_if(select_system(system1, system2, system3), first, last, stencil, result, pred);
} // end remove_copy_if()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,230 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/replace.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/replace.h>
#include <thrust/system/detail/sequential/replace.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(replace.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(replace.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/replace.h>
# include <thrust/system/cuda/detail/replace.h>
# include <thrust/system/omp/detail/replace.h>
# include <thrust/system/tbb/detail/replace.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T>
_CCCL_HOST_DEVICE void
replace(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const T& old_value,
const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace");
using thrust::system::detail::generic::replace;
return replace(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, old_value, new_value);
} // end replace()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename Predicate, typename T>
_CCCL_HOST_DEVICE void replace_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
Predicate pred,
const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_if");
using thrust::system::detail::generic::replace_if;
return replace_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, pred, new_value);
} // end replace_if()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename Predicate, typename T>
_CCCL_HOST_DEVICE void replace_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
InputIterator stencil,
Predicate pred,
const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_if");
using thrust::system::detail::generic::replace_if;
return replace_if(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, pred, new_value);
} // end replace_if()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename T>
_CCCL_HOST_DEVICE OutputIterator replace_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
const T& old_value,
const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_copy");
using thrust::system::detail::generic::replace_copy;
return replace_copy(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, old_value, new_value);
} // end replace_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename Predicate, typename T>
_CCCL_HOST_DEVICE OutputIterator replace_copy_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
Predicate pred,
const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_copy_if");
using thrust::system::detail::generic::replace_copy_if;
return replace_copy_if(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, pred, new_value);
} // end replace_copy_if()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename Predicate,
typename T>
_CCCL_HOST_DEVICE OutputIterator replace_copy_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first,
InputIterator1 last,
InputIterator2 stencil,
OutputIterator result,
Predicate pred,
const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_copy_if");
using thrust::system::detail::generic::replace_copy_if;
return replace_copy_if(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, stencil, result, pred, new_value);
} // end replace_copy_if()
template <typename InputIterator, typename OutputIterator, typename Predicate, typename T>
OutputIterator
replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_copy_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::replace_copy_if(select_system(system1, system2), first, last, result, pred, new_value);
} // end replace_copy_if()
template <typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate, typename T>
OutputIterator replace_copy_if(
InputIterator1 first,
InputIterator1 last,
InputIterator2 stencil,
OutputIterator result,
Predicate pred,
const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_copy_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::replace_copy_if(
select_system(system1, system2, system3), first, last, stencil, result, pred, new_value);
} // end replace_copy_if()
template <typename InputIterator, typename OutputIterator, typename T>
OutputIterator
replace_copy(InputIterator first, InputIterator last, OutputIterator result, const T& old_value, const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::replace_copy(select_system(system1, system2), first, last, result, old_value, new_value);
} // end replace_copy()
template <typename ForwardIterator, typename Predicate, typename T>
void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_if");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::replace_if(select_system(system), first, last, pred, new_value);
} // end replace_if()
template <typename ForwardIterator, typename InputIterator, typename Predicate, typename T>
void replace_if(ForwardIterator first, ForwardIterator last, InputIterator stencil, Predicate pred, const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator>::type;
using System2 = typename thrust::iterator_system<InputIterator>::type;
System1 system1;
System2 system2;
return thrust::replace_if(select_system(system1, system2), first, last, stencil, pred, new_value);
} // end replace_if()
template <typename ForwardIterator, typename T>
void replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::replace");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::replace(select_system(system), first, last, old_value, new_value);
} // end replace()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,87 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/reverse.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/reverse.h>
#include <thrust/system/detail/sequential/reverse.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(reverse.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(reverse.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/reverse.h>
# include <thrust/system/cuda/detail/reverse.h>
# include <thrust/system/omp/detail/reverse.h>
# include <thrust/system/tbb/detail/reverse.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename BidirectionalIterator>
_CCCL_HOST_DEVICE void reverse(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
BidirectionalIterator first,
BidirectionalIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reverse");
using thrust::system::detail::generic::reverse;
return reverse(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end reverse()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename BidirectionalIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator reverse_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
BidirectionalIterator first,
BidirectionalIterator last,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reverse_copy");
using thrust::system::detail::generic::reverse_copy;
return reverse_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result);
} // end reverse_copy()
template <typename BidirectionalIterator>
void reverse(BidirectionalIterator first, BidirectionalIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reverse");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<BidirectionalIterator>::type;
System system;
return thrust::reverse(select_system(system), first, last);
} // end reverse()
template <typename BidirectionalIterator, typename OutputIterator>
OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::reverse_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<BidirectionalIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::reverse_copy(select_system(system1, system2), first, last, result);
} // end reverse_copy()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,523 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/scan.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/scan.h>
#include <thrust/system/detail/generic/scan_by_key.h>
#include <thrust/system/detail/sequential/scan.h>
#include <thrust/system/detail/sequential/scan_by_key.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(scan.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(scan.h)
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(scan_by_key.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(scan_by_key.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/scan.h>
# include <thrust/system/cpp/detail/scan_by_key.h>
# include <thrust/system/cuda/detail/scan.h>
# include <thrust/system/cuda/detail/scan_by_key.h>
# include <thrust/system/omp/detail/scan.h>
# include <thrust/system/omp/detail/scan_by_key.h>
# include <thrust/system/tbb/detail/scan.h>
# include <thrust/system/tbb/detail/scan_by_key.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator inclusive_scan(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan");
using thrust::system::detail::generic::inclusive_scan;
return inclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result);
} // end inclusive_scan()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename AssociativeOperator>
_CCCL_HOST_DEVICE OutputIterator inclusive_scan(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
AssociativeOperator binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan");
using thrust::system::detail::generic::inclusive_scan;
return inclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, binary_op);
} // end inclusive_scan()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename T, typename AssociativeOperator>
_CCCL_HOST_DEVICE OutputIterator inclusive_scan(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
T init,
AssociativeOperator binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan");
using thrust::system::detail::generic::inclusive_scan;
return inclusive_scan(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, init, binary_op);
} // end inclusive_scan()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator exclusive_scan(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan");
using thrust::system::detail::generic::exclusive_scan;
return exclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result);
} // end exclusive_scan()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename T>
_CCCL_HOST_DEVICE OutputIterator exclusive_scan(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
T init)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan");
using thrust::system::detail::generic::exclusive_scan;
return exclusive_scan(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, init);
} // end exclusive_scan()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename T, typename AssociativeOperator>
_CCCL_HOST_DEVICE OutputIterator exclusive_scan(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator result,
T init,
AssociativeOperator binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan");
using thrust::system::detail::generic::exclusive_scan;
return exclusive_scan(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, result, init, binary_op);
} // end exclusive_scan()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator inclusive_scan_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan_by_key");
using thrust::system::detail::generic::inclusive_scan_by_key;
return inclusive_scan_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result);
} // end inclusive_scan_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename BinaryPredicate>
_CCCL_HOST_DEVICE OutputIterator inclusive_scan_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan_by_key");
using thrust::system::detail::generic::inclusive_scan_by_key;
return inclusive_scan_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, binary_pred);
} // end inclusive_scan_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename BinaryPredicate,
typename AssociativeOperator>
_CCCL_HOST_DEVICE OutputIterator inclusive_scan_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
BinaryPredicate binary_pred,
AssociativeOperator binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan_by_key");
using thrust::system::detail::generic::inclusive_scan_by_key;
return inclusive_scan_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
first1,
last1,
first2,
result,
binary_pred,
binary_op);
} // end inclusive_scan_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator exclusive_scan_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan_by_key");
using thrust::system::detail::generic::exclusive_scan_by_key;
return exclusive_scan_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result);
} // end exclusive_scan_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename OutputIterator, typename T>
_CCCL_HOST_DEVICE OutputIterator exclusive_scan_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
T init)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan_by_key");
using thrust::system::detail::generic::exclusive_scan_by_key;
return exclusive_scan_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, init);
} // end exclusive_scan_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename T,
typename BinaryPredicate>
_CCCL_HOST_DEVICE OutputIterator exclusive_scan_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
T init,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan_by_key");
using thrust::system::detail::generic::exclusive_scan_by_key;
return exclusive_scan_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2, result, init, binary_pred);
} // end exclusive_scan_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename T,
typename BinaryPredicate,
typename AssociativeOperator>
_CCCL_HOST_DEVICE OutputIterator exclusive_scan_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
T init,
BinaryPredicate binary_pred,
AssociativeOperator binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan_by_key");
using thrust::system::detail::generic::exclusive_scan_by_key;
return exclusive_scan_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
first1,
last1,
first2,
result,
init,
binary_pred,
binary_op);
} // end exclusive_scan_by_key()
template <typename InputIterator, typename OutputIterator>
OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::inclusive_scan(select_system(system1, system2), first, last, result);
} // end inclusive_scan()
template <typename InputIterator, typename OutputIterator, typename BinaryFunction>
OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::inclusive_scan(select_system(system1, system2), first, last, result, binary_op);
} // end inclusive_scan()
template <typename InputIterator, typename OutputIterator, typename T, typename BinaryFunction>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::inclusive_scan(select_system(system1, system2), first, last, result, init, binary_op);
} // end inclusive_scan()
template <typename InputIterator, typename OutputIterator>
OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::exclusive_scan(select_system(system1, system2), first, last, result);
} // end exclusive_scan()
template <typename InputIterator, typename OutputIterator, typename T>
OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::exclusive_scan(select_system(system1, system2), first, last, result, init);
} // end exclusive_scan()
template <typename InputIterator, typename OutputIterator, typename T, typename BinaryFunction>
OutputIterator
exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::exclusive_scan(select_system(system1, system2), first, last, result, init, binary_op);
} // end exclusive_scan()
template <typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator
inclusive_scan_by_key(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::inclusive_scan_by_key(select_system(system1, system2, system3), first1, last1, first2, result);
}
template <typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryPredicate>
OutputIterator inclusive_scan_by_key(
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::inclusive_scan_by_key(
select_system(system1, system2, system3), first1, last1, first2, result, binary_pred);
}
template <typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename BinaryPredicate,
typename AssociativeOperator>
OutputIterator inclusive_scan_by_key(
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
BinaryPredicate binary_pred,
AssociativeOperator binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::inclusive_scan_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::inclusive_scan_by_key(
select_system(system1, system2, system3), first1, last1, first2, result, binary_pred, binary_op);
}
template <typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator
exclusive_scan_by_key(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::exclusive_scan_by_key(select_system(system1, system2, system3), first1, last1, first2, result);
}
template <typename InputIterator1, typename InputIterator2, typename OutputIterator, typename T>
OutputIterator
exclusive_scan_by_key(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, T init)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::exclusive_scan_by_key(select_system(system1, system2, system3), first1, last1, first2, result, init);
}
template <typename InputIterator1, typename InputIterator2, typename OutputIterator, typename T, typename BinaryPredicate>
OutputIterator exclusive_scan_by_key(
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
T init,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::exclusive_scan_by_key(
select_system(system1, system2, system3), first1, last1, first2, result, init, binary_pred);
}
template <typename InputIterator1,
typename InputIterator2,
typename OutputIterator,
typename T,
typename BinaryPredicate,
typename AssociativeOperator>
OutputIterator exclusive_scan_by_key(
InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
OutputIterator result,
T init,
BinaryPredicate binary_pred,
AssociativeOperator binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::exclusive_scan_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::exclusive_scan_by_key(
select_system(system1, system2, system3), first1, last1, first2, result, init, binary_pred, binary_op);
}
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,156 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/scatter.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/scatter.h>
#include <thrust/system/detail/sequential/scatter.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(scatter.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(scatter.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/scatter.h>
# include <thrust/system/cuda/detail/scatter.h>
# include <thrust/system/omp/detail/scatter.h>
# include <thrust/system/tbb/detail/scatter.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator1, typename InputIterator2, typename RandomAccessIterator>
_CCCL_HOST_DEVICE void
scatter(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first,
InputIterator1 last,
InputIterator2 map,
RandomAccessIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::scatter");
using thrust::system::detail::generic::scatter;
return scatter(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, map, output);
} // end scatter()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename InputIterator3,
typename RandomAccessIterator>
_CCCL_HOST_DEVICE void scatter_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first,
InputIterator1 last,
InputIterator2 map,
InputIterator3 stencil,
RandomAccessIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::scatter_if");
using thrust::system::detail::generic::scatter_if;
return scatter_if(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, map, stencil, output);
} // end scatter_if()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename InputIterator3,
typename RandomAccessIterator,
typename Predicate>
_CCCL_HOST_DEVICE void scatter_if(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 first,
InputIterator1 last,
InputIterator2 map,
InputIterator3 stencil,
RandomAccessIterator output,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::scatter_if");
using thrust::system::detail::generic::scatter_if;
return scatter_if(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, map, stencil, output, pred);
} // end scatter_if()
template <typename InputIterator1, typename InputIterator2, typename RandomAccessIterator>
void scatter(InputIterator1 first, InputIterator1 last, InputIterator2 map, RandomAccessIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::scatter");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<RandomAccessIterator>::type;
System1 system1;
System2 system2;
System3 system3;
return thrust::scatter(select_system(system1, system2, system3), first, last, map, output);
} // end scatter()
template <typename InputIterator1, typename InputIterator2, typename InputIterator3, typename RandomAccessIterator>
void scatter_if(
InputIterator1 first, InputIterator1 last, InputIterator2 map, InputIterator3 stencil, RandomAccessIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::scatter_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<InputIterator3>::type;
using System4 = typename thrust::iterator_system<RandomAccessIterator>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
return thrust::scatter_if(select_system(system1, system2, system3, system4), first, last, map, stencil, output);
} // end scatter_if()
template <typename InputIterator1,
typename InputIterator2,
typename InputIterator3,
typename RandomAccessIterator,
typename Predicate>
void scatter_if(InputIterator1 first,
InputIterator1 last,
InputIterator2 map,
InputIterator3 stencil,
RandomAccessIterator output,
Predicate pred)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::scatter_if");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<InputIterator3>::type;
using System4 = typename thrust::iterator_system<RandomAccessIterator>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
return thrust::scatter_if(select_system(system1, system2, system3, system4), first, last, map, stencil, output, pred);
} // end scatter_if()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2018, NVIDIA CORPORATION. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/allocator_aware_execution_policy.h>
#include <thrust/system/detail/sequential/execution_policy.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
struct seq_t
: system::detail::sequential::execution_policy<seq_t>
, allocator_aware_execution_policy<system::detail::sequential::execution_policy>
{
constexpr seq_t() = default;
// allow any execution_policy to convert to the sequential one. required for minimum_system to pick it
template <typename DerivedPolicy>
_CCCL_HOST_DEVICE seq_t(const thrust::execution_policy<DerivedPolicy>&)
{}
};
} // namespace detail
//! \p thrust::seq is an execution policy which requires an algorithm invocation to execute sequentially in the current
//! thread. It can not be configured by a compile-time macro.
//!
//! The type of \p thrust::seq is implementation-defined.
//!
//! The following code snippet demonstrates how to use \p thrust::seq to explicitly execute an invocation of \p
//! thrust::for_each sequentially:
//!
//! \code
//! #include <thrust/for_each.h>
//! #include <thrust/execution_policy.h>
//! #include <vector>
//! #include <cstdio>
//!
//! struct printf_functor
//! {
//! __host__ __device__
//! void operator()(int x)
//! {
//! printf("%d\n", x);
//! }
//! };
//! ...
//! std::vector<int> vec{0, 1, 2};
//! thrust::for_each(thrust::seq, vec.begin(), vec.end(), printf_functor());
//!
//! // 0 1 2 is printed to standard output in sequential order
//! \endcode
//!
//! \see thrust::host
//! \see thrust::device
_CCCL_GLOBAL_CONSTANT detail::seq_t seq;
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,108 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/sequence.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/sequence.h>
#include <thrust/system/detail/sequential/sequence.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(sequence.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(sequence.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/sequence.h>
# include <thrust/system/cuda/detail/sequence.h>
# include <thrust/system/omp/detail/sequence.h>
# include <thrust/system/tbb/detail/sequence.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator>
_CCCL_HOST_DEVICE void
sequence(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sequence");
using thrust::system::detail::generic::sequence;
return sequence(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end sequence()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T>
_CCCL_HOST_DEVICE void sequence(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last, T init)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sequence");
using thrust::system::detail::generic::sequence;
return sequence(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, init);
} // end sequence()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T>
_CCCL_HOST_DEVICE void sequence(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
T init,
T step)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sequence");
using thrust::system::detail::generic::sequence;
return sequence(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, init, step);
} // end sequence()
template <typename ForwardIterator>
void sequence(ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sequence");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::sequence(select_system(system), first, last);
} // end sequence()
template <typename ForwardIterator, typename T>
void sequence(ForwardIterator first, ForwardIterator last, T init)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sequence");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::sequence(select_system(system), first, last, init);
} // end sequence()
template <typename ForwardIterator, typename T>
void sequence(ForwardIterator first, ForwardIterator last, T init, T step)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sequence");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::sequence(select_system(system), first, last, init, step);
} // end sequence()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,372 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/sort.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/sort.h>
#include <thrust/system/detail/sequential/sort.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(sort.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(sort.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/sort.h>
# include <thrust/system/cuda/detail/sort.h>
# include <thrust/system/omp/detail/sort.h>
# include <thrust/system/tbb/detail/sort.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename RandomAccessIterator>
_CCCL_HOST_DEVICE void sort(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
RandomAccessIterator first,
RandomAccessIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sort");
using thrust::system::detail::generic::sort;
return sort(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end sort()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename RandomAccessIterator, typename StrictWeakOrdering>
_CCCL_HOST_DEVICE void
sort(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
RandomAccessIterator first,
RandomAccessIterator last,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sort");
using thrust::system::detail::generic::sort;
return sort(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp);
} // end sort()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename RandomAccessIterator>
_CCCL_HOST_DEVICE void stable_sort(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
RandomAccessIterator first,
RandomAccessIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_sort");
using thrust::system::detail::generic::stable_sort;
return stable_sort(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end stable_sort()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename RandomAccessIterator, typename StrictWeakOrdering>
_CCCL_HOST_DEVICE void stable_sort(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
RandomAccessIterator first,
RandomAccessIterator last,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_sort");
using thrust::system::detail::generic::stable_sort;
return stable_sort(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp);
} // end stable_sort()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename RandomAccessIterator1, typename RandomAccessIterator2>
_CCCL_HOST_DEVICE void sort_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
RandomAccessIterator1 keys_first,
RandomAccessIterator1 keys_last,
RandomAccessIterator2 values_first)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sort_by_key");
using thrust::system::detail::generic::sort_by_key;
return sort_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first);
} // end sort_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename RandomAccessIterator1,
typename RandomAccessIterator2,
typename StrictWeakOrdering>
_CCCL_HOST_DEVICE void sort_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
RandomAccessIterator1 keys_first,
RandomAccessIterator1 keys_last,
RandomAccessIterator2 values_first,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sort_by_key");
using thrust::system::detail::generic::sort_by_key;
return sort_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, comp);
} // end sort_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename RandomAccessIterator1, typename RandomAccessIterator2>
_CCCL_HOST_DEVICE void stable_sort_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
RandomAccessIterator1 keys_first,
RandomAccessIterator1 keys_last,
RandomAccessIterator2 values_first)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_sort_by_key");
using thrust::system::detail::generic::stable_sort_by_key;
return stable_sort_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first);
} // end stable_sort_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename RandomAccessIterator1,
typename RandomAccessIterator2,
typename StrictWeakOrdering>
_CCCL_HOST_DEVICE void stable_sort_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
RandomAccessIterator1 keys_first,
RandomAccessIterator1 keys_last,
RandomAccessIterator2 values_first,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_sort_by_key");
using thrust::system::detail::generic::stable_sort_by_key;
return stable_sort_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, comp);
} // end stable_sort_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator>
_CCCL_HOST_DEVICE bool
is_sorted(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_sorted");
using thrust::system::detail::generic::is_sorted;
return is_sorted(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end is_sorted()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename Compare>
_CCCL_HOST_DEVICE bool
is_sorted(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
Compare comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_sorted");
using thrust::system::detail::generic::is_sorted;
return is_sorted(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp);
} // end is_sorted()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator>
_CCCL_HOST_DEVICE ForwardIterator is_sorted_until(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_sorted_until");
using thrust::system::detail::generic::is_sorted_until;
return is_sorted_until(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end is_sorted_until()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename Compare>
_CCCL_HOST_DEVICE ForwardIterator is_sorted_until(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
Compare comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_sorted_until");
using thrust::system::detail::generic::is_sorted_until;
return is_sorted_until(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, comp);
} // end is_sorted_until()
///////////////
// Key Sorts //
///////////////
template <typename RandomAccessIterator>
void sort(RandomAccessIterator first, RandomAccessIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sort");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<RandomAccessIterator>::type;
System system;
return thrust::sort(select_system(system), first, last);
} // end sort()
template <typename RandomAccessIterator, typename StrictWeakOrdering>
_CCCL_HOST_DEVICE void sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sort");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<RandomAccessIterator>::type;
System system;
return thrust::sort(select_system(system), first, last, comp);
} // end sort()
template <typename RandomAccessIterator>
void stable_sort(RandomAccessIterator first, RandomAccessIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_sort");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<RandomAccessIterator>::type;
System system;
return thrust::stable_sort(select_system(system), first, last);
} // end stable_sort()
template <typename RandomAccessIterator, typename StrictWeakOrdering>
void stable_sort(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_sort");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<RandomAccessIterator>::type;
System system;
return thrust::stable_sort(select_system(system), first, last, comp);
} // end stable_sort()
/////////////////////
// Key-Value Sorts //
/////////////////////
template <typename RandomAccessIterator1, typename RandomAccessIterator2>
void sort_by_key(RandomAccessIterator1 keys_first, RandomAccessIterator1 keys_last, RandomAccessIterator2 values_first)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sort_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<RandomAccessIterator1>::type;
using System2 = typename thrust::iterator_system<RandomAccessIterator2>::type;
System1 system1;
System2 system2;
return thrust::sort_by_key(select_system(system1, system2), keys_first, keys_last, values_first);
} // end sort_by_key()
template <typename RandomAccessIterator1, typename RandomAccessIterator2, typename StrictWeakOrdering>
void sort_by_key(RandomAccessIterator1 keys_first,
RandomAccessIterator1 keys_last,
RandomAccessIterator2 values_first,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::sort_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<RandomAccessIterator1>::type;
using System2 = typename thrust::iterator_system<RandomAccessIterator2>::type;
System1 system1;
System2 system2;
return thrust::sort_by_key(select_system(system1, system2), keys_first, keys_last, values_first, comp);
} // end sort_by_key()
template <typename RandomAccessIterator1, typename RandomAccessIterator2>
void stable_sort_by_key(
RandomAccessIterator1 keys_first, RandomAccessIterator1 keys_last, RandomAccessIterator2 values_first)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_sort_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<RandomAccessIterator1>::type;
using System2 = typename thrust::iterator_system<RandomAccessIterator2>::type;
System1 system1;
System2 system2;
return thrust::stable_sort_by_key(select_system(system1, system2), keys_first, keys_last, values_first);
} // end stable_sort_by_key()
template <typename RandomAccessIterator1, typename RandomAccessIterator2, typename StrictWeakOrdering>
void stable_sort_by_key(RandomAccessIterator1 keys_first,
RandomAccessIterator1 keys_last,
RandomAccessIterator2 values_first,
StrictWeakOrdering comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::stable_sort_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<RandomAccessIterator1>::type;
using System2 = typename thrust::iterator_system<RandomAccessIterator2>::type;
System1 system1;
System2 system2;
return thrust::stable_sort_by_key(select_system(system1, system2), keys_first, keys_last, values_first, comp);
} // end stable_sort_by_key()
template <typename ForwardIterator>
bool is_sorted(ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_sorted");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::is_sorted(select_system(system), first, last);
} // end is_sorted()
template <typename ForwardIterator, typename Compare>
bool is_sorted(ForwardIterator first, ForwardIterator last, Compare comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_sorted");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::is_sorted(select_system(system), first, last, comp);
} // end is_sorted()
template <typename ForwardIterator>
ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_sorted_until");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::is_sorted_until(select_system(system), first, last);
} // end is_sorted_until()
template <typename ForwardIterator, typename Compare>
ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::is_sorted_until");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::is_sorted_until(select_system(system), first, last, comp);
} // end is_sorted_until()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*
* (C) Copyright John Maddock 2000.
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying NOTICE file for the complete license)
*
* For more information, see http://www.boost.org
*/
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/preprocessor.h>
#include <thrust/detail/type_traits.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename, bool x>
struct depend_on_instantiation
{
static constexpr bool value = x;
};
//! Deprecated [Since 3.0]
#define THRUST_STATIC_ASSERT(B) static_assert(B)
//! Deprecated [Since 3.0]
#define THRUST_STATIC_ASSERT_MSG(B, msg) static_assert(B, msg)
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/swap.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/swap_ranges.h>
#include <thrust/system/detail/sequential/swap_ranges.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(swap_ranges.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(swap_ranges.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/swap_ranges.h>
# include <thrust/system/cuda/detail/swap_ranges.h>
# include <thrust/system/omp/detail/swap_ranges.h>
# include <thrust/system/tbb/detail/swap_ranges.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator1, typename ForwardIterator2>
_CCCL_HOST_DEVICE ForwardIterator2 swap_ranges(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator1 first1,
ForwardIterator1 last1,
ForwardIterator2 first2)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::swap_ranges");
using thrust::system::detail::generic::swap_ranges;
return swap_ranges(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first1, last1, first2);
} // end swap_ranges()
template <typename ForwardIterator1, typename ForwardIterator2>
ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::swap_ranges");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator1>::type;
using System2 = typename thrust::iterator_system<ForwardIterator2>::type;
System1 system1;
System2 system2;
return thrust::swap_ranges(select_system(system1, system2), first1, last1, first2);
} // end swap_ranges()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
#include <thrust/tabulate.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/tabulate.h>
#include <thrust/system/detail/sequential/tabulate.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(tabulate.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(tabulate.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/tabulate.h>
# include <thrust/system/cuda/detail/tabulate.h>
# include <thrust/system/omp/detail/tabulate.h>
# include <thrust/system/tbb/detail/tabulate.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename UnaryOperation>
_CCCL_HOST_DEVICE void
tabulate(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
UnaryOperation unary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::tabulate");
using thrust::system::detail::generic::tabulate;
return tabulate(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, unary_op);
} // end tabulate()
template <typename ForwardIterator, typename UnaryOperation>
void tabulate(ForwardIterator first, ForwardIterator last, UnaryOperation unary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::tabulate");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::tabulate(select_system(system), first, last, unary_op);
} // end tabulate()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,137 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file temporary_array.h
* \brief Container-like class temporary storage inside algorithms.
*/
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
THRUST_NAMESPACE_BEGIN
namespace detail
{
// Forward declare temporary_array, as it's used by the CUDA copy backend, which
// is included in contiguous_storage's definition.
template <typename T, typename System>
class temporary_array;
} // namespace detail
THRUST_NAMESPACE_END
#include <thrust/detail/allocator/no_throw_allocator.h>
#include <thrust/detail/allocator/temporary_allocator.h>
#include <thrust/detail/contiguous_storage.h>
#include <thrust/iterator/detail/tagged_iterator.h>
#include <thrust/iterator/iterator_traits.h>
#include <cuda/std/__host_stdlib/memory>
#include <cuda/std/__type_traits/is_convertible.h>
#include <cuda/std/__type_traits/type_identity.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename T, typename System>
class temporary_array : public contiguous_storage<T, no_throw_allocator<temporary_allocator<T, System>>>
{
private:
using super_t = contiguous_storage<T, no_throw_allocator<temporary_allocator<T, System>>>;
// to help out the constructor
using alloc_type = no_throw_allocator<temporary_allocator<T, System>>;
public:
using size_type = typename super_t::size_type;
_CCCL_HOST_DEVICE temporary_array(thrust::execution_policy<System>& system);
_CCCL_HOST_DEVICE temporary_array(thrust::execution_policy<System>& system, size_type n);
// provide a kill-switch to explicitly avoid initialization
_CCCL_HOST_DEVICE temporary_array(int uninit, thrust::execution_policy<System>& system, size_type n);
template <typename InputIterator>
_CCCL_HOST_DEVICE temporary_array(thrust::execution_policy<System>& system, InputIterator first, size_type n);
template <typename InputIterator, typename InputSystem>
_CCCL_HOST_DEVICE temporary_array(
thrust::execution_policy<System>& system,
thrust::execution_policy<InputSystem>& input_system,
InputIterator first,
size_type n);
template <typename InputIterator>
_CCCL_HOST_DEVICE temporary_array(thrust::execution_policy<System>& system, InputIterator first, InputIterator last);
template <typename InputSystem, typename InputIterator>
_CCCL_HOST_DEVICE temporary_array(
thrust::execution_policy<System>& system,
thrust::execution_policy<InputSystem>& input_system,
InputIterator first,
InputIterator last);
_CCCL_HOST_DEVICE ~temporary_array();
}; // end temporary_array
// XXX eliminate this when we do ranges for real
template <typename Iterator, typename System>
class tagged_iterator_range
{
public:
using iterator = thrust::detail::tagged_iterator<Iterator, System>;
template <typename Ignored1, typename Ignored2>
tagged_iterator_range(const Ignored1&, const Ignored2&, Iterator first, Iterator last)
: m_begin(first)
, m_end(last)
{}
iterator begin() const
{
return m_begin;
}
iterator end() const
{
return m_end;
}
private:
iterator m_begin, m_end;
};
// if FromSystem is convertible to ToSystem, then just make a shallow
// copy of the range. else, use a temporary_array
// note that the resulting iterator is explicitly tagged with ToSystem either way
template <typename Iterator, typename FromSystem, typename ToSystem>
struct move_to_system_base
: public eval_if<::cuda::std::is_convertible<FromSystem, ToSystem>::value,
::cuda::std::type_identity<tagged_iterator_range<Iterator, ToSystem>>,
::cuda::std::type_identity<temporary_array<thrust::detail::it_value_t<Iterator>, ToSystem>>>
{};
template <typename Iterator, typename FromSystem, typename ToSystem>
class move_to_system : public move_to_system_base<Iterator, FromSystem, ToSystem>::type
{
using super_t = typename move_to_system_base<Iterator, FromSystem, ToSystem>::type;
public:
move_to_system(thrust::execution_policy<FromSystem>& from_system,
thrust::execution_policy<ToSystem>& to_system,
Iterator first,
Iterator last)
: super_t(to_system, from_system, first, last)
{}
};
} // namespace detail
THRUST_NAMESPACE_END
#include <thrust/detail/temporary_array.inl>

View File

@@ -0,0 +1,108 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2021, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/temporary_array.h>
#include <thrust/detail/type_traits.h>
#include <thrust/system/detail/generic/select_system.h>
#include <cuda/std/__iterator/distance.h>
#include <cuda/std/__type_traits/is_trivially_copy_constructible.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename T, typename System>
_CCCL_HOST_DEVICE temporary_array<T, System>::temporary_array(thrust::execution_policy<System>& system)
: super_t(alloc_type(temporary_allocator<T, System>(system)))
{} // end temporary_array::temporary_array()
template <typename T, typename System>
_CCCL_HOST_DEVICE temporary_array<T, System>::temporary_array(thrust::execution_policy<System>& system, size_type n)
: super_t(n, alloc_type(temporary_allocator<T, System>(system)))
{
if constexpr (!::cuda::std::is_trivially_copy_constructible_v<T>)
{
super_t::value_initialize_n(super_t::begin(), n);
}
} // end temporary_array::temporary_array()
template <typename T, typename System>
_CCCL_HOST_DEVICE temporary_array<T, System>::temporary_array(int, thrust::execution_policy<System>& system, size_type n)
: super_t(n, alloc_type(temporary_allocator<T, System>(system)))
{
// avoid initialization
;
} // end temporary_array::temporary_array()
template <typename T, typename System>
template <typename InputIterator>
_CCCL_HOST_DEVICE
temporary_array<T, System>::temporary_array(thrust::execution_policy<System>& system, InputIterator first, size_type n)
: super_t(alloc_type(temporary_allocator<T, System>(system)))
{
super_t::allocate(n);
super_t::uninitialized_copy_n(system, first, n, super_t::begin());
} // end temporary_array::temporary_array()
template <typename T, typename System>
template <typename InputIterator, typename InputSystem>
_CCCL_HOST_DEVICE temporary_array<T, System>::temporary_array(
thrust::execution_policy<System>& system,
thrust::execution_policy<InputSystem>& input_system,
InputIterator first,
size_type n)
: super_t(alloc_type(temporary_allocator<T, System>(system)))
{
super_t::allocate(n);
super_t::uninitialized_copy_n(input_system, first, n, super_t::begin());
} // end temporary_array::temporary_array()
template <typename T, typename System>
template <typename InputIterator>
_CCCL_HOST_DEVICE temporary_array<T, System>::temporary_array(
thrust::execution_policy<System>& system, InputIterator first, InputIterator last)
: super_t(alloc_type(temporary_allocator<T, System>(system)))
{
super_t::allocate(::cuda::std::distance(first, last));
super_t::uninitialized_copy(system, first, last, super_t::begin());
} // end temporary_array::temporary_array()
template <typename T, typename System>
template <typename InputSystem, typename InputIterator>
_CCCL_HOST_DEVICE temporary_array<T, System>::temporary_array(
thrust::execution_policy<System>& system,
thrust::execution_policy<InputSystem>& input_system,
InputIterator first,
InputIterator last)
: super_t(alloc_type(temporary_allocator<T, System>(system)))
{
super_t::allocate(::cuda::std::distance(first, last));
super_t::uninitialized_copy(input_system, first, last, super_t::begin());
} // end temporary_array::temporary_array()
template <typename T, typename System>
_CCCL_HOST_DEVICE temporary_array<T, System>::~temporary_array()
{
// note that super_t::destroy will ignore trivial destructors automatically
super_t::destroy(super_t::begin(), super_t::end());
} // end temporary_array::~temporary_array()
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,80 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/execute_with_allocator.h>
#include <thrust/detail/execution_policy.h>
#include <thrust/detail/pointer.h>
#include <thrust/detail/raw_pointer_cast.h>
#include <cuda/std/__utility/pair.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/temporary_buffer.h>
#include <thrust/system/detail/sequential/temporary_buffer.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(temporary_buffer.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(temporary_buffer.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/temporary_buffer.h>
# include <thrust/system/cuda/detail/temporary_buffer.h>
# include <thrust/system/omp/detail/temporary_buffer.h>
# include <thrust/system/tbb/detail/temporary_buffer.h>
#endif
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename T, typename DerivedPolicy, typename Pair>
_CCCL_HOST_DEVICE ::cuda::std::pair<thrust::pointer<T, DerivedPolicy>,
typename thrust::pointer<T, DerivedPolicy>::difference_type>
down_cast_pair(Pair p)
{
// XXX should use a hypothetical thrust::static_pointer_cast here
thrust::pointer<T, DerivedPolicy> ptr =
thrust::pointer<T, DerivedPolicy>(static_cast<T*>(thrust::raw_pointer_cast(p.first)));
using result_type =
::cuda::std::pair<thrust::pointer<T, DerivedPolicy>, typename thrust::pointer<T, DerivedPolicy>::difference_type>;
return result_type(ptr, p.second);
} // end down_cast_pair()
} // namespace detail
_CCCL_EXEC_CHECK_DISABLE
template <typename T, typename DerivedPolicy>
_CCCL_HOST_DEVICE ::cuda::std::pair<thrust::pointer<T, DerivedPolicy>,
typename thrust::pointer<T, DerivedPolicy>::difference_type>
get_temporary_buffer(const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
typename thrust::pointer<T, DerivedPolicy>::difference_type n)
{
using thrust::detail::get_temporary_buffer; // execute_with_allocator
using thrust::system::detail::generic::get_temporary_buffer;
return thrust::detail::down_cast_pair<T, DerivedPolicy>(
get_temporary_buffer<T>(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), n));
} // end get_temporary_buffer()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename Pointer>
_CCCL_HOST_DEVICE void
return_temporary_buffer(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, Pointer p, std::ptrdiff_t n)
{
using thrust::detail::return_temporary_buffer; // execute_with_allocator
using thrust::system::detail::generic::return_temporary_buffer;
return return_temporary_buffer(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), p, n);
} // end return_temporary_buffer()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,68 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/transform_reduce.h>
#include <thrust/system/detail/sequential/transform_reduce.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(transform_reduce.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(transform_reduce.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/transform_reduce.h>
# include <thrust/system/cuda/detail/transform_reduce.h>
# include <thrust/system/omp/detail/transform_reduce.h>
# include <thrust/system/tbb/detail/transform_reduce.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator,
typename UnaryFunction,
typename OutputType,
typename BinaryFunction>
_CCCL_HOST_DEVICE OutputType transform_reduce(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
UnaryFunction unary_op,
OutputType init,
BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::transform_reduce");
using thrust::system::detail::generic::transform_reduce;
return transform_reduce(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, unary_op, init, binary_op);
} // end transform_reduce()
template <typename InputIterator, typename UnaryFunction, typename OutputType, typename BinaryFunction>
OutputType transform_reduce(
InputIterator first, InputIterator last, UnaryFunction unary_op, OutputType init, BinaryFunction binary_op)
{
_CCCL_NVTX_RANGE_SCOPE("thrust::transform_reduce");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<InputIterator>::type;
System system;
return thrust::transform_reduce(select_system(system), first, last, unary_op, init, binary_op);
} // end transform_reduce()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,115 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file trivial_sequence.h
* \brief Container-like class for wrapping sequences. The wrapped
* sequence always has trivial iterators, even when the input
* sequence does not.
*/
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/execution_policy.h>
#include <thrust/detail/temporary_array.h>
#include <thrust/detail/type_traits.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/type_traits/is_contiguous_iterator.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
// never instantiated
template <typename Iterator, typename DerivedPolicy, bool is_trivial>
struct _trivial_sequence
{};
// trivial case
template <typename Iterator, typename DerivedPolicy>
struct _trivial_sequence<Iterator, DerivedPolicy, true>
{
using iterator_type = Iterator;
Iterator first, last;
_CCCL_HOST_DEVICE _trivial_sequence(thrust::execution_policy<DerivedPolicy>&, Iterator _first, Iterator _last)
: first(_first)
, last(_last)
{}
_CCCL_HOST_DEVICE iterator_type begin()
{
return first;
}
_CCCL_HOST_DEVICE friend iterator_type begin(_trivial_sequence& sequence)
{
return sequence.first;
}
_CCCL_HOST_DEVICE iterator_type end()
{
return last;
}
_CCCL_HOST_DEVICE friend iterator_type end(_trivial_sequence& sequence)
{
return sequence.last;
}
};
// non-trivial case
template <typename Iterator, typename DerivedPolicy>
struct _trivial_sequence<Iterator, DerivedPolicy, false>
{
using iterator_value = it_value_t<Iterator>;
using iterator_type = typename thrust::detail::temporary_array<iterator_value, DerivedPolicy>::iterator;
thrust::detail::temporary_array<iterator_value, DerivedPolicy> buffer;
_CCCL_HOST_DEVICE _trivial_sequence(thrust::execution_policy<DerivedPolicy>& exec, Iterator first, Iterator last)
: buffer(exec, first, last)
{}
_CCCL_HOST_DEVICE iterator_type begin()
{
return buffer.begin();
}
_CCCL_HOST_DEVICE friend iterator_type begin(_trivial_sequence& sequence)
{
return sequence.begin();
}
_CCCL_HOST_DEVICE iterator_type end()
{
return buffer.end();
}
_CCCL_HOST_DEVICE friend iterator_type end(_trivial_sequence& sequence)
{
return sequence.end();
}
};
template <typename Iterator, typename DerivedPolicy>
struct trivial_sequence : detail::_trivial_sequence<Iterator, DerivedPolicy, is_contiguous_iterator_v<Iterator>>
{
using super_t = _trivial_sequence<Iterator, DerivedPolicy, is_contiguous_iterator_v<Iterator>>;
_CCCL_HOST_DEVICE trivial_sequence(thrust::execution_policy<DerivedPolicy>& exec, Iterator first, Iterator last)
: super_t(exec, first, last)
{}
};
} // end namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: Copyright (c) 2018, NVIDIA Corporation
// SPDX-FileCopyrightText: Copyright (c) 2013-2018, Eric Niebler (`THRUST_RETURNS`, etc)
// SPDX-FileCopyrightText: Copyright (c) 2016-2018, Casey Carter (`THRUST_RETURNS`, etc)
// SPDX-License-Identifier: BSL-1.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/preprocessor.h>
#include <cuda/std/__utility/forward.h>
///////////////////////////////////////////////////////////////////////////////
/// \def THRUST_FWD(x)
/// \brief Performs universal forwarding of a universal reference.
///
#define THRUST_FWD(x) ::cuda::std::forward<decltype(x)>(x)
/// \def THRUST_RETURNS(...)
/// \brief Expands to a function definition that returns the expression
/// \c __VA_ARGS__.
///
#define THRUST_RETURNS(...) \
noexcept(noexcept(__VA_ARGS__)) \
{ \
return (__VA_ARGS__); \
} \
/**/
/// \def THRUST_DECLTYPE_RETURNS(...)
/// \brief Expands to a function definition, including a trailing returning
/// type, that returns the expression \c __VA_ARGS__.
///
// Trailing return types seem to confuse Doxygen, and cause it to interpret
// parts of the function's body as new function signatures.
#if defined(_CCCL_DOXYGEN_INVOKED)
# define THRUST_DECLTYPE_RETURNS(...) \
{ \
return (__VA_ARGS__); \
} \
/**/
#else
# define THRUST_DECLTYPE_RETURNS(...) \
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) \
{ \
return (__VA_ARGS__); \
} \
/**/
#endif

View File

@@ -0,0 +1,126 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2022, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file type_traits.h
* \brief Temporarily define some type traits
* until nvcc can compile tr1::type_traits.
*/
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <cuda/std/__functional/invoke.h>
#include <cuda/std/__type_traits/conjunction.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/integral_constant.h>
#include <cuda/std/__type_traits/is_arithmetic.h>
#include <cuda/std/__type_traits/is_convertible.h>
#include <cuda/std/__type_traits/is_integral.h>
#include <cuda/std/__type_traits/type_identity.h>
THRUST_NAMESPACE_BEGIN
// forward declaration of device_reference
template <typename T>
class device_reference;
namespace detail
{
/// helper classes [4.3].
template <typename T, T v>
using integral_constant = ::cuda::std::integral_constant<T, v>;
using true_type = ::cuda::std::true_type;
using false_type = ::cuda::std::false_type;
template <typename T>
struct is_non_bool_integral : public ::cuda::std::is_integral<T>
{};
template <>
struct is_non_bool_integral<bool> : public false_type
{};
template <typename T>
struct is_non_bool_arithmetic : public ::cuda::std::is_arithmetic<T>
{};
template <>
struct is_non_bool_arithmetic<bool> : public false_type
{};
template <typename T>
inline constexpr bool is_proxy_reference_v = false;
template <typename Boolean>
struct not_ : public ::cuda::std::integral_constant<bool, !Boolean::value>
{}; // end not_
template <bool, typename Then, typename Else>
struct eval_if
{}; // end eval_if
template <typename Then, typename Else>
struct eval_if<true, Then, Else>
{
using type = typename Then::type;
}; // end eval_if
template <typename Then, typename Else>
struct eval_if<false, Then, Else>
{
using type = typename Else::type;
}; // end eval_if
template <bool, typename T>
struct lazy_enable_if
{};
template <typename T>
struct lazy_enable_if<true, T>
{
using type = typename T::type;
};
template <bool condition, typename T = void>
struct disable_if : ::cuda::std::enable_if<!condition, T>
{};
template <bool condition, typename T>
struct lazy_disable_if : lazy_enable_if<!condition, T>
{};
template <typename T1, typename T2, typename T = void>
using enable_if_convertible_t = ::cuda::std::enable_if_t<::cuda::std::is_convertible<T1, T2>::value, T>;
template <typename T1, typename T2, typename T = void>
struct disable_if_convertible : disable_if<::cuda::std::is_convertible<T1, T2>::value, T>
{};
struct largest_available_float
{
using type = double;
};
// T1 wins if they are both the same size
template <typename T1, typename T2>
struct larger_type
: thrust::detail::eval_if<(sizeof(T2) > sizeof(T1)), ::cuda::std::type_identity<T2>, ::cuda::std::type_identity<T1>>
{};
template <class F, class... Us>
using invoke_result = ::cuda::std::invoke_result<F, Us...>;
template <class F, class... Us>
using invoke_result_t = typename invoke_result<F, Us...>::type;
} // namespace detail
using detail::false_type;
using detail::integral_constant;
using detail::true_type;
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/type_traits.h>
#define __THRUST_DEFINE_HAS_NESTED_TYPE(trait_name, nested_type_name) \
template <typename T> \
struct trait_name \
{ \
using yes_type = char; \
using no_type = int; \
template <typename S> \
_CCCL_HOST_DEVICE static yes_type test(typename S::nested_type_name*); \
template <typename S> \
_CCCL_HOST_DEVICE static no_type test(...); \
static bool const value = sizeof(test<T>(0)) == sizeof(yes_type); \
using type = thrust::detail::integral_constant<bool, value>; \
};

View File

@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2020, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#include <cuda/std/__type_traits/void_t.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
namespace pointer_traits_detail
{
template <typename Ptr, typename Enable = void>
struct pointer_raw_pointer_impl
{};
template <typename T>
struct pointer_raw_pointer_impl<T*>
{
using type = T*;
};
template <typename Ptr>
struct pointer_raw_pointer_impl<Ptr, ::cuda::std::void_t<typename Ptr::raw_pointer>>
{
using type = typename Ptr::raw_pointer;
};
} // namespace pointer_traits_detail
template <typename T>
struct pointer_raw_pointer : pointer_traits_detail::pointer_raw_pointer_impl<T>
{};
// Check whether we are dealing with either a raw pointer or a thrust smart pointer
template <typename T, typename = void>
inline constexpr bool is_thrust_pointer_v = false;
template <typename T>
inline constexpr bool is_thrust_pointer_v<T*> = true;
template <typename T>
inline constexpr bool is_thrust_pointer_v<T, ::cuda::std::void_t<typename T::raw_pointer>> = true;
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/iterator/detail/any_assign.h>
#include <thrust/iterator/iterator_traits.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/is_void.h>
#include <cuda/std/__type_traits/void_t.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename T, typename SFINAE = void>
inline constexpr bool is_output_iterator = true;
template <typename T>
inline constexpr bool is_output_iterator<T, ::cuda::std::void_t<it_value_t<T>>> =
::cuda::std::is_void_v<it_value_t<T>> || ::cuda::std::is_same_v<it_value_t<T>, any_assign>;
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,78 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_convertible.h>
#include <cuda/std/__type_traits/is_same.h>
THRUST_NAMESPACE_BEGIN
namespace detail
{
struct no_minimum_type_marker
{};
// Returns the minimum type, or `no_minimum_type_marker`if T1 and T2 are unrelated.
template <typename T1,
typename T2,
bool GreaterEqual = ::cuda::std::is_convertible_v<T1, T2>,
bool LessEqual = ::cuda::std::is_convertible_v<T2, T1>>
struct smaller_type
{
using type = T1;
};
// T1 >= T2
template <typename T1, typename T2>
struct smaller_type<T1, T2, true, false>
{
using type = T2;
};
// unordered
template <typename T1, typename T2>
struct smaller_type<T1, T2, false, false>
{
using type = no_minimum_type_marker;
};
template <typename Head, typename... Tail>
struct minimum_type_impl : smaller_type<Head, typename minimum_type_impl<Tail...>::type>
{};
template <typename T>
struct minimum_type_impl<T>
{
using type = T;
};
// Has no nested ::type to produce a SFINAE-friendly error, in case the minimum_type is `no_minimum_type_marker`
template <typename SFINAE, typename... Ts>
struct minimum_type_check_marker
{};
template <typename... Ts>
struct minimum_type_check_marker<
::cuda::std::enable_if_t<!::cuda::std::is_same_v<typename minimum_type_impl<Ts...>::type, no_minimum_type_marker>>,
Ts...> : minimum_type_impl<Ts...>
{};
// Alias to the minimum type of the given pack. The minimum type is the one to which all other types are convertible.
// If no such type exists, a SFINAE-friendly compile-time error is generated.
template <typename... Ts>
using minimum_type = typename minimum_type_check_marker<void, Ts...>::type;
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,163 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2020, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/type_traits.h>
#include <thrust/detail/type_traits/has_nested_type.h>
#include <thrust/detail/type_traits/is_thrust_pointer.h>
#include <thrust/iterator/iterator_traits.h>
#include <cuda/std/__type_traits/add_lvalue_reference.h>
#include <cuda/std/__type_traits/conjunction.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_comparable.h>
#include <cuda/std/__type_traits/is_convertible.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/is_void.h>
#include <cuda/std/__type_traits/type_identity.h>
#include <cuda/std/cstddef>
THRUST_NAMESPACE_BEGIN
namespace detail
{
template <typename Ptr, typename T>
struct rebind_pointer;
template <typename T, typename U>
struct rebind_pointer<T*, U>
{
using type = U*;
};
// Rebind generic fancy pointers.
template <template <typename, typename...> class Ptr, typename OldT, typename... Tail, typename T>
struct rebind_pointer<Ptr<OldT, Tail...>, T>
{
using type = Ptr<T, Tail...>;
};
// Rebind `thrust::pointer`-like things with `thrust::reference`-like references.
template <template <typename, typename, typename, typename...> class Ptr,
typename OldT,
typename Tag,
template <typename...> class Ref,
typename... RefTail,
typename... PtrTail,
typename T>
struct rebind_pointer<Ptr<OldT, Tag, Ref<OldT, RefTail...>, PtrTail...>, T>
{
// static_assert(::cuda::std::is_same<OldT, Tag>::value, "0");
using type = Ptr<T, Tag, Ref<T, RefTail...>, PtrTail...>;
};
// Rebind `thrust::pointer`-like things with `thrust::reference`-like references
// and templated derived types.
template <template <typename, typename, typename, typename...> class Ptr,
typename OldT,
typename Tag,
template <typename...> class Ref,
typename... RefTail,
template <typename...> class DerivedPtr,
typename... DerivedPtrTail,
typename T>
struct rebind_pointer<Ptr<OldT, Tag, Ref<OldT, RefTail...>, DerivedPtr<OldT, DerivedPtrTail...>>, T>
{
// static_assert(::cuda::std::is_same<OldT, Tag>::value, "1");
using type = Ptr<T, Tag, Ref<T, RefTail...>, DerivedPtr<T, DerivedPtrTail...>>;
};
// Rebind `thrust::pointer`-like things with native reference types.
template <template <typename, typename, typename, typename...> class Ptr,
typename OldT,
typename Tag,
typename... PtrTail,
typename T>
struct rebind_pointer<Ptr<OldT, Tag, ::cuda::std::add_lvalue_reference_t<OldT>, PtrTail...>, T>
{
// static_assert(::cuda::std::is_same<OldT, Tag>::value, "2");
using type = Ptr<T, Tag, ::cuda::std::add_lvalue_reference_t<T>, PtrTail...>;
};
// Rebind `thrust::pointer`-like things with native reference types and templated
// derived types.
template <template <typename, typename, typename, typename...> class Ptr,
typename OldT,
typename Tag,
template <typename...> class DerivedPtr,
typename... DerivedPtrTail,
typename T>
struct rebind_pointer<Ptr<OldT, Tag, ::cuda::std::add_lvalue_reference_t<OldT>, DerivedPtr<OldT, DerivedPtrTail...>>, T>
{
// static_assert(::cuda::std::is_same<OldT, Tag>::value, "3");
using type = Ptr<T, Tag, ::cuda::std::add_lvalue_reference_t<T>, DerivedPtr<T, DerivedPtrTail...>>;
};
template <typename FromPtr, typename ToPtr>
inline constexpr bool is_pointer_system_convertible_v =
::cuda::std::is_convertible_v<iterator_system_t<FromPtr>, iterator_system_t<ToPtr>>;
template <typename FromPtr, typename ToPtr>
inline constexpr bool is_pointer_convertible_v =
::cuda::std::is_convertible_v<typename ::cuda::std::pointer_traits<FromPtr>::element_type*,
typename ::cuda::std::pointer_traits<ToPtr>::element_type*>
&& is_pointer_system_convertible_v<FromPtr, ToPtr>;
template <typename FromPtr, typename ToPtr>
inline constexpr bool is_void_pointer_system_convertible_v =
::cuda::std::is_void_v<typename ::cuda::std::pointer_traits<FromPtr>::element_type> //
&& is_pointer_system_convertible_v<FromPtr, ToPtr>;
// avoid inspecting traits of the arguments if they aren't known to be pointers
template <typename FromPtr, typename ToPtr, bool = is_thrust_pointer_v<FromPtr> && is_thrust_pointer_v<ToPtr>>
inline constexpr bool lazy_is_pointer_convertible_v = false;
template <typename FromPtr, typename ToPtr>
inline constexpr bool lazy_is_pointer_convertible_v<FromPtr, ToPtr, true> = is_pointer_convertible_v<FromPtr, ToPtr>;
template <typename FromPtr, typename ToPtr, bool = is_thrust_pointer_v<FromPtr> && is_thrust_pointer_v<ToPtr>>
inline constexpr bool lazy_is_void_pointer_system_convertible_v = false;
template <typename FromPtr, typename ToPtr>
inline constexpr bool lazy_is_void_pointer_system_convertible_v<FromPtr, ToPtr, true> =
is_void_pointer_system_convertible_v<FromPtr, ToPtr>;
template <typename FromPtr, typename ToPtr, typename T = void>
using enable_if_pointer_is_convertible_t = ::cuda::std::enable_if_t<lazy_is_pointer_convertible_v<FromPtr, ToPtr>, T>;
template <typename FromPtr, typename ToPtr, typename T = void>
using enable_if_void_pointer_is_system_convertible_t =
::cuda::std::enable_if_t<lazy_is_void_pointer_system_convertible_v<FromPtr, ToPtr>, T>;
// tagged pointers can only compare if they have a matching system and comparable pointer type
template <typename FromPtr, typename ToPtr>
inline constexpr bool ptr_can_compare_equal =
is_pointer_system_convertible_v<FromPtr, ToPtr>
&& ::cuda::std::__is_cpp17_equality_comparable_v<typename FromPtr::value_type*, typename ToPtr::value_type*>;
template <typename FromPtr, typename ToPtr>
inline constexpr bool ptr_can_compare_less_than =
is_pointer_system_convertible_v<FromPtr, ToPtr>
&& ::cuda::std::__is_cpp17_less_than_comparable_v<typename FromPtr::value_type*, typename ToPtr::value_type*>;
// tagged references can only compare if they have a matching system and comparable value type
template <typename FromPtr, typename ToPtr>
inline constexpr bool ref_can_compare_equal =
is_pointer_system_convertible_v<FromPtr, ToPtr>
&& ::cuda::std::__is_cpp17_equality_comparable_v<typename FromPtr::value_type, typename ToPtr::value_type>;
template <typename FromPtr, typename ToPtr>
inline constexpr bool ref_can_compare_less_than =
is_pointer_system_convertible_v<FromPtr, ToPtr>
&& ::cuda::std::__is_cpp17_less_than_comparable_v<typename FromPtr::value_type, typename ToPtr::value_type>;
} // namespace detail
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/nvtx_policy.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
#include <thrust/uninitialized_fill.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/uninitialized_fill.h>
#include <thrust/system/detail/sequential/uninitialized_fill.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(uninitialized_fill.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(uninitialized_fill.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/uninitialized_fill.h>
# include <thrust/system/cuda/detail/uninitialized_fill.h>
# include <thrust/system/omp/detail/uninitialized_fill.h>
# include <thrust/system/tbb/detail/uninitialized_fill.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename T>
_CCCL_HOST_DEVICE void uninitialized_fill(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
const T& x)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "uninitialized_fill");
using thrust::system::detail::generic::uninitialized_fill;
return uninitialized_fill(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, x);
} // end uninitialized_fill()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename Size, typename T>
_CCCL_HOST_DEVICE ForwardIterator uninitialized_fill_n(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, Size n, const T& x)
{
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<DerivedPolicy>(), "uninitialized_fill_n");
using thrust::system::detail::generic::uninitialized_fill_n;
return uninitialized_fill_n(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, n, x);
} // end uninitialized_fill_n()
template <typename ForwardIterator, typename T>
void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x)
{
using System = typename thrust::iterator_system<ForwardIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<System>(), "uninitialized_fill");
using thrust::system::detail::generic::select_system;
System system;
thrust::uninitialized_fill(select_system(system), first, last, x);
} // end uninitialized_fill()
template <typename ForwardIterator, typename Size, typename T>
ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x)
{
using System = typename thrust::iterator_system<ForwardIterator>::type;
_CCCL_NVTX_RANGE_SCOPE_IF(detail::should_enable_nvtx_for_policy<System>(), "uninitialized_fill_n");
using thrust::system::detail::generic::select_system;
System system;
return thrust::uninitialized_fill_n(select_system(system), first, n, x);
} // end uninitialized_fill_n()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,378 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/temporary_array.h>
#include <thrust/iterator/iterator_traits.h>
#include <thrust/system/detail/generic/select_system.h>
#include <thrust/unique.h>
// Include all active backend system implementations (generic, sequential, host and device)
#include <thrust/system/detail/generic/unique.h>
#include <thrust/system/detail/generic/unique_by_key.h>
#include <thrust/system/detail/sequential/unique.h>
#include <thrust/system/detail/sequential/unique_by_key.h>
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(unique.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(unique.h)
#include __THRUST_HOST_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(unique_by_key.h)
#include __THRUST_DEVICE_SYSTEM_ALGORITH_DETAIL_HEADER_INCLUDE(unique_by_key.h)
// Some build systems need a hint to know which files we could include
#if 0
# include <thrust/system/cpp/detail/unique.h>
# include <thrust/system/cpp/detail/unique_by_key.h>
# include <thrust/system/cuda/detail/unique.h>
# include <thrust/system/cuda/detail/unique_by_key.h>
# include <thrust/system/omp/detail/unique.h>
# include <thrust/system/omp/detail/unique_by_key.h>
# include <thrust/system/tbb/detail/unique.h>
# include <thrust/system/tbb/detail/unique_by_key.h>
#endif
THRUST_NAMESPACE_BEGIN
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator>
_CCCL_HOST_DEVICE ForwardIterator
unique(const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("unique");
using thrust::system::detail::generic::unique;
return unique(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end unique()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
_CCCL_HOST_DEVICE ForwardIterator unique(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique");
using thrust::system::detail::generic::unique;
return unique(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, binary_pred);
} // end unique()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator>
_CCCL_HOST_DEVICE OutputIterator unique_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("unique_copy");
using thrust::system::detail::generic::unique_copy;
return unique_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, output);
} // end unique_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename BinaryPredicate>
_CCCL_HOST_DEVICE OutputIterator unique_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator first,
InputIterator last,
OutputIterator output,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique_copy");
using thrust::system::detail::generic::unique_copy;
return unique_copy(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, output, binary_pred);
} // end unique_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator1, typename ForwardIterator2>
_CCCL_HOST_DEVICE ::cuda::std::pair<ForwardIterator1, ForwardIterator2> unique_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator1 keys_first,
ForwardIterator1 keys_last,
ForwardIterator2 values_first)
{
_CCCL_NVTX_RANGE_SCOPE("unique_by_key");
using thrust::system::detail::generic::unique_by_key;
return unique_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first);
} // end unique_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<ForwardIterator1, ForwardIterator2> unique_by_key(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator1 keys_first,
ForwardIterator1 keys_last,
ForwardIterator2 values_first,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique_by_key");
using thrust::system::detail::generic::unique_by_key;
return unique_by_key(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)), keys_first, keys_last, values_first, binary_pred);
} // end unique_by_key()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> unique_by_key_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output)
{
_CCCL_NVTX_RANGE_SCOPE("unique_by_key_copy");
using thrust::system::detail::generic::unique_by_key_copy;
return unique_by_key_copy(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
keys_first,
keys_last,
values_first,
keys_output,
values_output);
} // end unique_by_key_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy,
typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename BinaryPredicate>
_CCCL_HOST_DEVICE ::cuda::std::pair<OutputIterator1, OutputIterator2> unique_by_key_copy(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique_by_key_copy");
using thrust::system::detail::generic::unique_by_key_copy;
return unique_by_key_copy(
thrust::detail::derived_cast(thrust::detail::strip_const(exec)),
keys_first,
keys_last,
values_first,
keys_output,
values_output,
binary_pred);
} // end unique_by_key_copy()
template <typename ForwardIterator>
ForwardIterator unique(ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("unique");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::unique(select_system(system), first, last);
} // end unique()
template <typename ForwardIterator, typename BinaryPredicate>
ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::unique(select_system(system), first, last, binary_pred);
} // end unique()
template <typename InputIterator, typename OutputIterator>
OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator output)
{
_CCCL_NVTX_RANGE_SCOPE("unique_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::unique_copy(select_system(system1, system2), first, last, output);
} // end unique_copy()
template <typename InputIterator, typename OutputIterator, typename BinaryPredicate>
OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator output, BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator>::type;
using System2 = typename thrust::iterator_system<OutputIterator>::type;
System1 system1;
System2 system2;
return thrust::unique_copy(select_system(system1, system2), first, last, output, binary_pred);
} // end unique_copy()
template <typename ForwardIterator1, typename ForwardIterator2>
::cuda::std::pair<ForwardIterator1, ForwardIterator2>
unique_by_key(ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first)
{
_CCCL_NVTX_RANGE_SCOPE("unique_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator1>::type;
using System2 = typename thrust::iterator_system<ForwardIterator2>::type;
System1 system1;
System2 system2;
return thrust::unique_by_key(select_system(system1, system2), keys_first, keys_last, values_first);
} // end unique_by_key()
template <typename ForwardIterator1, typename ForwardIterator2, typename BinaryPredicate>
::cuda::std::pair<ForwardIterator1, ForwardIterator2> unique_by_key(
ForwardIterator1 keys_first, ForwardIterator1 keys_last, ForwardIterator2 values_first, BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique_by_key");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<ForwardIterator1>::type;
using System2 = typename thrust::iterator_system<ForwardIterator2>::type;
System1 system1;
System2 system2;
return thrust::unique_by_key(select_system(system1, system2), keys_first, keys_last, values_first, binary_pred);
} // end unique_by_key()
template <typename InputIterator1, typename InputIterator2, typename OutputIterator1, typename OutputIterator2>
::cuda::std::pair<OutputIterator1, OutputIterator2> unique_by_key_copy(
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output)
{
_CCCL_NVTX_RANGE_SCOPE("unique_by_key_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator1>::type;
using System4 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
return thrust::unique_by_key_copy(
select_system(system1, system2, system3, system4), keys_first, keys_last, values_first, keys_output, values_output);
} // end unique_by_key_copy()
template <typename InputIterator1,
typename InputIterator2,
typename OutputIterator1,
typename OutputIterator2,
typename BinaryPredicate>
::cuda::std::pair<OutputIterator1, OutputIterator2> unique_by_key_copy(
InputIterator1 keys_first,
InputIterator1 keys_last,
InputIterator2 values_first,
OutputIterator1 keys_output,
OutputIterator2 values_output,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique_by_key_copy");
using thrust::system::detail::generic::select_system;
using System1 = typename thrust::iterator_system<InputIterator1>::type;
using System2 = typename thrust::iterator_system<InputIterator2>::type;
using System3 = typename thrust::iterator_system<OutputIterator1>::type;
using System4 = typename thrust::iterator_system<OutputIterator2>::type;
System1 system1;
System2 system2;
System3 system3;
System4 system4;
return thrust::unique_by_key_copy(
select_system(system1, system2, system3, system4),
keys_first,
keys_last,
values_first,
keys_output,
values_output,
binary_pred);
} // end unique_by_key_copy()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator, typename BinaryPredicate>
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<ForwardIterator> unique_count(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec,
ForwardIterator first,
ForwardIterator last,
BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique_count");
using thrust::system::detail::generic::unique_count;
return unique_count(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last, binary_pred);
} // end unique_count()
_CCCL_EXEC_CHECK_DISABLE
template <typename DerivedPolicy, typename ForwardIterator>
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<ForwardIterator> unique_count(
const thrust::detail::execution_policy_base<DerivedPolicy>& exec, ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("unique_count");
using thrust::system::detail::generic::unique_count;
return unique_count(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), first, last);
} // end unique_count()
_CCCL_EXEC_CHECK_DISABLE
template <typename ForwardIterator, typename BinaryPredicate>
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<ForwardIterator>
unique_count(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred)
{
_CCCL_NVTX_RANGE_SCOPE("unique_count");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::unique_count(select_system(system), first, last, binary_pred);
} // end unique_count()
_CCCL_EXEC_CHECK_DISABLE
template <typename ForwardIterator>
_CCCL_HOST_DEVICE thrust::detail::it_difference_t<ForwardIterator>
unique_count(ForwardIterator first, ForwardIterator last)
{
_CCCL_NVTX_RANGE_SCOPE("unique_count");
using thrust::system::detail::generic::select_system;
using System = typename thrust::iterator_system<ForwardIterator>::type;
System system;
return thrust::unique_count(select_system(system), first, last);
} // end unique_count()
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2013, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
THRUST_NAMESPACE_BEGIN
struct use_default
{};
THRUST_NAMESPACE_END

View File

@@ -0,0 +1,603 @@
// SPDX-FileCopyrightText: Copyright (c) 2008-2018, NVIDIA Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
/*! \file vector_base.h
* \brief Defines the interface to a base class for
* host_vector & device_vector.
*/
#pragma once
#include <thrust/detail/config.h>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <thrust/detail/contiguous_storage.h>
#include <thrust/detail/type_traits.h>
#include <thrust/iterator/detail/normal_iterator.h>
#include <thrust/iterator/iterator_traits.h>
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__iterator/reverse_iterator.h>
#include <cuda/std/__type_traits/enable_if.h>
#include <cuda/std/__type_traits/is_swappable.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/swap.h>
#include <cuda/std/initializer_list>
#include <vector>
THRUST_NAMESPACE_BEGIN
struct default_init_t
{};
struct no_init_t
{};
//! Tag to indicate that a vector's elements should be default initialized
inline constexpr default_init_t default_init;
//! Tag to indicate that a vector's elements should not be initialized
inline constexpr no_init_t no_init;
namespace detail
{
template <typename T, typename Alloc>
class vector_base
{
private:
using storage_type = thrust::detail::contiguous_storage<T, Alloc>;
public:
// aliases
using value_type = typename storage_type::value_type;
using pointer = typename storage_type::pointer;
using const_pointer = typename storage_type::const_pointer;
using reference = typename storage_type::reference;
using const_reference = typename storage_type::const_reference;
using size_type = typename storage_type::size_type;
using difference_type = typename storage_type::difference_type;
using allocator_type = typename storage_type::allocator_type;
using iterator = typename storage_type::iterator;
using const_iterator = typename storage_type::const_iterator;
using reverse_iterator = ::cuda::std::reverse_iterator<iterator>;
using const_reverse_iterator = ::cuda::std::reverse_iterator<const_iterator>;
/*! This constructor creates an empty vector_base.
*/
vector_base();
/*! This constructor creates an empty vector_base.
* \param alloc The allocator to use by this vector_base.
*/
explicit vector_base(const Alloc& alloc);
/*! This constructor creates a vector_base with value-initialized elements.
* \param n The number of elements to create.
*/
explicit vector_base(size_type n);
//! This constructor creates a vector_base with default-initialized elements.
//! \param n The number of elements to create.
explicit vector_base(size_type n, default_init_t);
//! This constructor creates a vector_base without initializing elements. It mandates that the element type is
//! trivially default-constructible.
//! \param n The number of elements to create.
template <typename T2 = T>
explicit vector_base(size_type n, no_init_t);
/*! This constructor creates a vector_base with value-initialized elements.
* \param n The number of elements to create.
* \param alloc The allocator to use by this vector_base.
*/
explicit vector_base(size_type n, const Alloc& alloc);
/*! This constructor creates a vector_base with copies
* of an exemplar element.
* \param n The number of elements to initially create.
* \param value An element to copy.
*/
explicit vector_base(size_type n, const value_type& value);
/*! This constructor creates a vector_base with copies
* of an exemplar element.
* \param n The number of elements to initially create.
* \param value An element to copy.
* \param alloc The allocator to use by this vector_base.
*/
explicit vector_base(size_type n, const value_type& value, const Alloc& alloc);
/*! Copy constructor copies from an exemplar vector_base.
* \param v The vector_base to copy.
*/
vector_base(const vector_base& v);
/*! Copy constructor copies from an exemplar vector_base.
* \param v The vector_base to copy.
* \param alloc The allocator to use by this vector_base.
*/
vector_base(const vector_base& v, const Alloc& alloc);
/*! Move constructor moves from another vector_base.
* \param v The vector_base to move.
*/
vector_base(vector_base&& v) noexcept;
// FIXME: the internal Thrust machinery in range_init doesn't work with move
// iterators, which is necessary for the following constructor to be implemented
// correctly
// vector_base(vector_base &&v, const Alloc &alloc);
/*! Copy assign operator copies from another vector_base.
* \param v The vector_base to copy.
*/
vector_base& operator=(const vector_base& v);
/*! Move assign operator moves from another vector_base.
* \param v The vector_base to move.
*/
vector_base& operator=(vector_base&& v) noexcept;
/*! This constructor builds a \p vector_base from an intializer_list.
* \param il The intializer_list.
*/
vector_base(::cuda::std::initializer_list<T> il);
/*! This constructor builds a \p vector_base from an intializer_list.
* \param il The intializer_list.
* \param alloc The allocator to use by this device_vector.
*/
vector_base(::cuda::std::initializer_list<T> il, const Alloc& alloc);
/*! Assign operator copies from an initializer_list
* \param il The initializer_list.
*/
vector_base& operator=(::cuda::std::initializer_list<T> il);
/*! Copy constructor copies from an exemplar vector_base with different
* type.
* \param v The vector_base to copy.
*/
template <typename OtherT, typename OtherAlloc>
vector_base(const vector_base<OtherT, OtherAlloc>& v);
/*! assign operator makes a copy of an exemplar vector_base with different
* type.
* \param v The vector_base to copy.
*/
template <typename OtherT, typename OtherAlloc>
vector_base& operator=(const vector_base<OtherT, OtherAlloc>& v);
/*! Copy constructor copies from an exemplar std::vector.
* \param v The std::vector to copy.
* XXX TODO: Make this method redundant with a properly templatized constructor.
* We would like to copy from a vector whose element type is anything
* assignable to value_type.
*/
template <typename OtherT, typename OtherAlloc>
vector_base(const std::vector<OtherT, OtherAlloc>& v);
/*! assign operator makes a copy of an exemplar std::vector.
* \param v The vector to copy.
* XXX TODO: Templatize this assign on the type of the vector to copy from.
* We would like to copy from a vector whose element type is anything
* assignable to value_type.
*/
template <typename OtherT, typename OtherAlloc>
vector_base& operator=(const std::vector<OtherT, OtherAlloc>& v);
/*! This constructor builds a vector_base from a range.
* \param first The beginning of the range.
* \param last The end of the range.
*/
template <typename InputIterator, ::cuda::std::enable_if_t<::cuda::std::__has_input_traversal<InputIterator>, int> = 0>
vector_base(InputIterator first, InputIterator last);
/*! This constructor builds a vector_base from a range.
* \param first The beginning of the range.
* \param last The end of the range.
* \param alloc The allocator to use by this vector_base.
*/
template <typename InputIterator, ::cuda::std::enable_if_t<::cuda::std::__has_input_traversal<InputIterator>, int> = 0>
vector_base(InputIterator first, InputIterator last, const Alloc& alloc);
/*! The destructor erases the elements.
*/
~vector_base();
/*! \brief Resizes this vector_base to the specified number of elements.
* \param new_size Number of elements this vector_base should contain.
* \throw std::length_error If n exceeds max_size().
*
* This method will resize this vector_base to the specified number of
* elements. If the number is smaller than this vector_base's current
* size this vector_base is truncated, otherwise this vector_base is
* extended and new elements are value initialized.
*/
void resize(size_type new_size);
//! \brief Resizes this vector_base to the specified number of elements, performing default-initialization instead of
//! value-initialization.
//! \param new_size Number of elements this vector_base should contain.
//! \throw std::length_error If n exceeds max_size().
void resize(size_type new_size, default_init_t);
//! \brief Resizes this vector_base to the specified number of elements, without initializing elements. It mandates
//! that the element type is trivially default-constructible.
//! \param new_size Number of elements this vector_base should contain.
//! \throw std::length_error If n exceeds max_size().
template <typename T2 = T>
void resize(size_type new_size, no_init_t);
/*! \brief Resizes this vector_base to the specified number of elements.
* \param new_size Number of elements this vector_base should contain.
* \param x Data with which new elements should be populated.
* \throw std::length_error If n exceeds max_size().
*
* This method will resize this vector_base to the specified number of
* elements. If the number is smaller than this vector_base's current
* size this vector_base is truncated, otherwise this vector_base is
* extended and new elements are populated with given data.
*/
void resize(size_type new_size, const value_type& x);
/*! Returns the number of elements in this vector_base.
*/
_CCCL_HOST_DEVICE size_type size() const;
/*! Returns the size() of the largest possible vector_base.
* \return The largest possible return value of size().
*/
_CCCL_HOST_DEVICE size_type max_size() const;
/*! \brief If n is less than or equal to capacity(), this call has no effect.
* Otherwise, this method is a request for allocation of additional memory. If
* the request is successful, then capacity() is greater than or equal to
* n; otherwise, capacity() is unchanged. In either case, size() is unchanged.
* \throw std::length_error If n exceeds max_size().
*/
void reserve(size_type n);
/*! Returns the number of elements which have been reserved in this
* vector_base.
*/
_CCCL_HOST_DEVICE size_type capacity() const;
/*! This method shrinks the capacity of this vector_base to exactly
* fit its elements.
*/
void shrink_to_fit();
/*! \brief Subscript access to the data contained in this vector_dev.
* \param n The index of the element for which data should be accessed.
* \return Read/write reference to data.
*
* This operator allows for easy, array-style, data access.
* Note that data access with this operator is unchecked and
* out_of_range lookups are not defined.
*/
_CCCL_HOST_DEVICE reference operator[](size_type n);
/*! \brief Subscript read access to the data contained in this vector_dev.
* \param n The index of the element for which data should be accessed.
* \return Read reference to data.
*
* This operator allows for easy, array-style, data access.
* Note that data access with this operator is unchecked and
* out_of_range lookups are not defined.
*/
_CCCL_HOST_DEVICE const_reference operator[](size_type n) const;
/*! This method returns an iterator pointing to the beginning of
* this vector_base.
* \return mStart
*/
_CCCL_HOST_DEVICE iterator begin();
/*! This method returns a const_iterator pointing to the beginning
* of this vector_base.
* \return mStart
*/
_CCCL_HOST_DEVICE const_iterator begin() const;
/*! This method returns a const_iterator pointing to the beginning
* of this vector_base.
* \return mStart
*/
_CCCL_HOST_DEVICE const_iterator cbegin() const;
/*! This method returns a reverse_iterator pointing to the beginning of
* this vector_base's reversed sequence.
* \return A reverse_iterator pointing to the beginning of this
* vector_base's reversed sequence.
*/
_CCCL_HOST_DEVICE reverse_iterator rbegin();
/*! This method returns a const_reverse_iterator pointing to the beginning of
* this vector_base's reversed sequence.
* \return A const_reverse_iterator pointing to the beginning of this
* vector_base's reversed sequence.
*/
_CCCL_HOST_DEVICE const_reverse_iterator rbegin() const;
/*! This method returns a const_reverse_iterator pointing to the beginning of
* this vector_base's reversed sequence.
* \return A const_reverse_iterator pointing to the beginning of this
* vector_base's reversed sequence.
*/
_CCCL_HOST_DEVICE const_reverse_iterator crbegin() const;
/*! This method returns an iterator pointing to one element past the
* last of this vector_base.
* \return begin() + size().
*/
_CCCL_HOST_DEVICE iterator end();
/*! This method returns a const_iterator pointing to one element past the
* last of this vector_base.
* \return begin() + size().
*/
_CCCL_HOST_DEVICE const_iterator end() const;
/*! This method returns a const_iterator pointing to one element past the
* last of this vector_base.
* \return begin() + size().
*/
_CCCL_HOST_DEVICE const_iterator cend() const;
/*! This method returns a reverse_iterator pointing to one element past the
* last of this vector_base's reversed sequence.
* \return rbegin() + size().
*/
_CCCL_HOST_DEVICE reverse_iterator rend();
/*! This method returns a const_reverse_iterator pointing to one element past the
* last of this vector_base's reversed sequence.
* \return rbegin() + size().
*/
_CCCL_HOST_DEVICE const_reverse_iterator rend() const;
/*! This method returns a const_reverse_iterator pointing to one element past the
* last of this vector_base's reversed sequence.
* \return rbegin() + size().
*/
_CCCL_HOST_DEVICE const_reverse_iterator crend() const;
/*! This method returns a const_reference referring to the first element of this
* vector_base.
* \return The first element of this vector_base.
*/
_CCCL_HOST_DEVICE const_reference front() const;
/*! This method returns a reference pointing to the first element of this
* vector_base.
* \return The first element of this vector_base.
*/
_CCCL_HOST_DEVICE reference front();
/*! This method returns a const reference pointing to the last element of
* this vector_base.
* \return The last element of this vector_base.
*/
_CCCL_HOST_DEVICE const_reference back() const;
/*! This method returns a reference referring to the last element of
* this vector_dev.
* \return The last element of this vector_base.
*/
_CCCL_HOST_DEVICE reference back();
/*! This method returns a pointer to this vector_base's first element.
* \return A pointer to the first element of this vector_base.
*/
_CCCL_HOST_DEVICE pointer data();
/*! This method returns a const_pointer to this vector_base's first element.
* \return a const_pointer to the first element of this vector_base.
*/
_CCCL_HOST_DEVICE const_pointer data() const;
/*! This method resizes this vector_base to 0.
*/
void clear();
/*! This method returns true iff size() == 0.
* \return true if size() == 0; false, otherwise.
*/
_CCCL_HOST_DEVICE bool empty() const;
/*! This method appends the given element to the end of this vector_base.
* \param x The element to append.
*/
void push_back(const value_type& x);
/*! This method erases the last element of this vector_base, invalidating
* all iterators and references to it.
*/
void pop_back();
/*! This method swaps the contents of this vector_base with another vector_base.
* \param v The vector_base with which to swap.
*/
// NOLINTNEXTLINE(bugprone-exception-escape)
void swap(vector_base& v) noexcept(::cuda::std::is_nothrow_swappable_v<storage_type>
&& ::cuda::std::is_nothrow_swappable_v<size_type>)
{
using ::cuda::std::swap;
swap(m_storage, v.m_storage);
swap(m_size, v.m_size);
}
/*! This method removes the element at position pos.
* \param pos The position of the element of interest.
* \return An iterator pointing to the new location of the element that followed the element
* at position pos.
*/
iterator erase(iterator pos);
/*! This method removes the range of elements [first,last) from this vector_base.
* \param first The beginning of the range of elements to remove.
* \param last The end of the range of elements to remove.
* \return An iterator pointing to the new location of the element that followed the last
* element in the sequence [first,last).
*/
iterator erase(iterator first, iterator last);
/*! This method inserts a single copy of a given exemplar value at the
* specified position in this vector_base.
* \param position The insertion position.
* \param x The exemplar element to copy & insert.
* \return An iterator pointing to the newly inserted element.
*/
iterator insert(iterator position, const T& x);
/*! This method inserts a copy of an exemplar value to a range at the
* specified position in this vector_base.
* \param position The insertion position
* \param n The number of insertions to perform.
* \param x The value to replicate and insert.
*/
void insert(iterator position, size_type n, const T& x);
/*! This method inserts a copy of an input range at the specified position
* in this vector_base.
* \param position The insertion position.
* \param first The beginning of the range to copy.
* \param last The end of the range to copy.
*
* \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/iterator/input_iterator>Input
* Iterator</a>, and \p InputIterator's \c value_type is a model of <a
* href="https://en.cppreference.com/w/cpp/named_req/CopyAssignable">Assignable</a>.
*/
template <typename InputIterator>
void insert(iterator position, InputIterator first, InputIterator last);
/*! This version of \p assign replicates a given exemplar
* \p n times into this vector_base.
* \param n The number of times to copy \p x.
* \param x The exemplar element to replicate.
*/
void assign(size_type n, const T& x);
/*! This version of \p assign makes this vector_base a copy of a given input range.
* \param first The beginning of the range to copy.
* \param last The end of the range to copy.
*
* \tparam InputIterator is a model of <a href="https://en.cppreference.com/w/cpp/named_req/InputIterator">Input
* Iterator</a>.
*/
template <typename InputIterator>
void assign(InputIterator first, InputIterator last);
/*! This method returns a copy of this vector's allocator.
* \return A copy of the allocator used by this vector.
*/
allocator_type get_allocator() const;
_CCCL_SYNTHESIZE_SEQUENCE_ACCESS(vector_base, const_iterator)
_CCCL_SYNTHESIZE_SEQUENCE_REVERSE_ACCESS(vector_base, const_reverse_iterator)
protected:
// Our storage
storage_type m_storage;
// The size of this vector_base, in number of elements.
size_type m_size;
private:
template <typename InputIterator>
void range_init(InputIterator first, InputIterator last);
void value_init(size_type n);
void fill_init(size_type n, const T& x);
// these methods resolve the ambiguity of the insert() template of form (iterator, InputIterator, InputIterator)
template <typename InputIteratorOrIntegralType>
void
insert_dispatch(iterator position, InputIteratorOrIntegralType first, InputIteratorOrIntegralType last, false_type);
// these methods resolve the ambiguity of the insert() template of form (iterator, InputIterator, InputIterator)
template <typename InputIteratorOrIntegralType>
void insert_dispatch(iterator position, InputIteratorOrIntegralType n, InputIteratorOrIntegralType x, true_type);
// this method appends n value-initialized elements at the end
template <bool SkipInit = false>
void append(size_type n);
// this method performs insertion from a fill value
void fill_insert(iterator position, size_type n, const T& x);
// this method performs insertion from a range
template <typename InputIterator>
void copy_insert(iterator position, InputIterator first, InputIterator last);
// this method performs assignment from a range
template <typename InputIterator>
void range_assign(InputIterator first, InputIterator last);
// this method performs assignment from a fill value
void fill_assign(size_type n, const T& x);
// this method allocates new storage and construct copies the given range
template <typename ForwardIterator>
void
allocate_and_copy(size_type requested_size, ForwardIterator first, ForwardIterator last, storage_type& new_storage);
/*! This function assigns the contents of vector a to vector b and the
* contents of vector b to vector a.
*
* \param a The first vector of interest. After completion, the contents
* of b will be returned here.
* \param b The second vector of interest. After completion, the contents
* of a will be returned here.
*/
friend void swap(vector_base& a, vector_base& b) noexcept(noexcept(a.swap(b))) // NOLINT(bugprone-exception-escape)
{
a.swap(b);
}
}; // end vector_base
/*! This operator allows comparison between two vectors.
* \param lhs The first \p vector to compare.
* \param rhs The second \p vector to compare.
* \return \c true if and only if each corresponding element in either
* \p vector equals the other; \c false, otherwise.
*/
template <typename T1, typename Alloc1, typename T2, typename Alloc2>
bool operator==(const vector_base<T1, Alloc1>& lhs, const vector_base<T2, Alloc2>& rhs);
template <typename T1, typename Alloc1, typename T2, typename Alloc2>
bool operator==(const vector_base<T1, Alloc1>& lhs, const std::vector<T2, Alloc2>& rhs);
template <typename T1, typename Alloc1, typename T2, typename Alloc2>
bool operator==(const std::vector<T1, Alloc1>& lhs, const vector_base<T2, Alloc2>& rhs);
/*! This operator allows comparison between two vectors.
* \param lhs The first \p vector to compare.
* \param rhs The second \p vector to compare.
* \return \c false if and only if each corresponding element in either
* \p vector equals the other; \c true, otherwise.
*/
template <typename T1, typename Alloc1, typename T2, typename Alloc2>
bool operator!=(const vector_base<T1, Alloc1>& lhs, const vector_base<T2, Alloc2>& rhs);
template <typename T1, typename Alloc1, typename T2, typename Alloc2>
bool operator!=(const vector_base<T1, Alloc1>& lhs, const std::vector<T2, Alloc2>& rhs);
template <typename T1, typename Alloc1, typename T2, typename Alloc2>
bool operator!=(const std::vector<T1, Alloc1>& lhs, const vector_base<T2, Alloc2>& rhs);
} // namespace detail
THRUST_NAMESPACE_END
#include <thrust/detail/vector_base.inl>

File diff suppressed because it is too large Load Diff