Skip to content

Commit 713cbde

Browse files
committed
[SYCL]: fixed bug reported in CI
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 9041386 commit 713cbde

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

100644100755
Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,37 +4299,40 @@ pi_result piextUSMFree(pi_context Context, void *Ptr) {
42994299
ZE_CALL(zeMemGetAllocProperties(
43004300
Context->ZeContext, Ptr, &ZeMemoryAllocationProperties, &ZeDeviceHandle));
43014301

4302-
// All devices in the context are of the same platform.
4303-
auto Platform = Context->Devices[0]->Platform;
4304-
auto Device = Platform->getDeviceFromNativeHandle(ZeDeviceHandle);
4305-
assert(Device);
4302+
if (ZeDeviceHandle) {
4303+
// All devices in the context are of the same platform.
4304+
auto Platform = Context->Devices[0]->Platform;
4305+
auto Device = Platform->getDeviceFromNativeHandle(ZeDeviceHandle);
4306+
assert(Device);
4307+
4308+
auto DeallocationHelper =
4309+
[Context, Device,
4310+
Ptr](std::unordered_map<pi_device, USMAllocContext> &AllocContextMap) {
4311+
try {
4312+
auto It = AllocContextMap.find(Device);
4313+
if (It == AllocContextMap.end())
4314+
return PI_INVALID_VALUE;
4315+
4316+
// The right context is found, deallocate the pointer
4317+
It->second.deallocate(Ptr);
4318+
} catch (const UsmAllocationException &Ex) {
4319+
return Ex.getError();
4320+
}
43064321

4307-
auto DeallocationHelper =
4308-
[Context, Device,
4309-
Ptr](std::unordered_map<pi_device, USMAllocContext> &AllocContextMap) {
4310-
try {
4311-
auto It = AllocContextMap.find(Device);
4312-
if (It == AllocContextMap.end())
4313-
return PI_INVALID_VALUE;
4314-
4315-
// The right context is found, deallocate the pointer
4316-
It->second.deallocate(Ptr);
4317-
} catch (const UsmAllocationException &Ex) {
4318-
return Ex.getError();
4319-
}
4322+
return PI_SUCCESS;
4323+
};
43204324

4321-
return PI_SUCCESS;
4322-
};
4323-
4324-
switch (ZeMemoryAllocationProperties.type) {
4325-
case ZE_MEMORY_TYPE_SHARED:
4326-
return DeallocationHelper(Context->SharedMemAllocContexts);
4327-
case ZE_MEMORY_TYPE_DEVICE:
4328-
return DeallocationHelper(Context->DeviceMemAllocContexts);
4329-
default:
4330-
// Handled below
4331-
break;
4325+
switch (ZeMemoryAllocationProperties.type) {
4326+
case ZE_MEMORY_TYPE_SHARED:
4327+
return DeallocationHelper(Context->SharedMemAllocContexts);
4328+
case ZE_MEMORY_TYPE_DEVICE:
4329+
return DeallocationHelper(Context->DeviceMemAllocContexts);
4330+
default:
4331+
// Handled below
4332+
break;
4333+
}
43324334
}
4335+
43334336
return USMFreeImpl(Context, Ptr);
43344337
}
43354338

0 commit comments

Comments
 (0)