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> // for aspect
12 #include <sycl/ext/oneapi/properties/property.hpp> // for PropKind
13 #include <sycl/ext/oneapi/properties/property_utils.hpp> // for SizeListToStr
14 #include <sycl/ext/oneapi/properties/property_value.hpp> // for property_value
15 
16 #include <array> // for array
17 #include <stddef.h> // for size_t
18 #include <stdint.h> // for uint32_t
19 #include <type_traits> // for true_type
20 #include <utility> // for declval
21 
22 namespace sycl {
23 inline namespace _V1 {
24 namespace ext::oneapi::experimental {
25 namespace detail {
26 // Trait for checking that all size_t values are non-zero.
27 template <size_t... Xs> struct AllNonZero {
28  static constexpr bool value = true;
29 };
30 template <size_t X, size_t... Xs> struct AllNonZero<X, Xs...> {
31  static constexpr bool value = X > 0 && AllNonZero<Xs...>::value;
32 };
33 } // namespace detail
34 
35 struct properties_tag {};
36 
38  : detail::compile_time_property_key<detail::PropKind::WorkGroupSize> {
39  template <size_t... Dims>
41  std::integral_constant<size_t, Dims>...>;
42 };
43 
45  : detail::compile_time_property_key<detail::PropKind::WorkGroupSizeHint> {
46  template <size_t... Dims>
48  std::integral_constant<size_t, Dims>...>;
49 };
50 
52  : detail::compile_time_property_key<detail::PropKind::SubGroupSize> {
53  template <uint32_t Size>
55  std::integral_constant<uint32_t, Size>>;
56 };
57 
58 struct device_has_key : detail::compile_time_property_key<detail::PropKind::DeviceHas> {
59  template <aspect... Aspects>
61  std::integral_constant<aspect, Aspects>...>;
62 };
63 
64 template <size_t Dim0, size_t... Dims>
65 struct property_value<work_group_size_key, std::integral_constant<size_t, Dim0>,
66  std::integral_constant<size_t, Dims>...> {
67  static_assert(
68  sizeof...(Dims) + 1 <= 3,
69  "work_group_size property currently only supports up to three values.");
71  "work_group_size property must only contain non-zero values.");
72 
74 
75  constexpr size_t operator[](int Dim) const {
76  return std::array<size_t, sizeof...(Dims) + 1>{Dim0, Dims...}[Dim];
77  }
78 };
79 
80 template <size_t Dim0, size_t... Dims>
82  std::integral_constant<size_t, Dim0>,
83  std::integral_constant<size_t, Dims>...> {
84  static_assert(sizeof...(Dims) + 1 <= 3,
85  "work_group_size_hint property currently "
86  "only supports up to three values.");
87  static_assert(
89  "work_group_size_hint property must only contain non-zero values.");
90 
92 
93  constexpr size_t operator[](int Dim) const {
94  return std::array<size_t, sizeof...(Dims) + 1>{Dim0, Dims...}[Dim];
95  }
96 };
97 
98 template <uint32_t Size>
100  std::integral_constant<uint32_t, Size>> {
101  static_assert(Size != 0,
102  "sub_group_size_key property must contain a non-zero value.");
103 
105  using value_t = std::integral_constant<uint32_t, Size>;
106  static constexpr uint32_t value = Size;
107 };
108 
109 template <aspect... Aspects>
111  std::integral_constant<aspect, Aspects>...> {
113  static constexpr std::array<aspect, sizeof...(Aspects)> value{Aspects...};
114 };
115 
116 template <size_t Dim0, size_t... Dims>
117 inline constexpr work_group_size_key::value_t<Dim0, Dims...> work_group_size;
118 
119 template <size_t Dim0, size_t... Dims>
120 inline constexpr work_group_size_hint_key::value_t<Dim0, Dims...>
122 
123 template <uint32_t Size>
125 
126 template <aspect... Aspects>
127 inline constexpr device_has_key::value_t<Aspects...> device_has;
128 
129 namespace detail {
130 template <size_t Dim0, size_t... Dims>
131 struct PropertyMetaInfo<work_group_size_key::value_t<Dim0, Dims...>> {
132  static constexpr const char *name = "sycl-work-group-size";
133  static constexpr const char *value = SizeListToStr<Dim0, Dims...>::value;
134 };
135 template <size_t Dim0, size_t... Dims>
136 struct PropertyMetaInfo<work_group_size_hint_key::value_t<Dim0, Dims...>> {
137  static constexpr const char *name = "sycl-work-group-size-hint";
138  static constexpr const char *value = SizeListToStr<Dim0, Dims...>::value;
139 };
140 template <uint32_t Size>
141 struct PropertyMetaInfo<sub_group_size_key::value_t<Size>> {
142  static constexpr const char *name = "sycl-sub-group-size";
143  static constexpr uint32_t value = Size;
144 };
145 template <aspect... Aspects>
146 struct PropertyMetaInfo<device_has_key::value_t<Aspects...>> {
147  static constexpr const char *name = "sycl-device-has";
148  static constexpr const char *value =
149  SizeListToStr<static_cast<size_t>(Aspects)...>::value;
150 };
151 
152 template <typename T, typename = void>
153 struct HasKernelPropertiesGetMethod : std::false_type {};
154 
155 template <typename T>
157  std::void_t<decltype(std::declval<T>().get(
158  std::declval<properties_tag>()))>>
159  : std::true_type {
160  using properties_t =
161  decltype(std::declval<T>().get(std::declval<properties_tag>()));
162 };
163 
164 } // namespace detail
165 } // namespace ext::oneapi::experimental
166 } // namespace _V1
167 } // namespace sycl
168 
169 #ifdef __SYCL_DEVICE_ONLY__
170 #define SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(PROP) \
171  [[__sycl_detail__::add_ir_attributes_function( \
172  {"sycl-device-has"}, \
173  sycl::ext::oneapi::experimental::detail::PropertyMetaInfo< \
174  std::remove_cv_t<std::remove_reference_t<decltype(PROP)>>>::name, \
175  sycl::ext::oneapi::experimental::detail::PropertyMetaInfo< \
176  std::remove_cv_t<std::remove_reference_t<decltype(PROP)>>>::value)]]
177 #else
178 #define SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(PROP)
179 #endif
constexpr sub_group_size_key::value_t< Size > sub_group_size
Definition: properties.hpp:124
constexpr work_group_size_key::value_t< Dim0, Dims... > work_group_size
Definition: properties.hpp:117
constexpr device_has_key::value_t< Aspects... > device_has
Definition: properties.hpp:127
constexpr work_group_size_hint_key::value_t< Dim0, Dims... > work_group_size_hint
Definition: properties.hpp:121
Definition: access.hpp:18