Skip to content

[SYCL] Remove IsDeprecatedDeviceCopyable #16615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions sycl/include/sycl/detail/is_device_copyable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ inline namespace _V1 {
template <typename T> struct is_device_copyable;

namespace detail {
template <typename... T> struct tuple;

template <typename T, typename = void>
struct is_device_copyable_impl : std::is_trivially_copyable<T> {};

Expand Down Expand Up @@ -70,6 +72,10 @@ template <typename... Ts>
struct is_device_copyable<std::tuple<Ts...>>
: std::bool_constant<(... && is_device_copyable<Ts>::value)> {};

template <typename... Ts>
struct is_device_copyable<sycl::detail::tuple<Ts...>>
: std::bool_constant<(... && is_device_copyable<Ts>::value)> {};

Comment on lines +75 to +78
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better way might be just making sycl::detail::tuple trivially copyable automatically whenever all the contained types are, by fixing the implementation, but I'm not sure how big such a change would be or how to approach it.

// std::variant<Ts...> is implicitly device copyable type if each type T of
// Ts... is device copyable.
template <typename... Ts>
Expand All @@ -83,31 +89,14 @@ struct is_device_copyable<T[N]> : is_device_copyable<T> {};
template <typename T>
inline constexpr bool is_device_copyable_v = is_device_copyable<T>::value;
namespace detail {
template <typename T, typename = void>
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 <typename T>
struct __SYCL2020_DEPRECATED("This type isn't device copyable in SYCL 2020")
IsDeprecatedDeviceCopyable<
T, std::enable_if_t<std::is_trivially_copy_constructible_v<T> &&
std::is_trivially_destructible_v<T> &&
!is_device_copyable_v<T>>> : std::true_type {};

template <typename T, int N>
struct __SYCL2020_DEPRECATED("This type isn't device copyable in SYCL 2020")
IsDeprecatedDeviceCopyable<T[N]> : IsDeprecatedDeviceCopyable<T> {};

#ifdef __SYCL_DEVICE_ONLY__
// Checks that the fields of the type T with indices 0 to (NumFieldsToCheck -
// 1) are device copyable.
template <typename T, unsigned NumFieldsToCheck>
struct CheckFieldsAreDeviceCopyable
: CheckFieldsAreDeviceCopyable<T, NumFieldsToCheck - 1> {
using FieldT = decltype(__builtin_field_type(T, NumFieldsToCheck - 1));
static_assert(is_device_copyable_v<FieldT> ||
detail::IsDeprecatedDeviceCopyable<FieldT>::value,
static_assert(is_device_copyable_v<FieldT>,
"The specified type is not device copyable");
};

Expand All @@ -119,8 +108,7 @@ template <typename T, unsigned NumBasesToCheck>
struct CheckBasesAreDeviceCopyable
: CheckBasesAreDeviceCopyable<T, NumBasesToCheck - 1> {
using BaseT = decltype(__builtin_base_type(T, NumBasesToCheck - 1));
static_assert(is_device_copyable_v<BaseT> ||
detail::IsDeprecatedDeviceCopyable<BaseT>::value,
static_assert(is_device_copyable_v<BaseT>,
"The specified type is not device copyable");
};

Expand Down
6 changes: 5 additions & 1 deletion sycl/include/sycl/reduction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class ReductionIdentityContainer<
static constexpr bool has_identity = true;

ReductionIdentityContainer(const T &) {}
ReductionIdentityContainer() {}
ReductionIdentityContainer() = default;

/// Returns the statically known identity value.
static constexpr T getIdentity() {
Expand All @@ -407,6 +407,10 @@ class ReductionIdentityContainer<

ReductionIdentityContainer(const T &Identity) : MIdentity(Identity) {}

// Make it trivially copyable (need at least on of the special member
// functions):
ReductionIdentityContainer(const ReductionIdentityContainer &) = default;

/// Returns the identity value given by user.
T getIdentity() const { return MIdentity; }

Expand Down
10 changes: 0 additions & 10 deletions sycl/test/basic_tests/is_device_copyable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ 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;
Expand Down Expand Up @@ -67,7 +59,6 @@ void test() {
A IamGood;
IamGood.i = 0;
BCopyable IamBadButCopyable(1);
C IamAlsoGood;
DCopyable IamAlsoBadButCopyable{0};
marray<int, 5> MarrayForCopyableIsCopyable(0);
range<2> Range{1,2};
Expand All @@ -78,7 +69,6 @@ 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];
Expand Down
Loading