Skip to content

Commit 7da67f9

Browse files
[UMF] Update Disjoint Pool config params
1 parent 9812dff commit 7da67f9

File tree

3 files changed

+105
-52
lines changed

3 files changed

+105
-52
lines changed

source/common/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ target_include_directories(ur_common PUBLIC
2828

2929
message(STATUS "Download Unified Memory Framework from github.com")
3030
if (NOT DEFINED UMF_REPO)
31-
set(UMF_REPO "https://github.com/oneapi-src/unified-memory-framework.git")
31+
set(UMF_REPO "https://github.com/lukaszstolarczuk/unified-memory-framework.git")
3232
endif()
3333

3434
if (NOT DEFINED UMF_TAG)
35-
# v0.10.x: stable UMF branch for upcoming 0.11 UR release
36-
# Date: Tue Dec 3 15:48:31 2024 +0100
37-
# Merge pull request #899 from lplewa/benchmark
38-
set(UMF_TAG 705ced884cde190ad5036b77a6cf4322c2dc707e)
35+
# add-disjoint-config-getters
36+
set(UMF_TAG e687a8d9ba44df59bd816bcdfb8719d07a68b45b)
3937
endif()
4038

4139
message(STATUS "Will fetch Unified Memory Framework from ${UMF_REPO}")

source/common/umf_pools/disjoint_pool_config_parser.cpp

Lines changed: 100 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include "disjoint_pool_config_parser.hpp"
12+
#include "logger/ur_logger.hpp"
1213

1314
#include <iomanip>
1415
#include <iostream>
1516
#include <limits>
1617
#include <string>
1718

19+
#define CheckConfigRet(umf_ret) \
20+
if (umf_ret != UMF_RESULT_SUCCESS) { \
21+
logger::error("DisjointPool params failed"); \
22+
return; \
23+
}
24+
1825
namespace usm {
1926
constexpr auto operator""_B(unsigned long long x) -> size_t { return x; }
2027
constexpr auto operator""_KB(unsigned long long x) -> size_t {
@@ -27,45 +34,81 @@ constexpr auto operator""_GB(unsigned long long x) -> size_t {
2734
return x * 1024 * 1024 * 1024;
2835
}
2936

37+
DisjointPoolAllConfigs::~DisjointPoolAllConfigs() {
38+
for (auto &Config : Configs) {
39+
umfDisjointPoolParamsDestroy(Config);
40+
}
41+
}
42+
3043
DisjointPoolAllConfigs::DisjointPoolAllConfigs(int trace) {
44+
umf_result_t ret = UMF_RESULT_SUCCESS;
45+
3146
for (auto &Config : Configs) {
32-
Config = umfDisjointPoolParamsDefault();
33-
Config.PoolTrace = trace;
47+
umf_disjoint_pool_params_handle_t params = NULL;
48+
ret = umfDisjointPoolParamsCreate(&params);
49+
if (ret != UMF_RESULT_SUCCESS) {
50+
logger::error("DisjointPool params create failed");
51+
return;
52+
}
53+
ret = umfDisjointPoolParamsSetTrace(params, trace);
54+
CheckConfigRet(ret);
55+
56+
Config = params;
3457
}
3558

36-
Configs[DisjointPoolMemType::Host].Name = "Host";
37-
Configs[DisjointPoolMemType::Device].Name = "Device";
38-
Configs[DisjointPoolMemType::Shared].Name = "Shared";
39-
Configs[DisjointPoolMemType::SharedReadOnly].Name = "SharedReadOnly";
59+
ret = umfDisjointPoolParamsSetName(Configs[DisjointPoolMemType::Host], "Host");
60+
CheckConfigRet(ret);
61+
ret = umfDisjointPoolParamsSetName(Configs[DisjointPoolMemType::Device], "Device");
62+
CheckConfigRet(ret);
63+
ret = umfDisjointPoolParamsSetName(Configs[DisjointPoolMemType::Shared], "Shared");
64+
CheckConfigRet(ret);
65+
ret = umfDisjointPoolParamsSetName(Configs[DisjointPoolMemType::SharedReadOnly], "SharedReadOnly");
66+
CheckConfigRet(ret);
4067

4168
// Buckets for Host use a minimum of the cache line size of 64 bytes.
4269
// This prevents two separate allocations residing in the same cache line.
4370
// Buckets for Device and Shared allocations will use starting size of 512.
4471
// This is because memory compression on newer GPUs makes the
4572
// minimum granularity 512 bytes instead of 64.
46-
Configs[DisjointPoolMemType::Host].MinBucketSize = 64;
47-
Configs[DisjointPoolMemType::Device].MinBucketSize = 512;
48-
Configs[DisjointPoolMemType::Shared].MinBucketSize = 512;
49-
Configs[DisjointPoolMemType::SharedReadOnly].MinBucketSize = 512;
73+
ret = umfDisjointPoolParamsSetMinBucketSize(Configs[DisjointPoolMemType::Host], 64);
74+
CheckConfigRet(ret);
75+
ret = umfDisjointPoolParamsSetMinBucketSize(Configs[DisjointPoolMemType::Device], 512);
76+
CheckConfigRet(ret);
77+
ret = umfDisjointPoolParamsSetMinBucketSize(Configs[DisjointPoolMemType::Shared], 512);
78+
CheckConfigRet(ret);
79+
ret = umfDisjointPoolParamsSetMinBucketSize(Configs[DisjointPoolMemType::SharedReadOnly], 512);
80+
CheckConfigRet(ret);
5081

5182
// Initialize default pool settings.
52-
Configs[DisjointPoolMemType::Host].MaxPoolableSize = 2_MB;
53-
Configs[DisjointPoolMemType::Host].Capacity = 4;
54-
Configs[DisjointPoolMemType::Host].SlabMinSize = 64_KB;
83+
ret = umfDisjointPoolParamsSetMaxPoolableSize(Configs[DisjointPoolMemType::Host], 2_MB);
84+
CheckConfigRet(ret);
85+
ret = umfDisjointPoolParamsSetCapacity(Configs[DisjointPoolMemType::Host], 4);
86+
CheckConfigRet(ret);
87+
ret = umfDisjointPoolParamsSetSlabMinSize(Configs[DisjointPoolMemType::Host], 64_KB);
88+
CheckConfigRet(ret);
5589

56-
Configs[DisjointPoolMemType::Device].MaxPoolableSize = 4_MB;
57-
Configs[DisjointPoolMemType::Device].Capacity = 4;
58-
Configs[DisjointPoolMemType::Device].SlabMinSize = 64_KB;
90+
ret = umfDisjointPoolParamsSetMaxPoolableSize(Configs[DisjointPoolMemType::Device], 4_MB);
91+
CheckConfigRet(ret);
92+
ret = umfDisjointPoolParamsSetCapacity(Configs[DisjointPoolMemType::Device], 4);
93+
CheckConfigRet(ret);
94+
ret = umfDisjointPoolParamsSetSlabMinSize(Configs[DisjointPoolMemType::Device], 64_KB);
95+
CheckConfigRet(ret);
5996

6097
// Disable pooling of shared USM allocations.
61-
Configs[DisjointPoolMemType::Shared].MaxPoolableSize = 0;
62-
Configs[DisjointPoolMemType::Shared].Capacity = 0;
63-
Configs[DisjointPoolMemType::Shared].SlabMinSize = 2_MB;
98+
ret = umfDisjointPoolParamsSetMaxPoolableSize(Configs[DisjointPoolMemType::Shared], 0);
99+
CheckConfigRet(ret);
100+
ret = umfDisjointPoolParamsSetCapacity(Configs[DisjointPoolMemType::Shared], 0);
101+
CheckConfigRet(ret);
102+
ret = umfDisjointPoolParamsSetSlabMinSize(Configs[DisjointPoolMemType::Shared], 2_MB);
103+
CheckConfigRet(ret);
64104

65105
// Allow pooling of shared allocations that are only modified on host.
66-
Configs[DisjointPoolMemType::SharedReadOnly].MaxPoolableSize = 4_MB;
67-
Configs[DisjointPoolMemType::SharedReadOnly].Capacity = 4;
68-
Configs[DisjointPoolMemType::SharedReadOnly].SlabMinSize = 2_MB;
106+
ret = umfDisjointPoolParamsSetMaxPoolableSize(Configs[DisjointPoolMemType::SharedReadOnly], 4_MB);
107+
CheckConfigRet(ret);
108+
ret = umfDisjointPoolParamsSetCapacity(Configs[DisjointPoolMemType::SharedReadOnly], 4);
109+
CheckConfigRet(ret);
110+
ret = umfDisjointPoolParamsSetSlabMinSize(Configs[DisjointPoolMemType::SharedReadOnly], 2_MB);
111+
CheckConfigRet(ret);
69112
}
70113

71114
DisjointPoolAllConfigs parseDisjointPoolConfig(const std::string &config,
@@ -120,34 +163,46 @@ DisjointPoolAllConfigs parseDisjointPoolConfig(const std::string &config,
120163
DisjointPoolMemType memType =
121164
DisjointPoolMemType::All) {
122165
bool ParamWasSet;
166+
size_t TmpValue = 0;
167+
umf_result_t ret = UMF_RESULT_SUCCESS;
123168
DisjointPoolMemType LM = memType;
124169
if (memType == DisjointPoolMemType::All) {
125170
LM = DisjointPoolMemType::Host;
126171
}
127172

128-
bool More = ParamParser(Params, AllConfigs.Configs[LM].MaxPoolableSize,
129-
ParamWasSet);
173+
bool More = ParamParser(Params, TmpValue, ParamWasSet);
130174
if (ParamWasSet && memType == DisjointPoolMemType::All) {
131175
for (auto &Config : AllConfigs.Configs) {
132-
Config.MaxPoolableSize = AllConfigs.Configs[LM].MaxPoolableSize;
176+
ret = umfDisjointPoolParamsSetMaxPoolableSize(Config, TmpValue);
177+
CheckConfigRet(ret);
133178
}
179+
} else if (ParamWasSet) {
180+
ret = umfDisjointPoolParamsSetMaxPoolableSize(AllConfigs.Configs[LM], TmpValue);
181+
CheckConfigRet(ret);
134182
}
183+
135184
if (More) {
136-
More = ParamParser(Params, AllConfigs.Configs[LM].Capacity,
137-
ParamWasSet);
185+
More = ParamParser(Params, TmpValue, ParamWasSet);
138186
if (ParamWasSet && memType == DisjointPoolMemType::All) {
139187
for (auto &Config : AllConfigs.Configs) {
140-
Config.Capacity = AllConfigs.Configs[LM].Capacity;
188+
ret = umfDisjointPoolParamsSetCapacity(Config, TmpValue);
189+
CheckConfigRet(ret);
141190
}
191+
} else if (ParamWasSet) {
192+
ret = umfDisjointPoolParamsSetCapacity(AllConfigs.Configs[LM], TmpValue);
193+
CheckConfigRet(ret);
142194
}
143195
}
144196
if (More) {
145-
ParamParser(Params, AllConfigs.Configs[LM].SlabMinSize,
146-
ParamWasSet);
197+
ParamParser(Params, TmpValue, ParamWasSet);
147198
if (ParamWasSet && memType == DisjointPoolMemType::All) {
148199
for (auto &Config : AllConfigs.Configs) {
149-
Config.SlabMinSize = AllConfigs.Configs[LM].SlabMinSize;
200+
ret = umfDisjointPoolParamsSetSlabMinSize(Config, TmpValue);
201+
CheckConfigRet(ret);
150202
}
203+
} else if (ParamWasSet) {
204+
ret = umfDisjointPoolParamsSetSlabMinSize(AllConfigs.Configs[LM], TmpValue);
205+
CheckConfigRet(ret);
151206
}
152207
}
153208
};
@@ -224,8 +279,8 @@ DisjointPoolAllConfigs parseDisjointPoolConfig(const std::string &config,
224279
umfDisjointPoolSharedLimitsDestroy);
225280

226281
for (auto &Config : AllConfigs.Configs) {
227-
Config.SharedLimits = AllConfigs.limits.get();
228-
Config.PoolTrace = trace;
282+
umfDisjointPoolParamsSetSharedLimits(Config, AllConfigs.limits.get());
283+
umfDisjointPoolParamsSetTrace(Config, trace);
229284
}
230285

231286
if (!trace) {
@@ -241,33 +296,32 @@ DisjointPoolAllConfigs parseDisjointPoolConfig(const std::string &config,
241296
<< std::setw(12) << "Shared RO" << std::endl;
242297
std::cout
243298
<< std::setw(15) << "SlabMinSize" << std::setw(12)
244-
<< AllConfigs.Configs[DisjointPoolMemType::Host].SlabMinSize
299+
<< umfDisjointPoolParamsGetSlabMinSize(AllConfigs.Configs[DisjointPoolMemType::Host])
245300
<< std::setw(12)
246-
<< AllConfigs.Configs[DisjointPoolMemType::Device].SlabMinSize
301+
<< umfDisjointPoolParamsGetSlabMinSize(AllConfigs.Configs[DisjointPoolMemType::Device])
247302
<< std::setw(12)
248-
<< AllConfigs.Configs[DisjointPoolMemType::Shared].SlabMinSize
303+
<< umfDisjointPoolParamsGetSlabMinSize(AllConfigs.Configs[DisjointPoolMemType::Shared])
249304
<< std::setw(12)
250-
<< AllConfigs.Configs[DisjointPoolMemType::SharedReadOnly].SlabMinSize
305+
<< umfDisjointPoolParamsGetSlabMinSize(AllConfigs.Configs[DisjointPoolMemType::SharedReadOnly])
251306
<< std::endl;
252307
std::cout << std::setw(15) << "MaxPoolableSize" << std::setw(12)
253-
<< AllConfigs.Configs[DisjointPoolMemType::Host].MaxPoolableSize
308+
<< umfDisjointPoolParamsGetMaxPoolableSize(AllConfigs.Configs[DisjointPoolMemType::Host])
254309
<< std::setw(12)
255-
<< AllConfigs.Configs[DisjointPoolMemType::Device].MaxPoolableSize
310+
<< umfDisjointPoolParamsGetMaxPoolableSize(AllConfigs.Configs[DisjointPoolMemType::Device])
256311
<< std::setw(12)
257-
<< AllConfigs.Configs[DisjointPoolMemType::Shared].MaxPoolableSize
312+
<< umfDisjointPoolParamsGetMaxPoolableSize(AllConfigs.Configs[DisjointPoolMemType::Shared])
258313
<< std::setw(12)
259-
<< AllConfigs.Configs[DisjointPoolMemType::SharedReadOnly]
260-
.MaxPoolableSize
314+
<< umfDisjointPoolParamsGetMaxPoolableSize(AllConfigs.Configs[DisjointPoolMemType::SharedReadOnly])
261315
<< std::endl;
262316
std::cout
263317
<< std::setw(15) << "Capacity" << std::setw(12)
264-
<< AllConfigs.Configs[DisjointPoolMemType::Host].Capacity
318+
<< umfDisjointPoolParamsGetCapacity(AllConfigs.Configs[DisjointPoolMemType::Host])
265319
<< std::setw(12)
266-
<< AllConfigs.Configs[DisjointPoolMemType::Device].Capacity
320+
<< umfDisjointPoolParamsGetCapacity(AllConfigs.Configs[DisjointPoolMemType::Device])
267321
<< std::setw(12)
268-
<< AllConfigs.Configs[DisjointPoolMemType::Shared].Capacity
322+
<< umfDisjointPoolParamsGetCapacity(AllConfigs.Configs[DisjointPoolMemType::Shared])
269323
<< std::setw(12)
270-
<< AllConfigs.Configs[DisjointPoolMemType::SharedReadOnly].Capacity
324+
<< umfDisjointPoolParamsGetCapacity(AllConfigs.Configs[DisjointPoolMemType::SharedReadOnly])
271325
<< std::endl;
272326
std::cout << std::setw(15) << "MaxPoolSize" << std::setw(12) << MaxSize
273327
<< std::endl;

source/common/umf_pools/disjoint_pool_config_parser.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ class DisjointPoolAllConfigs {
2525
public:
2626
size_t EnableBuffers = 1;
2727
std::shared_ptr<umf_disjoint_pool_shared_limits_t> limits;
28-
umf_disjoint_pool_params_t Configs[DisjointPoolMemType::All];
28+
umf_disjoint_pool_params_handle_t Configs[DisjointPoolMemType::All];
2929

3030
DisjointPoolAllConfigs(int trace = 0);
31+
~DisjointPoolAllConfigs();
3132
};
3233

3334
// Parse optional config parameters of this form:

0 commit comments

Comments
 (0)