Skip to content

Commit 6cf33ae

Browse files
[SYCL] Correctly free the memory allocated in a sub-device context (#4312)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 7fe4ad5 commit 6cf33ae

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,9 +1536,16 @@ pi_device _pi_platform::getDeviceFromNativeHandle(ze_device_handle_t ZeDevice) {
15361536
return nullptr;
15371537
}
15381538

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.
15391544
auto it = std::find_if(PiDevicesCache.begin(), PiDevicesCache.end(),
15401545
[&](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);
15421549
});
15431550
if (it != PiDevicesCache.end()) {
15441551
return (*it).get();
@@ -6297,11 +6304,16 @@ static pi_result USMFreeHelper(pi_context Context, void *Ptr) {
62976304
}
62986305

62996306
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+
}
63056317

63066318
auto DeallocationHelper =
63076319
[Context, Device,

0 commit comments

Comments
 (0)