Skip to content

Revert "[L0] Refactor Copy Engine Usage checks for Performance" #18606

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

Draft
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions unified-runtime/source/adapters/level_zero/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,10 +1097,19 @@ ur_result_t urCommandBufferAppendUSMMemcpyExp(
ur_event_handle_t * /*Event*/,
ur_exp_command_buffer_command_handle_t * /*Command*/) {

bool PreferCopyEngine = !IsDevicePointer(CommandBuffer->Context, Src) ||
!IsDevicePointer(CommandBuffer->Context, Dst);
// For better performance, Copy Engines are not preferred given Shared
// pointers on DG2.
if (CommandBuffer->Device->isDG2() &&
(IsSharedPointer(CommandBuffer->Context, Src) ||
IsSharedPointer(CommandBuffer->Context, Dst))) {
PreferCopyEngine = false;
}
PreferCopyEngine |= UseCopyEngineForD2DCopy;

return enqueueCommandBufferMemCopyHelper(
UR_COMMAND_USM_MEMCPY, CommandBuffer, Dst, Src, Size,
PreferCopyEngineUsage(CommandBuffer->Device, CommandBuffer->Context, Src,
Dst),
UR_COMMAND_USM_MEMCPY, CommandBuffer, Dst, Src, Size, PreferCopyEngine,
NumSyncPointsInWaitList, SyncPointWaitList, SyncPoint);
}

Expand Down
55 changes: 30 additions & 25 deletions unified-runtime/source/adapters/level_zero/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,6 @@ bool IsSharedPointer(ur_context_handle_t Context, const void *Ptr) {
return (ZeMemoryAllocationProperties.type == ZE_MEMORY_TYPE_SHARED);
}

// Helper Function to check if the Copy Engine should be preferred given the
// types of memory used.
bool PreferCopyEngineUsage(ur_device_handle_t Device,
ur_context_handle_t Context, const void *Src,
void *Dst) {
bool PreferCopyEngine = false;
// Given Integrated Devices, Copy Engines are not preferred for any Copy
// operations.
if (!Device->isIntegrated()) {
// Given non D2D Copies, for better performance, Copy Engines are preferred
// only if one has both the Main and Link Copy Engines.
if (Device->hasLinkCopyEngine() && Device->hasMainCopyEngine() &&
(!IsDevicePointer(Context, Src) || !IsDevicePointer(Context, Dst))) {
PreferCopyEngine = true;
}
}
// Temporary option added to use force engine for D2D copy
PreferCopyEngine |= UseCopyEngineForD2DCopy;
return PreferCopyEngine;
}

// Shared by all memory read/write/copy PI interfaces.
// PI interfaces must have queue's and destination buffer's mutexes locked for
// exclusive use and source buffer's mutex locked for shared use on entry.
Expand Down Expand Up @@ -1259,10 +1238,23 @@ ur_result_t urEnqueueUSMMemcpy(
ur_event_handle_t *OutEvent) {
std::scoped_lock<ur_shared_mutex> lock(Queue->Mutex);

// Device to Device copies are found to execute slower on copy engine
// (versus compute engine).
bool PreferCopyEngine = !IsDevicePointer(Queue->Context, Src) ||
!IsDevicePointer(Queue->Context, Dst);
// For better performance, Copy Engines are not preferred given Shared
// pointers on DG2.
if (Queue->Device->isDG2() && (IsSharedPointer(Queue->Context, Src) ||
IsSharedPointer(Queue->Context, Dst))) {
PreferCopyEngine = false;
}

// Temporary option added to use copy engine for D2D copy
PreferCopyEngine |= UseCopyEngineForD2DCopy;

return enqueueMemCopyHelper( // TODO: do we need a new command type for this?
UR_COMMAND_MEM_BUFFER_COPY, Queue, Dst, Blocking, Size, Src,
NumEventsInWaitList, EventWaitList, OutEvent,
PreferCopyEngineUsage(Queue->Device, Queue->Context, Src, Dst));
NumEventsInWaitList, EventWaitList, OutEvent, PreferCopyEngine);
}

ur_result_t urEnqueueUSMPrefetch(
Expand Down Expand Up @@ -1462,13 +1454,26 @@ ur_result_t urEnqueueUSMMemcpy2D(

std::scoped_lock<ur_shared_mutex> lock(Queue->Mutex);

// Device to Device copies are found to execute slower on copy engine
// (versus compute engine).
bool PreferCopyEngine = !IsDevicePointer(Queue->Context, Src) ||
!IsDevicePointer(Queue->Context, Dst);
// For better performance, Copy Engines are not preferred given Shared
// pointers on DG2.
if (Queue->Device->isDG2() && (IsSharedPointer(Queue->Context, Src) ||
IsSharedPointer(Queue->Context, Dst))) {
PreferCopyEngine = false;
}

// Temporary option added to use copy engine for D2D copy
PreferCopyEngine |= UseCopyEngineForD2DCopy;

return enqueueMemCopyRectHelper( // TODO: do we need a new command type for
// this?
UR_COMMAND_MEM_BUFFER_COPY_RECT, Queue, Src, Dst, ZeroOffset, ZeroOffset,
Region, SrcPitch, DstPitch, 0, /*SrcSlicePitch=*/
0, /*DstSlicePitch=*/
Blocking, NumEventsInWaitList, EventWaitList, Event,
PreferCopyEngineUsage(Queue->Device, Queue->Context, Src, Dst));
Blocking, NumEventsInWaitList, EventWaitList, Event, PreferCopyEngine);
}

ur_result_t urMemImageCreate(
Expand Down
3 changes: 0 additions & 3 deletions unified-runtime/source/adapters/level_zero/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ struct ur_device_handle_t_;

bool IsDevicePointer(ur_context_handle_t Context, const void *Ptr);
bool IsSharedPointer(ur_context_handle_t Context, const void *Ptr);
bool PreferCopyEngineUsage(ur_device_handle_t Device,
ur_context_handle_t Context, const void *Src,
void *Dst);

// This is an experimental option to test performance of device to device copy
// operations on copy engines (versus compute engine)
Expand Down
Loading