Skip to content

Commit 294efcb

Browse files
committed
is_device_copyable specialization for const properties and associated tests
Signed-off-by: Steffen Larsen <[email protected]>
1 parent 0b23c3e commit 294efcb

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

sycl/include/CL/sycl/types.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,12 +2399,6 @@ struct is_device_copyable<
23992399
T, std::enable_if_t<std::is_trivially_copyable<T>::value>>
24002400
: std::true_type {};
24012401

2402-
// Specializations of device copyable should propagate onto constants.
2403-
template <typename T>
2404-
struct is_device_copyable<
2405-
const T, std::enable_if_t<!std::is_trivially_copyable<const T>::value>>
2406-
: is_device_copyable<T> {};
2407-
24082402
#if __cplusplus >= 201703L
24092403
template <typename T>
24102404
inline constexpr bool is_device_copyable_v = is_device_copyable<T>::value;

sycl/include/sycl/ext/oneapi/properties/properties.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ struct is_device_copyable<
213213
std::enable_if_t<!std::is_trivially_copyable<
214214
ext::oneapi::experimental::properties<PropertiesT>>::value>>
215215
: is_device_copyable<PropertiesT> {};
216+
template <typename PropertiesT>
217+
struct is_device_copyable<
218+
const ext::oneapi::experimental::properties<PropertiesT>,
219+
std::enable_if_t<!std::is_trivially_copyable<
220+
const ext::oneapi::experimental::properties<PropertiesT>>::value>>
221+
: is_device_copyable<PropertiesT> {};
216222

217223
} // namespace sycl
218224
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/test/extensions/properties/mock_compile_time_properties.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,36 @@ inline bool operator==(const foz &lhs, const foz &rhs) {
5656
}
5757
inline bool operator!=(const foz &lhs, const foz &rhs) { return !(lhs == rhs); }
5858

59+
struct fir {
60+
fir(float v1, bool v2) : value1(v1), value2(v2) {}
61+
// Define copy constructor to make foz non-trivially copyable
62+
fir(const foz &f) {
63+
value1 = f.value1;
64+
value2 = f.value2;
65+
}
66+
float value1;
67+
bool value2;
68+
};
69+
70+
inline bool operator==(const fir &lhs, const fir &rhs) {
71+
return lhs.value1 == rhs.value1 && lhs.value2 == rhs.value2;
72+
}
73+
inline bool operator!=(const fir &lhs, const fir &rhs) { return !(lhs == rhs); }
74+
5975
inline constexpr bar_key::value_t bar;
6076
template <int K> inline constexpr baz_key::value_t<K> baz;
6177
template <typename... Ts> inline constexpr boo_key::value_t<Ts...> boo;
6278

6379
using foo_key = foo;
6480
using foz_key = foz;
81+
using fir_key = fir;
6582

6683
template <> struct is_property_key<bar_key> : std::true_type {};
6784
template <> struct is_property_key<baz_key> : std::true_type {};
6885
template <> struct is_property_key<boo_key> : std::true_type {};
6986
template <> struct is_property_key<foo_key> : std::true_type {};
7087
template <> struct is_property_key<foz_key> : std::true_type {};
88+
template <> struct is_property_key<fir_key> : std::true_type {};
7189

7290
template <typename syclObjectT>
7391
struct is_property_key_of<bar_key, syclObjectT> : std::true_type {};
@@ -79,6 +97,8 @@ template <typename syclObjectT>
7997
struct is_property_key_of<foo_key, syclObjectT> : std::true_type {};
8098
template <typename syclObjectT>
8199
struct is_property_key_of<foz_key, syclObjectT> : std::true_type {};
100+
template <typename syclObjectT>
101+
struct is_property_key_of<fir_key, syclObjectT> : std::true_type {};
82102

83103
namespace detail {
84104
template <> struct PropertyToKind<bar_key> {
@@ -101,13 +121,18 @@ template <> struct PropertyToKind<foz_key> {
101121
static constexpr PropKind Kind =
102122
static_cast<enum PropKind>(PropKind::PropKindSize + 4);
103123
};
124+
template <> struct PropertyToKind<fir_key> {
125+
static constexpr PropKind Kind =
126+
static_cast<enum PropKind>(PropKind::PropKindSize + 4);
127+
};
104128

105129
template <> struct IsCompileTimeProperty<bar_key> : std::true_type {};
106130
template <> struct IsCompileTimeProperty<baz_key> : std::true_type {};
107131
template <> struct IsCompileTimeProperty<boo_key> : std::true_type {};
108132

109133
template <> struct IsRuntimeProperty<foo_key> : std::true_type {};
110134
template <> struct IsRuntimeProperty<foz_key> : std::true_type {};
135+
template <> struct IsRuntimeProperty<fir_key> : std::true_type {};
111136
} // namespace detail
112137
} // namespace experimental
113138
} // namespace oneapi

sycl/test/extensions/properties/properties_device_copyable.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@
88
class TestClass1 {};
99
class TestClass2 {};
1010

11+
namespace sycl {
12+
// Explicitly mark fir property as device-copyable
13+
template <>
14+
struct is_device_copyable<sycl::ext::oneapi::experimental::fir>
15+
: std::true_type {};
16+
template <>
17+
struct is_device_copyable<const sycl::ext::oneapi::experimental::fir>
18+
: std::true_type {};
19+
}
20+
1121
int main() {
1222
// Check only compile-time properties are device-copyable
1323
using P1 = decltype(sycl::ext::oneapi::experimental::properties(
1424
sycl::ext::oneapi::experimental::baz<1>,
1525
sycl::ext::oneapi::experimental::boo<TestClass1, TestClass2>,
1626
sycl::ext::oneapi::experimental::bar));
17-
27+
using CP1 = const P1;
1828
static_assert(sycl::is_device_copyable_v<
1929
sycl::ext::oneapi::experimental::baz_key::value_t<1>>);
2030
static_assert(
@@ -23,28 +33,44 @@ int main() {
2333
static_assert(sycl::is_device_copyable_v<
2434
sycl::ext::oneapi::experimental::bar_key::value_t>);
2535
static_assert(sycl::is_device_copyable_v<P1>);
36+
static_assert(sycl::is_device_copyable_v<CP1>);
2637

2738
// Check property list with non-device-copyable property
2839
using P2 = decltype(sycl::ext::oneapi::experimental::properties(
2940
sycl::ext::oneapi::experimental::bar,
3041
sycl::ext::oneapi::experimental::foz{42.42, false}));
42+
using CP2 = const P2;
3143
static_assert(
3244
!sycl::is_device_copyable_v<sycl::ext::oneapi::experimental::foz>);
3345
static_assert(!sycl::is_device_copyable_v<P2>);
46+
static_assert(!sycl::is_device_copyable_v<CP2>);
47+
48+
// Check property list with explicit device-copyable property
49+
using P3 = decltype(sycl::ext::oneapi::experimental::properties(
50+
sycl::ext::oneapi::experimental::bar,
51+
sycl::ext::oneapi::experimental::fir{42.42, false}));
52+
using CP3 = const P3;
53+
static_assert(
54+
sycl::is_device_copyable_v<sycl::ext::oneapi::experimental::fir>);
55+
static_assert(sycl::is_device_copyable_v<P3>);
56+
static_assert(sycl::is_device_copyable_v<CP3>);
3457

3558
// Check property list with device-copyable compile-time and runtime
3659
// properties
37-
using P3 = decltype(sycl::ext::oneapi::experimental::properties(
60+
using P4 = decltype(sycl::ext::oneapi::experimental::properties(
3861
sycl::ext::oneapi::experimental::baz<1>,
3962
sycl::ext::oneapi::experimental::foo{1234}));
63+
using CP4 = const P4;
4064
static_assert(
4165
sycl::is_device_copyable_v<sycl::ext::oneapi::experimental::foo>);
42-
static_assert(sycl::is_device_copyable_v<P3>);
66+
static_assert(sycl::is_device_copyable_v<P4>);
67+
static_assert(sycl::is_device_copyable_v<CP4>);
4368

4469
// Check that device-copyable property list can indeed be used in a kernel
4570
const auto PropertyList = sycl::ext::oneapi::experimental::properties(
4671
sycl::ext::oneapi::experimental::baz<1>,
47-
sycl::ext::oneapi::experimental::foo{0});
72+
sycl::ext::oneapi::experimental::foo{0},
73+
sycl::ext::oneapi::experimental::fir{12.34, true});
4874

4975
sycl::queue Q;
5076
Q.submit([&](sycl::handler &CGH) {
@@ -53,8 +79,11 @@ int main() {
5379
sycl::ext::oneapi::experimental::baz_key>();
5480
decltype(PropertyList)::has_property<
5581
sycl::ext::oneapi::experimental::foo_key>();
82+
decltype(PropertyList)::has_property<
83+
sycl::ext::oneapi::experimental::fir_key>();
5684
PropertyList.get_property<sycl::ext::oneapi::experimental::baz_key>();
5785
PropertyList.get_property<sycl::ext::oneapi::experimental::foo_key>();
86+
PropertyList.get_property<sycl::ext::oneapi::experimental::fir_key>();
5887
});
5988
});
6089
return 0;

0 commit comments

Comments
 (0)