DPC++ Runtime
Runtime libraries for oneAPI DPC++
property_list_base.hpp
Go to the documentation of this file.
1 //==------- property_list_base.hpp --- Base for SYCL property lists --------==//
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/detail/property_helper.hpp> // for DataLessPropKind, Propert...
12 #include <sycl/exception.hpp>
13 
14 #include <algorithm> // for iter_swap
15 #include <bitset> // for bitset
16 #include <memory> // for shared_ptr, __shared_ptr_...
17 #include <type_traits> // for enable_if_t
18 #include <utility> // for move
19 #include <vector> // for vector
20 
21 namespace sycl {
22 inline namespace _V1 {
23 namespace detail {
25 protected:
26  explicit PropertyListBase(
27  std::bitset<DataLessPropKind::DataLessPropKindSize> DataLessProps)
28  : MDataLessProps(DataLessProps) {}
30  std::bitset<DataLessPropKind::DataLessPropKindSize> DataLessProps,
31  std::vector<std::shared_ptr<PropertyWithDataBase>> PropsWithData)
32  : MDataLessProps(DataLessProps),
33  MPropsWithData(std::move(PropsWithData)) {}
34  void ctorHelper() {}
35 
36  template <typename... PropsT, class PropT>
37  typename std::enable_if_t<std::is_base_of_v<DataLessPropertyBase, PropT>>
38  ctorHelper(PropT &, PropsT... Props) {
39  const int PropKind = static_cast<int>(PropT::getKind());
40  MDataLessProps[PropKind] = true;
41  ctorHelper(Props...);
42  }
43 
44  template <typename... PropsT, class PropT>
45  typename std::enable_if_t<std::is_base_of_v<PropertyWithDataBase, PropT>>
46  ctorHelper(PropT &Prop, PropsT... Props) {
47  MPropsWithData.emplace_back(new PropT(Prop));
48  ctorHelper(Props...);
49  }
50 
51  // Compile-time-constant properties are simply skipped
52  template <typename... PropsT, class PropT>
53  typename std::enable_if_t<!std::is_base_of_v<PropertyWithDataBase, PropT> &&
54  !std::is_base_of_v<DataLessPropertyBase, PropT>>
55  ctorHelper(PropT &, PropsT... Props) {
56  ctorHelper(Props...);
57  }
58 
59  template <typename PropT>
60  typename std::enable_if_t<std::is_base_of_v<DataLessPropertyBase, PropT>,
61  bool>
63  const int PropKind = static_cast<int>(PropT::getKind());
65  return false;
66  return MDataLessProps[PropKind];
67  }
68 
69  template <typename PropT>
70  typename std::enable_if_t<std::is_base_of_v<PropertyWithDataBase, PropT>,
71  bool>
73  const int PropKind = static_cast<int>(PropT::getKind());
74  for (const std::shared_ptr<PropertyWithDataBase> &Prop : MPropsWithData)
75  if (Prop->isSame(PropKind))
76  return true;
77  return false;
78  }
79 
80  template <typename PropT>
81  typename std::enable_if_t<std::is_base_of_v<DataLessPropertyBase, PropT>,
82  PropT>
84  // In case of simple property we can just construct it
85  return PropT{};
86  }
87 
88  template <typename PropT>
89  typename std::enable_if_t<std::is_base_of_v<PropertyWithDataBase, PropT>,
90  PropT>
92  const int PropKind = static_cast<int>(PropT::getKind());
95  "The property is not found");
96 
97  for (const std::shared_ptr<PropertyWithDataBase> &Prop : MPropsWithData)
98  if (Prop->isSame(PropKind))
99  return *static_cast<PropT *>(Prop.get());
100 
102  "The property is not found");
103  }
104 
106  const std::vector<std::shared_ptr<PropertyWithDataBase>> &PropsWithData) {
107  for (auto &Prop : PropsWithData) {
111  MPropsWithData.push_back(Prop);
112  break;
113  }
114  }
115  }
116 
118  auto It = MPropsWithData.begin();
119  for (; It != MPropsWithData.end(); ++It) {
120  if ((*It)->isSame(Kind))
121  break;
122  }
123  if (It != MPropsWithData.end()) {
124  std::iter_swap(It, MPropsWithData.end() - 1);
125  MPropsWithData.pop_back();
126  }
127  }
128 
129  // Stores enabled/disabled for simple properties
130  std::bitset<DataLessPropKind::DataLessPropKindSize> MDataLessProps;
131  // Stores shared_ptrs to complex properties
132  std::vector<std::shared_ptr<PropertyWithDataBase>> MPropsWithData;
133 };
134 } // namespace detail
135 } // namespace _V1
136 } // namespace sycl
PropertyListBase(std::bitset< DataLessPropKind::DataLessPropKindSize > DataLessProps)
std::enable_if_t< std::is_base_of_v< PropertyWithDataBase, PropT >, PropT > get_property_helper() const
std::enable_if_t< std::is_base_of_v< DataLessPropertyBase, PropT >, PropT > get_property_helper() const
PropertyListBase(std::bitset< DataLessPropKind::DataLessPropKindSize > DataLessProps, std::vector< std::shared_ptr< PropertyWithDataBase >> PropsWithData)
std::enable_if_t< std::is_base_of_v< PropertyWithDataBase, PropT > > ctorHelper(PropT &Prop, PropsT... Props)
std::vector< std::shared_ptr< PropertyWithDataBase > > MPropsWithData
std::enable_if_t<!std::is_base_of_v< PropertyWithDataBase, PropT > &&!std::is_base_of_v< DataLessPropertyBase, PropT > > ctorHelper(PropT &, PropsT... Props)
void delete_accessor_property_helper(const PropWithDataKind &Kind)
std::enable_if_t< std::is_base_of_v< PropertyWithDataBase, PropT >, bool > has_property_helper() const noexcept
std::enable_if_t< std::is_base_of_v< DataLessPropertyBase, PropT >, bool > has_property_helper() const noexcept
std::enable_if_t< std::is_base_of_v< DataLessPropertyBase, PropT > > ctorHelper(PropT &, PropsT... Props)
void add_or_replace_accessor_properties_helper(const std::vector< std::shared_ptr< PropertyWithDataBase >> &PropsWithData)
std::bitset< DataLessPropKind::DataLessPropKindSize > MDataLessProps
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition: exception.cpp:65
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324