@@ -144,6 +144,43 @@ ur_result_t adapterStateInit() {
144
144
return UR_RESULT_SUCCESS;
145
145
}
146
146
147
+ /*
148
+ This constructor initializes the `ur_adapter_handle_t_` object and
149
+ sets up the environment for Level Zero (L0) initialization.
150
+ The behavior of the initialization process is influenced by two
151
+ environment variables:
152
+ `UR_L0_ENABLE_SYSMAN_ENV_DEFAULT` and `UR_L0_ENABLE_ZESINIT_DEFAULT`.
153
+
154
+ | Environment Variable | Value | Behavior |
155
+ |--------------------------------|-------|----------------------------|
156
+ | UR_L0_ENABLE_SYSMAN_ENV_DEFAULT| 1 | Enables the default SysMan |
157
+ | | | environment initialization |
158
+ | | | by setting |
159
+ | | | `ZES_ENABLE_SYSMAN` to "1".|
160
+ | | 0 | Disables the default SysMan|
161
+ | | | environment initialization.|
162
+ | | unset | Defaults to 1, enabling the|
163
+ | | | SysMan environment |
164
+ | | | initialization. |
165
+ | UR_L0_ENABLE_ZESINIT_DEFAULT | 1 | Enables the default SysMan |
166
+ | | | initialization by loading |
167
+ | | | SysMan-related functions |
168
+ | | | and calling `zesInit`. |
169
+ | | 0 | Disables the default SysMan|
170
+ | | | initialization with zesInit|
171
+ | | unset | Defaults to 0, disabling |
172
+ | | | the SysMan initialization |
173
+ | | | thru zesInit. |
174
+
175
+ Behavior Summary:
176
+ - If `UR_L0_ENABLE_SYSMAN_ENV_DEFAULT` is set to 1 or is unset,
177
+ `ZES_ENABLE_SYSMAN` is set to "1".
178
+ - If `UR_L0_ENABLE_ZESINIT_DEFAULT` is set to 1 and
179
+ `UR_L0_ENABLE_SYSMAN_ENV_DEFAULT` is not set to 1,
180
+ SysMan-related functions are loaded and `zesInit` is called.
181
+ - If `UR_L0_ENABLE_ZESINIT_DEFAULT` is set to 0 or is unset,
182
+ SysMan initialization is skipped.
183
+ */
147
184
ur_adapter_handle_t_::ur_adapter_handle_t_ ()
148
185
: logger(logger::get_logger(" level_zero" )) {
149
186
@@ -169,6 +206,14 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
169
206
return ;
170
207
}
171
208
209
+ // Check if the user has disabled the default L0 Env initialization.
210
+ const int UrSysManEnvInitEnabled = [] {
211
+ const char *UrRet = std::getenv (" UR_L0_ENABLE_SYSMAN_ENV_DEFAULT" );
212
+ if (!UrRet)
213
+ return 1 ;
214
+ return std::atoi (UrRet);
215
+ }();
216
+
172
217
// initialize level zero only once.
173
218
if (GlobalAdapter->ZeResult == std::nullopt) {
174
219
// Setting these environment variables before running zeInit will enable
@@ -196,6 +241,11 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
196
241
if (UrL0InitAllDrivers) {
197
242
L0InitFlags |= ZE_INIT_FLAG_VPU_ONLY;
198
243
}
244
+
245
+ // Set ZES_ENABLE_SYSMAN by default if the user has not set it.
246
+ if (UrSysManEnvInitEnabled) {
247
+ setEnvVar (" ZES_ENABLE_SYSMAN" , " 1" );
248
+ }
199
249
logger::debug (" \n zeInit with flags value of {}\n " ,
200
250
static_cast <int >(L0InitFlags));
201
251
GlobalAdapter->ZeResult = ZE_CALL_NOCHECK (zeInit, (L0InitFlags));
@@ -223,15 +273,29 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
223
273
#else
224
274
HMODULE processHandle = nullptr ;
225
275
#endif
226
- GlobalAdapter->getDeviceByUUIdFunctionPtr =
227
- (zes_pfnDriverGetDeviceByUuidExp_t)ur_loader::LibLoader::getFunctionPtr (
228
- processHandle, " zesDriverGetDeviceByUuidExp" );
229
- GlobalAdapter->getSysManDriversFunctionPtr =
230
- (zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr (
231
- processHandle, " zesDriverGet" );
232
- GlobalAdapter->sysManInitFunctionPtr =
233
- (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr (processHandle,
234
- " zesInit" );
276
+
277
+ // Check if the user has enabled the default L0 SysMan initialization.
278
+ const int UrSysmanZesinitEnable = [] {
279
+ const char *UrRet = std::getenv (" UR_L0_ENABLE_ZESINIT_DEFAULT" );
280
+ if (!UrRet)
281
+ return 0 ;
282
+ return std::atoi (UrRet);
283
+ }();
284
+
285
+ // Enable zesInit by default only if ZES_ENABLE_SYSMAN has not been set by
286
+ // default and UrSysmanZesinitEnable is true.
287
+ if (UrSysmanZesinitEnable && !UrSysManEnvInitEnabled) {
288
+ GlobalAdapter->getDeviceByUUIdFunctionPtr =
289
+ (zes_pfnDriverGetDeviceByUuidExp_t)
290
+ ur_loader::LibLoader::getFunctionPtr (
291
+ processHandle, " zesDriverGetDeviceByUuidExp" );
292
+ GlobalAdapter->getSysManDriversFunctionPtr =
293
+ (zes_pfnDriverGet_t)ur_loader::LibLoader::getFunctionPtr (
294
+ processHandle, " zesDriverGet" );
295
+ GlobalAdapter->sysManInitFunctionPtr =
296
+ (zes_pfnInit_t)ur_loader::LibLoader::getFunctionPtr (processHandle,
297
+ " zesInit" );
298
+ }
235
299
if (GlobalAdapter->getDeviceByUUIdFunctionPtr &&
236
300
GlobalAdapter->getSysManDriversFunctionPtr &&
237
301
GlobalAdapter->sysManInitFunctionPtr ) {
0 commit comments