Skip to content

[SYCL][LevelZero] Add support to detect host->device and device->host transfers for USM #3975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6129,6 +6129,19 @@ pi_result piextUSMEnqueueMemset(pi_queue Queue, void *Ptr, pi_int32 Value,
Count, NumEventsInWaitlist, EventsWaitlist, Event);
}

// Helper function to check if a pointer is a device pointer.
static bool IsDevicePointer(pi_context Context, const void *Ptr) {
ze_device_handle_t ZeDeviceHandle;
ze_memory_allocation_properties_t ZeMemoryAllocationProperties = {};

// Query memory type of the pointer
ZE_CALL(zeMemGetAllocProperties,
(Context->ZeContext, Ptr, &ZeMemoryAllocationProperties,
&ZeDeviceHandle));

return (ZeMemoryAllocationProperties.type == ZE_MEMORY_TYPE_DEVICE);
}

pi_result piextUSMEnqueueMemcpy(pi_queue Queue, pi_bool Blocking, void *DstPtr,
const void *SrcPtr, size_t Size,
pi_uint32 NumEventsInWaitlist,
Expand All @@ -6141,10 +6154,14 @@ pi_result piextUSMEnqueueMemcpy(pi_queue Queue, pi_bool Blocking, void *DstPtr,

PI_ASSERT(Queue, PI_INVALID_QUEUE);

// Device to Device copies are found to execute slower on copy engine
// (versus compute engine).
bool PreferCopyEngine = !IsDevicePointer(Queue->Context, SrcPtr) ||
!IsDevicePointer(Queue->Context, DstPtr);
return enqueueMemCopyHelper(
// TODO: do we need a new command type for this?
PI_COMMAND_TYPE_MEM_BUFFER_COPY, Queue, DstPtr, Blocking, Size, SrcPtr,
NumEventsInWaitlist, EventsWaitlist, Event);
NumEventsInWaitlist, EventsWaitlist, Event, PreferCopyEngine);
}

/// Hint to migrate memory to the device
Expand Down