diff --git a/sycl/include/sycl/detail/is_device_copyable.hpp b/sycl/include/sycl/detail/is_device_copyable.hpp index 32556349aed2b..388029e6a16a3 100644 --- a/sycl/include/sycl/detail/is_device_copyable.hpp +++ b/sycl/include/sycl/detail/is_device_copyable.hpp @@ -7,6 +7,8 @@ //===----------------------------------------------------------------------===// #pragma once +#include + #include #include #include @@ -80,5 +82,84 @@ struct is_device_copyable : is_device_copyable {}; template inline constexpr bool is_device_copyable_v = is_device_copyable::value; +namespace detail { +template +struct IsDeprecatedDeviceCopyable : std::false_type {}; + +// TODO: using C++ attribute [[deprecated]] or the macro __SYCL2020_DEPRECATED +// does not produce expected warning message for the type 'T'. +template +struct __SYCL2020_DEPRECATED("This type isn't device copyable in SYCL 2020") + IsDeprecatedDeviceCopyable< + T, std::enable_if_t && + std::is_trivially_destructible_v && + !is_device_copyable_v>> : std::true_type {}; + +template +struct __SYCL2020_DEPRECATED("This type isn't device copyable in SYCL 2020") + IsDeprecatedDeviceCopyable : IsDeprecatedDeviceCopyable {}; + +#ifdef __SYCL_DEVICE_ONLY__ +// Checks that the fields of the type T with indices 0 to (NumFieldsToCheck - +// 1) are device copyable. +template +struct CheckFieldsAreDeviceCopyable + : CheckFieldsAreDeviceCopyable { + using FieldT = decltype(__builtin_field_type(T, NumFieldsToCheck - 1)); + static_assert(is_device_copyable_v || + detail::IsDeprecatedDeviceCopyable::value, + "The specified type is not device copyable"); +}; + +template struct CheckFieldsAreDeviceCopyable {}; + +// Checks that the base classes of the type T with indices 0 to +// (NumFieldsToCheck - 1) are device copyable. +template +struct CheckBasesAreDeviceCopyable + : CheckBasesAreDeviceCopyable { + using BaseT = decltype(__builtin_base_type(T, NumBasesToCheck - 1)); + static_assert(is_device_copyable_v || + detail::IsDeprecatedDeviceCopyable::value, + "The specified type is not device copyable"); +}; + +template struct CheckBasesAreDeviceCopyable {}; + +// All the captures of a lambda or functor of type FuncT passed to a kernel +// must be is_device_copyable, which extends to bases and fields of FuncT. +// Fields are captures of lambda/functors and bases are possible base classes +// of functors also allowed by SYCL. +// The SYCL-2020 implementation must check each of the fields & bases of the +// type FuncT, only one level deep, which is enough to see if they are all +// device copyable by using the result of is_device_copyable returned for them. +// At this moment though the check also allowes using types for which +// (is_trivially_copy_constructible && is_trivially_destructible) returns true +// and (is_device_copyable) returns false. That is the deprecated behavior and +// is currently/temporarily supported only to not break older SYCL programs. +template +struct CheckDeviceCopyable + : CheckFieldsAreDeviceCopyable, + CheckBasesAreDeviceCopyable {}; + +template +class RoundedRangeKernel; +template +class RoundedRangeKernelWithKH; + +// Below are two specializations for CheckDeviceCopyable when a kernel lambda +// is wrapped after range rounding optimization. +template +struct CheckDeviceCopyable< + RoundedRangeKernel> + : CheckDeviceCopyable {}; + +template +struct CheckDeviceCopyable< + RoundedRangeKernelWithKH> + : CheckDeviceCopyable {}; + +#endif // __SYCL_DEVICE_ONLY__ +} // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/types.hpp b/sycl/include/sycl/types.hpp index 0ac53ecdd5731..92f14a6165481 100644 --- a/sycl/include/sycl/types.hpp +++ b/sycl/include/sycl/types.hpp @@ -28,83 +28,3 @@ #endif #include // bfloat16 - -namespace sycl { -inline namespace _V1 { -namespace detail { - -template -struct IsDeprecatedDeviceCopyable : std::false_type {}; - -// TODO: using C++ attribute [[deprecated]] or the macro __SYCL2020_DEPRECATED -// does not produce expected warning message for the type 'T'. -template -struct __SYCL2020_DEPRECATED("This type isn't device copyable in SYCL 2020") - IsDeprecatedDeviceCopyable< - T, std::enable_if_t && - std::is_trivially_destructible_v && - !is_device_copyable_v>> : std::true_type {}; - -template -struct __SYCL2020_DEPRECATED("This type isn't device copyable in SYCL 2020") - IsDeprecatedDeviceCopyable : IsDeprecatedDeviceCopyable {}; - -#ifdef __SYCL_DEVICE_ONLY__ -// Checks that the fields of the type T with indices 0 to (NumFieldsToCheck - -// 1) are device copyable. -template -struct CheckFieldsAreDeviceCopyable - : CheckFieldsAreDeviceCopyable { - using FieldT = decltype(__builtin_field_type(T, NumFieldsToCheck - 1)); - static_assert(is_device_copyable_v || - detail::IsDeprecatedDeviceCopyable::value, - "The specified type is not device copyable"); -}; - -template struct CheckFieldsAreDeviceCopyable {}; - -// Checks that the base classes of the type T with indices 0 to -// (NumFieldsToCheck - 1) are device copyable. -template -struct CheckBasesAreDeviceCopyable - : CheckBasesAreDeviceCopyable { - using BaseT = decltype(__builtin_base_type(T, NumBasesToCheck - 1)); - static_assert(is_device_copyable_v || - detail::IsDeprecatedDeviceCopyable::value, - "The specified type is not device copyable"); -}; - -template struct CheckBasesAreDeviceCopyable {}; - -// All the captures of a lambda or functor of type FuncT passed to a kernel -// must be is_device_copyable, which extends to bases and fields of FuncT. -// Fields are captures of lambda/functors and bases are possible base classes -// of functors also allowed by SYCL. -// The SYCL-2020 implementation must check each of the fields & bases of the -// type FuncT, only one level deep, which is enough to see if they are all -// device copyable by using the result of is_device_copyable returned for them. -// At this moment though the check also allowes using types for which -// (is_trivially_copy_constructible && is_trivially_destructible) returns true -// and (is_device_copyable) returns false. That is the deprecated behavior and -// is currently/temporarily supported only to not break older SYCL programs. -template -struct CheckDeviceCopyable - : CheckFieldsAreDeviceCopyable, - CheckBasesAreDeviceCopyable {}; - -// Below are two specializations for CheckDeviceCopyable when a kernel lambda -// is wrapped after range rounding optimization. -template -struct CheckDeviceCopyable< - RoundedRangeKernel> - : CheckDeviceCopyable {}; - -template -struct CheckDeviceCopyable< - RoundedRangeKernelWithKH> - : CheckDeviceCopyable {}; - -#endif // __SYCL_DEVICE_ONLY__ -} // namespace detail -} // namespace _V1 -} // namespace sycl