Skip to content

Commit 882a6d1

Browse files
committed
[UR][L0] Fix duplicate driver reporting given legacy and new drivers
- 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 7c3c668 commit 882a6d1

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,38 @@ 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 = true;
181187
for (uint32_t Y = 0; Y < ZeDriverGetCount; ++Y) {
182188
ZeStruct<ze_driver_properties_t> ZeDriverGetProperties;
183189
ZeStruct<ze_driver_properties_t> ZeInitDriverProperties;
184190
ZE2UR_CALL(zeDriverGetProperties,
185191
(ZeDriverGetHandles[Y], &ZeDriverGetProperties));
186192
ZE2UR_CALL(zeDriverGetProperties,
187193
(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 !=
194+
// If zeDriverGet driver is the same version as zeInitDriver driver,
195+
// then do not add it again.
196+
if (ZeDriverGetProperties.driverVersion ==
192197
ZeInitDriverProperties.driverVersion) {
193198
UR_LOG(DEBUG,
194-
"\nzeDriverHandle {} added to the zeInitDrivers list "
195-
"of possible handles.\n",
199+
"\nzeDriverHandle {} matched between zeDriverGet and "
200+
"zeInitDrivers. Not adding duplicate driver to list\n",
196201
ZeDriverGetHandles[Y]);
197-
ZeDrivers.push_back(ZeDriverGetHandles[Y]);
202+
unMatchedDriverHandle = false;
203+
break;
198204
}
199205
}
206+
if (unMatchedDriverHandle) {
207+
UR_LOG(DEBUG,
208+
"\nzeDriverHandle {} not found in zeInitDrivers. Adding to "
209+
"driver list.\n",
210+
ZeDriverGetHandles[Y]);
211+
ZeDrivers.push_back(ZeDriverGetHandles[Y]);
212+
}
200213
}
201214
}
202215
} else {

0 commit comments

Comments
 (0)