@@ -24,39 +24,21 @@ class memory_pool_impl;
2424
2525// / Memory pool
2626class __SYCL_EXPORT memory_pool {
27-
2827public:
29- // NOT SUPPORTED: Host side pools unsupported.
30- memory_pool (const sycl::context &, sycl::usm::alloc kind,
31- const property_list & = {}) {
32- if (kind == sycl::usm::alloc::device || kind == sycl::usm::alloc::shared)
33- throw sycl::exception (sycl::make_error_code (sycl::errc::invalid),
34- " Device and shared allocation kinds are disallowed "
35- " without specifying a device!" );
36- if (kind == sycl::usm::alloc::unknown)
37- throw sycl::exception (sycl::make_error_code (sycl::errc::invalid),
38- " Unknown allocation kinds are disallowed!" );
39-
40- throw sycl::exception (
41- sycl::make_error_code (sycl::errc::feature_not_supported),
42- " Host allocated pools are unsupported!" );
43- }
44-
28+ template <typename Properties = empty_properties_t ,
29+ typename = std::enable_if_t <
30+ detail::all_are_properties_of_v<memory_pool, Properties>>>
4531 memory_pool (const sycl::context &ctx, const sycl::device &dev,
46- sycl::usm::alloc kind, const property_list &props = {});
32+ sycl::usm::alloc kind, Properties props = {})
33+ : memory_pool(ctx, dev, kind, stripProps(props)) {}
4734
35+ template <typename Properties = empty_properties_t ,
36+ typename = std::enable_if_t <
37+ detail::all_are_properties_of_v<memory_pool, Properties>>>
4838 memory_pool (const sycl::queue &q, sycl::usm::alloc kind,
49- const property_list & props = {})
39+ Properties props = {})
5040 : memory_pool(q.get_context(), q.get_device(), kind, props) {}
5141
52- // NOT SUPPORTED: Creating a pool from an existing allocation is unsupported.
53- memory_pool (const sycl::context &, void *, size_t ,
54- const property_list & = {}) {
55- throw sycl::exception (
56- sycl::make_error_code (sycl::errc::feature_not_supported),
57- " Creating a pool from an existing allocation is unsupported!" );
58- }
59-
6042 ~memory_pool () = default ;
6143
6244 // Copy constructible/assignable, move constructible/assignable.
@@ -79,20 +61,21 @@ class __SYCL_EXPORT memory_pool {
7961
8062 void increase_threshold_to (size_t newThreshold);
8163
82- // Property getters.
83- template <typename PropertyT> bool has_property () const noexcept {
84- return getPropList ().template has_property <PropertyT>();
85- }
86- template <typename PropertyT> PropertyT get_property () const {
87- return getPropList ().template get_property <PropertyT>();
88- }
89-
9064protected:
65+ struct pool_properties {
66+ size_t initial_threshold;
67+ size_t maximum_size;
68+ bool zero_init;
69+ };
70+
9171 std::shared_ptr<detail::memory_pool_impl> impl;
9272
9373 memory_pool (std::shared_ptr<detail::memory_pool_impl> Impl)
9474 : impl(std::move(Impl)) {}
9575
76+ memory_pool (const sycl::context &ctx, const sycl::device &dev,
77+ sycl::usm::alloc kind, pool_properties props);
78+
9679 template <class Obj >
9780 friend const decltype (Obj::impl) &
9881 sycl::detail::getSyclObjImpl(const Obj &SyclObject);
@@ -104,7 +87,23 @@ class __SYCL_EXPORT memory_pool {
10487 friend T sycl::detail::createSyclObjFromImpl (
10588 std::add_lvalue_reference_t <const decltype (T::impl)> ImplObj);
10689
107- const property_list &getPropList () const ;
90+ template <typename Properties> pool_properties stripProps (Properties props) {
91+ pool_properties poolProps{};
92+ if constexpr (decltype (props)::template has_property<initial_threshold>()) {
93+ poolProps.initial_threshold =
94+ props.template get_property <initial_threshold>().value ;
95+ }
96+
97+ if constexpr (decltype (props)::template has_property<maximum_size>()) {
98+ poolProps.maximum_size =
99+ props.template get_property <maximum_size>().value ;
100+ }
101+
102+ if constexpr (decltype (props)::template has_property<zero_init>()) {
103+ poolProps.zero_init = true ;
104+ }
105+ return poolProps;
106+ }
108107};
109108
110109} // namespace ext::oneapi::experimental
0 commit comments