Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

214 lines
6.2 KiB
C++

// Copyright (c) 2018 NVIDIA Corporation
// Modifications Copyright© 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
// Author: Bryce Adelstein Lelbach <brycelelbach@gmail.com>
//
// 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 <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/addressof.h>
#include <thrust/detail/allocator/allocator_traits.h>
#include <thrust/detail/memory_wrapper.h>
#include <thrust/detail/nv_target.h>
#include <thrust/detail/type_traits.h>
#include <thrust/iterator/iterator_traits.h>
#include <new>
#include <utility>
#if !_THRUST_HAS_DEVICE_SYSTEM_STD
# include <type_traits>
#endif
THRUST_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
template <typename T>
THRUST_HOST_DEVICE void destroy_at(T* location) noexcept
{
location->~T();
}
template <typename Allocator, typename T>
THRUST_HOST_DEVICE void destroy_at(Allocator const& alloc, T* location) noexcept
{
using traits = typename detail::allocator_traits<
_THRUST_STD::remove_cv_t<_THRUST_STD::remove_reference_t<Allocator>>>::template rebind_traits<T>::other;
typename traits::allocator_type alloc_T(alloc);
traits::destroy(alloc_T, location);
}
template <typename ForwardIt>
THRUST_HOST_DEVICE ForwardIt destroy(ForwardIt first, ForwardIt last) noexcept
{
for (; first != last; ++first)
{
destroy_at(addressof(*first));
}
return first;
}
template <typename Allocator, typename ForwardIt>
THRUST_HOST_DEVICE ForwardIt destroy(Allocator const& alloc, ForwardIt first, ForwardIt last) noexcept
{
using T = typename iterator_traits<ForwardIt>::value_type;
using traits = typename detail::allocator_traits<
_THRUST_STD::remove_cv_t<_THRUST_STD::remove_reference_t<Allocator>>>::template rebind_traits<T>::other;
typename traits::allocator_type alloc_T(alloc);
for (; first != last; ++first)
{
destroy_at(alloc_T, addressof(*first));
}
return first;
}
template <typename ForwardIt, typename Size>
THRUST_HOST_DEVICE ForwardIt destroy_n(ForwardIt first, Size n) noexcept
{
for (; n > 0; (void) ++first, --n)
{
destroy_at(addressof(*first));
}
return first;
}
template <typename Allocator, typename ForwardIt, typename Size>
THRUST_HOST_DEVICE ForwardIt destroy_n(Allocator const& alloc, ForwardIt first, Size n) noexcept
{
using T = typename iterator_traits<ForwardIt>::value_type;
using traits = typename detail::allocator_traits<
_THRUST_STD::remove_cv_t<_THRUST_STD::remove_reference_t<Allocator>>>::template rebind_traits<T>::other;
typename traits::allocator_type alloc_T(alloc);
for (; n > 0; (void) ++first, --n)
{
destroy_at(alloc_T, addressof(*first));
}
return first;
}
template <typename ForwardIt, typename... Args>
THRUST_HOST_DEVICE void uninitialized_construct(ForwardIt first, ForwardIt last, Args const&... args)
{
using T = typename iterator_traits<ForwardIt>::value_type;
ForwardIt current = first;
// No exceptions in CUDA.
NV_IF_TARGET(
NV_IS_HOST,
(
try {
for (; current != last; ++current)
{
::new (static_cast<void*>(addressof(*current))) T(args...);
}
} catch (...) {
destroy(first, current);
throw;
}),
(for (; current != last; ++current) { ::new (static_cast<void*>(addressof(*current))) T(args...); }));
}
template <typename Allocator, typename ForwardIt, typename... Args>
void uninitialized_construct_with_allocator(Allocator const& alloc, ForwardIt first, ForwardIt last, Args const&... args)
{
using T = typename iterator_traits<ForwardIt>::value_type;
using traits = typename detail::allocator_traits<
typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>::template rebind_traits<T>;
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 <typename ForwardIt, typename Size, typename... Args>
void uninitialized_construct_n(ForwardIt first, Size n, Args const&... args)
{
using T = typename iterator_traits<ForwardIt>::value_type;
ForwardIt current = first;
// No exceptions in CUDA.
NV_IF_TARGET(
NV_IS_HOST,
(
try {
for (; n > 0; ++current, --n)
{
::new (static_cast<void*>(addressof(*current))) T(args...);
}
} catch (...) {
destroy(first, current);
throw;
}),
(for (; n > 0; ++current, --n) { ::new (static_cast<void*>(addressof(*current))) T(args...); }));
}
template <typename Allocator, typename ForwardIt, typename Size, typename... Args>
void uninitialized_construct_n_with_allocator(Allocator const& alloc, ForwardIt first, Size n, Args const&... args)
{
using T = typename iterator_traits<ForwardIt>::value_type;
using traits = typename detail::allocator_traits<
typename std::remove_cv<typename std::remove_reference<Allocator>::type>::type>::template rebind_traits<T>;
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