Skip to content

Commit

Permalink
[L0] Update UR to link the Loader as static
Browse files Browse the repository at this point in the history
Signed-off-by: Neil R. Spruit <[email protected]>
  • Loading branch information
nrspruit committed Feb 7, 2025
1 parent 95e03b4 commit b107caa
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
7 changes: 5 additions & 2 deletions cmake/FetchLevelZero.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat-extra-semi")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
endif()
if(UR_STATIC_ADAPTER_L0)
set(BUILD_STATIC ON)
endif()

if (UR_LEVEL_ZERO_LOADER_REPO STREQUAL "")
set(UR_LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
set(UR_LEVEL_ZERO_LOADER_REPO "https://github.com/nrspruit/level-zero.git")
endif()
if (UR_LEVEL_ZERO_LOADER_TAG STREQUAL "")
set(UR_LEVEL_ZERO_LOADER_TAG v1.19.2)
set(UR_LEVEL_ZERO_LOADER_TAG 57295a21ab26f1e3b3ad5e7198a6d787fcb0e71c)
endif()

# Disable due to a bug https://github.com/oneapi-src/level-zero/issues/104
Expand Down
4 changes: 2 additions & 2 deletions source/adapters/level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ if(UR_BUILD_ADAPTER_L0)

# 'utils' target from 'level-zero-loader' includes path which is prefixed
# in the source directory, this breaks the installation of 'utils' target.
set_target_properties(utils PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
install(TARGETS ur_umf LevelZeroLoader LevelZeroLoader-Headers ComputeRuntimeLevelZero-Headers ze_loader utils
set_target_properties(level_zero_utils PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
install(TARGETS ur_umf LevelZeroLoader LevelZeroLoader-Headers ComputeRuntimeLevelZero-Headers ze_loader level_zero_utils
EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
26 changes: 15 additions & 11 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,12 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
// Dynamically load the new L0 apis separately.
// This must be done to avoid attempting to use symbols that do
// not exist in older loader runtimes.
#ifndef UR_STATIC_ADAPTER_LEVEL_ZERO
#ifdef _WIN32
HMODULE processHandle = GetModuleHandle(NULL);
GlobalAdapter->processHandle = GetModuleHandle(NULL);
#else
HMODULE processHandle = nullptr;
GlobalAdapter->processHandle = nullptr;
#endif
#endif

// initialize level zero only once.
Expand Down Expand Up @@ -412,9 +414,13 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
}

if (useInitDrivers) {
#ifdef UR_STATIC_ADAPTER_LEVEL_ZERO
GlobalAdapter->initDriversFunctionPtr = zeInitDrivers;
#else
GlobalAdapter->initDriversFunctionPtr =
(ze_pfnInitDrivers_t)ur_loader::LibLoader::getFunctionPtr(
processHandle, "zeInitDrivers");
GlobalAdapter->processHandle, "zeInitDrivers");
#endif
if (GlobalAdapter->initDriversFunctionPtr) {
logger::debug("\nzeInitDrivers with flags value of {}\n",
static_cast<int>(GlobalAdapter->InitDriversDesc.flags));
Expand Down Expand Up @@ -455,14 +461,6 @@ 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 = [&UserForcedSysManInit] {
Expand All @@ -484,6 +482,11 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
ZesInitNeeded = true;
}
if (ZesInitNeeded) {
#ifdef UR_STATIC_ADAPTER_LEVEL_ZERO
GlobalAdapter->getDeviceByUUIdFunctionPtr = zesDriverGetDeviceByUuidExp;
GlobalAdapter->getSysManDriversFunctionPtr = zesDriverGet;
GlobalAdapter->sysManInitFunctionPtr = zesInit;
#else
GlobalAdapter->getDeviceByUUIdFunctionPtr =
(zes_pfnDriverGetDeviceByUuidExp_t)
ur_loader::LibLoader::getFunctionPtr(
Expand All @@ -494,6 +497,7 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
GlobalAdapter->sysManInitFunctionPtr =
(zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(
GlobalAdapter->processHandle, "zesInit");
#endif
}
if (GlobalAdapter->getDeviceByUUIdFunctionPtr &&
GlobalAdapter->getSysManDriversFunctionPtr &&
Expand Down
41 changes: 28 additions & 13 deletions source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,52 +345,67 @@ ur_result_t ur_platform_handle_t_::initialize() {
// Check if mutable command list extension is supported and initialize
// function pointers.
if (MutableCommandListSpecExtensionSupported) {
#ifdef UR_STATIC_ADAPTER_LEVEL_ZERO
ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp =
zeCommandListGetNextCommandIdExp;
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandsExp =
zeCommandListUpdateMutableCommandsExp;
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandSignalEventExp =
zeCommandListUpdateMutableCommandSignalEventExp;
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandWaitEventsExp =
zeCommandListUpdateMutableCommandWaitEventsExp;
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandKernelsExp =
zeCommandListUpdateMutableCommandKernelsExp;
ZeMutableCmdListExt.zexCommandListGetNextCommandIdWithKernelsExp =
zeCommandListGetNextCommandIdWithKernelsExp;
#else
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;
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandKernelsExp =
(ze_pfnCommandListUpdateMutableCommandKernelsExp_t)
ur_loader::LibLoader::getFunctionPtr(
GlobalAdapter->processHandle,
"zeCommandListUpdateMutableCommandKernelsExp");
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandKernelsExp !=
nullptr;
ZeMutableCmdListExt.zexCommandListGetNextCommandIdWithKernelsExp =
(ze_pfnCommandListGetNextCommandIdWithKernelsExp_t)
ur_loader::LibLoader::getFunctionPtr(
GlobalAdapter->processHandle,
"zeCommandListGetNextCommandIdWithKernelsExp");
#endif
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListGetNextCommandIdExp != nullptr;
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListGetNextCommandIdWithKernelsExp !=
nullptr;
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandKernelsExp !=
nullptr;
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandWaitEventsExp !=
nullptr;
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandSignalEventExp !=
nullptr;
ZeMutableCmdListExt.Supported |=
ZeMutableCmdListExt.zexCommandListUpdateMutableCommandsExp != nullptr;
ZeMutableCmdListExt.LoaderExtension = true;
} else {
ZeMutableCmdListExt.Supported |=
Expand Down

0 comments on commit b107caa

Please sign in to comment.