Skip to content

Commit 0498efe

Browse files
authored
[SYCL][LevelZero] Add support to detect host->device and device->host transfers for USM (#3975)
Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent 0bbb68e commit 0498efe

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6129,6 +6129,19 @@ pi_result piextUSMEnqueueMemset(pi_queue Queue, void *Ptr, pi_int32 Value,
61296129
Count, NumEventsInWaitlist, EventsWaitlist, Event);
61306130
}
61316131

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+
61326145
pi_result piextUSMEnqueueMemcpy(pi_queue Queue, pi_bool Blocking, void *DstPtr,
61336146
const void *SrcPtr, size_t Size,
61346147
pi_uint32 NumEventsInWaitlist,
@@ -6141,10 +6154,14 @@ pi_result piextUSMEnqueueMemcpy(pi_queue Queue, pi_bool Blocking, void *DstPtr,
61416154

61426155
PI_ASSERT(Queue, PI_INVALID_QUEUE);
61436156

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);
61446161
return enqueueMemCopyHelper(
61456162
// TODO: do we need a new command type for this?
61466163
PI_COMMAND_TYPE_MEM_BUFFER_COPY, Queue, DstPtr, Blocking, Size, SrcPtr,
6147-
NumEventsInWaitlist, EventsWaitlist, Event);
6164+
NumEventsInWaitlist, EventsWaitlist, Event, PreferCopyEngine);
61486165
}
61496166

61506167
/// Hint to migrate memory to the device

0 commit comments

Comments
 (0)