@@ -1536,9 +1536,16 @@ pi_device _pi_platform::getDeviceFromNativeHandle(ze_device_handle_t ZeDevice) {
1536
1536
return nullptr ;
1537
1537
}
1538
1538
1539
+ // TODO: our sub-sub-device representation is currently [Level-Zero device
1540
+ // handle + Level-Zero compute group/engine index], so there is now no 1:1
1541
+ // mapping from L0 device handle to PI device assumed in this function. Until
1542
+ // Level-Zero adds unique ze_device_handle_t for sub-sub-devices, here we
1543
+ // filter out PI sub-sub-devices.
1539
1544
auto it = std::find_if (PiDevicesCache.begin (), PiDevicesCache.end (),
1540
1545
[&](std::unique_ptr<_pi_device> &D) {
1541
- return D.get ()->ZeDevice == ZeDevice;
1546
+ return D.get ()->ZeDevice == ZeDevice &&
1547
+ (D.get ()->RootDevice == nullptr ||
1548
+ D.get ()->RootDevice ->RootDevice == nullptr );
1542
1549
});
1543
1550
if (it != PiDevicesCache.end ()) {
1544
1551
return (*it).get ();
@@ -6297,11 +6304,16 @@ static pi_result USMFreeHelper(pi_context Context, void *Ptr) {
6297
6304
}
6298
6305
6299
6306
if (ZeDeviceHandle) {
6300
- // All devices in the context are of the same platform.
6301
- auto Platform = Context->Devices [0 ]->Platform ;
6302
- auto Device = Platform->getDeviceFromNativeHandle (ZeDeviceHandle);
6303
-
6304
- PI_ASSERT (Device, PI_INVALID_DEVICE);
6307
+ pi_device Device;
6308
+ if (Context->Devices .size () == 1 ) {
6309
+ Device = Context->Devices [0 ];
6310
+ PI_ASSERT (Device->ZeDevice == ZeDeviceHandle, PI_INVALID_DEVICE);
6311
+ } else {
6312
+ // All devices in the context are of the same platform.
6313
+ auto Platform = Context->Devices [0 ]->Platform ;
6314
+ Device = Platform->getDeviceFromNativeHandle (ZeDeviceHandle);
6315
+ PI_ASSERT (Device, PI_INVALID_DEVICE);
6316
+ }
6305
6317
6306
6318
auto DeallocationHelper =
6307
6319
[Context, Device,
0 commit comments