Skip to content

Commit

Permalink
Merge pull request #2498 from Bensuo/fabio/fix_l0_old_loader_no_trans…
Browse files Browse the repository at this point in the history
…late

Update usage of zeCommandListImmediateAppendCommandListsExp to use dlsym
  • Loading branch information
aarongreig authored Dec 23, 2024
2 parents 76a9623 + 59b37e3 commit 232e62f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
25 changes: 12 additions & 13 deletions source/adapters/level_zero/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@ namespace {
// given Context and Device.
bool checkImmediateAppendSupport(ur_context_handle_t Context,
ur_device_handle_t Device) {
// TODO The L0 driver is not reporting this extension yet. Once it does,
// switch to using the variable zeDriverImmediateCommandListAppendFound.

// Minimum version that supports zeCommandListImmediateAppendCommandListsExp.
constexpr uint32_t MinDriverVersion = 30898;
bool DriverSupportsImmediateAppend =
Context->getPlatform()->isDriverVersionNewerOrSimilar(1, 3,
MinDriverVersion);
Context->getPlatform()->ZeCommandListImmediateAppendExt.Supported;

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

Expand Down Expand Up @@ -1569,7 +1562,10 @@ ur_result_t enqueueImmediateAppendPath(
ur_event_handle_t *Event, ur_command_list_ptr_t CommandListHelper,
bool DoProfiling) {

ur_platform_handle_t Platform = CommandBuffer->Context->getPlatform();

assert(CommandListHelper->second.IsImmediate);
assert(Platform->ZeCommandListImmediateAppendExt.Supported);

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

ZE2UR_CALL(zeCommandListImmediateAppendCommandListsExp,
ZE2UR_CALL(Platform->ZeCommandListImmediateAppendExt
.zeCommandListImmediateAppendCommandListsExp,
(ZeCopyEngineImmediateListHelper->first, 1,
&CommandBuffer->ZeCopyCommandList, nullptr,
UrZeEventList.Length, UrZeEventList.ZeEventList));
Expand All @@ -1599,7 +1596,8 @@ ur_result_t enqueueImmediateAppendPath(
ze_event_handle_t &EventToSignal =
DoProfiling ? CommandBuffer->ComputeFinishedEvent->ZeEvent
: (*Event)->ZeEvent;
ZE2UR_CALL(zeCommandListImmediateAppendCommandListsExp,
ZE2UR_CALL(Platform->ZeCommandListImmediateAppendExt
.zeCommandListImmediateAppendCommandListsExp,
(CommandListHelper->first, 1, &CommandBuffer->ZeComputeCommandList,
EventToSignal, WaitList.Length, WaitList.ZeEventList));

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

ZE2UR_CALL(zeCommandListImmediateAppendCommandListsExp,
ZE2UR_CALL(Platform->ZeCommandListImmediateAppendExt
.zeCommandListImmediateAppendCommandListsExp,
(CommandListHelper->first, 1,
&CommandBuffer->ZeCommandListResetEvents, nullptr, 0, nullptr));
}
Expand Down
24 changes: 24 additions & 0 deletions source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ ur_result_t ur_platform_handle_t_::initialize() {

bool MutableCommandListSpecExtensionSupported = false;
bool ZeIntelExternalSemaphoreExtensionSupported = false;
bool ZeImmediateCommandListAppendExtensionFound = false;
for (auto &extension : ZeExtensions) {
// Check if global offset extension is available
if (strncmp(extension.name, ZE_GLOBAL_OFFSET_EXP_NAME,
Expand All @@ -248,6 +249,14 @@ ur_result_t ur_platform_handle_t_::initialize() {
ZeDriverEventPoolCountingEventsExtensionFound = true;
}
}
// Check if the ImmediateAppendCommandLists extension is available.
if (strncmp(extension.name, ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME,
strlen(ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_NAME) + 1) == 0) {
if (extension.version ==
ZE_IMMEDIATE_COMMAND_LIST_APPEND_EXP_VERSION_CURRENT) {
ZeImmediateCommandListAppendExtensionFound = true;
}
}
// Check if extension is available for Mutable Command List v1.1.
if (strncmp(extension.name, ZE_MUTABLE_COMMAND_LIST_EXP_NAME,
strlen(ZE_MUTABLE_COMMAND_LIST_EXP_NAME) + 1) == 0) {
Expand Down Expand Up @@ -427,6 +436,21 @@ ur_result_t ur_platform_handle_t_::initialize() {
&ZeMutableCmdListExt
.zexCommandListGetNextCommandIdWithKernelsExp))) == 0);
}

// Check if ImmediateAppendCommandList is supported and initialize the
// function pointer.
if (ZeImmediateCommandListAppendExtensionFound) {
ZeCommandListImmediateAppendExt
.zeCommandListImmediateAppendCommandListsExp =
(ze_pfnCommandListImmediateAppendCommandListsExp_t)
ur_loader::LibLoader::getFunctionPtr(
GlobalAdapter->processHandle,
"zeCommandListImmediateAppendCommandListsExp");
ZeCommandListImmediateAppendExt.Supported =
ZeCommandListImmediateAppendExt
.zeCommandListImmediateAppendCommandListsExp != nullptr;
}

return UR_RESULT_SUCCESS;
}

Expand Down
9 changes: 8 additions & 1 deletion source/adapters/level_zero/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,11 @@ struct ur_platform_handle_t_ : public _ur_platform {
ze_result_t (*zexDeviceReleaseExternalSemaphoreExp)(
ze_intel_external_semaphore_exp_handle_t);
} ZeExternalSemaphoreExt;
};

struct ZeCommandListImmediateAppendExtension {
bool Supported = false;
ze_result_t (*zeCommandListImmediateAppendCommandListsExp)(
ze_command_list_handle_t, uint32_t, ze_command_list_handle_t *,
ze_event_handle_t, uint32_t, ze_event_handle_t *);
} ZeCommandListImmediateAppendExt;
};

0 comments on commit 232e62f

Please sign in to comment.