@@ -78,18 +78,25 @@ ur_result_t getZesDeviceHandle(zes_uuid_t coreDeviceUuid,
7878
7979ur_result_t initPlatforms (PlatformVec &platforms,
8080 ze_result_t ZesResult) noexcept try {
81- uint32_t ZeDriverCount = 0 ;
82- ZE2UR_CALL (zeDriverGet, (&ZeDriverCount, nullptr ));
83- if (ZeDriverCount == 0 ) {
81+ if (!GlobalAdapter->initDriversFunctionPtr ) {
82+ ZE2UR_CALL (zeDriverGet, (&GlobalAdapter->ZeDriverCount , nullptr ));
83+ }
84+ if (GlobalAdapter->ZeDriverCount == 0 ) {
8485 return UR_RESULT_SUCCESS;
8586 }
8687
8788 std::vector<ze_driver_handle_t > ZeDrivers;
8889 std::vector<ze_device_handle_t > ZeDevices;
89- ZeDrivers.resize (ZeDriverCount);
90-
91- ZE2UR_CALL (zeDriverGet, (&ZeDriverCount, ZeDrivers.data ()));
92- for (uint32_t I = 0 ; I < ZeDriverCount; ++I) {
90+ ZeDrivers.resize (GlobalAdapter->ZeDriverCount );
91+
92+ if (GlobalAdapter->initDriversFunctionPtr ) {
93+ ZE2UR_CALL (GlobalAdapter->initDriversFunctionPtr ,
94+ (&GlobalAdapter->ZeDriverCount , ZeDrivers.data (),
95+ &GlobalAdapter->InitDriversDesc ));
96+ } else {
97+ ZE2UR_CALL (zeDriverGet, (&GlobalAdapter->ZeDriverCount , ZeDrivers.data ()));
98+ }
99+ for (uint32_t I = 0 ; I < GlobalAdapter->ZeDriverCount ; ++I) {
93100 // Keep track of the first platform init for this Driver
94101 bool DriverPlatformInit = false ;
95102 ze_device_properties_t device_properties{};
@@ -214,6 +221,15 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
214221 return std::atoi (UrRet);
215222 }();
216223
224+ // Dynamically load the new L0 apis separately.
225+ // This must be done to avoid attempting to use symbols that do
226+ // not exist in older loader runtimes.
227+ #ifdef _WIN32
228+ HMODULE processHandle = GetModuleHandle (NULL );
229+ #else
230+ HMODULE processHandle = nullptr ;
231+ #endif
232+
217233 // initialize level zero only once.
218234 if (GlobalAdapter->ZeResult == std::nullopt ) {
219235 // Setting these environment variables before running zeInit will enable
@@ -235,20 +251,35 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
235251 // called multiple times. Declaring the return value as "static" ensures
236252 // it's only called once.
237253
238- // Init with all flags set to enable for all driver types to be init in
239- // the application.
240- ze_init_flags_t L0InitFlags = ZE_INIT_FLAG_GPU_ONLY;
241- if (UrL0InitAllDrivers) {
242- L0InitFlags |= ZE_INIT_FLAG_VPU_ONLY;
243- }
254+ GlobalAdapter->initDriversFunctionPtr =
255+ (ze_pfnInitDrivers_t)ur_loader::LibLoader::getFunctionPtr (
256+ processHandle, " zeInitDrivers" );
244257
245258 // Set ZES_ENABLE_SYSMAN by default if the user has not set it.
246259 if (UrSysManEnvInitEnabled) {
247260 setEnvVar (" ZES_ENABLE_SYSMAN" , " 1" );
248261 }
249- logger::debug (" \n zeInit with flags value of {}\n " ,
250- static_cast <int >(L0InitFlags));
251- GlobalAdapter->ZeResult = ZE_CALL_NOCHECK (zeInit, (L0InitFlags));
262+
263+ if (GlobalAdapter->initDriversFunctionPtr ) {
264+ GlobalAdapter->InitDriversDesc .pNext = nullptr ;
265+ GlobalAdapter->InitDriversDesc .flags = ZE_INIT_DRIVER_TYPE_FLAG_GPU;
266+ logger::debug (" \n zeInitDrivers with flags value of {}\n " ,
267+ static_cast <int >(GlobalAdapter->InitDriversDesc .flags ));
268+ GlobalAdapter->ZeResult =
269+ ZE_CALL_NOCHECK (GlobalAdapter->initDriversFunctionPtr ,
270+ (&GlobalAdapter->ZeDriverCount , nullptr ,
271+ &GlobalAdapter->InitDriversDesc ));
272+ } else {
273+ // Init with all flags set to enable for all driver types to be init in
274+ // the application.
275+ ze_init_flags_t L0InitFlags = ZE_INIT_FLAG_GPU_ONLY;
276+ if (UrL0InitAllDrivers) {
277+ L0InitFlags |= ZE_INIT_FLAG_VPU_ONLY;
278+ }
279+ logger::debug (" \n zeInit with flags value of {}\n " ,
280+ static_cast <int >(L0InitFlags));
281+ GlobalAdapter->ZeResult = ZE_CALL_NOCHECK (zeInit, (L0InitFlags));
282+ }
252283 }
253284 assert (GlobalAdapter->ZeResult !=
254285 std::nullopt ); // verify that level-zero is initialized
@@ -265,14 +296,6 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
265296
266297 return ;
267298 }
268- // Dynamically load the new L0 SysMan separate init and new EXP apis
269- // separately. This must be done to avoid attempting to use symbols that do
270- // not exist in older loader runtimes.
271- #ifdef _WIN32
272- HMODULE processHandle = GetModuleHandle (NULL );
273- #else
274- HMODULE processHandle = nullptr ;
275- #endif
276299
277300 // Check if the user has enabled the default L0 SysMan initialization.
278301 const int UrSysmanZesinitEnable = [] {
0 commit comments