Skip to content

Commit bc4312b

Browse files
aarongreigkbenzie
authored andcommitted
Merge pull request #2498 from Bensuo/fabio/fix_l0_old_loader_no_translate
Update usage of zeCommandListImmediateAppendCommandListsExp to use dlsym
1 parent 02582da commit bc4312b

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

@@ -1568,7 +1561,10 @@ ur_result_t enqueueImmediateAppendPath(
15681561
ur_event_handle_t *Event, ur_command_list_ptr_t CommandListHelper,
15691562
bool DoProfiling) {
15701563

1564+
ur_platform_handle_t Platform = CommandBuffer->Context->getPlatform();
1565+
15711566
assert(CommandListHelper->second.IsImmediate);
1567+
assert(Platform->ZeCommandListImmediateAppendExt.Supported);
15721568

15731569
_ur_ze_event_list_t UrZeEventList;
15741570
if (NumEventsInWaitList) {
@@ -1586,7 +1582,8 @@ ur_result_t enqueueImmediateAppendPath(
15861582
nullptr /*ForcedCmdQueue*/));
15871583
assert(ZeCopyEngineImmediateListHelper->second.IsImmediate);
15881584

1589-
ZE2UR_CALL(zeCommandListImmediateAppendCommandListsExp,
1585+
ZE2UR_CALL(Platform->ZeCommandListImmediateAppendExt
1586+
.zeCommandListImmediateAppendCommandListsExp,
15901587
(ZeCopyEngineImmediateListHelper->first, 1,
15911588
&CommandBuffer->ZeCopyCommandList, nullptr,
15921589
UrZeEventList.Length, UrZeEventList.ZeEventList));
@@ -1598,7 +1595,8 @@ ur_result_t enqueueImmediateAppendPath(
15981595
ze_event_handle_t &EventToSignal =
15991596
DoProfiling ? CommandBuffer->ComputeFinishedEvent->ZeEvent
16001597
: (*Event)->ZeEvent;
1601-
ZE2UR_CALL(zeCommandListImmediateAppendCommandListsExp,
1598+
ZE2UR_CALL(Platform->ZeCommandListImmediateAppendExt
1599+
.zeCommandListImmediateAppendCommandListsExp,
16021600
(CommandListHelper->first, 1, &CommandBuffer->ZeComputeCommandList,
16031601
EventToSignal, WaitList.Length, WaitList.ZeEventList));
16041602

@@ -1615,7 +1613,8 @@ ur_result_t enqueueImmediateAppendPath(
16151613
(CommandListHelper->first,
16161614
CommandBuffer->ExecutionFinishedEvent->ZeEvent, 0, nullptr));
16171615

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

source/adapters/level_zero/platform.cpp

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

223223
bool MutableCommandListSpecExtensionSupported = false;
224224
bool ZeIntelExternalSemaphoreExtensionSupported = false;
225+
bool ZeImmediateCommandListAppendExtensionFound = false;
225226
for (auto &extension : ZeExtensions) {
226227
// Check if global offset extension is available
227228
if (strncmp(extension.name, ZE_GLOBAL_OFFSET_EXP_NAME,
@@ -246,6 +247,14 @@ ur_result_t ur_platform_handle_t_::initialize() {
246247
ZeDriverEventPoolCountingEventsExtensionFound = true;
247248
}
248249
}
250+
// Check if the ImmediateAppendCommandLists extension is available.
251+
if (strncmp(extension.name, ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME,
252+
strlen(ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME) + 1) == 0) {
253+
if (extension.version ==
254+
ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_VERSION_CURRENT) {
255+
ZeImmediateCommandListAppendExtensionFound = true;
256+
}
257+
}
249258
// Check if extension is available for Mutable Command List v1.1.
250259
if (strncmp(extension.name, ZE_MUTABLE_COMMAND_LIST_EXP_NAME,
251260
strlen(ZE_MUTABLE_COMMAND_LIST_EXP_NAME) + 1) == 0) {
@@ -425,6 +434,21 @@ ur_result_t ur_platform_handle_t_::initialize() {
425434
&ZeMutableCmdListExt
426435
.zexCommandListGetNextCommandIdWithKernelsExp))) == 0);
427436
}
437+
438+
// Check if ImmediateAppendCommandList is supported and initialize the
439+
// function pointer.
440+
if (ZeImmediateCommandListAppendExtensionFound) {
441+
ZeCommandListImmediateAppendExt
442+
.zeCommandListImmediateAppendCommandListsExp =
443+
(ze_pfnCommandListImmediateAppendCommandListsExp_t)
444+
ur_loader::LibLoader::getFunctionPtr(
445+
GlobalAdapter->processHandle,
446+
"zeCommandListImmediateAppendCommandListsExp");
447+
ZeCommandListImmediateAppendExt.Supported =
448+
ZeCommandListImmediateAppendExt
449+
.zeCommandListImmediateAppendCommandListsExp != nullptr;
450+
}
451+
428452
return UR_RESULT_SUCCESS;
429453
}
430454

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)