DPC++ Runtime
Runtime libraries for oneAPI DPC++
accessor_property_list.hpp
Go to the documentation of this file.
1 //==----- accessor_property_list.hpp --- SYCL accessor property list -------==//
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 
15 
17 namespace sycl {
18 // Forward declaration
19 template <typename, int, access::mode, access::target, access::placeholder,
20  typename PropertyListT>
21 class accessor;
22 namespace detail {
23 // This helper template must be specialized for nested instance template
24 // of each compile-time-constant property.
25 template <typename T> struct IsCompileTimePropertyInstance : std::false_type {};
26 } // namespace detail
27 namespace ext {
28 namespace oneapi {
29 
30 template <typename T> struct is_compile_time_property : std::false_type {};
31 
42 template <typename... PropsT>
44  // These structures check if compile-time-constant property is present in
45  // list. For runtime properties this check is always true.
46  template <class T, class U> struct AreSameTemplate : std::is_same<T, U> {};
47  template <template <class...> class T, class T1, class T2>
48  struct AreSameTemplate<T<T1>, T<T2>> : std::true_type {};
49 #if __cplusplus >= 201703L
50  // Declaring non-type template parameters with auto is a C++17 feature. Since
51  // the extension is written against SYCL 2020, which implies use of C++17,
52  // there's no need to provide alternative implementations for older standards.
53  template <template <auto...> class T, auto... T1, auto... T2>
54  struct AreSameTemplate<T<T1...>, T<T2...>> : std::true_type {};
55 #endif
56  // This template helps to identify if PropListT parameter pack contains
57  // property of PropT type, where PropT is a nested instance template of
58  // compile-time-constant property.
59  template <typename PropT, typename... PropListT> struct ContainsProperty;
60  template <typename PropT> struct ContainsProperty<PropT> : std::false_type {};
61  template <typename PropT, typename Head, typename... Tail>
62  struct ContainsProperty<PropT, Head, Tail...>
63  : sycl::detail::conditional_t<AreSameTemplate<PropT, Head>::value,
64  std::true_type,
65  ContainsProperty<PropT, Tail...>> {};
66 
67  // PropertyContainer is a helper structure, that holds list of properties.
68  // It is used to avoid multiple parameter packs in templates.
69  template <typename...> struct PropertyContainer {
70  using Head = void;
71  using Rest = void;
72  };
73  template <typename T, typename... Other>
74  struct PropertyContainer<T, Other...> {
75  using Head = T;
76  using Rest = PropertyContainer<Other...>;
77  };
78  template <typename T> struct PropertyContainer<T> {
79  using Head = T;
80  using Rest = void;
81  };
82 
83 #if __cplusplus >= 201703L
84  // This template serves the same purpose as ContainsProperty, but operates on
85  // template template arguments.
86  template <typename ContainerT, template <auto...> typename PropT,
87  auto... Args>
88  struct ContainsPropertyInstance
90  !std::is_same_v<typename ContainerT::Head, void> &&
91  AreSameTemplate<PropT<Args...>,
92  typename ContainerT::Head>::value,
93  std::true_type,
94  ContainsPropertyInstance<typename ContainerT::Rest, PropT,
95  Args...>> {};
96 
97  template <template <auto...> typename PropT, auto... Args>
98  struct ContainsPropertyInstance<void, PropT, Args...> : std::false_type {};
99 #endif
100 
101  // This template checks if two lists of properties contain the same set of
102  // compile-time-constant properties in any order. Run time properties are
103  // skipped.
104  template <typename ContainerT, typename... OtherProps>
105  struct ContainsSameProperties
107  !sycl::detail::IsCompileTimePropertyInstance<
108  typename ContainerT::Head>::value ||
109  ContainsProperty<typename ContainerT::Head,
110  OtherProps...>::value,
111  ContainsSameProperties<typename ContainerT::Rest, OtherProps...>,
112  std::false_type> {};
113  template <typename... OtherProps>
114  struct ContainsSameProperties<void, OtherProps...> : std::true_type {};
115 
116 #if __cplusplus >= 201703L
117  // This template helps to extract exact property instance type based on
118  // template template argument. If there's an instance of target property in
119  // ContainerT, find instance template and use it as type. Otherwise, just
120  // use void as return type.
121  template <typename ContainerT, template <auto...> class PropT, auto... Args>
122  struct GetCompileTimePropertyHelper {
123  using type = typename sycl::detail::conditional_t<
124  AreSameTemplate<typename ContainerT::Head, PropT<Args...>>::value,
125  typename ContainerT::Head,
126  typename GetCompileTimePropertyHelper<typename ContainerT::Rest, PropT,
127  Args...>::type>;
128  };
129  template <typename Head, template <auto...> class PropT, auto... Args>
130  struct GetCompileTimePropertyHelper<PropertyContainer<Head>, PropT, Args...> {
131  using type = typename sycl::detail::conditional_t<
132  AreSameTemplate<Head, PropT<Args...>>::value, Head, void>;
133  };
134 #endif
135 
136  // The structs validate that all objects passed are SYCL properties.
137  // Properties are either run time SYCL 1.2.1 properties, and thus derive from
138  // either DataLessPropertyBase or from PropertyWithDataBase, or
139  // compile-time-constant properties, and thus specialize
140  // IsCompileTimePropertyInstance template.
141  template <typename... Tail> struct AllProperties : std::true_type {};
142  template <typename T, typename... Tail>
143  struct AllProperties<T, Tail...>
145  std::is_base_of<sycl::detail::DataLessPropertyBase, T>::value ||
146  std::is_base_of<sycl::detail::PropertyWithDataBase, T>::value ||
147  sycl::detail::IsCompileTimePropertyInstance<T>::value,
148  AllProperties<Tail...>, std::false_type> {};
149 
150  accessor_property_list(
151  std::bitset<sycl::detail::DataLessPropKind::DataLessPropKindSize>
152  DataLessProps,
153  std::vector<std::shared_ptr<sycl::detail::PropertyWithDataBase>>
154  PropsWithData)
155  : sycl::detail::PropertyListBase(DataLessProps, PropsWithData) {}
156 
157 public:
158  template <typename = typename sycl::detail::enable_if_t<
159  AllProperties<PropsT...>::value>>
160  accessor_property_list(PropsT... Props)
161  : sycl::detail::PropertyListBase(false) {
162  ctorHelper(Props...);
163  }
164 
166  : sycl::detail::PropertyListBase(Props.MDataLessProps,
167  Props.MPropsWithData) {}
168 
169  template <typename... OtherProps,
170  typename = typename sycl::detail::enable_if_t<
171  ContainsSameProperties<PropertyContainer<PropsT...>,
172  OtherProps...>::value &&
173  ContainsSameProperties<PropertyContainer<OtherProps...>,
174  PropsT...>::value>>
176  : sycl::detail::PropertyListBase(OtherList.MDataLessProps,
177  OtherList.MPropsWithData) {}
178 
179  template <typename PropT, typename = typename sycl::detail::enable_if_t<
181  PropT get_property() const {
182  if (!has_property<PropT>())
183  throw sycl::invalid_object_error("The property is not found",
185 
186  return get_property_helper<PropT>();
187  }
188 
189  template <class PropT>
191  bool>
192  has_property() const {
193  return has_property_helper<PropT>();
194  }
195 
196 #if __cplusplus >= 201703L
197  template <typename T>
198  static constexpr bool has_property(
200  return ContainsPropertyInstance<PropertyContainer<PropsT...>,
201  T::template instance>::value;
202  }
203 
204  template <typename T>
205  static constexpr auto get_property(
206  typename std::enable_if_t<
207  is_compile_time_property<T>::value &&
208  ContainsPropertyInstance<PropertyContainer<PropsT...>,
209  T::template instance>::value> * = 0) {
210  return typename GetCompileTimePropertyHelper<PropertyContainer<PropsT...>,
211  T::template instance>::type{};
212  }
213 #endif
214 
215 private:
216  template <typename, int, access::mode, access::target, access::placeholder,
217  typename PropertyListT>
218  friend class sycl::accessor;
219 
220  template <typename... OtherProps> friend class accessor_property_list;
221 
222  friend class sycl::property_list;
223 
224  // Helper method, used by accessor to restrict conversions to compatible
225  // property lists.
226  template <typename... OtherPropsT>
227  static constexpr bool areSameCompileTimeProperties() {
228  return ContainsSameProperties<PropertyContainer<OtherPropsT...>,
229  PropsT...>::value;
230  }
231 };
232 } // namespace oneapi
233 } // namespace ext
234 
235 } // namespace sycl
236 } // __SYCL_INLINE_NAMESPACE(cl)
property_list.hpp
cl::sycl::ext::oneapi::accessor_property_list::accessor_property_list
accessor_property_list(const accessor_property_list< OtherProps... > &OtherList)
Definition: accessor_property_list.hpp:175
T
property_list_base.hpp
cl::sycl::access::placeholder
placeholder
Definition: access.hpp:43
conditional_t
cl::sycl::detail::IsCompileTimePropertyInstance
Definition: accessor_property_list.hpp:25
cl::sycl::ext::oneapi::accessor_property_list::has_property
sycl::detail::enable_if_t<!is_compile_time_property< PropT >::value, bool > has_property() const
Definition: accessor_property_list.hpp:192
sycl
Definition: invoke_simd.hpp:68
cl::sycl::property_list
Objects of the property_list class are containers for the SYCL properties.
Definition: property_list.hpp:26
access.hpp
cl::sycl::ext::oneapi::accessor_property_list::accessor_property_list
accessor_property_list(PropsT... Props)
Definition: accessor_property_list.hpp:160
cl::sycl::detail::PropertyListBase
Definition: property_list_base.hpp:22
cl::sycl::accessor
Buffer accessor.
Definition: accessor.hpp:223
cl::sycl::access::target
target
Definition: access.hpp:17
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::ext::oneapi::is_compile_time_property
Definition: accessor_property_list.hpp:30
cl::sycl::ext::oneapi::accessor_property_list
Objects of the accessor_property_list class are containers for the SYCL properties.
Definition: property_list.hpp:19
PI_INVALID_VALUE
@ PI_INVALID_VALUE
Definition: pi.h:91
cl::sycl::ext::oneapi::experimental::detail::get_property
static constexpr std::enable_if_t< HasProperty, typename FindCompileTimePropertyValueType< CTPropertyT, PropertiesT >::type > get_property()
Definition: properties.hpp:65
cl::sycl::ext::oneapi::accessor_property_list::get_property
PropT get_property() const
Definition: accessor_property_list.hpp:181
common.hpp
cl::sycl::access::mode
mode
Definition: access.hpp:28
cl::sycl::detail::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Definition: stl_type_traits.hpp:24
cl::sycl::ext::oneapi::accessor_property_list::accessor_property_list
accessor_property_list(const sycl::property_list &Props)
Definition: accessor_property_list.hpp:165
cl::sycl::errc::accessor
@ accessor
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12