@@ -120,6 +120,43 @@ ur_result_t initPlatforms(PlatformVec &platforms,
120120
121121ur_result_t adapterStateInit () { return UR_RESULT_SUCCESS; }
122122
123+ /*
124+ This constructor initializes the `ur_adapter_handle_t_` object and
125+ sets up the environment for Level Zero (L0) initialization.
126+ The behavior of the initialization process is influenced by two
127+ environment variables:
128+ `UR_L0_ENABLE_SYSMAN_ENV_DEFAULT` and `UR_L0_ENABLE_ZESINIT_DEFAULT`.
129+
130+ | Environment Variable | Value | Behavior |
131+ |--------------------------------|-------|----------------------------|
132+ | UR_L0_ENABLE_SYSMAN_ENV_DEFAULT| 1 | Enables the default SysMan |
133+ | | | environment initialization |
134+ | | | by setting |
135+ | | | `ZES_ENABLE_SYSMAN` to "1".|
136+ | | 0 | Disables the default SysMan|
137+ | | | environment initialization.|
138+ | | unset | Defaults to 1, enabling the|
139+ | | | SysMan environment |
140+ | | | initialization. |
141+ | UR_L0_ENABLE_ZESINIT_DEFAULT | 1 | Enables the default SysMan |
142+ | | | initialization by loading |
143+ | | | SysMan-related functions |
144+ | | | and calling `zesInit`. |
145+ | | 0 | Disables the default SysMan|
146+ | | | initialization with zesInit|
147+ | | unset | Defaults to 0, disabling |
148+ | | | the SysMan initialization |
149+ | | | thru zesInit. |
150+
151+ Behavior Summary:
152+ - If `UR_L0_ENABLE_SYSMAN_ENV_DEFAULT` is set to 1 or is unset,
153+ `ZES_ENABLE_SYSMAN` is set to "1".
154+ - If `UR_L0_ENABLE_ZESINIT_DEFAULT` is set to 1 and
155+ `UR_L0_ENABLE_SYSMAN_ENV_DEFAULT` is not set to 1,
156+ SysMan-related functions are loaded and `zesInit` is called.
157+ - If `UR_L0_ENABLE_ZESINIT_DEFAULT` is set to 0 or is unset,
158+ SysMan initialization is skipped.
159+ */
123160ur_adapter_handle_t_::ur_adapter_handle_t_ ()
124161 : logger(logger::get_logger(" level_zero" )) {
125162
@@ -145,6 +182,14 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
145182 return ;
146183 }
147184
185+ // Check if the user has disabled the default L0 Env initialization.
186+ const int UrSysManEnvInitEnabled = [] {
187+ const char *UrRet = std::getenv (" UR_L0_ENABLE_SYSMAN_ENV_DEFAULT" );
188+ if (!UrRet)
189+ return 1 ;
190+ return std::atoi (UrRet);
191+ }();
192+
148193 // initialize level zero only once.
149194 if (GlobalAdapter->ZeResult == std::nullopt ) {
150195 // Setting these environment variables before running zeInit will enable
@@ -172,6 +217,11 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
172217 if (UrL0InitAllDrivers) {
173218 L0InitFlags |= ZE_INIT_FLAG_VPU_ONLY;
174219 }
220+
221+ // Set ZES_ENABLE_SYSMAN by default if the user has not set it.
222+ if (UrSysManEnvInitEnabled) {
223+ setEnvVar (" ZES_ENABLE_SYSMAN" , " 1" );
224+ }
175225 logger::debug (" \n zeInit with flags value of {}\n " ,
176226 static_cast <int >(L0InitFlags));
177227 GlobalAdapter->ZeResult = ZE_CALL_NOCHECK (zeInit, (L0InitFlags));
@@ -199,15 +249,29 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
199249#else
200250 HMODULE processHandle = nullptr ;
201251#endif
202- GlobalAdapter->getDeviceByUUIdFunctionPtr =
203- (zes_pfnDriverGetDeviceByUuidExp_t)ur_loader::LibLoader::getFunctionPtr (
204- processHandle, " zesDriverGetDeviceByUuidExp" );
205- GlobalAdapter->getSysManDriversFunctionPtr =
206- (zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr (
207- processHandle, " zesDriverGet" );
208- GlobalAdapter->sysManInitFunctionPtr =
209- (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr (processHandle,
210- " zesInit" );
252+
253+ // Check if the user has enabled the default L0 SysMan initialization.
254+ const int UrSysmanZesinitEnable = [] {
255+ const char *UrRet = std::getenv (" UR_L0_ENABLE_ZESINIT_DEFAULT" );
256+ if (!UrRet)
257+ return 0 ;
258+ return std::atoi (UrRet);
259+ }();
260+
261+ // Enable zesInit by default only if ZES_ENABLE_SYSMAN has not been set by
262+ // default and UrSysmanZesinitEnable is true.
263+ if (UrSysmanZesinitEnable && !UrSysManEnvInitEnabled) {
264+ GlobalAdapter->getDeviceByUUIdFunctionPtr =
265+ (zes_pfnDriverGetDeviceByUuidExp_t)
266+ ur_loader::LibLoader::getFunctionPtr (
267+ processHandle, " zesDriverGetDeviceByUuidExp" );
268+ GlobalAdapter->getSysManDriversFunctionPtr =
269+ (zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr (
270+ processHandle, " zesDriverGet" );
271+ GlobalAdapter->sysManInitFunctionPtr =
272+ (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr (processHandle,
273+ " zesInit" );
274+ }
211275 if (GlobalAdapter->getDeviceByUUIdFunctionPtr &&
212276 GlobalAdapter->getSysManDriversFunctionPtr &&
213277 GlobalAdapter->sysManInitFunctionPtr ) {
0 commit comments