Skip to content

Commit 1493fa2

Browse files
kswiecickikbenzie
authored andcommitted
Enable e2e tests (#19493)
L0v2 adapter was marked as unsupported in some async alloc tests due to missing features. Those tests were failing because of the missing functions: `urUSMPoolGetInfoExp`, `urUSMPoolSetInfoExp`, `urUSMPoolCreateExp`, `urUSMPoolDestroyExp`, `urUSMPoolGetDefaultDevicePoolExp`. Closes #18488
1 parent bc57d86 commit 1493fa2

File tree

4 files changed

+139
-30
lines changed

4 files changed

+139
-30
lines changed

source/adapters/level_zero/usm.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,26 @@ ur_result_t UR_APICALL urUSMPoolDestroyExp(ur_context_handle_t /*Context*/,
607607
return UR_RESULT_SUCCESS;
608608
}
609609

610-
ur_result_t UR_APICALL urUSMPoolSetInfoExp(ur_usm_pool_handle_t,
611-
ur_usm_pool_info_t, void *, size_t) {
610+
ur_result_t UR_APICALL urUSMPoolSetInfoExp(ur_usm_pool_handle_t /*Pool*/,
611+
ur_usm_pool_info_t PropName,
612+
void * /*PropValue*/,
613+
size_t PropSize) {
614+
if (PropSize < sizeof(size_t)) {
615+
return UR_RESULT_ERROR_INVALID_SIZE;
616+
}
617+
618+
switch (PropName) {
619+
// TODO: Support for pool release threshold and maximum size hints.
620+
case UR_USM_POOL_INFO_RELEASE_THRESHOLD_EXP:
621+
case UR_USM_POOL_INFO_MAXIMUM_SIZE_EXP:
622+
// TODO: Allow user to overwrite pool peak statistics.
623+
case UR_USM_POOL_INFO_RESERVED_HIGH_EXP:
624+
case UR_USM_POOL_INFO_USED_HIGH_EXP:
625+
break;
626+
default:
627+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
628+
}
629+
612630
return UR_RESULT_SUCCESS;
613631
}
614632

source/adapters/level_zero/v2/api.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,6 @@ ur_result_t urEventSetCallback(ur_event_handle_t hEvent,
4141
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
4242
}
4343

44-
ur_result_t UR_APICALL urUSMPoolCreateExp(ur_context_handle_t hContext,
45-
ur_device_handle_t hDevice,
46-
ur_usm_pool_desc_t *PoolDesc,
47-
ur_usm_pool_handle_t *pPool) {
48-
UR_LOG(ERR, "{} function not implemented!", __FUNCTION__);
49-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
50-
}
51-
52-
ur_result_t UR_APICALL urUSMPoolDestroyExp(ur_context_handle_t hContext,
53-
ur_device_handle_t hDevice,
54-
ur_usm_pool_handle_t hPool) {
55-
UR_LOG(ERR, "{} function not implemented!", __FUNCTION__);
56-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
57-
}
58-
59-
ur_result_t UR_APICALL urUSMPoolSetInfoExp(ur_usm_pool_handle_t hPool,
60-
ur_usm_pool_info_t propName,
61-
void *pPropValue, size_t propSize) {
62-
UR_LOG(ERR, "{} function not implemented!", __FUNCTION__);
63-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
64-
}
65-
6644
ur_result_t UR_APICALL urUSMPoolGetDevicePoolExp(ur_context_handle_t hContext,
6745
ur_device_handle_t hDevice,
6846
ur_usm_pool_handle_t *pPool) {

source/adapters/level_zero/v2/usm.cpp

Lines changed: 116 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,68 @@ ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t hContext,
188188
}
189189
}
190190

191+
ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t hContext,
192+
ur_device_handle_t hDevice,
193+
ur_usm_pool_desc_t *pPoolDesc)
194+
: hContext(hContext) {
195+
// TODO: handle UR_USM_POOL_FLAG_ZERO_INITIALIZE_BLOCK from pPoolDesc
196+
auto disjointPoolConfigs = initializeDisjointPoolConfig();
197+
198+
if (disjointPoolConfigs.has_value()) {
199+
if (auto limits = find_stype_node<ur_usm_pool_limits_desc_t>(pPoolDesc)) {
200+
for (auto &config : disjointPoolConfigs.value().Configs) {
201+
config.MaxPoolableSize = limits->maxPoolableSize;
202+
config.SlabMinSize = limits->minDriverAllocSize;
203+
}
204+
}
205+
} else {
206+
// If pooling is disabled, do nothing.
207+
UR_LOG(INFO, "USM pooling is disabled. Skiping pool limits adjustment.");
208+
}
209+
210+
// Create pool descriptor for single device provided
211+
std::vector<usm::pool_descriptor> descriptors;
212+
{
213+
auto &desc = descriptors.emplace_back();
214+
desc.poolHandle = this;
215+
desc.hContext = hContext;
216+
desc.hDevice = hDevice;
217+
desc.type = UR_USM_TYPE_DEVICE;
218+
}
219+
{
220+
auto &desc = descriptors.emplace_back();
221+
desc.poolHandle = this;
222+
desc.hContext = hContext;
223+
desc.hDevice = hDevice;
224+
desc.type = UR_USM_TYPE_SHARED;
225+
desc.deviceReadOnly = false;
226+
}
227+
{
228+
auto &desc = descriptors.emplace_back();
229+
desc.poolHandle = this;
230+
desc.hContext = hContext;
231+
desc.hDevice = hDevice;
232+
desc.type = UR_USM_TYPE_SHARED;
233+
desc.deviceReadOnly = true;
234+
}
235+
236+
for (auto &desc : descriptors) {
237+
std::unique_ptr<UsmPool> usmPool;
238+
if (disjointPoolConfigs.has_value()) {
239+
auto &poolConfig =
240+
disjointPoolConfigs.value().Configs[descToDisjoinPoolMemType(desc)];
241+
auto pool = usm::makeDisjointPool(makeProvider(desc), poolConfig);
242+
usmPool = std::make_unique<UsmPool>(this, std::move(pool));
243+
} else {
244+
auto pool = usm::makeProxyPool(makeProvider(desc));
245+
usmPool = std::make_unique<UsmPool>(this, std::move(pool));
246+
}
247+
UMF_CALL_THROWS(
248+
umfPoolSetTag(usmPool->umfPool.get(), usmPool.get(), nullptr));
249+
poolManager.addPool(desc, std::move(usmPool));
250+
}
251+
}
252+
191253
ur_context_handle_t ur_usm_pool_handle_t_::getContextHandle() const {
192254
return hContext;
193255
}
@@ -358,27 +420,27 @@ size_t ur_usm_pool_handle_t_::getTotalReservedSize() {
358420
}
359421

360422
size_t ur_usm_pool_handle_t_::getPeakReservedSize() {
361-
size_t totalAllocatedSize = 0;
423+
size_t maxPeakSize = 0;
362424
umf_result_t umfRet = UMF_RESULT_SUCCESS;
363425
poolManager.forEachPool([&](UsmPool *p) {
364426
umf_memory_provider_handle_t hProvider = nullptr;
365-
size_t allocatedSize = 0;
427+
size_t peakSize = 0;
366428
umfRet = umfPoolGetMemoryProvider(p->umfPool.get(), &hProvider);
367429
if (umfRet != UMF_RESULT_SUCCESS) {
368430
return false;
369431
}
370432

371-
umfRet = umfCtlGet("umf.provider.by_handle.{}.stats.peak_memory",
372-
&allocatedSize, sizeof(allocatedSize), hProvider);
433+
umfRet = umfCtlGet("umf.provider.by_handle.{}.stats.peak_memory", &peakSize,
434+
sizeof(peakSize), hProvider);
373435
if (umfRet != UMF_RESULT_SUCCESS) {
374436
return false;
375437
}
376438

377-
totalAllocatedSize += allocatedSize;
439+
maxPeakSize = std::max(maxPeakSize, peakSize);
378440
return true;
379441
});
380442

381-
return umfRet == UMF_RESULT_SUCCESS ? totalAllocatedSize : 0;
443+
return umfRet == UMF_RESULT_SUCCESS ? maxPeakSize : 0;
382444
}
383445

384446
size_t ur_usm_pool_handle_t_::getTotalUsedSize() {
@@ -460,6 +522,32 @@ ur_result_t urUSMPoolGetInfo(
460522
return exceptionToResult(std::current_exception());
461523
}
462524

525+
ur_result_t urUSMPoolCreateExp(ur_context_handle_t hContext,
526+
ur_device_handle_t hDevice,
527+
ur_usm_pool_desc_t *pPoolDesc,
528+
ur_usm_pool_handle_t *pPool) try {
529+
*pPool = new ur_usm_pool_handle_t_(hContext, hDevice, pPoolDesc);
530+
hContext->addUsmPool(*pPool);
531+
return UR_RESULT_SUCCESS;
532+
} catch (umf_result_t e) {
533+
return umf::umf2urResult(e);
534+
} catch (...) {
535+
return exceptionToResult(std::current_exception());
536+
}
537+
538+
ur_result_t urUSMPoolDestroyExp(ur_context_handle_t, ur_device_handle_t,
539+
ur_usm_pool_handle_t hPool) try {
540+
if (hPool->RefCount.release()) {
541+
hPool->getContextHandle()->removeUsmPool(hPool);
542+
delete hPool;
543+
}
544+
return UR_RESULT_SUCCESS;
545+
} catch (umf_result_t e) {
546+
return umf::umf2urResult(e);
547+
} catch (...) {
548+
return exceptionToResult(std::current_exception());
549+
}
550+
463551
ur_result_t urUSMPoolGetInfoExp(ur_usm_pool_handle_t hPool,
464552
ur_usm_pool_info_t propName, void *pPropValue,
465553
size_t *pPropSizeRet) {
@@ -497,6 +585,28 @@ ur_result_t urUSMPoolGetInfoExp(ur_usm_pool_handle_t hPool,
497585
return UR_RESULT_SUCCESS;
498586
}
499587

588+
ur_result_t urUSMPoolSetInfoExp(ur_usm_pool_handle_t /*hPool*/,
589+
ur_usm_pool_info_t propName,
590+
void * /*pPropValue*/, size_t propSize) {
591+
if (propSize < sizeof(size_t)) {
592+
return UR_RESULT_ERROR_INVALID_SIZE;
593+
}
594+
595+
switch (propName) {
596+
// TODO: Support for pool release threshold and maximum size hints.
597+
case UR_USM_POOL_INFO_RELEASE_THRESHOLD_EXP:
598+
case UR_USM_POOL_INFO_MAXIMUM_SIZE_EXP:
599+
// TODO: Allow user to overwrite pool peak statistics.
600+
case UR_USM_POOL_INFO_RESERVED_HIGH_EXP:
601+
case UR_USM_POOL_INFO_USED_HIGH_EXP:
602+
break;
603+
default:
604+
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
605+
}
606+
607+
return UR_RESULT_SUCCESS;
608+
}
609+
500610
ur_result_t urUSMPoolGetDefaultDevicePoolExp(ur_context_handle_t hContext,
501611
ur_device_handle_t,
502612
ur_usm_pool_handle_t *pPool) {

source/adapters/level_zero/v2/usm.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ struct AllocationStats {
5555
struct ur_usm_pool_handle_t_ : ur_object {
5656
ur_usm_pool_handle_t_(ur_context_handle_t hContext,
5757
ur_usm_pool_desc_t *pPoolDes);
58+
ur_usm_pool_handle_t_(ur_context_handle_t hContext,
59+
ur_device_handle_t hDevice,
60+
ur_usm_pool_desc_t *pPoolDes);
5861

5962
ur_context_handle_t getContextHandle() const;
6063

0 commit comments

Comments
 (0)