From 6ba65403fbe6e25c2947e7c10a671b8d3f3ad208 Mon Sep 17 00:00:00 2001 From: "Neil R. Spruit" Date: Tue, 19 Nov 2024 08:09:02 -0800 Subject: [PATCH] [L0] Add support for the MCL 1.1 apis thru the spec extensions - Use the MCL 1.1 spec extensions instead of the driver experimental extensions when available. Signed-off-by: Neil R. Spruit --- source/adapters/level_zero/adapter.cpp | 16 +++- source/adapters/level_zero/adapter.hpp | 1 + source/adapters/level_zero/platform.cpp | 110 ++++++++++++++++-------- source/adapters/level_zero/platform.hpp | 1 + 4 files changed, 86 insertions(+), 42 deletions(-) diff --git a/source/adapters/level_zero/adapter.cpp b/source/adapters/level_zero/adapter.cpp index cba63dcc6b..8995a5e25b 100644 --- a/source/adapters/level_zero/adapter.cpp +++ b/source/adapters/level_zero/adapter.cpp @@ -407,6 +407,14 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() return; } + // Dynamically load the new L0 SysMan separate init and new EXP apis + // separately. This must be done to avoid attempting to use symbols that do + // not exist in older loader runtimes. +#ifdef _WIN32 + GlobalAdapter->processHandle = GetModuleHandle(NULL); +#else + GlobalAdapter->processHandle = nullptr; +#endif // Check if the user has enabled the default L0 SysMan initialization. const int UrSysmanZesinitEnable = [] { @@ -422,13 +430,13 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() GlobalAdapter->getDeviceByUUIdFunctionPtr = (zes_pfnDriverGetDeviceByUuidExp_t) ur_loader::LibLoader::getFunctionPtr( - processHandle, "zesDriverGetDeviceByUuidExp"); + GlobalAdapter->processHandle, "zesDriverGetDeviceByUuidExp"); GlobalAdapter->getSysManDriversFunctionPtr = (zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr( - processHandle, "zesDriverGet"); + GlobalAdapter->processHandle, "zesDriverGet"); GlobalAdapter->sysManInitFunctionPtr = - (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(processHandle, - "zesInit"); + (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr( + GlobalAdapter->processHandle, "zesInit"); } if (GlobalAdapter->getDeviceByUUIdFunctionPtr && GlobalAdapter->getSysManDriversFunctionPtr && diff --git a/source/adapters/level_zero/adapter.hpp b/source/adapters/level_zero/adapter.hpp index 51398abbb2..277d2334b9 100644 --- a/source/adapters/level_zero/adapter.hpp +++ b/source/adapters/level_zero/adapter.hpp @@ -45,6 +45,7 @@ struct ur_adapter_handle_t_ { std::optional ZesResult; ZeCache> PlatformCache; logger::Logger &logger; + HMODULE processHandle = nullptr; }; extern ur_adapter_handle_t_ *GlobalAdapter; diff --git a/source/adapters/level_zero/platform.cpp b/source/adapters/level_zero/platform.cpp index 1e65e55048..520b52a1c8 100644 --- a/source/adapters/level_zero/platform.cpp +++ b/source/adapters/level_zero/platform.cpp @@ -220,6 +220,7 @@ ur_result_t ur_platform_handle_t_::initialize() { ZE2UR_CALL(zeDriverGetExtensionProperties, (ZeDriver, &Count, ZeExtensions.data())); + bool MutableCommandListSpecExtensionSupported = false; for (auto &extension : ZeExtensions) { // Check if global offset extension is available if (strncmp(extension.name, ZE_GLOBAL_OFFSET_EXP_NAME, @@ -244,13 +245,11 @@ 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) { - zeDriverImmediateCommandListAppendFound = 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) { + if (extension.version == ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_1) { + MutableCommandListSpecExtensionSupported = true; } } zeDriverExtensionMap[extension.name] = extension.version; @@ -289,37 +288,72 @@ ur_result_t ur_platform_handle_t_::initialize() { // Check if mutable command list extension is supported and initialize // function pointers. - ZeMutableCmdListExt.Supported |= - (ZE_CALL_NOCHECK( - zeDriverGetExtensionFunctionAddress, - (ZeDriver, "zeCommandListGetNextCommandIdExp", - reinterpret_cast( - &ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp))) == 0); - - ZeMutableCmdListExt.Supported &= - (ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress, - (ZeDriver, "zeCommandListUpdateMutableCommandsExp", - reinterpret_cast( - &ZeMutableCmdListExt - .zexCommandListUpdateMutableCommandsExp))) == - 0); - - ZeMutableCmdListExt.Supported &= - (ZE_CALL_NOCHECK( - zeDriverGetExtensionFunctionAddress, - (ZeDriver, "zeCommandListUpdateMutableCommandSignalEventExp", - reinterpret_cast( - &ZeMutableCmdListExt - .zexCommandListUpdateMutableCommandSignalEventExp))) == 0); - - ZeMutableCmdListExt.Supported &= - (ZE_CALL_NOCHECK( - zeDriverGetExtensionFunctionAddress, - (ZeDriver, "zeCommandListUpdateMutableCommandWaitEventsExp", - reinterpret_cast( - &ZeMutableCmdListExt - .zexCommandListUpdateMutableCommandWaitEventsExp))) == 0); - + if (MutableCommandListSpecExtensionSupported) { + ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp = + (ze_pfnCommandListGetNextCommandIdExp_t) + ur_loader::LibLoader::getFunctionPtr( + GlobalAdapter->processHandle, + "zeCommandListGetNextCommandIdExp"); + ZeMutableCmdListExt.Supported |= + ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp != nullptr; + ZeMutableCmdListExt.zexCommandListUpdateMutableCommandsExp = + (ze_pfnCommandListUpdateMutableCommandsExp_t) + ur_loader::LibLoader::getFunctionPtr( + GlobalAdapter->processHandle, + "zeCommandListUpdateMutableCommandsExp"); + ZeMutableCmdListExt.Supported |= + ZeMutableCmdListExt.zexCommandListUpdateMutableCommandsExp != nullptr; + ZeMutableCmdListExt.zexCommandListUpdateMutableCommandSignalEventExp = + (ze_pfnCommandListUpdateMutableCommandSignalEventExp_t) + ur_loader::LibLoader::getFunctionPtr( + GlobalAdapter->processHandle, + "zeCommandListUpdateMutableCommandSignalEventExp"); + ZeMutableCmdListExt.Supported |= + ZeMutableCmdListExt.zexCommandListUpdateMutableCommandSignalEventExp != + nullptr; + ZeMutableCmdListExt.zexCommandListUpdateMutableCommandWaitEventsExp = + (ze_pfnCommandListUpdateMutableCommandWaitEventsExp_t) + ur_loader::LibLoader::getFunctionPtr( + GlobalAdapter->processHandle, + "zeCommandListUpdateMutableCommandWaitEventsExp"); + ZeMutableCmdListExt.Supported |= + ZeMutableCmdListExt.zexCommandListUpdateMutableCommandWaitEventsExp != + nullptr; + } else { + ZeMutableCmdListExt.Supported |= + (ZE_CALL_NOCHECK( + zeDriverGetExtensionFunctionAddress, + (ZeDriver, "zeCommandListGetNextCommandIdExp", + reinterpret_cast( + &ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp))) == + 0); + + ZeMutableCmdListExt.Supported &= + (ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress, + (ZeDriver, "zeCommandListUpdateMutableCommandsExp", + reinterpret_cast( + &ZeMutableCmdListExt + .zexCommandListUpdateMutableCommandsExp))) == + 0); + + ZeMutableCmdListExt.Supported &= + (ZE_CALL_NOCHECK( + zeDriverGetExtensionFunctionAddress, + (ZeDriver, "zeCommandListUpdateMutableCommandSignalEventExp", + reinterpret_cast( + &ZeMutableCmdListExt + .zexCommandListUpdateMutableCommandSignalEventExp))) == + 0); + + ZeMutableCmdListExt.Supported &= + (ZE_CALL_NOCHECK( + zeDriverGetExtensionFunctionAddress, + (ZeDriver, "zeCommandListUpdateMutableCommandWaitEventsExp", + reinterpret_cast( + &ZeMutableCmdListExt + .zexCommandListUpdateMutableCommandWaitEventsExp))) == + 0); + } return UR_RESULT_SUCCESS; } diff --git a/source/adapters/level_zero/platform.hpp b/source/adapters/level_zero/platform.hpp index 515f71b8c4..413bb5c48a 100644 --- a/source/adapters/level_zero/platform.hpp +++ b/source/adapters/level_zero/platform.hpp @@ -12,6 +12,7 @@ #include "common.hpp" #include "ur_api.h" #include "ze_api.h" +#include "ze_ddi.h" #include "zes_api.h" struct ur_device_handle_t_;