Skip to content

Commit 14ac760

Browse files
committed
Update usage of zeCommandListImmediateAppendCommandListsExp to use dlsym
The implementation was using zeCommandListImmediateAppendCommandListsExp directly with the loader. This creates an issue with old loaders that don't support this entrypoint. Instead, this change uses dlsym to load the function if available.
1 parent 6f36300 commit 14ac760

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-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: 17 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,7 @@ ur_result_t ur_platform_handle_t_::initialize() {
248249
ZeDriverEventPoolCountingEventsExtensionFound = true;
249250
}
250251
}
252+
251253
// Check if extension is available for Mutable Command List v1.1.
252254
if (strncmp(extension.name, ZE_MUTABLE_COMMAND_LIST_EXP_NAME,
253255
strlen(ZE_MUTABLE_COMMAND_LIST_EXP_NAME) + 1) == 0) {
@@ -427,6 +429,21 @@ ur_result_t ur_platform_handle_t_::initialize() {
427429
&ZeMutableCmdListExt
428430
.zexCommandListGetNextCommandIdWithKernelsExp))) == 0);
429431
}
432+
433+
// Check if ImmediateAppendCommandList is supported and initialize the
434+
// function pointer.
435+
if (ZeImmediateCommandListAppendExtensionFound) {
436+
ZeCommandListImmediateAppendExt
437+
.zeCommandListImmediateAppendCommandListsExp =
438+
(ze_pfnCommandListImmediateAppendCommandListsExp_t)
439+
ur_loader::LibLoader::getFunctionPtr(
440+
GlobalAdapter->processHandle,
441+
"zeCommandListImmediateAppendCommandListsExp");
442+
ZeCommandListImmediateAppendExt.Supported =
443+
ZeCommandListImmediateAppendExt
444+
.zeCommandListImmediateAppendCommandListsExp != nullptr;
445+
}
446+
430447
return UR_RESULT_SUCCESS;
431448
}
432449

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)