Skip to content

Commit 5c5b121

Browse files
authored
[UR][L0] Fix duplicate driver reporting given legacy and new drivers (intel#20321)
- Fix an issue where two drivers may report driver handles in reverse order causing duplicate handles to be reported to the user. - Updated driver version check to ensure the same driver is only ever reported once. Signed-off-by: Neil R. Spruit <[email protected]>
1 parent 97e67b4 commit 5c5b121

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

unified-runtime/source/adapters/level_zero/adapter.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,41 @@ ur_result_t initPlatforms(ur_adapter_handle_t_ *adapter, PlatformVec &platforms,
178178
ZeDrivers.assign(ZeInitDriversHandles.begin(), ZeInitDriversHandles.end());
179179
if (ZeDriverGetCount > 0 && adapter->ZeInitDriversCount > 0) {
180180
for (uint32_t X = 0; X < adapter->ZeInitDriversCount; ++X) {
181+
// zeDriverGet and zeInitDrivers can return the driver handles in
182+
// reverse order based on driver ordering causing an issue if the
183+
// drivers are expected to be in the same order. To resolve, this loop
184+
// checks if the driver from zeDriverGet already exists in zeInitDrivers
185+
// and only adds it if it is not found.
186+
bool unMatchedDriverHandle = false;
187+
ze_driver_handle_t driverGetHandle = nullptr;
181188
for (uint32_t Y = 0; Y < ZeDriverGetCount; ++Y) {
189+
unMatchedDriverHandle = true;
182190
ZeStruct<ze_driver_properties_t> ZeDriverGetProperties;
183191
ZeStruct<ze_driver_properties_t> ZeInitDriverProperties;
184192
ZE2UR_CALL(zeDriverGetProperties,
185193
(ZeDriverGetHandles[Y], &ZeDriverGetProperties));
186194
ZE2UR_CALL(zeDriverGetProperties,
187195
(ZeInitDriversHandles[X], &ZeInitDriverProperties));
188-
// If zeDriverGet driver is different from zeInitDriver driver, add it
189-
// to the list. This allows for older drivers to be used alongside
190-
// newer drivers.
191-
if (ZeDriverGetProperties.driverVersion !=
196+
driverGetHandle = ZeDriverGetHandles[Y];
197+
// If zeDriverGet driver is the same version as zeInitDriver driver,
198+
// then do not add it again.
199+
if (ZeDriverGetProperties.driverVersion ==
192200
ZeInitDriverProperties.driverVersion) {
193201
UR_LOG(DEBUG,
194-
"\nzeDriverHandle {} added to the zeInitDrivers list "
195-
"of possible handles.\n",
202+
"\nzeDriverHandle {} matched between zeDriverGet and "
203+
"zeInitDrivers. Not adding duplicate driver to list\n",
196204
ZeDriverGetHandles[Y]);
197-
ZeDrivers.push_back(ZeDriverGetHandles[Y]);
205+
unMatchedDriverHandle = false;
206+
break;
198207
}
199208
}
209+
if (unMatchedDriverHandle) {
210+
UR_LOG(DEBUG,
211+
"\nzeDriverHandle {} not found in zeInitDrivers. Adding to "
212+
"driver list.\n",
213+
driverGetHandle);
214+
ZeDrivers.push_back(driverGetHandle);
215+
}
200216
}
201217
}
202218
} else {

0 commit comments

Comments
 (0)