// Copyright (c) 2018 NVIDIA Corporation // Author: Bryce Adelstein Lelbach // // Distributed under the Boost Software License v1.0 (boost.org/LICENSE_1_0.txt) // TODO: These need to be turned into proper Thrust algorithms (dispatch layer, // backends, etc). #pragma once #include #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) # pragma GCC system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) # pragma clang system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) # pragma system_header #endif // no system header #include #include #include #include #include #include #include #include THRUST_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// template _CCCL_HOST_DEVICE void destroy_at(T* location) { location->~T(); } template _CCCL_HOST_DEVICE void destroy_at(Allocator const& alloc, T* location) { typedef typename detail::allocator_traits<::cuda::std::__remove_cv_t<::cuda::std::__libcpp_remove_reference_t>>:: template rebind_traits::other traits; typename traits::allocator_type alloc_T(alloc); traits::destroy(alloc_T, location); } template _CCCL_HOST_DEVICE ForwardIt destroy(ForwardIt first, ForwardIt last) { for (; first != last; ++first) { destroy_at(addressof(*first)); } return first; } template _CCCL_HOST_DEVICE ForwardIt destroy(Allocator const& alloc, ForwardIt first, ForwardIt last) { typedef typename iterator_traits::value_type T; typedef typename detail::allocator_traits<::cuda::std::__remove_cv_t<::cuda::std::__libcpp_remove_reference_t>>:: template rebind_traits::other traits; typename traits::allocator_type alloc_T(alloc); for (; first != last; ++first) { destroy_at(alloc_T, addressof(*first)); } return first; } template _CCCL_HOST_DEVICE ForwardIt destroy_n(ForwardIt first, Size n) { for (; n > 0; (void) ++first, --n) { destroy_at(addressof(*first)); } return first; } template _CCCL_HOST_DEVICE ForwardIt destroy_n(Allocator const& alloc, ForwardIt first, Size n) { typedef typename iterator_traits::value_type T; typedef typename detail::allocator_traits<::cuda::std::__remove_cv_t<::cuda::std::__libcpp_remove_reference_t>>:: template rebind_traits::other traits; typename traits::allocator_type alloc_T(alloc); for (; n > 0; (void) ++first, --n) { destroy_at(alloc_T, addressof(*first)); } return first; } template _CCCL_HOST_DEVICE void uninitialized_construct(ForwardIt first, ForwardIt last, Args const&... args) { using T = typename iterator_traits::value_type; ForwardIt current = first; // No exceptions in CUDA. NV_IF_TARGET( NV_IS_HOST, ( try { for (; current != last; ++current) { ::new (static_cast(addressof(*current))) T(args...); } } catch (...) { destroy(first, current); throw; }), (for (; current != last; ++current) { ::new (static_cast(addressof(*current))) T(args...); })); } template void uninitialized_construct_with_allocator(Allocator const& alloc, ForwardIt first, ForwardIt last, Args const&... args) { using T = typename iterator_traits::value_type; using traits = typename detail::allocator_traits< typename std::remove_cv::type>::type>::template rebind_traits; typename traits::allocator_type alloc_T(alloc); ForwardIt current = first; // No exceptions in CUDA. NV_IF_TARGET( NV_IS_HOST, ( try { for (; current != last; ++current) { traits::construct(alloc_T, addressof(*current), args...); } } catch (...) { destroy(alloc_T, first, current); throw; }), (for (; current != last; ++current) { traits::construct(alloc_T, addressof(*current), args...); })); } template void uninitialized_construct_n(ForwardIt first, Size n, Args const&... args) { using T = typename iterator_traits::value_type; ForwardIt current = first; // No exceptions in CUDA. NV_IF_TARGET( NV_IS_HOST, ( try { for (; n > 0; ++current, --n) { ::new (static_cast(addressof(*current))) T(args...); } } catch (...) { destroy(first, current); throw; }), (for (; n > 0; ++current, --n) { ::new (static_cast(addressof(*current))) T(args...); })); } template void uninitialized_construct_n_with_allocator(Allocator const& alloc, ForwardIt first, Size n, Args const&... args) { using T = typename iterator_traits::value_type; using traits = typename detail::allocator_traits< typename std::remove_cv::type>::type>::template rebind_traits; typename traits::allocator_type alloc_T(alloc); ForwardIt current = first; // No exceptions in CUDA. NV_IF_TARGET( NV_IS_HOST, ( try { for (; n > 0; (void) ++current, --n) { traits::construct(alloc_T, addressof(*current), args...); } } catch (...) { destroy(alloc_T, first, current); throw; }), (for (; n > 0; (void) ++current, --n) { traits::construct(alloc_T, addressof(*current), args...); })); } /////////////////////////////////////////////////////////////////////////////// THRUST_NAMESPACE_END