DPC++ Runtime
Runtime libraries for oneAPI DPC++
properties.hpp
Go to the documentation of this file.
1 //==-- properties.hpp - SYCL properties associated with
2 // annotated_arg/ptr --==//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #pragma once
11 
12 #include <sycl/ext/oneapi/properties/properties.hpp> // for properties_t
13 
14 #include <type_traits> // for false_type, con...
15 #include <utility> // for declval
16 
17 namespace sycl {
18 inline namespace _V1 {
19 namespace ext {
20 namespace oneapi {
21 namespace experimental {
22 
23 template <typename T, typename PropertyListT> class annotated_arg;
24 template <typename T, typename PropertyListT> class annotated_ptr;
25 
26 //===----------------------------------------------------------------------===//
27 // Utility type trait for annotated_arg/annotated_ptr deduction guide
28 //===----------------------------------------------------------------------===//
29 template <typename T, typename PropertyValueT>
30 struct is_valid_property : std::false_type {};
31 
32 namespace detail {
33 // Deduce a `properties<>` type from given variadic properties
34 template <typename... Args> struct DeducedProperties {
35  using type = decltype(properties{std::declval<Args>()...});
36 };
37 
38 // Partial specialization for deducing a `properties<>` type by forwarding the
39 // given `properties<>` type
40 template <typename... Args>
41 struct DeducedProperties<detail::properties_t<Args...>> {
42  using type = detail::properties_t<Args...>;
43 };
44 } // namespace detail
45 
46 template <typename T, typename... Props>
47 struct check_property_list : std::true_type {};
48 
49 template <typename T, typename Prop, typename... Props>
50 struct check_property_list<T, Prop, Props...>
51  : std::conditional_t<is_valid_property<T, Prop>::value,
52  check_property_list<T, Props...>, std::false_type> {
53  static constexpr bool is_valid_property_for_given_type =
55  static_assert(is_valid_property_for_given_type,
56  "Property is invalid for the given type.");
57 };
58 
59 template <typename PropTy> struct propagateToPtrAnnotation : std::false_type {};
60 
61 // Partial specilization for property_value
62 template <typename PropKeyT, typename... PropValuesTs>
63 struct propagateToPtrAnnotation<property_value<PropKeyT, PropValuesTs...>>
64  : propagateToPtrAnnotation<PropKeyT> {};
65 
66 //===----------------------------------------------------------------------===//
67 // Common properties of annotated_arg/annotated_ptr
68 //===----------------------------------------------------------------------===//
70  : detail::compile_time_property_key<detail::PropKind::Alignment> {
71  template <int K>
73 };
74 
75 template <int K> inline constexpr alignment_key::value_t<K> alignment;
76 
77 template <typename T, int W>
78 struct is_valid_property<T, alignment_key::value_t<W>>
79  : std::bool_constant<std::is_pointer<T>::value> {};
80 
81 template <typename T, typename PropertyListT>
83  : std::true_type {};
84 
85 template <typename T, typename PropertyListT>
87  : std::true_type {};
88 
89 template <> struct propagateToPtrAnnotation<alignment_key> : std::true_type {};
90 
91 namespace detail {
92 template <int N> struct PropertyMetaInfo<alignment_key::value_t<N>> {
93  static constexpr const char *name = "sycl-alignment";
94  static constexpr int value = N;
95 };
96 
97 } // namespace detail
98 
99 } // namespace experimental
100 } // namespace oneapi
101 } // namespace ext
102 } // namespace _V1
103 } // namespace sycl
constexpr alignment_key::value_t< K > alignment
Definition: properties.hpp:75
Definition: access.hpp:18
decltype(properties{std::declval< Args >()...}) type
Definition: properties.hpp:35