Skip to content

Commit 2a04c70

Browse files
committed
Align with spec changes
1 parent 7fe7b8d commit 2a04c70

File tree

11 files changed

+56
-185
lines changed

11 files changed

+56
-185
lines changed

sycl/include/sycl/ext/oneapi/experimental/async_alloc/memory_pool.hpp

Lines changed: 17 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,6 @@ class memory_pool_impl;
2525
/// Memory pool
2626
class __SYCL_EXPORT memory_pool {
2727
public:
28-
// Type to store pool properties values.
29-
// Every property is represented by a pair that represent
30-
// (is_property_assigned, property_value)
31-
struct pool_properties {
32-
std::pair<bool, size_t> initial_threshold;
33-
std::pair<bool, size_t> maximum_size;
34-
std::pair<bool, bool> read_only;
35-
std::pair<bool, bool> zero_init;
36-
};
37-
38-
// NOT SUPPORTED: Host side pools unsupported.
39-
template <typename Properties = empty_properties_t,
40-
typename = std::enable_if_t<
41-
detail::all_are_properties_of_v<memory_pool, Properties>>>
42-
memory_pool(const sycl::context &, sycl::usm::alloc kind, Properties = {}) {
43-
if (kind == sycl::usm::alloc::device || kind == sycl::usm::alloc::shared)
44-
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
45-
"Device and shared allocation kinds are disallowed "
46-
"without specifying a device!");
47-
if (kind == sycl::usm::alloc::unknown)
48-
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
49-
"Unknown allocation kinds are disallowed!");
50-
51-
throw sycl::exception(
52-
sycl::make_error_code(sycl::errc::feature_not_supported),
53-
"Host allocated pools are unsupported!");
54-
}
55-
5628
template <typename Properties = empty_properties_t,
5729
typename = std::enable_if_t<
5830
detail::all_are_properties_of_v<memory_pool, Properties>>>
@@ -67,16 +39,6 @@ class __SYCL_EXPORT memory_pool {
6739
Properties props = {})
6840
: memory_pool(q.get_context(), q.get_device(), kind, props) {}
6941

70-
// NOT SUPPORTED: Creating a pool from an existing allocation is unsupported.
71-
template <typename Properties = empty_properties_t,
72-
typename = std::enable_if_t<
73-
detail::all_are_properties_of_v<memory_pool, Properties>>>
74-
memory_pool(const sycl::context &, void *, size_t, Properties = {}) {
75-
throw sycl::exception(
76-
sycl::make_error_code(sycl::errc::feature_not_supported),
77-
"Creating a pool from an existing allocation is unsupported!");
78-
}
79-
8042
~memory_pool() = default;
8143

8244
// Copy constructible/assignable, move constructible/assignable.
@@ -99,50 +61,20 @@ class __SYCL_EXPORT memory_pool {
9961

10062
void increase_threshold_to(size_t newThreshold);
10163

102-
// Property getters.
103-
template <typename PropertyT> bool has_property() const noexcept {
104-
const auto props = getProps();
105-
if constexpr (std::is_same_v<PropertyT, initial_threshold>) {
106-
return props.initial_threshold.first;
107-
}
108-
if constexpr (std::is_same_v<PropertyT, maximum_size>) {
109-
return props.maximum_size.first;
110-
}
111-
if constexpr (std::is_same_v<PropertyT, read_only>) {
112-
return props.read_only.first;
113-
}
114-
if constexpr (std::is_same_v<PropertyT, zero_init>) {
115-
return props.zero_init.first;
116-
}
117-
return false;
118-
}
119-
120-
template <typename PropertyT> PropertyT get_property() const {
121-
if (!has_property<PropertyT>())
122-
throw sycl::exception(make_error_code(errc::invalid),
123-
"The property is not found");
124-
const auto props = getProps();
125-
if constexpr (std::is_same_v<PropertyT, initial_threshold>) {
126-
return initial_threshold(props.initial_threshold.second);
127-
}
128-
if constexpr (std::is_same_v<PropertyT, maximum_size>) {
129-
return maximum_size(props.maximum_size.second);
130-
}
131-
if constexpr (std::is_same_v<PropertyT, read_only>) {
132-
return read_only();
133-
}
134-
if constexpr (std::is_same_v<PropertyT, zero_init>) {
135-
return zero_init();
136-
}
137-
}
138-
13964
protected:
65+
struct pool_properties {
66+
std::pair<bool, size_t> initial_threshold;
67+
std::pair<bool, size_t> maximum_size;
68+
std::pair<bool, bool> zero_init;
69+
};
70+
14071
std::shared_ptr<detail::memory_pool_impl> impl;
14172

14273
memory_pool(std::shared_ptr<detail::memory_pool_impl> Impl) : impl(Impl) {}
14374

14475
memory_pool(const sycl::context &ctx, const sycl::device &dev,
145-
const sycl::usm::alloc kind, const pool_properties &props);
76+
sycl::usm::alloc kind, pool_properties props);
77+
14678
template <class Obj>
14779
friend const decltype(Obj::impl) &
14880
sycl::detail::getSyclObjImpl(const Obj &SyclObject);
@@ -154,31 +86,22 @@ class __SYCL_EXPORT memory_pool {
15486
friend T sycl::detail::createSyclObjFromImpl(
15587
std::add_lvalue_reference_t<const decltype(T::impl)> ImplObj);
15688

157-
const pool_properties &getProps() const;
158-
159-
template <typename Properties = empty_properties_t>
160-
pool_properties stripProps(Properties props) {
161-
pool_properties PoolProps{};
162-
163-
if constexpr (decltype(props)::template has_property<
164-
initial_threshold_key>()) {
165-
PoolProps.initial_threshold = {
89+
template <typename Properties> pool_properties stripProps(Properties props) {
90+
pool_properties poolProps{};
91+
if constexpr (decltype(props)::template has_property<initial_threshold>()) {
92+
poolProps.initial_threshold = {
16693
true, props.template get_property<initial_threshold>().value};
16794
}
16895

169-
if constexpr (decltype(props)::template has_property<maximum_size_key>()) {
170-
PoolProps.maximum_size = {
96+
if constexpr (decltype(props)::template has_property<maximum_size>()) {
97+
poolProps.maximum_size = {
17198
true, props.template get_property<maximum_size>().value};
17299
}
173100

174-
if constexpr (decltype(props)::template has_property<read_only_key>()) {
175-
PoolProps.read_only = {true, true};
176-
}
177-
178-
if constexpr (decltype(props)::template has_property<zero_init_key>()) {
179-
PoolProps.zero_init = {true, true};
101+
if constexpr (decltype(props)::template has_property<zero_init>()) {
102+
poolProps.zero_init = {true, true};
180103
}
181-
return PoolProps;
104+
return poolProps;
182105
}
183106
};
184107

sycl/include/sycl/ext/oneapi/experimental/async_alloc/memory_pool_properties.hpp

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,12 @@ inline bool operator!=(const maximum_size &lhs, const maximum_size &rhs) {
5050
return !(lhs == rhs);
5151
}
5252

53-
// Property that provides a performance hint that all allocations from this pool
54-
// will only be read from within SYCL kernel functions.
55-
// enum class read_only_enum { none, read_only };
56-
struct read_only
57-
: detail::run_time_property_key<read_only, detail::PropKind::ReadOnly> {
58-
// read_only(read_only_enum mode) : value(mode) {}
59-
read_only() {};
60-
61-
// read_only_enum value;
62-
};
63-
64-
using read_only_key = read_only;
65-
inline bool operator==(const read_only &, const read_only &) { return true; }
66-
inline bool operator!=(const read_only &lhs, const read_only &rhs) {
67-
return !(lhs == rhs);
68-
}
69-
7053
// Property that initial allocations to a pool (not subsequent allocations from
7154
// prior frees) are iniitialised to zero.
7255
// enum class zero_init_enum { none, zero_init };
7356
struct zero_init
7457
: detail::run_time_property_key<zero_init, detail::PropKind::ZeroInit> {
75-
// zero_init(zero_init_enum mode) : value(mode) {}
7658
zero_init() {};
77-
78-
// zero_init_enum value;
7959
};
8060

8161
using zero_init_key = zero_init;
@@ -85,16 +65,14 @@ inline bool operator!=(const zero_init &lhs, const zero_init &rhs) {
8565
}
8666

8767
template <>
88-
struct is_property_key_of<initial_threshold, memory_pool> : std::true_type {};
89-
90-
template <>
91-
struct is_property_key_of<maximum_size, memory_pool> : std::true_type {};
68+
struct is_property_key_of<initial_threshold_key, memory_pool> : std::true_type {
69+
};
9270

9371
template <>
94-
struct is_property_key_of<read_only, memory_pool> : std::true_type {};
72+
struct is_property_key_of<maximum_size_key, memory_pool> : std::true_type {};
9573

9674
template <>
97-
struct is_property_key_of<zero_init, memory_pool> : std::true_type {};
75+
struct is_property_key_of<zero_init_key, memory_pool> : std::true_type {};
9876

9977
} // namespace ext::oneapi::experimental
10078
} // namespace _V1

sycl/include/sycl/ext/oneapi/properties/property.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ enum PropKind : uint32_t {
227227
NativeLocalBlockIO = 82,
228228
InitialThreshold = 83,
229229
MaximumSize = 84,
230-
ReadOnly = 85,
231230
ZeroInit = 86,
232231
// PropKindSize must always be the last value.
233232
PropKindSize = 87,

sycl/source/detail/context_impl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <detail/context_impl.hpp>
1010
#include <detail/context_info.hpp>
1111
#include <detail/event_info.hpp>
12+
#include <detail/memory_pool_impl.hpp>
1213
#include <detail/platform_impl.hpp>
1314
#include <detail/queue_impl.hpp>
1415
#include <sycl/detail/common.hpp>
@@ -601,9 +602,7 @@ context_impl::get_default_memory_pool(const context &Context,
601602
auto MemPoolImplPtr = std::make_shared<
602603
sycl::ext::oneapi::experimental::detail::memory_pool_impl>(
603604
Context, Device, sycl::usm::alloc::device, PoolHandle,
604-
true /*Default pool*/,
605-
ext::oneapi::experimental::memory_pool::
606-
pool_properties{} /*Empty Properties*/);
605+
true /*Default pool*/);
607606

608607
// Hold onto a weak_ptr of the memory_pool_impl. Prevents circular
609608
// dependencies between the context_impl and memory_pool_impl.

sycl/source/detail/graph_memory_pool.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ graph_mem_pool::malloc(size_t Size, usm::alloc AllocType,
3737
if (Props.zero_init.second) {
3838
AllocInfo.ZeroInit = true;
3939
}
40-
if (Props.read_only.second) {
41-
AllocInfo.ReadOnly = true;
42-
}
4340
}
4441

4542
switch (AllocType) {

sycl/source/detail/memory_pool.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ __SYCL_EXPORT size_t memory_pool::get_threshold() const {
2727
return impl->get_threshold();
2828
}
2929

30-
const memory_pool::pool_properties &memory_pool::getProps() const {
31-
return impl->getProps();
32-
}
33-
3430
__SYCL_EXPORT size_t memory_pool::get_reserved_size_current() const {
3531
return impl->get_reserved_size_current();
3632
}
@@ -45,11 +41,9 @@ __SYCL_EXPORT void memory_pool::increase_threshold_to(size_t newThreshold) {
4541
impl->set_new_threshold(newThreshold);
4642
}
4743

48-
__SYCL_EXPORT memory_pool::memory_pool(const sycl::context &ctx,
49-
const sycl::device &dev,
50-
sycl::usm::alloc kind,
51-
const pool_properties &props) {
52-
44+
memory_pool::memory_pool(const sycl::context &ctx, const sycl::device &dev,
45+
sycl::usm::alloc kind,
46+
memory_pool::pool_properties props) {
5347
if (kind == sycl::usm::alloc::host)
5448
throw sycl::exception(
5549
sycl::make_error_code(sycl::errc::invalid),
@@ -60,7 +54,11 @@ __SYCL_EXPORT memory_pool::memory_pool(const sycl::context &ctx,
6054
sycl::make_error_code(sycl::errc::feature_not_supported),
6155
"Only device allocated memory pools are supported!");
6256

63-
impl = std::make_shared<detail::memory_pool_impl>(ctx, dev, kind, props);
57+
detail::pool_properties poolProps{
58+
{props.initial_threshold.first, props.initial_threshold.second},
59+
{props.maximum_size.first, props.maximum_size.second},
60+
{props.zero_init.first, props.zero_init.second}};
61+
impl = std::make_shared<detail::memory_pool_impl>(ctx, dev, kind, poolProps);
6462
}
6563

6664
} // namespace ext::oneapi::experimental

sycl/source/detail/memory_pool_impl.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ namespace detail {
2020

2121
// <--- Helpers --->
2222
namespace {
23-
ur_usm_pool_handle_t
24-
create_memory_pool_device(const sycl::context &ctx, const sycl::device &dev,
25-
const size_t threshold, const size_t maxSize,
26-
const bool readOnly, const bool zeroInit) {
23+
ur_usm_pool_handle_t create_memory_pool_device(const sycl::context &ctx,
24+
const sycl::device &dev,
25+
const size_t threshold,
26+
const size_t maxSize,
27+
const bool zeroInit) {
2728
auto [urDevice, urCtx, Adapter] = get_ur_handles(dev, ctx);
2829

2930
ur_usm_pool_limits_desc_t LimitsDesc{UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC,
3031
nullptr, maxSize, threshold};
3132

3233
ur_usm_pool_flags_t Flags = {UR_USM_POOL_FLAG_USE_NATIVE_MEMORY_POOL_EXP};
33-
if (readOnly)
34-
Flags += UR_USM_POOL_FLAG_READ_ONLY_EXP;
3534
if (zeroInit)
3635
Flags += UR_USM_POOL_FLAG_ZERO_INITIALIZE_BLOCK;
3736

@@ -61,14 +60,14 @@ void destroy_memory_pool(const sycl::context &ctx, const sycl::device &dev,
6160
memory_pool_impl::memory_pool_impl(const sycl::context &ctx,
6261
const sycl::device &dev,
6362
const sycl::usm::alloc kind,
64-
const memory_pool::pool_properties &props)
63+
const pool_properties props)
6564
: MContextImplPtr(sycl::detail::getSyclObjImpl(ctx)), MDevice(dev),
6665
MKind(kind), MProps(props) {
6766

6867
if (kind == sycl::usm::alloc::device)
6968
MPoolHandle = create_memory_pool_device(
7069
ctx, dev, MProps.initial_threshold.second, MProps.maximum_size.second,
71-
MProps.read_only.second, MProps.zero_init.second);
70+
MProps.zero_init.second);
7271
else
7372
throw sycl::exception(
7473
sycl::make_error_code(sycl::errc::feature_not_supported),
@@ -80,13 +79,12 @@ memory_pool_impl::memory_pool_impl(const sycl::context &ctx,
8079
const sycl::usm::alloc kind,
8180
ur_usm_pool_handle_t poolHandle,
8281
const bool isDefaultPool,
83-
const memory_pool::pool_properties &props)
82+
const pool_properties props)
8483
: MContextImplPtr(sycl::detail::getSyclObjImpl(ctx)), MDevice(dev),
8584
MKind(kind), MPoolHandle(poolHandle), MIsDefaultPool(isDefaultPool),
8685
MProps(props) {}
8786

8887
memory_pool_impl::~memory_pool_impl() {
89-
9088
// Default memory pools cannot be destroyed.
9189
if (MIsDefaultPool)
9290
return;

sycl/source/detail/memory_pool_impl.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@ inline namespace _V1 {
1818
namespace ext::oneapi::experimental {
1919
namespace detail {
2020

21+
// Type to store pool properties values.
22+
// Every property is represented by a pair that represent
23+
// (is_property_assigned, property_value)
24+
struct pool_properties {
25+
std::pair<bool, size_t> initial_threshold;
26+
std::pair<bool, size_t> maximum_size;
27+
std::pair<bool, bool> zero_init;
28+
};
29+
2130
class memory_pool_impl {
2231
public:
2332
memory_pool_impl(const sycl::context &ctx, const sycl::device &dev,
2433
const sycl::usm::alloc kind,
25-
const memory_pool::pool_properties &props);
34+
const pool_properties props = {});
2635
memory_pool_impl(const sycl::context &ctx, const sycl::device &dev,
2736
const sycl::usm::alloc kind, ur_usm_pool_handle_t poolHandle,
28-
const bool isDefaultPool,
29-
const memory_pool::pool_properties &props);
37+
const bool isDefaultPool, const pool_properties props = {});
3038

3139
~memory_pool_impl();
3240

@@ -39,7 +47,7 @@ class memory_pool_impl {
3947
return sycl::detail::createSyclObjFromImpl<sycl::context>(MContextImplPtr);
4048
}
4149
sycl::usm::alloc get_alloc_kind() const { return MKind; }
42-
const memory_pool::pool_properties &getProps() const { return MProps; }
50+
const pool_properties &getProps() const { return MProps; }
4351

4452
// Returns backend specific values.
4553
size_t get_allocation_chunk_size() const;
@@ -59,7 +67,7 @@ class memory_pool_impl {
5967
sycl::usm::alloc MKind;
6068
ur_usm_pool_handle_t MPoolHandle{0};
6169
bool MIsDefaultPool = false;
62-
memory_pool::pool_properties MProps;
70+
pool_properties MProps;
6371
};
6472

6573
} // namespace detail

0 commit comments

Comments
 (0)