Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[L0] Update UR to link the Loader as static #2667

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/multi_device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ jobs:
run: cmake --build ${{github.workspace}}/build -j $(nproc)

- name: Test adapter specific
env:
ZE_DEBUG: 1
ZE_ENABLE_LOADER_DEBUG_TRACE: 1
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -L "adapter-specific" --timeout 180

- name: Test adapters
env:
ZE_DEBUG: 1
ZE_ENABLE_LOADER_DEBUG_TRACE: 1
working-directory: ${{github.workspace}}/build
run: env UR_CTS_ADAPTER_PLATFORM="${{matrix.adapter.platform}}" ctest -C ${{matrix.build_type}} --output-on-failure -L "conformance" -E "exp_command_buffer" --timeout 180
5 changes: 3 additions & 2 deletions cmake/FetchLevelZero.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ 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()
set(BUILD_STATIC ON)

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 dc17e65e99fb4b2382567076098b2c5989b73de7)
endif()

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

target_compile_definitions(ur_adapter_level_zero PUBLIC UR_STATIC_LEVEL_ZERO)
if(UR_STATIC_ADAPTER_L0)
target_compile_definitions(ur_adapter_level_zero PUBLIC UR_STATIC_ADAPTER_LEVEL_ZERO)

# '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_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_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_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_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
4 changes: 2 additions & 2 deletions source/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ target_include_directories(ur_common PUBLIC

message(STATUS "Download Unified Memory Framework from github.com")
if (NOT DEFINED UMF_REPO)
set(UMF_REPO "https://github.com/oneapi-src/unified-memory-framework.git")
set(UMF_REPO "https://github.com/igchor/unified-memory-framework.git")
endif()

if (NOT DEFINED UMF_TAG)
# commit ace9f4a60b686463fdad15cd016c548237cb79e0
# Author: Rafał Rudnicki <[email protected]>
# Date: Mon Feb 10 11:39:15 2025 +0100
# Merge pull request #1088 from ldorau/Fix_remove_CUDA_ERROR_INVALID_RESOURCE_TYPE
set(UMF_TAG ace9f4a60b686463fdad15cd016c548237cb79e0)
set(UMF_TAG 05d5f1a190f209794979daae22dd7daf7b66be44)
endif()

message(STATUS "Will fetch Unified Memory Framework from ${UMF_REPO}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ TEST_P(urLevelZeroKernelNativeHandleTest, OwnedHandleRelease) {

auto kernel_name =
uur::KernelsEnvironment::instance->GetEntryPointNames("foo")[0];

ze_init_driver_type_desc_t desc = {};
desc.stype = ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC;
desc.flags = ZE_INIT_DRIVER_TYPE_FLAG_GPU;
desc.pNext = nullptr;
uint32_t pCount = 0;
zeInitDrivers(&pCount, nullptr, &desc);
ze_module_desc_t moduleDesc{};
moduleDesc.stype = ZE_STRUCTURE_TYPE_MODULE_DESC;
moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
Expand Down
Loading