Skip to content

Commit 3b17da6

Browse files
[SYCL] Implement SYCL 2020 property traits (#4887)
SYCL 2020 introduces the is_property and is_property_of traits for marking valid properties and the SYCL objects they can be used as properties for. These changes add the following: 1. The is_property and is_property_of trait classes and the associated is_property_v and is_property_of_v shortcuts. 2. Specializations of the new trait classes for all existing SYCL properties. 3. Adjustment of the restriction for the property_list ctor using is_property. Signed-off-by: Steffen Larsen <steffen.larsen@intel.com>
1 parent d6a6401 commit 3b17da6

File tree

9 files changed

+529
-4
lines changed

9 files changed

+529
-4
lines changed

sycl/include/CL/sycl/properties/accessor_properties.hpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/sycl/detail/common.hpp>
1212
#include <CL/sycl/detail/property_helper.hpp>
13+
#include <CL/sycl/properties/property_traits.hpp>
1314
#include <sycl/ext/oneapi/accessor_property_list.hpp>
1415
#include <type_traits>
1516

@@ -111,6 +112,85 @@ struct is_compile_time_property<sycl::ext::intel::property::buffer_location>
111112
} // namespace oneapi
112113
} // namespace ext
113114

115+
// Forward declaration
116+
template <typename DataT, int Dimensions, access::mode AccessMode,
117+
access::target AccessTarget, access::placeholder IsPlaceholder,
118+
typename PropertyListT>
119+
class accessor;
120+
template <typename DataT, int Dimensions, access::mode AccessMode,
121+
access::target AccessTarget, access::placeholder IsPlaceholder>
122+
class image_accessor;
123+
template <typename DataT, int Dimensions, access::mode AccessMode>
124+
class host_accessor;
125+
126+
// Accessor property trait specializations
127+
template <> struct is_property<property::noinit> : std::true_type {};
128+
template <> struct is_property<property::no_init> : std::true_type {};
129+
template <>
130+
struct is_property<ext::oneapi::property::no_offset> : std::true_type {};
131+
template <>
132+
struct is_property<ext::oneapi::property::no_alias> : std::true_type {};
133+
template <>
134+
struct is_property<ext::intel::property::buffer_location> : std::true_type {};
135+
136+
template <typename DataT, int Dimensions, access::mode AccessMode,
137+
access::target AccessTarget, access::placeholder IsPlaceholder,
138+
typename PropertyListT>
139+
struct is_property_of<property::noinit,
140+
accessor<DataT, Dimensions, AccessMode, AccessTarget,
141+
IsPlaceholder, PropertyListT>> : std::true_type {
142+
};
143+
template <typename DataT, int Dimensions, access::mode AccessMode,
144+
access::target AccessTarget, access::placeholder IsPlaceholder,
145+
typename PropertyListT>
146+
struct is_property_of<property::no_init,
147+
accessor<DataT, Dimensions, AccessMode, AccessTarget,
148+
IsPlaceholder, PropertyListT>> : std::true_type {
149+
};
150+
template <typename DataT, int Dimensions, access::mode AccessMode,
151+
access::target AccessTarget, access::placeholder IsPlaceholder,
152+
typename PropertyListT>
153+
struct is_property_of<ext::oneapi::property::no_offset,
154+
accessor<DataT, Dimensions, AccessMode, AccessTarget,
155+
IsPlaceholder, PropertyListT>> : std::true_type {
156+
};
157+
template <typename DataT, int Dimensions, access::mode AccessMode,
158+
access::target AccessTarget, access::placeholder IsPlaceholder,
159+
typename PropertyListT>
160+
struct is_property_of<ext::oneapi::property::no_alias,
161+
accessor<DataT, Dimensions, AccessMode, AccessTarget,
162+
IsPlaceholder, PropertyListT>> : std::true_type {
163+
};
164+
template <typename DataT, int Dimensions, access::mode AccessMode,
165+
access::target AccessTarget, access::placeholder IsPlaceholder,
166+
typename PropertyListT>
167+
struct is_property_of<ext::intel::property::buffer_location,
168+
accessor<DataT, Dimensions, AccessMode, AccessTarget,
169+
IsPlaceholder, PropertyListT>> : std::true_type {
170+
};
171+
172+
template <typename DataT, int Dimensions, access::mode AccessMode,
173+
access::target AccessTarget, access::placeholder IsPlaceholder>
174+
struct is_property_of<
175+
property::noinit,
176+
image_accessor<DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder>>
177+
: std::true_type {};
178+
template <typename DataT, int Dimensions, access::mode AccessMode,
179+
access::target AccessTarget, access::placeholder IsPlaceholder>
180+
struct is_property_of<
181+
property::no_init,
182+
image_accessor<DataT, Dimensions, AccessMode, AccessTarget, IsPlaceholder>>
183+
: std::true_type {};
184+
185+
template <typename DataT, int Dimensions, access::mode AccessMode>
186+
struct is_property_of<property::noinit,
187+
host_accessor<DataT, Dimensions, AccessMode>>
188+
: std::true_type {};
189+
template <typename DataT, int Dimensions, access::mode AccessMode>
190+
struct is_property_of<property::no_init,
191+
host_accessor<DataT, Dimensions, AccessMode>>
192+
: std::true_type {};
193+
114194
namespace detail {
115195
template <int I>
116196
struct IsCompileTimePropertyInstance<

sycl/include/CL/sycl/properties/buffer_properties.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/sycl/context.hpp>
1212
#include <CL/sycl/detail/property_helper.hpp>
13+
#include <CL/sycl/properties/property_traits.hpp>
1314

1415
__SYCL_INLINE_NAMESPACE(cl) {
1516
namespace sycl {
@@ -64,5 +65,43 @@ class use_pinned_host_memory : public sycl::detail::DataLessProperty<
6465
} // namespace property
6566
} // namespace oneapi
6667
} // namespace ext
68+
69+
// Forward declaration
70+
template <typename T, int Dimensions, typename AllocatorT, typename Enable>
71+
class buffer;
72+
73+
// Buffer property trait specializations
74+
template <>
75+
struct is_property<property::buffer::use_host_ptr> : std::true_type {};
76+
template <> struct is_property<property::buffer::use_mutex> : std::true_type {};
77+
template <>
78+
struct is_property<property::buffer::context_bound> : std::true_type {};
79+
template <>
80+
struct is_property<property::buffer::mem_channel> : std::true_type {};
81+
template <>
82+
struct is_property<ext::oneapi::property::buffer::use_pinned_host_memory>
83+
: std::true_type {};
84+
85+
template <typename T, int Dimensions, typename AllocatorT>
86+
struct is_property_of<property::buffer::use_host_ptr,
87+
buffer<T, Dimensions, AllocatorT, void>>
88+
: std::true_type {};
89+
template <typename T, int Dimensions, typename AllocatorT>
90+
struct is_property_of<property::buffer::use_mutex,
91+
buffer<T, Dimensions, AllocatorT, void>>
92+
: std::true_type {};
93+
template <typename T, int Dimensions, typename AllocatorT>
94+
struct is_property_of<property::buffer::context_bound,
95+
buffer<T, Dimensions, AllocatorT, void>>
96+
: std::true_type {};
97+
template <typename T, int Dimensions, typename AllocatorT>
98+
struct is_property_of<property::buffer::mem_channel,
99+
buffer<T, Dimensions, AllocatorT, void>>
100+
: std::true_type {};
101+
template <typename T, int Dimensions, typename AllocatorT>
102+
struct is_property_of<ext::oneapi::property::buffer::use_pinned_host_memory,
103+
buffer<T, Dimensions, AllocatorT, void>>
104+
: std::true_type {};
105+
67106
} // namespace sycl
68107
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/properties/context_properties.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/sycl/context.hpp>
1212
#include <CL/sycl/detail/property_helper.hpp>
13+
#include <CL/sycl/properties/property_traits.hpp>
1314

1415
__SYCL_INLINE_NAMESPACE(cl) {
1516
namespace sycl {
@@ -21,5 +22,18 @@ class use_primary_context
2122
} // namespace cuda
2223
} // namespace context
2324
} // namespace property
25+
26+
// Forward declaration
27+
class context;
28+
29+
// Context property trait specializations
30+
template <>
31+
struct is_property<property::context::cuda::use_primary_context>
32+
: std::true_type {};
33+
34+
template <>
35+
struct is_property_of<property::context::cuda::use_primary_context, context>
36+
: std::true_type {};
37+
2438
} // namespace sycl
2539
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/properties/image_properties.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/sycl/context.hpp>
1212
#include <CL/sycl/detail/property_helper.hpp>
13+
#include <CL/sycl/properties/property_traits.hpp>
1314

1415
__SYCL_INLINE_NAMESPACE(cl) {
1516
namespace sycl {
@@ -40,5 +41,26 @@ class context_bound
4041
};
4142
} // namespace image
4243
} // namespace property
44+
45+
// Forward declaration
46+
template <int Dimensions, typename AllocatorT> class image;
47+
48+
// Image property trait specializations
49+
template <>
50+
struct is_property<property::image::use_host_ptr> : std::true_type {};
51+
template <> struct is_property<property::image::use_mutex> : std::true_type {};
52+
template <>
53+
struct is_property<property::image::context_bound> : std::true_type {};
54+
55+
template <int Dimensions, typename AllocatorT>
56+
struct is_property_of<property::image::use_host_ptr,
57+
image<Dimensions, AllocatorT>> : std::true_type {};
58+
template <int Dimensions, typename AllocatorT>
59+
struct is_property_of<property::image::use_mutex, image<Dimensions, AllocatorT>>
60+
: std::true_type {};
61+
template <int Dimensions, typename AllocatorT>
62+
struct is_property_of<property::image::context_bound,
63+
image<Dimensions, AllocatorT>> : std::true_type {};
64+
4365
} // namespace sycl
4466
} // __SYCL_INLINE_NAMESPACE(cl)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//==------------ property_traits.hpp --- SYCL property traits --------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
__SYCL_INLINE_NAMESPACE(cl) {
12+
namespace sycl {
13+
14+
// Property traits
15+
template <typename propertyT> struct is_property : public std::false_type {};
16+
17+
template <typename propertyT, typename syclObjectT>
18+
struct is_property_of : public std::false_type {};
19+
20+
template <typename propertyT>
21+
__SYCL_INLINE_CONSTEXPR bool is_property_v = is_property<propertyT>::value;
22+
23+
template <typename propertyT, typename syclObjectT>
24+
__SYCL_INLINE_CONSTEXPR bool is_property_of_v =
25+
is_property_of<propertyT, syclObjectT>::value;
26+
27+
} // namespace sycl
28+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/properties/queue_properties.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

1111
#include <CL/sycl/detail/property_helper.hpp>
12+
#include <CL/sycl/properties/property_traits.hpp>
1213

1314
__SYCL_INLINE_NAMESPACE(cl) {
1415
namespace sycl {
@@ -23,5 +24,26 @@ class use_default_stream
2324
} // namespace cuda
2425
} // namespace queue
2526
} // namespace property
27+
28+
// Forward declaration
29+
class queue;
30+
31+
// Queue property trait specializations
32+
template <> struct is_property<property::queue::in_order> : std::true_type {};
33+
template <>
34+
struct is_property<property::queue::enable_profiling> : std::true_type {};
35+
template <>
36+
struct is_property<property::queue::cuda::use_default_stream> : std::true_type {
37+
};
38+
39+
template <>
40+
struct is_property_of<property::queue::in_order, queue> : std::true_type {};
41+
template <>
42+
struct is_property_of<property::queue::enable_profiling, queue>
43+
: std::true_type {};
44+
template <>
45+
struct is_property_of<property::queue::cuda::use_default_stream, queue>
46+
: std::true_type {};
47+
2648
} // namespace sycl
2749
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/properties/reduction_properties.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/sycl/context.hpp>
1212
#include <CL/sycl/detail/property_helper.hpp>
13+
#include <CL/sycl/properties/property_traits.hpp>
1314

1415
__SYCL_INLINE_NAMESPACE(cl) {
1516
namespace sycl {
@@ -19,5 +20,11 @@ class initialize_to_identity
1920
: public detail::DataLessProperty<detail::InitializeToIdentity> {};
2021
} // namespace reduction
2122
} // namespace property
23+
24+
// Reduction property trait specializations
25+
template <>
26+
struct is_property<property::reduction::initialize_to_identity>
27+
: std::true_type {};
28+
2229
} // namespace sycl
2330
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/property_list.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/sycl/detail/common.hpp>
1212
#include <CL/sycl/detail/property_list_base.hpp>
13+
#include <CL/sycl/properties/property_traits.hpp>
1314

1415
__SYCL_INLINE_NAMESPACE(cl) {
1516
namespace sycl {
@@ -28,10 +29,8 @@ class property_list : protected detail::PropertyListBase {
2829
template <typename... Tail> struct AllProperties : std::true_type {};
2930
template <typename T, typename... Tail>
3031
struct AllProperties<T, Tail...>
31-
: detail::conditional_t<
32-
std::is_base_of<detail::DataLessPropertyBase, T>::value ||
33-
std::is_base_of<detail::PropertyWithDataBase, T>::value,
34-
AllProperties<Tail...>, std::false_type> {};
32+
: detail::conditional_t<is_property<T>::value, AllProperties<Tail...>,
33+
std::false_type> {};
3534

3635
public:
3736
template <typename... PropsT, typename = typename detail::enable_if_t<

0 commit comments

Comments
 (0)