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/common.hpp>
14 
15 #include <bitset>
16 #include <memory>
17 #include <vector>
18 
19 namespace sycl {
21 namespace detail {
23 protected:
24  explicit PropertyListBase(
25  std::bitset<DataLessPropKind::DataLessPropKindSize> DataLessProps)
26  : MDataLessProps(DataLessProps) {}
28  std::bitset<DataLessPropKind::DataLessPropKindSize> DataLessProps,
29  std::vector<std::shared_ptr<PropertyWithDataBase>> PropsWithData)
30  : MDataLessProps(DataLessProps),
31  MPropsWithData(std::move(PropsWithData)) {}
32  void ctorHelper() {}
33 
34  template <typename... PropsT, class PropT>
35  typename std::enable_if_t<std::is_base_of<DataLessPropertyBase, PropT>::value>
36  ctorHelper(PropT &, PropsT... Props) {
37  const int PropKind = static_cast<int>(PropT::getKind());
38  MDataLessProps[PropKind] = true;
39  ctorHelper(Props...);
40  }
41 
42  template <typename... PropsT, class PropT>
43  typename std::enable_if_t<std::is_base_of<PropertyWithDataBase, PropT>::value>
44  ctorHelper(PropT &Prop, PropsT... Props) {
45  MPropsWithData.emplace_back(new PropT(Prop));
46  ctorHelper(Props...);
47  }
48 
49  // Compile-time-constant properties are simply skipped
50  template <typename... PropsT, class PropT>
51  typename std::enable_if_t<
52  !std::is_base_of<PropertyWithDataBase, PropT>::value &&
53  !std::is_base_of<DataLessPropertyBase, PropT>::value>
54  ctorHelper(PropT &, PropsT... Props) {
55  ctorHelper(Props...);
56  }
57 
58  template <typename PropT>
59  typename std::enable_if_t<std::is_base_of<DataLessPropertyBase, PropT>::value,
60  bool>
61  has_property_helper() const noexcept {
62  const int PropKind = static_cast<int>(PropT::getKind());
64  return false;
65  return MDataLessProps[PropKind];
66  }
67 
68  template <typename PropT>
69  typename std::enable_if_t<std::is_base_of<PropertyWithDataBase, PropT>::value,
70  bool>
71  has_property_helper() const noexcept {
72  const int PropKind = static_cast<int>(PropT::getKind());
73  for (const std::shared_ptr<PropertyWithDataBase> &Prop : MPropsWithData)
74  if (Prop->isSame(PropKind))
75  return true;
76  return false;
77  }
78 
79  template <typename PropT>
80  typename std::enable_if_t<std::is_base_of<DataLessPropertyBase, PropT>::value,
81  PropT>
83  // In case of simple property we can just construct it
84  return PropT{};
85  }
86 
87  template <typename PropT>
88  typename std::enable_if_t<std::is_base_of<PropertyWithDataBase, PropT>::value,
89  PropT>
91  const int PropKind = static_cast<int>(PropT::getKind());
93  throw sycl::invalid_object_error("The property is not found",
94  PI_ERROR_INVALID_VALUE);
95 
96  for (const std::shared_ptr<PropertyWithDataBase> &Prop : MPropsWithData)
97  if (Prop->isSame(PropKind))
98  return *static_cast<PropT *>(Prop.get());
99 
100  throw sycl::invalid_object_error("The property is not found",
101  PI_ERROR_INVALID_VALUE);
102  }
103 
105  const std::vector<std::shared_ptr<PropertyWithDataBase>> &PropsWithData) {
106  for (auto &Prop : PropsWithData) {
108  delete_accessor_property_helper(
110  MPropsWithData.push_back(Prop);
111  break;
112  }
113  }
114  }
115 
117  auto It = MPropsWithData.begin();
118  for (; It != MPropsWithData.end(); ++It) {
119  if ((*It)->isSame(Kind))
120  break;
121  }
122  if (It != MPropsWithData.end()) {
123  std::iter_swap(It, MPropsWithData.end() - 1);
124  MPropsWithData.pop_back();
125  }
126  }
127 
128  // Stores enabled/disabled for simple properties
129  std::bitset<DataLessPropKind::DataLessPropKindSize> MDataLessProps;
130  // Stores shared_ptrs to complex properties
131  std::vector<std::shared_ptr<PropertyWithDataBase>> MPropsWithData;
132 };
133 } // namespace detail
134 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
135 } // namespace sycl
PropertyListBase(std::bitset< DataLessPropKind::DataLessPropKindSize > DataLessProps)
PropertyListBase(std::bitset< DataLessPropKind::DataLessPropKindSize > DataLessProps, std::vector< std::shared_ptr< PropertyWithDataBase >> PropsWithData)
std::vector< std::shared_ptr< PropertyWithDataBase > > MPropsWithData
std::enable_if_t< !std::is_base_of< PropertyWithDataBase, PropT >::value &&!std::is_base_of< DataLessPropertyBase, PropT >::value > ctorHelper(PropT &, PropsT... Props)
void delete_accessor_property_helper(const PropWithDataKind &Kind)
std::enable_if_t< std::is_base_of< PropertyWithDataBase, PropT >::value, bool > has_property_helper() const noexcept
std::enable_if_t< std::is_base_of< PropertyWithDataBase, PropT >::value > ctorHelper(PropT &Prop, PropsT... Props)
std::enable_if_t< std::is_base_of< DataLessPropertyBase, PropT >::value, bool > has_property_helper() const noexcept
std::enable_if_t< std::is_base_of< PropertyWithDataBase, PropT >::value, PropT > get_property_helper() const
void add_or_replace_accessor_properties_helper(const std::vector< std::shared_ptr< PropertyWithDataBase >> &PropsWithData)
std::enable_if_t< std::is_base_of< DataLessPropertyBase, PropT >::value, PropT > get_property_helper() const
std::enable_if_t< std::is_base_of< DataLessPropertyBase, PropT >::value > ctorHelper(PropT &, PropsT... Props)
std::bitset< DataLessPropKind::DataLessPropKindSize > MDataLessProps
#define __SYCL_INLINE_VER_NAMESPACE(X)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14