diff --git a/source/adapters/level_zero/command_buffer.cpp b/source/adapters/level_zero/command_buffer.cpp index b96aeeede9..c4d9614159 100644 --- a/source/adapters/level_zero/command_buffer.cpp +++ b/source/adapters/level_zero/command_buffer.cpp @@ -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 @@ -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(); } @@ -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) { @@ -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)); @@ -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)); @@ -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)); } diff --git a/source/adapters/level_zero/platform.cpp b/source/adapters/level_zero/platform.cpp index 6ae1deaabc..26b5a03ed6 100644 --- a/source/adapters/level_zero/platform.cpp +++ b/source/adapters/level_zero/platform.cpp @@ -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, @@ -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) { @@ -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; } diff --git a/source/adapters/level_zero/platform.hpp b/source/adapters/level_zero/platform.hpp index 748460158c..0faa122651 100644 --- a/source/adapters/level_zero/platform.hpp +++ b/source/adapters/level_zero/platform.hpp @@ -134,4 +134,11 @@ struct ur_platform_handle_t_ : public _ur_platform { ze_result_t (*zexDeviceReleaseExternalSemaphoreExp)( ze_intel_external_semaphore_exp_handle_t); } ZeExternalSemaphoreExt; -}; \ No newline at end of file + + 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; +};