diff --git a/unified-runtime/source/adapters/level_zero/adapter.cpp b/unified-runtime/source/adapters/level_zero/adapter.cpp index ec178d271f73..c70012ceeed7 100644 --- a/unified-runtime/source/adapters/level_zero/adapter.cpp +++ b/unified-runtime/source/adapters/level_zero/adapter.cpp @@ -178,25 +178,41 @@ ur_result_t initPlatforms(ur_adapter_handle_t_ *adapter, PlatformVec &platforms, ZeDrivers.assign(ZeInitDriversHandles.begin(), ZeInitDriversHandles.end()); if (ZeDriverGetCount > 0 && adapter->ZeInitDriversCount > 0) { for (uint32_t X = 0; X < adapter->ZeInitDriversCount; ++X) { + // zeDriverGet and zeInitDrivers can return the driver handles in + // reverse order based on driver ordering causing an issue if the + // drivers are expected to be in the same order. To resolve, this loop + // checks if the driver from zeDriverGet already exists in zeInitDrivers + // and only adds it if it is not found. + bool unMatchedDriverHandle = false; + ze_driver_handle_t driverGetHandle = nullptr; for (uint32_t Y = 0; Y < ZeDriverGetCount; ++Y) { + unMatchedDriverHandle = true; ZeStruct ZeDriverGetProperties; ZeStruct ZeInitDriverProperties; ZE2UR_CALL(zeDriverGetProperties, (ZeDriverGetHandles[Y], &ZeDriverGetProperties)); ZE2UR_CALL(zeDriverGetProperties, (ZeInitDriversHandles[X], &ZeInitDriverProperties)); - // If zeDriverGet driver is different from zeInitDriver driver, add it - // to the list. This allows for older drivers to be used alongside - // newer drivers. - if (ZeDriverGetProperties.driverVersion != + driverGetHandle = ZeDriverGetHandles[Y]; + // If zeDriverGet driver is the same version as zeInitDriver driver, + // then do not add it again. + if (ZeDriverGetProperties.driverVersion == ZeInitDriverProperties.driverVersion) { UR_LOG(DEBUG, - "\nzeDriverHandle {} added to the zeInitDrivers list " - "of possible handles.\n", + "\nzeDriverHandle {} matched between zeDriverGet and " + "zeInitDrivers. Not adding duplicate driver to list\n", ZeDriverGetHandles[Y]); - ZeDrivers.push_back(ZeDriverGetHandles[Y]); + unMatchedDriverHandle = false; + break; } } + if (unMatchedDriverHandle) { + UR_LOG(DEBUG, + "\nzeDriverHandle {} not found in zeInitDrivers. Adding to " + "driver list.\n", + driverGetHandle); + ZeDrivers.push_back(driverGetHandle); + } } } } else {