DPC++ Runtime
Runtime libraries for oneAPI DPC++
properties.hpp
Go to the documentation of this file.
1 //==------- properties.hpp - SYCL properties associated with kernels -------==//
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 #include <array> // for array
12 #include <stddef.h> // for size_t
13 #include <stdint.h> // for uint32_T
14 #include <sycl/aspects.hpp> // for aspect
15 #include <sycl/ext/oneapi/experimental/forward_progress.hpp> // for forward_progress_guarantee enum
16 #include <sycl/ext/oneapi/properties/property.hpp> // for PropKind
17 #include <sycl/ext/oneapi/properties/property_utils.hpp> // for SizeListToStr
18 #include <sycl/ext/oneapi/properties/property_value.hpp> // for property_value
19 #include <type_traits> // for true_type
20 #include <utility> // for declval
21 namespace sycl {
22 inline namespace _V1 {
23 namespace ext::oneapi::experimental {
24 namespace detail {
25 // Trait for checking that all size_t values are non-zero.
26 template <size_t... Xs> struct AllNonZero {
27  static constexpr bool value = true;
28 };
29 template <size_t X, size_t... Xs> struct AllNonZero<X, Xs...> {
30  static constexpr bool value = X > 0 && AllNonZero<Xs...>::value;
31 };
32 } // namespace detail
33 
34 struct properties_tag {};
35 
37  : detail::compile_time_property_key<detail::PropKind::WorkGroupSize> {
38  template <size_t... Dims>
40  std::integral_constant<size_t, Dims>...>;
41 };
42 
44  : detail::compile_time_property_key<detail::PropKind::WorkGroupSizeHint> {
45  template <size_t... Dims>
47  std::integral_constant<size_t, Dims>...>;
48 };
49 
51  : detail::compile_time_property_key<detail::PropKind::SubGroupSize> {
52  template <uint32_t Size>
54  std::integral_constant<uint32_t, Size>>;
55 };
56 
58  : detail::compile_time_property_key<detail::PropKind::DeviceHas> {
59  template <aspect... Aspects>
61  std::integral_constant<aspect, Aspects>...>;
62 };
63 
65  template <int Dims>
66  using value_t =
68 };
69 
72 };
73 
74 template <size_t Dim0, size_t... Dims>
75 struct property_value<work_group_size_key, std::integral_constant<size_t, Dim0>,
76  std::integral_constant<size_t, Dims>...> {
77  static_assert(
78  sizeof...(Dims) + 1 <= 3,
79  "work_group_size property currently only supports up to three values.");
81  "work_group_size property must only contain non-zero values.");
82 
84 
85  constexpr size_t operator[](int Dim) const {
86  return std::array<size_t, sizeof...(Dims) + 1>{Dim0, Dims...}[Dim];
87  }
88 };
89 
90 template <size_t Dim0, size_t... Dims>
92  std::integral_constant<size_t, Dim0>,
93  std::integral_constant<size_t, Dims>...> {
94  static_assert(sizeof...(Dims) + 1 <= 3,
95  "work_group_size_hint property currently "
96  "only supports up to three values.");
97  static_assert(
99  "work_group_size_hint property must only contain non-zero values.");
100 
102 
103  constexpr size_t operator[](int Dim) const {
104  return std::array<size_t, sizeof...(Dims) + 1>{Dim0, Dims...}[Dim];
105  }
106 };
107 
108 template <uint32_t Size>
110  std::integral_constant<uint32_t, Size>> {
111  static_assert(Size != 0,
112  "sub_group_size_key property must contain a non-zero value.");
113 
115  using value_t = std::integral_constant<uint32_t, Size>;
116  static constexpr uint32_t value = Size;
117 };
118 
119 template <aspect... Aspects>
121  std::integral_constant<aspect, Aspects>...> {
123  static constexpr std::array<aspect, sizeof...(Aspects)> value{Aspects...};
124 };
125 
126 template <int Dims>
127 struct property_value<nd_range_kernel_key, std::integral_constant<int, Dims>> {
128  static_assert(
129  Dims >= 1 && Dims <= 3,
130  "nd_range_kernel_key property must use dimension of 1, 2 or 3.");
131 
133  using value_t = int;
134  static constexpr int dimensions = Dims;
135 };
136 
139 };
140 
141 template <size_t Dim0, size_t... Dims>
142 inline constexpr work_group_size_key::value_t<Dim0, Dims...> work_group_size;
143 
144 template <size_t Dim0, size_t... Dims>
145 inline constexpr work_group_size_hint_key::value_t<Dim0, Dims...>
147 
148 template <uint32_t Size>
150 
151 template <aspect... Aspects>
152 inline constexpr device_has_key::value_t<Aspects...> device_has;
153 
154 template <int Dims>
156 
158 
160  : detail::compile_time_property_key<detail::PropKind::WorkGroupProgress> {
161  template <forward_progress_guarantee Guarantee,
162  execution_scope CoordinationScope>
165  std::integral_constant<forward_progress_guarantee, Guarantee>,
166  std::integral_constant<execution_scope, CoordinationScope>>;
167 };
168 
170  : detail::compile_time_property_key<detail::PropKind::SubGroupProgress> {
171  template <forward_progress_guarantee Guarantee,
172  execution_scope CoordinationScope>
175  std::integral_constant<forward_progress_guarantee, Guarantee>,
176  std::integral_constant<execution_scope, CoordinationScope>>;
177 };
178 
180  : detail::compile_time_property_key<detail::PropKind::WorkItemProgress> {
181  template <forward_progress_guarantee Guarantee,
182  execution_scope CoordinationScope>
185  std::integral_constant<forward_progress_guarantee, Guarantee>,
186  std::integral_constant<execution_scope, CoordinationScope>>;
187 };
188 
189 template <forward_progress_guarantee Guarantee,
190  execution_scope CoordinationScope>
193  std::integral_constant<forward_progress_guarantee, Guarantee>,
194  std::integral_constant<execution_scope, CoordinationScope>> {
196  static constexpr forward_progress_guarantee guarantee = Guarantee;
197  static constexpr execution_scope coordinationScope = CoordinationScope;
198 };
199 
200 template <forward_progress_guarantee Guarantee,
201  execution_scope CoordinationScope>
204  std::integral_constant<forward_progress_guarantee, Guarantee>,
205  std::integral_constant<execution_scope, CoordinationScope>> {
207  static constexpr forward_progress_guarantee guarantee = Guarantee;
208  static constexpr execution_scope coordinationScope = CoordinationScope;
209 };
210 
211 template <forward_progress_guarantee Guarantee,
212  execution_scope CoordinationScope>
215  std::integral_constant<forward_progress_guarantee, Guarantee>,
216  std::integral_constant<execution_scope, CoordinationScope>> {
218  static constexpr forward_progress_guarantee guarantee = Guarantee;
219  static constexpr execution_scope coordinationScope = CoordinationScope;
220 };
221 
222 template <forward_progress_guarantee Guarantee,
223  execution_scope CoordinationScope>
226 
227 template <forward_progress_guarantee Guarantee,
228  execution_scope CoordinationScope>
231 
232 template <forward_progress_guarantee Guarantee,
233  execution_scope CoordinationScope>
236 
237 template <> struct is_property_key<work_group_progress_key> : std::true_type {};
238 template <> struct is_property_key<sub_group_progress_key> : std::true_type {};
239 template <> struct is_property_key<work_item_progress_key> : std::true_type {};
240 
241 namespace detail {
242 
243 template <size_t... Dims>
244 struct HasCompileTimeEffect<work_group_size_key::value_t<Dims...>>
245  : std::true_type {};
246 template <size_t... Dims>
248  : std::true_type {};
249 template <uint32_t Size>
251  : std::true_type {};
252 template <sycl::aspect... Aspects>
253 struct HasCompileTimeEffect<device_has_key::value_t<Aspects...>>
254  : std::true_type {};
255 
256 template <size_t Dim0, size_t... Dims>
257 struct PropertyMetaInfo<work_group_size_key::value_t<Dim0, Dims...>> {
258  static constexpr const char *name = "sycl-work-group-size";
259  static constexpr const char *value = SizeListToStr<Dim0, Dims...>::value;
260 };
261 template <size_t Dim0, size_t... Dims>
262 struct PropertyMetaInfo<work_group_size_hint_key::value_t<Dim0, Dims...>> {
263  static constexpr const char *name = "sycl-work-group-size-hint";
264  static constexpr const char *value = SizeListToStr<Dim0, Dims...>::value;
265 };
266 template <uint32_t Size>
267 struct PropertyMetaInfo<sub_group_size_key::value_t<Size>> {
268  static constexpr const char *name = "sycl-sub-group-size";
269  static constexpr uint32_t value = Size;
270 };
271 template <aspect... Aspects>
272 struct PropertyMetaInfo<device_has_key::value_t<Aspects...>> {
273  static constexpr const char *name = "sycl-device-has";
274  static constexpr const char *value =
275  SizeListToStr<static_cast<size_t>(Aspects)...>::value;
276 };
277 template <int Dims>
278 struct PropertyMetaInfo<nd_range_kernel_key::value_t<Dims>> {
279  static constexpr const char *name = "sycl-nd-range-kernel";
280  static constexpr int value = Dims;
281 };
282 template <> struct PropertyMetaInfo<single_task_kernel_key::value_t> {
283  static constexpr const char *name = "sycl-single-task-kernel";
284  static constexpr int value = 0;
285 };
286 
287 template <typename T, typename = void>
288 struct HasKernelPropertiesGetMethod : std::false_type {};
289 
290 template <typename T>
292  std::void_t<decltype(std::declval<T>().get(
293  std::declval<properties_tag>()))>>
294  : std::true_type {
295  using properties_t =
296  decltype(std::declval<T>().get(std::declval<properties_tag>()));
297 };
298 
299 } // namespace detail
300 } // namespace ext::oneapi::experimental
301 } // namespace _V1
302 } // namespace sycl
303 
304 #ifdef __SYCL_DEVICE_ONLY__
305 #define SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(PROP) \
306  [[__sycl_detail__::add_ir_attributes_function( \
307  sycl::ext::oneapi::experimental::detail::PropertyMetaInfo< \
308  std::remove_cv_t<std::remove_reference_t<decltype(PROP)>>>::name, \
309  sycl::ext::oneapi::experimental::detail::PropertyMetaInfo< \
310  std::remove_cv_t<std::remove_reference_t<decltype(PROP)>>>::value)]]
311 #else
312 #define SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(PROP)
313 #endif
constexpr single_task_kernel_key::value_t single_task_kernel
Definition: properties.hpp:157
constexpr sub_group_size_key::value_t< Size > sub_group_size
Definition: properties.hpp:149
constexpr nd_range_kernel_key::value_t< Dims > nd_range_kernel
Definition: properties.hpp:155
constexpr work_group_size_key::value_t< Dim0, Dims... > work_group_size
Definition: properties.hpp:142
constexpr device_has_key::value_t< Aspects... > device_has
Definition: properties.hpp:152
constexpr work_group_progress_key::value_t< Guarantee, CoordinationScope > work_group_progress
Definition: properties.hpp:225
constexpr sub_group_progress_key::value_t< Guarantee, CoordinationScope > sub_group_progress
Definition: properties.hpp:230
constexpr work_item_progress_key::value_t< Guarantee, CoordinationScope > work_item_progress
Definition: properties.hpp:235
constexpr work_group_size_hint_key::value_t< Dim0, Dims... > work_group_size_hint
Definition: properties.hpp:146
Definition: access.hpp:18