From a5fc1f6ec95b4a3a3a3eec92f554a1a21301de62 Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Thu, 8 Sep 2022 07:02:34 -0700 Subject: [PATCH 1/2] [SYCL] Fix USM free for descendent devices Now that use of descendent devices of context members is supported, we cannot rely on always choosing the only device in single-device contexts. Remove this branch to always fetch the context from the platform. --- sycl/plugins/level_zero/pi_level_zero.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 35f6ceb84a1fb..42dfd1c9e8dab 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -8173,15 +8173,10 @@ static pi_result USMFreeHelper(pi_context Context, void *Ptr, PI_ERROR_INVALID_DEVICE); } else { pi_device Device; - if (Context->Devices.size() == 1) { - Device = Context->Devices[0]; - PI_ASSERT(Device->ZeDevice == ZeDeviceHandle, PI_ERROR_INVALID_DEVICE); - } else { - // All devices in the context are of the same platform. - auto Platform = Context->getPlatform(); - Device = Platform->getDeviceFromNativeHandle(ZeDeviceHandle); - PI_ASSERT(Device, PI_ERROR_INVALID_DEVICE); - } + // All devices in the context are of the same platform. + auto Platform = Context->getPlatform(); + Device = Platform->getDeviceFromNativeHandle(ZeDeviceHandle); + PI_ASSERT(Device, PI_ERROR_INVALID_DEVICE); auto DeallocationHelper = [Context, Device, Ptr, OwnZeMemHandle]( From 370fb11bca4c346e3c51948ad33494b44fdd14cf Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Thu, 8 Sep 2022 07:19:00 -0700 Subject: [PATCH 2/2] Adjust comment --- sycl/plugins/level_zero/pi_level_zero.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 42dfd1c9e8dab..0ba8851aa2ffc 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -8173,7 +8173,7 @@ static pi_result USMFreeHelper(pi_context Context, void *Ptr, PI_ERROR_INVALID_DEVICE); } else { pi_device Device; - // All devices in the context are of the same platform. + // All context member devices or their descendants are of the same platform. auto Platform = Context->getPlatform(); Device = Platform->getDeviceFromNativeHandle(ZeDeviceHandle); PI_ASSERT(Device, PI_ERROR_INVALID_DEVICE);