From a6cd1cfe41efb1e1bdf94a7c2d9f6e7ccd62aed0 Mon Sep 17 00:00:00 2001 From: Piotr Balcer Date: Mon, 28 Oct 2024 16:29:45 +0100 Subject: [PATCH 1/2] Merge pull request #2242 from nrspruit/sysman_env_disable [L0] Enable Sysman Thru Env by default and have zesInit be optional --- source/adapters/level_zero/adapter.cpp | 82 +++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 9 deletions(-) diff --git a/source/adapters/level_zero/adapter.cpp b/source/adapters/level_zero/adapter.cpp index d35d999d7b..75bd91934a 100644 --- a/source/adapters/level_zero/adapter.cpp +++ b/source/adapters/level_zero/adapter.cpp @@ -120,6 +120,43 @@ ur_result_t initPlatforms(PlatformVec &platforms, ur_result_t adapterStateInit() { return UR_RESULT_SUCCESS; } +/* +This constructor initializes the `ur_adapter_handle_t_` object and +sets up the environment for Level Zero (L0) initialization. +The behavior of the initialization process is influenced by two +environment variables: +`UR_L0_ENABLE_SYSMAN_ENV_DEFAULT` and `UR_L0_ENABLE_ZESINIT_DEFAULT`. + +| Environment Variable | Value | Behavior | +|--------------------------------|-------|----------------------------| +| UR_L0_ENABLE_SYSMAN_ENV_DEFAULT| 1 | Enables the default SysMan | +| | | environment initialization | +| | | by setting | +| | | `ZES_ENABLE_SYSMAN` to "1".| +| | 0 | Disables the default SysMan| +| | | environment initialization.| +| | unset | Defaults to 1, enabling the| +| | | SysMan environment | +| | | initialization. | +| UR_L0_ENABLE_ZESINIT_DEFAULT | 1 | Enables the default SysMan | +| | | initialization by loading | +| | | SysMan-related functions | +| | | and calling `zesInit`. | +| | 0 | Disables the default SysMan| +| | | initialization with zesInit| +| | unset | Defaults to 0, disabling | +| | | the SysMan initialization | +| | | thru zesInit. | + +Behavior Summary: +- If `UR_L0_ENABLE_SYSMAN_ENV_DEFAULT` is set to 1 or is unset, + `ZES_ENABLE_SYSMAN` is set to "1". +- If `UR_L0_ENABLE_ZESINIT_DEFAULT` is set to 1 and + `UR_L0_ENABLE_SYSMAN_ENV_DEFAULT` is not set to 1, + SysMan-related functions are loaded and `zesInit` is called. +- If `UR_L0_ENABLE_ZESINIT_DEFAULT` is set to 0 or is unset, + SysMan initialization is skipped. +*/ ur_adapter_handle_t_::ur_adapter_handle_t_() : logger(logger::get_logger("level_zero")) { @@ -145,6 +182,14 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() return; } + // Check if the user has disabled the default L0 Env initialization. + const int UrSysManEnvInitEnabled = [] { + const char *UrRet = std::getenv("UR_L0_ENABLE_SYSMAN_ENV_DEFAULT"); + if (!UrRet) + return 1; + return std::atoi(UrRet); + }(); + // initialize level zero only once. if (GlobalAdapter->ZeResult == std::nullopt) { // Setting these environment variables before running zeInit will enable @@ -172,6 +217,11 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() if (UrL0InitAllDrivers) { L0InitFlags |= ZE_INIT_FLAG_VPU_ONLY; } + + // Set ZES_ENABLE_SYSMAN by default if the user has not set it. + if (UrSysManEnvInitEnabled) { + setEnvVar("ZES_ENABLE_SYSMAN", "1"); + } logger::debug("\nzeInit with flags value of {}\n", static_cast(L0InitFlags)); GlobalAdapter->ZeResult = ZE_CALL_NOCHECK(zeInit, (L0InitFlags)); @@ -199,15 +249,29 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() #else HMODULE processHandle = nullptr; #endif - GlobalAdapter->getDeviceByUUIdFunctionPtr = - (zes_pfnDriverGetDeviceByUuidExp_t)ur_loader::LibLoader::getFunctionPtr( - processHandle, "zesDriverGetDeviceByUuidExp"); - GlobalAdapter->getSysManDriversFunctionPtr = - (zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr( - processHandle, "zesDriverGet"); - GlobalAdapter->sysManInitFunctionPtr = - (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(processHandle, - "zesInit"); + + // Check if the user has enabled the default L0 SysMan initialization. + const int UrSysmanZesinitEnable = [] { + const char *UrRet = std::getenv("UR_L0_ENABLE_ZESINIT_DEFAULT"); + if (!UrRet) + return 0; + return std::atoi(UrRet); + }(); + + // Enable zesInit by default only if ZES_ENABLE_SYSMAN has not been set by + // default and UrSysmanZesinitEnable is true. + if (UrSysmanZesinitEnable && !UrSysManEnvInitEnabled) { + GlobalAdapter->getDeviceByUUIdFunctionPtr = + (zes_pfnDriverGetDeviceByUuidExp_t) + ur_loader::LibLoader::getFunctionPtr( + processHandle, "zesDriverGetDeviceByUuidExp"); + GlobalAdapter->getSysManDriversFunctionPtr = + (zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr( + processHandle, "zesDriverGet"); + GlobalAdapter->sysManInitFunctionPtr = + (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr(processHandle, + "zesInit"); + } if (GlobalAdapter->getDeviceByUUIdFunctionPtr && GlobalAdapter->getSysManDriversFunctionPtr && GlobalAdapter->sysManInitFunctionPtr) { From 3b5fb34895115e752afa80b9cfa340adda1204af Mon Sep 17 00:00:00 2001 From: "Neil R. Spruit" Date: Mon, 28 Oct 2024 10:09:49 -0700 Subject: [PATCH 2/2] Set version to v0.10.10 Signed-off-by: Neil R. Spruit --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d04d8d5dae..d3707f4879 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception cmake_minimum_required(VERSION 3.20.0 FATAL_ERROR) -project(unified-runtime VERSION 0.10.9) +project(unified-runtime VERSION 0.10.10) # Check if unified runtime is built as a standalone project. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR UR_STANDALONE_BUILD)