@@ -4299,37 +4299,40 @@ pi_result piextUSMFree(pi_context Context, void *Ptr) {
4299
4299
ZE_CALL (zeMemGetAllocProperties (
4300
4300
Context->ZeContext , Ptr , &ZeMemoryAllocationProperties, &ZeDeviceHandle));
4301
4301
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
+ }
4306
4321
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
+ };
4320
4324
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
+ }
4332
4334
}
4335
+
4333
4336
return USMFreeImpl (Context, Ptr );
4334
4337
}
4335
4338
0 commit comments