From d30a046d79efd358cfbf8f46848080f50674334f Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Thu, 11 Jul 2024 11:12:46 +0200 Subject: [PATCH] Use libcu++ void_t everywhere * Make libcu++ void_t available in C++11 * Replace uses of CUB and Thrust's void_t by libcu++ * Deprecate Thrust's void_t * Deprecate libcu++'s __void_t --- cub/cub/block/radix_rank_sort_operations.cuh | 6 +---- cub/cub/util_type.cuh | 22 +++++++++---------- .../cuda/std/__complex/vector_support.h | 4 ++-- .../cuda/std/__concepts/destructible.h | 2 +- libcudacxx/include/cuda/std/__cuda/barrier.h | 4 ++-- .../cuda/std/__functional/is_transparent.h | 2 +- .../cuda/std/__iterator/iterator_traits.h | 12 +++++----- .../cuda/std/__memory/allocator_traits.h | 16 +++++++------- .../include/cuda/std/__memory/construct_at.h | 2 +- .../cuda/std/__memory/pointer_traits.h | 4 ++-- .../cuda/std/__memory/uses_allocator.h | 4 ++-- .../cuda/std/__type_traits/common_type.h | 6 ++--- .../cuda/std/__type_traits/is_allocator.h | 4 ++-- .../include/cuda/std/__type_traits/void_t.h | 4 +--- .../cuda/std/detail/libcxx/include/variant | 2 +- .../stream_ref.constructor.pass.cpp | 7 ++---- .../meta.unary.prop.query/void_t.pass.cpp | 2 +- .../functional/operators/operator_adaptors.h | 1 - .../result_of_adaptable_function.h | 4 +++- .../iterator/detail/iterator_traits.inl | 5 +++-- thrust/thrust/iterator/iterator_traits.h | 1 - thrust/thrust/optional.h | 14 ++++-------- thrust/thrust/system/cuda/detail/core/util.h | 2 +- .../system/tbb/detail/reduce_by_key.inl | 5 +++-- thrust/thrust/type_traits/void_t.h | 3 +-- 25 files changed, 62 insertions(+), 76 deletions(-) diff --git a/cub/cub/block/radix_rank_sort_operations.cuh b/cub/cub/block/radix_rank_sort_operations.cuh index 5800b136c0a..e56a0ec1e27 100644 --- a/cub/cub/block/radix_rank_sort_operations.cuh +++ b/cub/cub/block/radix_rank_sort_operations.cuh @@ -199,10 +199,6 @@ _CCCL_HOST_DEVICE void for_each_member(F f, DecomposerT decomposer, T& aggregate namespace radix { - -template -using void_t = void; - template struct is_fundamental_type { @@ -210,7 +206,7 @@ struct is_fundamental_type }; template -struct is_fundamental_type::UnsignedBits>> +struct is_fundamental_type::UnsignedBits>> { static constexpr bool value = true; }; diff --git a/cub/cub/util_type.cuh b/cub/cub/util_type.cuh index 30c228c6334..e23f6e6578a 100644 --- a/cub/cub/util_type.cuh +++ b/cub/cub/util_type.cuh @@ -825,16 +825,16 @@ struct DoubleBuffer * \brief Defines a structure \p detector_name that is templated on type \p T. The \p detector_name struct exposes a * constant member \p value indicating whether or not parameter \p T exposes a nested type \p nested_type_name */ -# define CUB_DEFINE_DETECT_NESTED_TYPE(detector_name, nested_type_name) \ - template \ - struct detector_name : ::cuda::std::false_type \ - { \ - CUB_DEPRECATED_BECAUSE("Use ::value instead") static constexpr bool VALUE = false; \ - }; \ - template \ - struct detector_name> : ::cuda::std::true_type \ - { \ - CUB_DEPRECATED_BECAUSE("Use ::value instead") static constexpr bool VALUE = true; \ +# define CUB_DEFINE_DETECT_NESTED_TYPE(detector_name, nested_type_name) \ + template \ + struct detector_name : ::cuda::std::false_type \ + { \ + CUB_DEPRECATED_BECAUSE("Use ::value instead") static constexpr bool VALUE = false; \ + }; \ + template \ + struct detector_name> : ::cuda::std::true_type \ + { \ + CUB_DEPRECATED_BECAUSE("Use ::value instead") static constexpr bool VALUE = true; \ }; /****************************************************************************** @@ -854,7 +854,7 @@ struct BinaryOpHasIdxParam : ::cuda::std::false_type template struct BinaryOpHasIdxParam()( + ::cuda::std::void_t()( ::cuda::std::declval(), ::cuda::std::declval(), int{}))>> : ::cuda::std::true_type { CUB_DEPRECATED_BECAUSE("Use ::value instead") static constexpr bool HAS_PARAM = true; diff --git a/libcudacxx/include/cuda/std/__complex/vector_support.h b/libcudacxx/include/cuda/std/__complex/vector_support.h index 7deebe9c6cb..2c754036cbe 100644 --- a/libcudacxx/include/cuda/std/__complex/vector_support.h +++ b/libcudacxx/include/cuda/std/__complex/vector_support.h @@ -67,7 +67,7 @@ struct __complex_can_implicitly_construct : false_type {}; template -struct __complex_can_implicitly_construct<_Dest, _Source, __void_t()})>> +struct __complex_can_implicitly_construct<_Dest, _Source, void_t()})>> : true_type {}; @@ -82,7 +82,7 @@ struct __has_vector_type : false_type {}; template -struct __has_vector_type<_Tp, __void_t<__type_to_vector_t<_Tp>>> : true_type +struct __has_vector_type<_Tp, void_t<__type_to_vector_t<_Tp>>> : true_type {}; template diff --git a/libcudacxx/include/cuda/std/__concepts/destructible.h b/libcudacxx/include/cuda/std/__concepts/destructible.h index e19763d8c12..f51d05daba5 100644 --- a/libcudacxx/include/cuda/std/__concepts/destructible.h +++ b/libcudacxx/include/cuda/std/__concepts/destructible.h @@ -48,7 +48,7 @@ _LIBCUDACXX_INLINE_VAR constexpr bool __destructible_impl<_Tp, # if defined(_CCCL_COMPILER_GCC) __enable_if_t<_CCCL_TRAIT(is_destructible, _Tp)>> # else // ^^^ _CCCL_COMPILER_GCC ^^^ / vvv !_CCCL_COMPILER_GCC vvv - __void_t().~_Tp())>> + void_t().~_Tp())>> # endif // !_CCCL_COMPILER_GCC = noexcept(_CUDA_VSTD::declval<_Tp>().~_Tp()); diff --git a/libcudacxx/include/cuda/std/__cuda/barrier.h b/libcudacxx/include/cuda/std/__cuda/barrier.h index c5cd6f18e79..3bb2efec354 100644 --- a/libcudacxx/include/cuda/std/__cuda/barrier.h +++ b/libcudacxx/include/cuda/std/__cuda/barrier.h @@ -26,7 +26,7 @@ #endif // no system header #include -#include // _CUDA_VSTD::__void_t +#include // _CUDA_VSTD::void_t #include // _LIBCUDACXX_UNREACHABLE #if defined(_CCCL_CUDA_COMPILER) @@ -1063,7 +1063,7 @@ struct __get_size_align // aligned_size_t overload: return n. template -struct __get_size_align> +struct __get_size_align> { static constexpr int align = T::align; }; diff --git a/libcudacxx/include/cuda/std/__functional/is_transparent.h b/libcudacxx/include/cuda/std/__functional/is_transparent.h index 852cf89ad3f..369453b4fab 100644 --- a/libcudacxx/include/cuda/std/__functional/is_transparent.h +++ b/libcudacxx/include/cuda/std/__functional/is_transparent.h @@ -33,7 +33,7 @@ struct __is_transparent : false_type {}; template -struct __is_transparent<_Tp, _Up, __void_t> : true_type +struct __is_transparent<_Tp, _Up, void_t> : true_type {}; #endif diff --git a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h index 56023c3cfde..b487ee7ab82 100644 --- a/libcudacxx/include/cuda/std/__iterator/iterator_traits.h +++ b/libcudacxx/include/cuda/std/__iterator/iterator_traits.h @@ -52,7 +52,7 @@ struct __cccl_type_is_defined : _CUDA_VSTD::false_type {}; template -struct __cccl_type_is_defined<_Tp, _CUDA_VSTD::__void_t> : _CUDA_VSTD::true_type +struct __cccl_type_is_defined<_Tp, _CUDA_VSTD::void_t> : _CUDA_VSTD::true_type {}; // detect whether the used STL has contiguous_iterator_tag defined @@ -206,11 +206,11 @@ struct __has_iterator_typedefs _LIBCUDACXX_INLINE_VISIBILITY static false_type __test(...); template _LIBCUDACXX_INLINE_VISIBILITY static true_type - __test(__void_t* = nullptr, - __void_t* = nullptr, - __void_t* = nullptr, - __void_t* = nullptr, - __void_t* = nullptr); + __test(void_t* = nullptr, + void_t* = nullptr, + void_t* = nullptr, + void_t* = nullptr, + void_t* = nullptr); public: static const bool value = decltype(__test<_Tp>(0, 0, 0, 0, 0))::value; diff --git a/libcudacxx/include/cuda/std/__memory/allocator_traits.h b/libcudacxx/include/cuda/std/__memory/allocator_traits.h index 57d02d7eadd..584d8c7c660 100644 --- a/libcudacxx/include/cuda/std/__memory/allocator_traits.h +++ b/libcudacxx/include/cuda/std/__memory/allocator_traits.h @@ -43,12 +43,12 @@ _CCCL_NV_DIAG_SUPPRESS(1215) _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _CCCL_STD_VER <= 2014 -# define _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \ - template \ - struct NAME : false_type \ - {}; \ - template \ - struct NAME<_Tp, __void_t> : true_type \ +# define _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \ + template \ + struct NAME : false_type \ + {}; \ + template \ + struct NAME<_Tp, void_t> : true_type \ {} #else // ^^^ _CCCL_STD_VER <= 2014 ^^^ / vvv _CCCL_STD_VER >= 2017 vvv @@ -56,7 +56,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD template \ inline constexpr bool NAME##_v = false; \ template \ - inline constexpr bool NAME##_v<_Tp, __void_t> = true; + inline constexpr bool NAME##_v<_Tp, void_t> = true; #endif // _CCCL_STD_VER >= 2017 // __pointer @@ -190,7 +190,7 @@ template struct __has_rebind_other : false_type {}; template -struct __has_rebind_other<_Tp, _Up, __void_t::other>> : true_type +struct __has_rebind_other<_Tp, _Up, void_t::other>> : true_type {}; template ::value> diff --git a/libcudacxx/include/cuda/std/__memory/construct_at.h b/libcudacxx/include/cuda/std/__memory/construct_at.h index f7958ace534..2837765f1a0 100644 --- a/libcudacxx/include/cuda/std/__memory/construct_at.h +++ b/libcudacxx/include/cuda/std/__memory/construct_at.h @@ -85,7 +85,7 @@ struct __is_narrowing_impl<_To, _From> : true_type // This is a bit hacky, but we rely on the fact that arithmetic types cannot have more than one argument to their // constructor template -struct __is_narrowing_impl<_To, _From, __void_t()})>> : false_type +struct __is_narrowing_impl<_To, _From, void_t()})>> : false_type {}; template diff --git a/libcudacxx/include/cuda/std/__memory/pointer_traits.h b/libcudacxx/include/cuda/std/__memory/pointer_traits.h index e806e47fbbf..62e1eff4b3f 100644 --- a/libcudacxx/include/cuda/std/__memory/pointer_traits.h +++ b/libcudacxx/include/cuda/std/__memory/pointer_traits.h @@ -40,7 +40,7 @@ struct __has_element_type : false_type {}; template -struct __has_element_type<_Tp, __void_t> : true_type +struct __has_element_type<_Tp, void_t> : true_type {}; template ::value> @@ -123,7 +123,7 @@ struct __has_difference_type : false_type {}; template -struct __has_difference_type<_Tp, __void_t> : true_type +struct __has_difference_type<_Tp, void_t> : true_type {}; template ::value> diff --git a/libcudacxx/include/cuda/std/__memory/uses_allocator.h b/libcudacxx/include/cuda/std/__memory/uses_allocator.h index f44af4bcfe2..789ecc9f4ce 100644 --- a/libcudacxx/include/cuda/std/__memory/uses_allocator.h +++ b/libcudacxx/include/cuda/std/__memory/uses_allocator.h @@ -33,7 +33,7 @@ template struct __has_allocator_type : false_type {}; template -struct __has_allocator_type<_Tp, __void_t> : true_type +struct __has_allocator_type<_Tp, void_t> : true_type {}; template @@ -46,7 +46,7 @@ struct __uses_allocator<_Tp, _Alloc, true> : is_convertible<_Alloc, typename _Tp template _LIBCUDACXX_INLINE_VAR constexpr bool __has_allocator_type_v = false; template -_LIBCUDACXX_INLINE_VAR constexpr bool __has_allocator_type_v<_Tp, __void_t> = true; +_LIBCUDACXX_INLINE_VAR constexpr bool __has_allocator_type_v<_Tp, void_t> = true; template _LIBCUDACXX_INLINE_VAR constexpr bool __uses_allocator_v = false; diff --git a/libcudacxx/include/cuda/std/__type_traits/common_type.h b/libcudacxx/include/cuda/std/__type_traits/common_type.h index e77e10fb190..7eb629a95e9 100644 --- a/libcudacxx/include/cuda/std/__type_traits/common_type.h +++ b/libcudacxx/include/cuda/std/__type_traits/common_type.h @@ -61,7 +61,7 @@ struct __common_type2_imp // sub-bullet 3 - "if decay_t() : declval())> ..." template -struct __common_type2_imp<_Tp, _Up, __void_t<__cond_type<_Tp, _Up>>> +struct __common_type2_imp<_Tp, _Up, void_t<__cond_type<_Tp, _Up>>> { typedef _LIBCUDACXX_NODEBUG_TYPE __decay_t<__cond_type<_Tp, _Up>> type; }; @@ -74,13 +74,13 @@ template struct __common_types; template -struct __common_type_impl<__common_types<_Tp, _Up>, __void_t<__common_type_t<_Tp, _Up>>> +struct __common_type_impl<__common_types<_Tp, _Up>, void_t<__common_type_t<_Tp, _Up>>> { typedef __common_type_t<_Tp, _Up> type; }; template -struct __common_type_impl<__common_types<_Tp, _Up, _Vp, _Rest...>, __void_t<__common_type_t<_Tp, _Up>>> +struct __common_type_impl<__common_types<_Tp, _Up, _Vp, _Rest...>, void_t<__common_type_t<_Tp, _Up>>> : __common_type_impl<__common_types<__common_type_t<_Tp, _Up>, _Vp, _Rest...>> {}; diff --git a/libcudacxx/include/cuda/std/__type_traits/is_allocator.h b/libcudacxx/include/cuda/std/__type_traits/is_allocator.h index 5f364ba9e46..d22a0c288e6 100644 --- a/libcudacxx/include/cuda/std/__type_traits/is_allocator.h +++ b/libcudacxx/include/cuda/std/__type_traits/is_allocator.h @@ -33,8 +33,8 @@ struct __is_allocator : false_type template struct __is_allocator<_Alloc, - __void_t, - __void_t().allocate(size_t(0)))>> : true_type + void_t, + void_t().allocate(size_t(0)))>> : true_type {}; _LIBCUDACXX_END_NAMESPACE_STD diff --git a/libcudacxx/include/cuda/std/__type_traits/void_t.h b/libcudacxx/include/cuda/std/__type_traits/void_t.h index df597333135..7b3e94b93aa 100644 --- a/libcudacxx/include/cuda/std/__type_traits/void_t.h +++ b/libcudacxx/include/cuda/std/__type_traits/void_t.h @@ -22,13 +22,11 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD -#if _CCCL_STD_VER > 2011 template using void_t = void; -#endif template -using __void_t = void; +using __void_t _LIBCUDACXX_DEPRECATED = void; _LIBCUDACXX_END_NAMESPACE_STD diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/variant b/libcudacxx/include/cuda/std/detail/libcxx/include/variant index 6e22195b91e..96331e8158d 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/variant +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/variant @@ -1366,7 +1366,7 @@ struct __narrowing_check {}; template - struct __narrowing_check_impl<_Dest, _Source, __void_t()})>> + struct __narrowing_check_impl<_Dest, _Source, void_t()})>> { using type = __type_identity<_Dest>; }; diff --git a/libcudacxx/test/libcudacxx/cuda/stream_ref/stream_ref.constructor.pass.cpp b/libcudacxx/test/libcudacxx/cuda/stream_ref/stream_ref.constructor.pass.cpp index 51d176c8a82..8242d18a9fe 100644 --- a/libcudacxx/test/libcudacxx/cuda/stream_ref/stream_ref.constructor.pass.cpp +++ b/libcudacxx/test/libcudacxx/cuda/stream_ref/stream_ref.constructor.pass.cpp @@ -17,15 +17,12 @@ static_assert(cuda::std::is_default_constructible::value, ""); static_assert(!cuda::std::is_constructible::value, ""); static_assert(!cuda::std::is_constructible::value, ""); -template -using void_t = void; - #if TEST_STD_VER < 2014 template struct has_value_type : cuda::std::false_type {}; template -struct has_value_type> : cuda::std::true_type +struct has_value_type> : cuda::std::true_type {}; static_assert(has_value_type::value, ""); #else @@ -33,7 +30,7 @@ template constexpr bool has_value_type = false; template -constexpr bool has_value_type_v> = true; +constexpr bool has_value_type_v> = true; static_assert(has_value_type, ""); #endif diff --git a/libcudacxx/test/libcudacxx/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp index c7cbacc64ad..faf34fff081 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp @@ -10,7 +10,7 @@ // void_t -// UNSUPPORTED: c++98, c++03, c++11 +// UNSUPPORTED: c++98, c++03 // XFAIL: gcc-5.1, gcc-5.2 diff --git a/thrust/thrust/detail/functional/operators/operator_adaptors.h b/thrust/thrust/detail/functional/operators/operator_adaptors.h index 1bfa431b96b..31587ac7349 100644 --- a/thrust/thrust/detail/functional/operators/operator_adaptors.h +++ b/thrust/thrust/detail/functional/operators/operator_adaptors.h @@ -29,7 +29,6 @@ #include #include #include -#include #include diff --git a/thrust/thrust/detail/type_traits/result_of_adaptable_function.h b/thrust/thrust/detail/type_traits/result_of_adaptable_function.h index cb4d4a477e8..0a0d526cd97 100644 --- a/thrust/thrust/detail/type_traits/result_of_adaptable_function.h +++ b/thrust/thrust/detail/type_traits/result_of_adaptable_function.h @@ -28,6 +28,8 @@ #include #include +#include + #include THRUST_NAMESPACE_BEGIN @@ -54,7 +56,7 @@ struct result_of_adaptable_function // specialization for invocations which define result_type template -struct result_of_adaptable_function> +struct result_of_adaptable_function> { using type = typename Functor::result_type; }; diff --git a/thrust/thrust/iterator/detail/iterator_traits.inl b/thrust/thrust/iterator/detail/iterator_traits.inl index 25bc70cd7c0..7164a7f9fce 100644 --- a/thrust/thrust/iterator/detail/iterator_traits.inl +++ b/thrust/thrust/iterator/detail/iterator_traits.inl @@ -29,7 +29,8 @@ #include #include #include -#include + +#include THRUST_NAMESPACE_BEGIN @@ -77,7 +78,7 @@ struct iterator_system_impl {}; template -struct iterator_system_impl::iterator_category>> +struct iterator_system_impl::iterator_category>> : detail::iterator_category_to_system::iterator_category> {}; diff --git a/thrust/thrust/iterator/iterator_traits.h b/thrust/thrust/iterator/iterator_traits.h index 1ca9c197e30..4001410613b 100644 --- a/thrust/thrust/iterator/iterator_traits.h +++ b/thrust/thrust/iterator/iterator_traits.h @@ -38,7 +38,6 @@ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) # pragma system_header #endif // no system header -#include #include diff --git a/thrust/thrust/optional.h b/thrust/thrust/optional.h index a94e2b9552e..a0add00e61f 100644 --- a/thrust/thrust/optional.h +++ b/thrust/thrust/optional.h @@ -26,6 +26,8 @@ #include #include +#include + #define THRUST_OPTIONAL_VERSION_MAJOR 0 #define THRUST_OPTIONAL_VERSION_MINOR 2 @@ -167,15 +169,6 @@ _CCCL_HOST_DEVICE constexpr auto invoke(Fn&& f, Args&&... args) noexcept(noexcep } #endif -// std::void_t from C++17 -template -struct voider -{ - using type = void; -}; -template -using void_t = typename voider::type; - // Trait for checking if a type is a thrust::optional template struct is_optional_impl : std::false_type @@ -197,7 +190,8 @@ using get_map_return = optional>>; template struct returns_void_impl; template -struct returns_void_impl>, U...> : std::is_void> +struct returns_void_impl>, U...> + : std::is_void> {}; template using returns_void = returns_void_impl; diff --git a/thrust/thrust/system/cuda/detail/core/util.h b/thrust/thrust/system/cuda/detail/core/util.h index 7b98ba9d23d..3ed80513cf3 100644 --- a/thrust/thrust/system/cuda/detail/core/util.h +++ b/thrust/thrust/system/cuda/detail/core/util.h @@ -224,7 +224,7 @@ struct temp_storage_size }; template -struct temp_storage_size> +struct temp_storage_size> { static constexpr std::size_t value = sizeof(typename Agent::TempStorage); }; diff --git a/thrust/thrust/system/tbb/detail/reduce_by_key.inl b/thrust/thrust/system/tbb/detail/reduce_by_key.inl index de3b1b76b51..c92be73937a 100644 --- a/thrust/thrust/system/tbb/detail/reduce_by_key.inl +++ b/thrust/thrust/system/tbb/detail/reduce_by_key.inl @@ -35,7 +35,8 @@ #include #include #include -#include + +#include #include #include @@ -66,7 +67,7 @@ struct partial_sum_type }; template -struct partial_sum_type> +struct partial_sum_type> { using type = typename BinaryFunction::result_type; }; diff --git a/thrust/thrust/type_traits/void_t.h b/thrust/thrust/type_traits/void_t.h index 5d3aa52c211..76bf3bf4b87 100644 --- a/thrust/thrust/type_traits/void_t.h +++ b/thrust/thrust/type_traits/void_t.h @@ -46,9 +46,8 @@ struct THRUST_DEPRECATED_BECAUSE("Use ::cuda::std::void_t") voider using type = void; }; -// TODO(bgruber): deprecate and replace by cuda::std::void_t eventually template -using void_t = void; +using void_t THRUST_DEPRECATED_BECAUSE("Use ::cuda::std::void_t") = void; /*! \} // type traits */