@@ -24,39 +24,21 @@ class memory_pool_impl;
24
24
25
25
// / Memory pool
26
26
class __SYCL_EXPORT memory_pool {
27
-
28
27
public:
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>>>
45
31
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)) {}
47
34
35
+ template <typename Properties = empty_properties_t ,
36
+ typename = std::enable_if_t <
37
+ detail::all_are_properties_of_v<memory_pool, Properties>>>
48
38
memory_pool (const sycl::queue &q, sycl::usm::alloc kind,
49
- const property_list & props = {})
39
+ Properties props = {})
50
40
: memory_pool(q.get_context(), q.get_device(), kind, props) {}
51
41
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
-
60
42
~memory_pool () = default ;
61
43
62
44
// Copy constructible/assignable, move constructible/assignable.
@@ -79,20 +61,21 @@ class __SYCL_EXPORT memory_pool {
79
61
80
62
void increase_threshold_to (size_t newThreshold);
81
63
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
-
90
64
protected:
65
+ struct pool_properties {
66
+ size_t initial_threshold;
67
+ size_t maximum_size;
68
+ bool zero_init;
69
+ };
70
+
91
71
std::shared_ptr<detail::memory_pool_impl> impl;
92
72
93
73
memory_pool (std::shared_ptr<detail::memory_pool_impl> Impl)
94
74
: impl(std::move(Impl)) {}
95
75
76
+ memory_pool (const sycl::context &ctx, const sycl::device &dev,
77
+ sycl::usm::alloc kind, pool_properties props);
78
+
96
79
template <class Obj >
97
80
friend const decltype (Obj::impl) &
98
81
sycl::detail::getSyclObjImpl(const Obj &SyclObject);
@@ -104,7 +87,23 @@ class __SYCL_EXPORT memory_pool {
104
87
friend T sycl::detail::createSyclObjFromImpl (
105
88
std::add_lvalue_reference_t <const decltype (T::impl)> ImplObj);
106
89
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
+ }
108
107
};
109
108
110
109
} // namespace ext::oneapi::experimental
0 commit comments