@@ -42,6 +42,19 @@ bool IsDevicePointer(ur_context_handle_t Context, const void *Ptr) {
4242 return (ZeMemoryAllocationProperties.type == ZE_MEMORY_TYPE_DEVICE);
4343}
4444
45+ // Helper function to check if a pointer is a shared pointer.
46+ bool IsSharedPointer (ur_context_handle_t Context, const void *Ptr) {
47+ ze_device_handle_t ZeDeviceHandle;
48+ ZeStruct<ze_memory_allocation_properties_t > ZeMemoryAllocationProperties;
49+
50+ // Query memory type of the pointer
51+ ZE2UR_CALL (zeMemGetAllocProperties,
52+ (Context->ZeContext , Ptr, &ZeMemoryAllocationProperties,
53+ &ZeDeviceHandle));
54+
55+ return (ZeMemoryAllocationProperties.type == ZE_MEMORY_TYPE_SHARED);
56+ }
57+
4558// Shared by all memory read/write/copy PI interfaces.
4659// PI interfaces must have queue's and destination buffer's mutexes locked for
4760// exclusive use and source buffer's mutex locked for shared use on entry.
@@ -1191,6 +1204,12 @@ ur_result_t ur_queue_handle_legacy_t_::enqueueUSMMemcpy(
11911204 // (versus compute engine).
11921205 bool PreferCopyEngine = !IsDevicePointer (Queue->Context , Src) ||
11931206 !IsDevicePointer (Queue->Context , Dst);
1207+ // For better performance, Copy Engines are not preferred given Shared
1208+ // pointers on DG2.
1209+ if (Queue->Device ->isDG2 () && (IsSharedPointer (Queue->Context , Src) ||
1210+ IsSharedPointer (Queue->Context , Dst))) {
1211+ PreferCopyEngine = false ;
1212+ }
11941213
11951214 // Temporary option added to use copy engine for D2D copy
11961215 PreferCopyEngine |= UseCopyEngineForD2DCopy;
@@ -1390,6 +1409,12 @@ ur_result_t ur_queue_handle_legacy_t_::enqueueUSMMemcpy2D(
13901409 // (versus compute engine).
13911410 bool PreferCopyEngine = !IsDevicePointer (Queue->Context , Src) ||
13921411 !IsDevicePointer (Queue->Context , Dst);
1412+ // For better performance, Copy Engines are not preferred given Shared
1413+ // pointers on DG2.
1414+ if (Queue->Device ->isDG2 () && (IsSharedPointer (Queue->Context , Src) ||
1415+ IsSharedPointer (Queue->Context , Dst))) {
1416+ PreferCopyEngine = false ;
1417+ }
13931418
13941419 // Temporary option added to use copy engine for D2D copy
13951420 PreferCopyEngine |= UseCopyEngineForD2DCopy;
0 commit comments