Skip to content

[L0][UR] Do not set global offset unless required #18242

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 5 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions sycl/source/detail/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ class NDRDescT {
ClusterDimensions[I] = (I < Dims) ? N[I] : 1;
}

bool hasOffset() const {
bool HasOffset = false;
for (int I = 0; I < 3; ++I)
HasOffset |= GlobalOffset[I];
return HasOffset;
}

NDRDescT &operator=(const NDRDescT &Desc) = default;
NDRDescT &operator=(NDRDescT &&Desc) = default;

Expand Down
18 changes: 13 additions & 5 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,10 @@ static ur_result_t SetKernelParamsAndLaunch(

size_t RequiredWGSize[3] = {0, 0, 0};
size_t *LocalSize = nullptr;
size_t *GlobalOffset = nullptr;

if (NDRDesc.hasOffset())
GlobalOffset = &NDRDesc.GlobalOffset[0];

if (HasLocalSize)
LocalSize = &NDRDesc.LocalSize[0];
Expand Down Expand Up @@ -2478,9 +2482,9 @@ static ur_result_t SetKernelParamsAndLaunch(
ur_event_handle_t UREvent = nullptr;
ur_result_t Error =
Adapter->call_nocheck<UrApiKind::urEnqueueKernelLaunchCustomExp>(
Queue->getHandleRef(), Kernel, NDRDesc.Dims,
&NDRDesc.GlobalOffset[0], &NDRDesc.GlobalSize[0], LocalSize,
property_list.size(), property_list.data(), RawEvents.size(),
Queue->getHandleRef(), Kernel, NDRDesc.Dims, GlobalOffset,
&NDRDesc.GlobalSize[0], LocalSize, property_list.size(),
property_list.data(), RawEvents.size(),
RawEvents.empty() ? nullptr : &RawEvents[0],
OutEventImpl ? &UREvent : nullptr);
if ((Error == UR_RESULT_SUCCESS) && OutEventImpl) {
Expand All @@ -2497,7 +2501,7 @@ static ur_result_t SetKernelParamsAndLaunch(
Args...);
}
return Adapter->call_nocheck<UrApiKind::urEnqueueKernelLaunch>(Args...);
}(Queue->getHandleRef(), Kernel, NDRDesc.Dims, &NDRDesc.GlobalOffset[0],
}(Queue->getHandleRef(), Kernel, NDRDesc.Dims, GlobalOffset,
&NDRDesc.GlobalSize[0], LocalSize, RawEvents.size(),
RawEvents.empty() ? nullptr : &RawEvents[0],
OutEventImpl ? &UREvent : nullptr);
Expand Down Expand Up @@ -2605,6 +2609,10 @@ ur_result_t enqueueImpCommandBufferKernel(

size_t RequiredWGSize[3] = {0, 0, 0};
size_t *LocalSize = nullptr;
size_t *GlobalOffset = nullptr;

if (NDRDesc.hasOffset())
GlobalOffset = &NDRDesc.GlobalOffset[0];

if (HasLocalSize)
LocalSize = &NDRDesc.LocalSize[0];
Expand Down Expand Up @@ -2633,7 +2641,7 @@ ur_result_t enqueueImpCommandBufferKernel(

ur_result_t Res =
Adapter->call_nocheck<UrApiKind::urCommandBufferAppendKernelLaunchExp>(
CommandBuffer, UrKernel, NDRDesc.Dims, &NDRDesc.GlobalOffset[0],
CommandBuffer, UrKernel, NDRDesc.Dims, GlobalOffset,
&NDRDesc.GlobalSize[0], LocalSize, AltUrKernels.size(),
AltUrKernels.size() ? AltUrKernels.data() : nullptr,
SyncPoints.size(), SyncPoints.size() ? SyncPoints.data() : nullptr, 0,
Expand Down
10 changes: 10 additions & 0 deletions unified-runtime/source/adapters/level_zero/v2/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,19 @@ ur_result_t ur_kernel_handle_t_::prepareForSubmission(
std::function<void(void *, void *, size_t)> migrate) {
auto hZeKernel = getZeHandle(hDevice);

// If we have a new offset, update the zeKernel object
if (pGlobalWorkOffset != NULL) {
UR_CALL(
setKernelGlobalOffset(hContext, hZeKernel, workDim, pGlobalWorkOffset));
hadOffset = true;
}

// If we have no offset now but the last submission had one, clear it
else if (hadOffset) {
size_t zeroOffset[3] = {0, 0, 0};
UR_CALL(
setKernelGlobalOffset(hContext, hZeKernel, workDim, zeroOffset));
hadOffset = false;
}

ZE2UR_CALL(zeKernelSetGroupSize,
Expand Down
3 changes: 3 additions & 0 deletions unified-runtime/source/adapters/level_zero/v2/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,7 @@ struct ur_kernel_handle_t_ : ur_object {

// pointer to any non-null kernel in deviceKernels
ur_single_device_kernel_t *nonEmptyKernel;

// keep track of whether the offset is non-zero
bool hadOffset = false;
};
Loading