Skip to content

[SYCL] Correctly free the memory allocated in a sub-device context #4312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,9 +1519,16 @@ pi_device _pi_platform::getDeviceFromNativeHandle(ze_device_handle_t ZeDevice) {
return nullptr;
}

// TODO: our sub-sub-device representation is currently [Level-Zero device
// handle + Level-Zero compute group/engine index], so there is now no 1:1
// mapping from L0 device handle to PI device assumed in this function. Until
// Level-Zero adds unique ze_device_handle_t for sub-sub-devices, here we
// filter out PI sub-sub-devices.
auto it = std::find_if(PiDevicesCache.begin(), PiDevicesCache.end(),
[&](std::unique_ptr<_pi_device> &D) {
return D.get()->ZeDevice == ZeDevice;
return D.get()->ZeDevice == ZeDevice &&
(D.get()->RootDevice == nullptr ||
D.get()->RootDevice->RootDevice == nullptr);
});
if (it != PiDevicesCache.end()) {
return (*it).get();
Expand Down Expand Up @@ -6267,11 +6274,16 @@ static pi_result USMFreeHelper(pi_context Context, void *Ptr) {
}

if (ZeDeviceHandle) {
// All devices in the context are of the same platform.
auto Platform = Context->Devices[0]->Platform;
auto Device = Platform->getDeviceFromNativeHandle(ZeDeviceHandle);

PI_ASSERT(Device, PI_INVALID_DEVICE);
pi_device Device;
if (Context->Devices.size() == 1) {
Device = Context->Devices[0];
PI_ASSERT(Device->ZeDevice == ZeDeviceHandle, PI_INVALID_DEVICE);
} else {
// All devices in the context are of the same platform.
auto Platform = Context->Devices[0]->Platform;
Device = Platform->getDeviceFromNativeHandle(ZeDeviceHandle);
PI_ASSERT(Device, PI_INVALID_DEVICE);
}

auto DeallocationHelper =
[Context, Device,
Expand Down