From 6eb6141036c1ab6c91f6f1c37a575832e3599160 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Wed, 22 Jan 2025 16:38:44 -0800 Subject: [PATCH] Partially revert a5e820976484 [SYCL] Remove `IsDeprecatedDeviceCopyable` (#16615) Restore (logically) previous condition while keeping the rest of cleanups in place. Deprecation warning never worked, so I'm not even trying to implement that. --- .../sycl/detail/is_device_copyable.hpp | 21 ++++++++++++------- sycl/test/basic_tests/is_device_copyable.cpp | 10 +++++++++ .../basic_tests/is_device_copyable_neg.cpp | 6 +++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/sycl/include/sycl/detail/is_device_copyable.hpp b/sycl/include/sycl/detail/is_device_copyable.hpp index bac24f4df3a11..ea036779546a6 100644 --- a/sycl/include/sycl/detail/is_device_copyable.hpp +++ b/sycl/include/sycl/detail/is_device_copyable.hpp @@ -93,20 +93,25 @@ namespace detail { template struct CheckFieldsAreDeviceCopyable; template struct CheckBasesAreDeviceCopyable; +template +inline constexpr bool is_deprecated_device_copyable_v = + is_device_copyable_v || (std::is_trivially_copy_constructible_v && + std::is_trivially_destructible_v); + template struct CheckFieldsAreDeviceCopyable> { - static_assert( - ((is_device_copyable_v && - ...)), - "The specified type is not device copyable"); + static_assert(((is_deprecated_device_copyable_v< + decltype(__builtin_field_type(T, FieldIds))> && + ...)), + "The specified type is not device copyable"); }; template struct CheckBasesAreDeviceCopyable> { - static_assert( - ((is_device_copyable_v && - ...)), - "The specified type is not device copyable"); + static_assert(((is_deprecated_device_copyable_v< + decltype(__builtin_base_type(T, BaseIds))> && + ...)), + "The specified type is not device copyable"); }; // All the captures of a lambda or functor of type FuncT passed to a kernel diff --git a/sycl/test/basic_tests/is_device_copyable.cpp b/sycl/test/basic_tests/is_device_copyable.cpp index 3e48bd5d77857..1c4199e954530 100644 --- a/sycl/test/basic_tests/is_device_copyable.cpp +++ b/sycl/test/basic_tests/is_device_copyable.cpp @@ -25,6 +25,14 @@ struct BCopyable { BCopyable(const BCopyable &x) : i(x.i) {} }; +// Not trivially copyable, but trivially copy constructible/destructible. +// Such types are passed to kernels to stay compatible with deprecated +// sycl 1.2.1 rules. +struct C : A { + const A C2; + C() : A{0}, C2{2} {} +}; + // Not copyable type, but it will be declared as device copyable. struct DCopyable { int i; @@ -59,6 +67,7 @@ void test() { A IamGood; IamGood.i = 0; BCopyable IamBadButCopyable(1); + C IamAlsoGood; DCopyable IamAlsoBadButCopyable{0}; marray MarrayForCopyableIsCopyable(0); range<2> Range{1,2}; @@ -69,6 +78,7 @@ void test() { int A = IamGood.i; int B = IamBadButCopyable.i; int C = IamAlsoBadButCopyable.i; + int D = IamAlsoGood.i; int E = MarrayForCopyableIsCopyable[0]; int F = Range[1]; int G = Id[2]; diff --git a/sycl/test/basic_tests/is_device_copyable_neg.cpp b/sycl/test/basic_tests/is_device_copyable_neg.cpp index c9007685ae693..61f88d6369aad 100644 --- a/sycl/test/basic_tests/is_device_copyable_neg.cpp +++ b/sycl/test/basic_tests/is_device_copyable_neg.cpp @@ -56,7 +56,7 @@ void test() { B IamAlsoBad{0}; marray MarrayForNotCopyable; queue Q; - // expected-error@*:* {{static assertion failed due to requirement 'is_device_copyable_v': The specified type is not device copyable}} + // expected-error@*:* {{static assertion failed due to requirement 'is_deprecated_device_copyable_v': The specified type is not device copyable}} Q.single_task([=] { int A = IamBad.i; int B = IamAlsoBad.i; @@ -64,10 +64,10 @@ void test() { }); FunctorA FA; - // expected-error@*:* {{static assertion failed due to requirement 'is_device_copyable_v': The specified type is not device copyable}} + // expected-error@*:* {{static assertion failed due to requirement 'is_deprecated_device_copyable_v': The specified type is not device copyable}} Q.single_task(FA); FunctorB FB; - // expected-error@*:* {{static assertion failed due to requirement 'is_device_copyable_v': The specified type is not device copyable}} + // expected-error@*:* {{static assertion failed due to requirement 'is_deprecated_device_copyable_v': The specified type is not device copyable}} Q.single_task(FB); }