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+
1825namespace usm {
1926constexpr auto operator " " _B(unsigned long long x) -> size_t { return x; }
2027constexpr 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+
3043DisjointPoolAllConfigs::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 (¶ms);
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
71114DisjointPoolAllConfigs 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;
0 commit comments