From 410df043c3416bec79077ebcea49c474af831765 Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Fri, 19 Jul 2024 02:34:04 +0200 Subject: [PATCH] Proclaim pair and tuple trivially relocatable --- thrust/testing/type_traits.cu | 35 +++++++++++++++++++ thrust/thrust/pair.h | 8 +++++ thrust/thrust/tuple.h | 6 ++++ .../type_traits/is_trivially_relocatable.h | 14 ++++++++ 4 files changed, 63 insertions(+) diff --git a/thrust/testing/type_traits.cu b/thrust/testing/type_traits.cu index bab73c76c4c..ec012812e43 100644 --- a/thrust/testing/type_traits.cu +++ b/thrust/testing/type_traits.cu @@ -5,8 +5,14 @@ #include #include #include +#include +#include #include +#include +#include +#include + #include void TestIsContiguousIterator() @@ -146,3 +152,32 @@ void TestIsCommutative() } } DECLARE_UNITTEST(TestIsCommutative); + +void TestTriviallyRelocatable() +{ + static_assert(thrust::is_trivially_relocatable::value, ""); +#if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + static_assert(thrust::is_trivially_relocatable<__half>::value, ""); + static_assert(thrust::is_trivially_relocatable::value, ""); + static_assert(thrust::is_trivially_relocatable::value, ""); + static_assert(thrust::is_trivially_relocatable::value, ""); + static_assert(thrust::is_trivially_relocatable::value, ""); + static_assert(thrust::is_trivially_relocatable<__int128>::value, ""); +#endif // THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA + static_assert(thrust::is_trivially_relocatable>::value, ""); + static_assert(thrust::is_trivially_relocatable<::cuda::std::complex>::value, ""); + static_assert(thrust::is_trivially_relocatable>::value, ""); + static_assert(thrust::is_trivially_relocatable<::cuda::std::pair>::value, ""); + static_assert(thrust::is_trivially_relocatable>::value, ""); + static_assert(thrust::is_trivially_relocatable<::cuda::std::tuple>::value, ""); + static_assert(thrust::is_trivially_relocatable< + ::cuda::std::tuple>>, + thrust::tuple<::cuda::std::pair>, int>>>::value, + ""); + + static_assert(!thrust::is_trivially_relocatable>::value, ""); + static_assert(!thrust::is_trivially_relocatable<::cuda::std::pair>::value, ""); + static_assert(!thrust::is_trivially_relocatable>::value, ""); + static_assert(!thrust::is_trivially_relocatable<::cuda::std::tuple>::value, ""); +}; +DECLARE_UNITTEST(TestTriviallyRelocatable); diff --git a/thrust/thrust/pair.h b/thrust/thrust/pair.h index 0e567a35b66..def1aeaf170 100644 --- a/thrust/thrust/pair.h +++ b/thrust/thrust/pair.h @@ -30,6 +30,9 @@ # pragma system_header #endif // no system header +#include + +#include #include THRUST_NAMESPACE_BEGIN @@ -117,6 +120,11 @@ make_pair(T1&& t1, T2&& t2) using _CUDA_VSTD::get; +template +struct proclaim_trivially_relocatable> + : ::cuda::std::conjunction, is_trivially_relocatable> +{}; + /*! \endcond */ diff --git a/thrust/thrust/tuple.h b/thrust/thrust/tuple.h index 1ff1031804e..3e7cd87daeb 100644 --- a/thrust/thrust/tuple.h +++ b/thrust/thrust/tuple.h @@ -39,6 +39,8 @@ # pragma system_header #endif // no system header +#include + #include #include #include @@ -232,6 +234,10 @@ inline _CCCL_HOST_DEVICE tuple tie(Ts&... ts) noexcept using _CUDA_VSTD::get; +template +struct proclaim_trivially_relocatable> : ::cuda::std::conjunction...> +{}; + /*! \endcond */ diff --git a/thrust/thrust/type_traits/is_trivially_relocatable.h b/thrust/thrust/type_traits/is_trivially_relocatable.h index 7732d7c6ab1..fda5931dcd4 100644 --- a/thrust/thrust/type_traits/is_trivially_relocatable.h +++ b/thrust/thrust/type_traits/is_trivially_relocatable.h @@ -36,6 +36,10 @@ #include #include +#include +#include +#include + #include THRUST_NAMESPACE_BEGIN @@ -285,6 +289,16 @@ THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double3) THRUST_PROCLAIM_TRIVIALLY_RELOCATABLE(double4) #endif +template +struct THRUST_NS_QUALIFIER::proclaim_trivially_relocatable<::cuda::std::pair> + : ::cuda::std::conjunction, is_trivially_relocatable> +{}; + +template +struct THRUST_NS_QUALIFIER::proclaim_trivially_relocatable<::cuda::std::tuple> + : ::cuda::std::conjunction...> +{}; + /*! \endcond */