Skip to content

Commit 1fd29f4

Browse files
Partially revert a5e8209 [SYCL] Remove IsDeprecatedDeviceCopyable (#16615) (#16744)
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.
1 parent 4f29c44 commit 1fd29f4

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

sycl/include/sycl/detail/is_device_copyable.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,25 @@ namespace detail {
9393
template <typename T, typename> struct CheckFieldsAreDeviceCopyable;
9494
template <typename T, typename> struct CheckBasesAreDeviceCopyable;
9595

96+
template <typename T>
97+
inline constexpr bool is_deprecated_device_copyable_v =
98+
is_device_copyable_v<T> || (std::is_trivially_copy_constructible_v<T> &&
99+
std::is_trivially_destructible_v<T>);
100+
96101
template <typename T, unsigned... FieldIds>
97102
struct CheckFieldsAreDeviceCopyable<T, std::index_sequence<FieldIds...>> {
98-
static_assert(
99-
((is_device_copyable_v<decltype(__builtin_field_type(T, FieldIds))> &&
100-
...)),
101-
"The specified type is not device copyable");
103+
static_assert(((is_deprecated_device_copyable_v<
104+
decltype(__builtin_field_type(T, FieldIds))> &&
105+
...)),
106+
"The specified type is not device copyable");
102107
};
103108

104109
template <typename T, unsigned... BaseIds>
105110
struct CheckBasesAreDeviceCopyable<T, std::index_sequence<BaseIds...>> {
106-
static_assert(
107-
((is_device_copyable_v<decltype(__builtin_base_type(T, BaseIds))> &&
108-
...)),
109-
"The specified type is not device copyable");
111+
static_assert(((is_deprecated_device_copyable_v<
112+
decltype(__builtin_base_type(T, BaseIds))> &&
113+
...)),
114+
"The specified type is not device copyable");
110115
};
111116

112117
// All the captures of a lambda or functor of type FuncT passed to a kernel

sycl/test/basic_tests/is_device_copyable.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ struct BCopyable {
2525
BCopyable(const BCopyable &x) : i(x.i) {}
2626
};
2727

28+
// Not trivially copyable, but trivially copy constructible/destructible.
29+
// Such types are passed to kernels to stay compatible with deprecated
30+
// sycl 1.2.1 rules.
31+
struct C : A {
32+
const A C2;
33+
C() : A{0}, C2{2} {}
34+
};
35+
2836
// Not copyable type, but it will be declared as device copyable.
2937
struct DCopyable {
3038
int i;
@@ -59,6 +67,7 @@ void test() {
5967
A IamGood;
6068
IamGood.i = 0;
6169
BCopyable IamBadButCopyable(1);
70+
C IamAlsoGood;
6271
DCopyable IamAlsoBadButCopyable{0};
6372
marray<int, 5> MarrayForCopyableIsCopyable(0);
6473
range<2> Range{1,2};
@@ -69,6 +78,7 @@ void test() {
6978
int A = IamGood.i;
7079
int B = IamBadButCopyable.i;
7180
int C = IamAlsoBadButCopyable.i;
81+
int D = IamAlsoGood.i;
7282
int E = MarrayForCopyableIsCopyable[0];
7383
int F = Range[1];
7484
int G = Id[2];

sycl/test/basic_tests/is_device_copyable_neg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ void test() {
5656
B IamAlsoBad{0};
5757
marray<B, 2> MarrayForNotCopyable;
5858
queue Q;
59-
// expected-error@*:* {{static assertion failed due to requirement 'is_device_copyable_v<A>': The specified type is not device copyable}}
59+
// expected-error@*:* {{static assertion failed due to requirement 'is_deprecated_device_copyable_v<A>': The specified type is not device copyable}}
6060
Q.single_task<class TestA>([=] {
6161
int A = IamBad.i;
6262
int B = IamAlsoBad.i;
6363
int MB = MarrayForNotCopyable[0].i;
6464
});
6565

6666
FunctorA FA;
67-
// expected-error@*:* {{static assertion failed due to requirement 'is_device_copyable_v<C>': The specified type is not device copyable}}
67+
// expected-error@*:* {{static assertion failed due to requirement 'is_deprecated_device_copyable_v<C>': The specified type is not device copyable}}
6868
Q.single_task<class TestB>(FA);
6969

7070
FunctorB FB;
71-
// expected-error@*:* {{static assertion failed due to requirement 'is_device_copyable_v<D>': The specified type is not device copyable}}
71+
// expected-error@*:* {{static assertion failed due to requirement 'is_deprecated_device_copyable_v<D>': The specified type is not device copyable}}
7272
Q.single_task<class TestC>(FB);
7373
}

0 commit comments

Comments
 (0)