@@ -6129,6 +6129,19 @@ pi_result piextUSMEnqueueMemset(pi_queue Queue, void *Ptr, pi_int32 Value,
6129
6129
Count, NumEventsInWaitlist, EventsWaitlist, Event);
6130
6130
}
6131
6131
6132
+ // Helper function to check if a pointer is a device pointer.
6133
+ static bool IsDevicePointer (pi_context Context, const void *Ptr) {
6134
+ ze_device_handle_t ZeDeviceHandle;
6135
+ ze_memory_allocation_properties_t ZeMemoryAllocationProperties = {};
6136
+
6137
+ // Query memory type of the pointer
6138
+ ZE_CALL (zeMemGetAllocProperties,
6139
+ (Context->ZeContext , Ptr, &ZeMemoryAllocationProperties,
6140
+ &ZeDeviceHandle));
6141
+
6142
+ return (ZeMemoryAllocationProperties.type == ZE_MEMORY_TYPE_DEVICE);
6143
+ }
6144
+
6132
6145
pi_result piextUSMEnqueueMemcpy (pi_queue Queue, pi_bool Blocking, void *DstPtr,
6133
6146
const void *SrcPtr, size_t Size,
6134
6147
pi_uint32 NumEventsInWaitlist,
@@ -6141,10 +6154,14 @@ pi_result piextUSMEnqueueMemcpy(pi_queue Queue, pi_bool Blocking, void *DstPtr,
6141
6154
6142
6155
PI_ASSERT (Queue, PI_INVALID_QUEUE);
6143
6156
6157
+ // Device to Device copies are found to execute slower on copy engine
6158
+ // (versus compute engine).
6159
+ bool PreferCopyEngine = !IsDevicePointer (Queue->Context , SrcPtr) ||
6160
+ !IsDevicePointer (Queue->Context , DstPtr);
6144
6161
return enqueueMemCopyHelper (
6145
6162
// TODO: do we need a new command type for this?
6146
6163
PI_COMMAND_TYPE_MEM_BUFFER_COPY, Queue, DstPtr, Blocking, Size, SrcPtr,
6147
- NumEventsInWaitlist, EventsWaitlist, Event);
6164
+ NumEventsInWaitlist, EventsWaitlist, Event, PreferCopyEngine );
6148
6165
}
6149
6166
6150
6167
// / Hint to migrate memory to the device
0 commit comments