Skip to content

Commit 232e62f

Browse files
authored
Merge pull request #2498 from Bensuo/fabio/fix_l0_old_loader_no_translate
Update usage of zeCommandListImmediateAppendCommandListsExp to use dlsym
2 parents 76a9623 + 59b37e3 commit 232e62f

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

source/adapters/level_zero/command_buffer.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,9 @@ namespace {
2626
// given Context and Device.
2727
bool checkImmediateAppendSupport(ur_context_handle_t Context,
2828
ur_device_handle_t Device) {
29-
// TODO The L0 driver is not reporting this extension yet. Once it does,
30-
// switch to using the variable zeDriverImmediateCommandListAppendFound.
3129

32-
// Minimum version that supports zeCommandListImmediateAppendCommandListsExp.
33-
constexpr uint32_t MinDriverVersion = 30898;
3430
bool DriverSupportsImmediateAppend =
35-
Context->getPlatform()->isDriverVersionNewerOrSimilar(1, 3,
36-
MinDriverVersion);
31+
Context->getPlatform()->ZeCommandListImmediateAppendExt.Supported;
3732

3833
// If this environment variable is:
3934
// - Set to 1: the immediate append path will always be enabled as long the
@@ -58,10 +53,8 @@ bool checkImmediateAppendSupport(ur_context_handle_t Context,
5853
if (EnableAppendPath && !DriverSupportsImmediateAppend) {
5954
logger::error("{} is set but "
6055
"the current driver does not support the "
61-
"zeCommandListImmediateAppendCommandListsExp entrypoint. A "
62-
"driver version of at least {} is required to use the "
63-
"immediate append path.",
64-
AppendEnvVarName, MinDriverVersion);
56+
"zeCommandListImmediateAppendCommandListsExp entrypoint.",
57+
AppendEnvVarName);
6558
std::abort();
6659
}
6760

@@ -1569,7 +1562,10 @@ ur_result_t enqueueImmediateAppendPath(
15691562
ur_event_handle_t *Event, ur_command_list_ptr_t CommandListHelper,
15701563
bool DoProfiling) {
15711564

1565+
ur_platform_handle_t Platform = CommandBuffer->Context->getPlatform();
1566+
15721567
assert(CommandListHelper->second.IsImmediate);
1568+
assert(Platform->ZeCommandListImmediateAppendExt.Supported);
15731569

15741570
_ur_ze_event_list_t UrZeEventList;
15751571
if (NumEventsInWaitList) {
@@ -1587,7 +1583,8 @@ ur_result_t enqueueImmediateAppendPath(
15871583
nullptr /*ForcedCmdQueue*/));
15881584
assert(ZeCopyEngineImmediateListHelper->second.IsImmediate);
15891585

1590-
ZE2UR_CALL(zeCommandListImmediateAppendCommandListsExp,
1586+
ZE2UR_CALL(Platform->ZeCommandListImmediateAppendExt
1587+
.zeCommandListImmediateAppendCommandListsExp,
15911588
(ZeCopyEngineImmediateListHelper->first, 1,
15921589
&CommandBuffer->ZeCopyCommandList, nullptr,
15931590
UrZeEventList.Length, UrZeEventList.ZeEventList));
@@ -1599,7 +1596,8 @@ ur_result_t enqueueImmediateAppendPath(
15991596
ze_event_handle_t &EventToSignal =
16001597
DoProfiling ? CommandBuffer->ComputeFinishedEvent->ZeEvent
16011598
: (*Event)->ZeEvent;
1602-
ZE2UR_CALL(zeCommandListImmediateAppendCommandListsExp,
1599+
ZE2UR_CALL(Platform->ZeCommandListImmediateAppendExt
1600+
.zeCommandListImmediateAppendCommandListsExp,
16031601
(CommandListHelper->first, 1, &CommandBuffer->ZeComputeCommandList,
16041602
EventToSignal, WaitList.Length, WaitList.ZeEventList));
16051603

@@ -1616,7 +1614,8 @@ ur_result_t enqueueImmediateAppendPath(
16161614
(CommandListHelper->first,
16171615
CommandBuffer->ExecutionFinishedEvent->ZeEvent, 0, nullptr));
16181616

1619-
ZE2UR_CALL(zeCommandListImmediateAppendCommandListsExp,
1617+
ZE2UR_CALL(Platform->ZeCommandListImmediateAppendExt
1618+
.zeCommandListImmediateAppendCommandListsExp,
16201619
(CommandListHelper->first, 1,
16211620
&CommandBuffer->ZeCommandListResetEvents, nullptr, 0, nullptr));
16221621
}

source/adapters/level_zero/platform.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ ur_result_t ur_platform_handle_t_::initialize() {
224224

225225
bool MutableCommandListSpecExtensionSupported = false;
226226
bool ZeIntelExternalSemaphoreExtensionSupported = false;
227+
bool ZeImmediateCommandListAppendExtensionFound = false;
227228
for (auto &extension : ZeExtensions) {
228229
// Check if global offset extension is available
229230
if (strncmp(extension.name, ZE_GLOBAL_OFFSET_EXP_NAME,
@@ -248,6 +249,14 @@ ur_result_t ur_platform_handle_t_::initialize() {
248249
ZeDriverEventPoolCountingEventsExtensionFound = true;
249250
}
250251
}
252+
// Check if the ImmediateAppendCommandLists extension is available.
253+
if (strncmp(extension.name, ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME,
254+
strlen(ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME) + 1) == 0) {
255+
if (extension.version ==
256+
ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_VERSION_CURRENT) {
257+
ZeImmediateCommandListAppendExtensionFound = true;
258+
}
259+
}
251260
// Check if extension is available for Mutable Command List v1.1.
252261
if (strncmp(extension.name, ZE_MUTABLE_COMMAND_LIST_EXP_NAME,
253262
strlen(ZE_MUTABLE_COMMAND_LIST_EXP_NAME) + 1) == 0) {
@@ -427,6 +436,21 @@ ur_result_t ur_platform_handle_t_::initialize() {
427436
&ZeMutableCmdListExt
428437
.zexCommandListGetNextCommandIdWithKernelsExp))) == 0);
429438
}
439+
440+
// Check if ImmediateAppendCommandList is supported and initialize the
441+
// function pointer.
442+
if (ZeImmediateCommandListAppendExtensionFound) {
443+
ZeCommandListImmediateAppendExt
444+
.zeCommandListImmediateAppendCommandListsExp =
445+
(ze_pfnCommandListImmediateAppendCommandListsExp_t)
446+
ur_loader::LibLoader::getFunctionPtr(
447+
GlobalAdapter->processHandle,
448+
"zeCommandListImmediateAppendCommandListsExp");
449+
ZeCommandListImmediateAppendExt.Supported =
450+
ZeCommandListImmediateAppendExt
451+
.zeCommandListImmediateAppendCommandListsExp != nullptr;
452+
}
453+
430454
return UR_RESULT_SUCCESS;
431455
}
432456

source/adapters/level_zero/platform.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,11 @@ struct ur_platform_handle_t_ : public _ur_platform {
134134
ze_result_t (*zexDeviceReleaseExternalSemaphoreExp)(
135135
ze_intel_external_semaphore_exp_handle_t);
136136
} ZeExternalSemaphoreExt;
137-
};
137+
138+
struct ZeCommandListImmediateAppendExtension {
139+
bool Supported = false;
140+
ze_result_t (*zeCommandListImmediateAppendCommandListsExp)(
141+
ze_command_list_handle_t, uint32_t, ze_command_list_handle_t *,
142+
ze_event_handle_t, uint32_t, ze_event_handle_t *);
143+
} ZeCommandListImmediateAppendExt;
144+
};

0 commit comments

Comments
 (0)