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 <sycl/aspects.hpp>
15 
16 #include <array>
17 
18 namespace sycl {
20 namespace ext::oneapi::experimental {
21 namespace detail {
22 // Trait for checking that all size_t values are non-zero.
23 template <size_t... Xs> struct AllNonZero {
24  static inline constexpr bool value = true;
25 };
26 template <size_t X, size_t... Xs> struct AllNonZero<X, Xs...> {
27  static inline constexpr bool value = X > 0 && AllNonZero<Xs...>::value;
28 };
29 } // namespace detail
30 
31 struct properties_tag {};
32 
34  template <size_t... Dims>
36  std::integral_constant<size_t, Dims>...>;
37 };
38 
40  template <size_t... Dims>
42  std::integral_constant<size_t, Dims>...>;
43 };
44 
46  template <uint32_t Size>
48  std::integral_constant<uint32_t, Size>>;
49 };
50 
52  template <aspect... Aspects>
54  std::integral_constant<aspect, Aspects>...>;
55 };
56 
57 template <size_t Dim0, size_t... Dims>
58 struct property_value<work_group_size_key, std::integral_constant<size_t, Dim0>,
59  std::integral_constant<size_t, Dims>...> {
60  static_assert(
61  sizeof...(Dims) + 1 <= 3,
62  "work_group_size property currently only supports up to three values.");
64  "work_group_size property must only contain non-zero values.");
65 
67 
68  constexpr size_t operator[](int Dim) const {
69  return std::array<size_t, sizeof...(Dims) + 1>{Dim0, Dims...}[Dim];
70  }
71 };
72 
73 template <size_t Dim0, size_t... Dims>
75  std::integral_constant<size_t, Dim0>,
76  std::integral_constant<size_t, Dims>...> {
77  static_assert(sizeof...(Dims) + 1 <= 3,
78  "work_group_size_hint property currently "
79  "only supports up to three values.");
80  static_assert(
82  "work_group_size_hint property must only contain non-zero values.");
83 
85 
86  constexpr size_t operator[](int Dim) const {
87  return std::array<size_t, sizeof...(Dims) + 1>{Dim0, Dims...}[Dim];
88  }
89 };
90 
91 template <uint32_t Size>
93  std::integral_constant<uint32_t, Size>> {
94  static_assert(Size != 0,
95  "sub_group_size_key property must contain a non-zero value.");
96 
98  using value_t = std::integral_constant<uint32_t, Size>;
99  static constexpr uint32_t value = Size;
100 };
101 
102 template <aspect... Aspects>
104  std::integral_constant<aspect, Aspects>...> {
106  static constexpr std::array<aspect, sizeof...(Aspects)> value{Aspects...};
107 };
108 
109 template <size_t Dim0, size_t... Dims>
110 inline constexpr work_group_size_key::value_t<Dim0, Dims...> work_group_size;
111 
112 template <size_t Dim0, size_t... Dims>
113 inline constexpr work_group_size_hint_key::value_t<Dim0, Dims...>
115 
116 template <uint32_t Size>
118 
119 template <aspect... Aspects>
120 inline constexpr device_has_key::value_t<Aspects...> device_has;
121 
122 template <> struct is_property_key<work_group_size_key> : std::true_type {};
123 template <>
124 struct is_property_key<work_group_size_hint_key> : std::true_type {};
125 template <> struct is_property_key<sub_group_size_key> : std::true_type {};
126 template <> struct is_property_key<device_has_key> : std::true_type {};
127 
128 namespace detail {
129 template <> struct PropertyToKind<work_group_size_key> {
130  static constexpr PropKind Kind = PropKind::WorkGroupSize;
131 };
133  static constexpr PropKind Kind = PropKind::WorkGroupSizeHint;
134 };
135 template <> struct PropertyToKind<sub_group_size_key> {
136  static constexpr PropKind Kind = PropKind::SubGroupSize;
137 };
138 template <> struct PropertyToKind<device_has_key> {
139  static constexpr PropKind Kind = PropKind::DeviceHas;
140 };
141 
142 template <>
143 struct IsCompileTimeProperty<work_group_size_key> : std::true_type {};
144 template <>
146 template <>
147 struct IsCompileTimeProperty<sub_group_size_key> : std::true_type {};
148 template <> struct IsCompileTimeProperty<device_has_key> : std::true_type {};
149 
150 template <size_t Dim0, size_t... Dims>
151 struct PropertyMetaInfo<work_group_size_key::value_t<Dim0, Dims...>> {
152  static constexpr const char *name = "sycl-work-group-size";
153  static constexpr const char *value = SizeListToStr<Dim0, Dims...>::value;
154 };
155 template <size_t Dim0, size_t... Dims>
156 struct PropertyMetaInfo<work_group_size_hint_key::value_t<Dim0, Dims...>> {
157  static constexpr const char *name = "sycl-work-group-size-hint";
158  static constexpr const char *value = SizeListToStr<Dim0, Dims...>::value;
159 };
160 template <uint32_t Size>
161 struct PropertyMetaInfo<sub_group_size_key::value_t<Size>> {
162  static constexpr const char *name = "sycl-sub-group-size";
163  static constexpr uint32_t value = Size;
164 };
165 template <aspect... Aspects>
166 struct PropertyMetaInfo<device_has_key::value_t<Aspects...>> {
167  static constexpr const char *name = "sycl-device-has";
168  static constexpr const char *value =
169  SizeListToStr<static_cast<size_t>(Aspects)...>::value;
170 };
171 
172 template <typename T, typename = void>
173 struct HasKernelPropertiesGetMethod : std::false_type {};
174 
175 template <typename T>
177  T, sycl::detail::void_t<decltype(std::declval<T>().get(
178  std::declval<properties_tag>()))>> : std::true_type {
179  using properties_t =
180  decltype(std::declval<T>().get(std::declval<properties_tag>()));
181 };
182 
183 } // namespace detail
184 } // namespace ext::oneapi::experimental
185 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
186 } // namespace sycl
187 
188 #ifdef __SYCL_DEVICE_ONLY__
189 #define SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(PROP) \
190  [[__sycl_detail__::add_ir_attributes_function( \
191  {"sycl-device-has"}, \
192  sycl::ext::oneapi::experimental::detail::PropertyMetaInfo< \
193  std::remove_cv_t<std::remove_reference_t<decltype(PROP)>>>::name, \
194  sycl::ext::oneapi::experimental::detail::PropertyMetaInfo< \
195  std::remove_cv_t<std::remove_reference_t<decltype(PROP)>>>::value)]]
196 #else
197 #define SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(PROP)
198 #endif
aspects.hpp
sycl::_V1::ext::oneapi::experimental::detail::PropKind
PropKind
Definition: property.hpp:165
sycl::_V1::ext::oneapi::experimental::detail::SubGroupSize
@ SubGroupSize
Definition: property.hpp:174
sycl::_V1::ext::oneapi::experimental::device_has
constexpr device_has_key::value_t< Aspects... > device_has
Definition: properties.hpp:120
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::ext::oneapi::experimental::properties_tag
Definition: properties.hpp:31
sycl::_V1::ext::oneapi::experimental::property_value< work_group_size_hint_key, std::integral_constant< size_t, Dim0 >, std::integral_constant< size_t, Dims >... >::operator[]
constexpr size_t operator[](int Dim) const
Definition: properties.hpp:86
sycl::_V1::ext::oneapi::experimental::detail::IsCompileTimeProperty
Definition: property.hpp:209
sycl::_V1::ext::oneapi::experimental::detail::WorkGroupSizeHint
@ WorkGroupSizeHint
Definition: property.hpp:173
sycl::_V1::ext::oneapi::experimental::property_value< device_has_key, std::integral_constant< aspect, Aspects >... >
Definition: properties.hpp:103
sycl::_V1::ext::oneapi::experimental::detail::WorkGroupSize
@ WorkGroupSize
Definition: property.hpp:172
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::ext::oneapi::experimental::detail::AllNonZero
Definition: properties.hpp:23
sycl::_V1::ext::oneapi::experimental::detail::HasKernelPropertiesGetMethod< T, sycl::detail::void_t< decltype(std::declval< T >().get(std::declval< properties_tag >()))> >::properties_t
decltype(std::declval< T >().get(std::declval< properties_tag >())) properties_t
Definition: properties.hpp:180
sycl::_V1::ext::oneapi::experimental::device_has_key
Definition: properties.hpp:51
sycl::_V1::ext::oneapi::experimental::work_group_size_hint_key
Definition: properties.hpp:39
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
sycl::_V1::ext::oneapi::experimental::work_group_size_hint
constexpr work_group_size_hint_key::value_t< Dim0, Dims... > work_group_size_hint
Definition: properties.hpp:114
sycl::_V1::ext::oneapi::experimental::detail::DeviceHas
@ DeviceHas
Definition: property.hpp:175
property_value.hpp
sycl::_V1::ext::oneapi::experimental::sub_group_size_key
Definition: properties.hpp:45
sycl::_V1::ext::oneapi::experimental::property_value< sub_group_size_key, std::integral_constant< uint32_t, Size > >
Definition: properties.hpp:92
sycl::_V1::ext::oneapi::experimental::detail::PropertyMetaInfo
Definition: property.hpp:212
sycl::_V1::ext::oneapi::experimental::property_value< work_group_size_key, std::integral_constant< size_t, Dim0 >, std::integral_constant< size_t, Dims >... >::operator[]
constexpr size_t operator[](int Dim) const
Definition: properties.hpp:68
std
Definition: accessor.hpp:3230
property_utils.hpp
sycl::_V1::ext::oneapi::experimental::sub_group_size
constexpr sub_group_size_key::value_t< Size > sub_group_size
Definition: properties.hpp:117
property.hpp
sycl::_V1::ext::oneapi::experimental::detail::PropertyToKind
Definition: property.hpp:197
sycl::_V1::ext::oneapi::experimental::work_group_size
constexpr work_group_size_key::value_t< Dim0, Dims... > work_group_size
Definition: properties.hpp:110
sycl::_V1::ext::oneapi::experimental::property_value
Definition: property_utils.hpp:22
sycl::_V1::ext::oneapi::experimental::property_value< sub_group_size_key, std::integral_constant< uint32_t, Size > >::value_t
std::integral_constant< uint32_t, Size > value_t
Definition: properties.hpp:98
sycl::_V1::ext::oneapi::experimental::work_group_size_key
Definition: properties.hpp:33
sycl::_V1::ext::oneapi::experimental::is_property_key
Definition: property.hpp:221
sycl::_V1::ext::oneapi::experimental::detail::HasKernelPropertiesGetMethod
Definition: properties.hpp:173
sycl::_V1::detail::void_t
void void_t
Definition: stl_type_traits.hpp:42