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 
14 
15 #include <bitset>
16 #include <memory>
17 #include <vector>
18 
20 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 detail::enable_if_t<
36  std::is_base_of<DataLessPropertyBase, PropT>::value>
37  ctorHelper(PropT &, PropsT... Props) {
38  const int PropKind = static_cast<int>(PropT::getKind());
39  MDataLessProps[PropKind] = true;
40  ctorHelper(Props...);
41  }
42 
43  template <typename... PropsT, class PropT>
44  typename detail::enable_if_t<
45  std::is_base_of<PropertyWithDataBase, PropT>::value>
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 detail::enable_if_t<
54  !std::is_base_of<PropertyWithDataBase, PropT>::value &&
55  !std::is_base_of<DataLessPropertyBase, PropT>::value>
56  ctorHelper(PropT &, PropsT... Props) {
57  ctorHelper(Props...);
58  }
59 
60  template <typename PropT>
61  typename detail::enable_if_t<
62  std::is_base_of<DataLessPropertyBase, PropT>::value, bool>
64  const int PropKind = static_cast<int>(PropT::getKind());
66  return false;
67  return MDataLessProps[PropKind];
68  }
69 
70  template <typename PropT>
71  typename detail::enable_if_t<
72  std::is_base_of<PropertyWithDataBase, PropT>::value, bool>
74  const int PropKind = static_cast<int>(PropT::getKind());
75  for (const std::shared_ptr<PropertyWithDataBase> &Prop : MPropsWithData)
76  if (Prop->isSame(PropKind))
77  return true;
78  return false;
79  }
80 
81  template <typename PropT>
82  typename detail::enable_if_t<
83  std::is_base_of<DataLessPropertyBase, PropT>::value, PropT>
85  // In case of simple property we can just construct it
86  return PropT{};
87  }
88 
89  template <typename PropT>
90  typename detail::enable_if_t<
91  std::is_base_of<PropertyWithDataBase, PropT>::value, PropT>
93  const int PropKind = static_cast<int>(PropT::getKind());
95  throw sycl::invalid_object_error("The property is not found",
97 
98  for (const std::shared_ptr<PropertyWithDataBase> &Prop : MPropsWithData)
99  if (Prop->isSame(PropKind))
100  return *static_cast<PropT *>(Prop.get());
101 
102  throw sycl::invalid_object_error("The property is not found",
104  }
105 
107  const std::vector<std::shared_ptr<PropertyWithDataBase>> &PropsWithData) {
108  for (auto &Prop : PropsWithData) {
110  delete_accessor_property_helper(
112  MPropsWithData.push_back(Prop);
113  break;
114  }
115  }
116  }
117 
119  auto It = MPropsWithData.begin();
120  for (; It != MPropsWithData.end(); ++It) {
121  if ((*It)->isSame(Kind))
122  break;
123  }
124  if (It != MPropsWithData.end()) {
125  std::iter_swap(It, MPropsWithData.end() - 1);
126  MPropsWithData.pop_back();
127  }
128  }
129 
130  // Stores enabled/disabled for simple properties
131  std::bitset<DataLessPropKind::DataLessPropKindSize> MDataLessProps;
132  // Stores shared_ptrs to complex properties
133  std::vector<std::shared_ptr<PropertyWithDataBase>> MPropsWithData;
134 };
135 } // namespace detail
136 } // namespace sycl
137 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::PropertyListBase::MPropsWithData
std::vector< std::shared_ptr< PropertyWithDataBase > > MPropsWithData
Definition: property_list_base.hpp:133
cl::sycl::detail::PropertyListBase::PropertyListBase
PropertyListBase(std::bitset< DataLessPropKind::DataLessPropKindSize > DataLessProps, std::vector< std::shared_ptr< PropertyWithDataBase >> PropsWithData)
Definition: property_list_base.hpp:27
cl::sycl::ext::oneapi::experimental::detail::PropKind
PropKind
Definition: property.hpp:146
cl::sycl::detail::AccPropBufferLocation
@ AccPropBufferLocation
Definition: property_helper.hpp:51
cl::sycl::detail::PropertyListBase::PropertyListBase
PropertyListBase(std::bitset< DataLessPropKind::DataLessPropKindSize > DataLessProps)
Definition: property_list_base.hpp:24
cl::sycl::detail::PropertyListBase::ctorHelper
detail::enable_if_t< !std::is_base_of< PropertyWithDataBase, PropT >::value &&!std::is_base_of< DataLessPropertyBase, PropT >::value > ctorHelper(PropT &, PropsT... Props)
Definition: property_list_base.hpp:56
cl::sycl::detail::PropertyListBase::delete_accessor_property_helper
void delete_accessor_property_helper(const PropWithDataKind &Kind)
Definition: property_list_base.hpp:118
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::PropertyListBase::add_or_replace_accessor_properties_helper
void add_or_replace_accessor_properties_helper(const std::vector< std::shared_ptr< PropertyWithDataBase >> &PropsWithData)
Definition: property_list_base.hpp:106
stl_type_traits.hpp
cl::sycl::detail::PropertyListBase
Definition: property_list_base.hpp:22
cl::sycl::detail::PropertyListBase::has_property_helper
detail::enable_if_t< std::is_base_of< DataLessPropertyBase, PropT >::value, bool > has_property_helper() const
Definition: property_list_base.hpp:63
cl::sycl::detail::PropertyListBase::has_property_helper
detail::enable_if_t< std::is_base_of< PropertyWithDataBase, PropT >::value, bool > has_property_helper() const
Definition: property_list_base.hpp:73
cl::sycl::detail::PropertyListBase::ctorHelper
detail::enable_if_t< std::is_base_of< PropertyWithDataBase, PropT >::value > ctorHelper(PropT &Prop, PropsT... Props)
Definition: property_list_base.hpp:46
cl::sycl::detail::PropertyListBase::get_property_helper
detail::enable_if_t< std::is_base_of< DataLessPropertyBase, PropT >::value, PropT > get_property_helper() const
Definition: property_list_base.hpp:84
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::PropWithDataKindSize
@ PropWithDataKindSize
Definition: property_helper.hpp:52
property_helper.hpp
cl::sycl::detail::PropertyListBase::get_property_helper
detail::enable_if_t< std::is_base_of< PropertyWithDataBase, PropT >::value, PropT > get_property_helper() const
Definition: property_list_base.hpp:92
cl::sycl::detail::PropertyListBase::ctorHelper
detail::enable_if_t< std::is_base_of< DataLessPropertyBase, PropT >::value > ctorHelper(PropT &, PropsT... Props)
Definition: property_list_base.hpp:37
cl::sycl::detail::PropertyListBase::ctorHelper
void ctorHelper()
Definition: property_list_base.hpp:32
PI_INVALID_VALUE
@ PI_INVALID_VALUE
Definition: pi.h:91
std
Definition: accessor.hpp:2616
cl::sycl::detail::PropertyListBase::MDataLessProps
std::bitset< DataLessPropKind::DataLessPropKindSize > MDataLessProps
Definition: property_list_base.hpp:131
cl::sycl::detail::LastKnownDataLessPropKind
@ LastKnownDataLessPropKind
Definition: property_helper.hpp:39
common.hpp
cl::sycl::detail::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Definition: stl_type_traits.hpp:24
cl::sycl::detail::PropWithDataKind
PropWithDataKind
Definition: property_helper.hpp:45
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12