Skip to content

[SYCL] global size zero assertion narrowed - #22957

Open
cperkinsintel wants to merge 5 commits into
intel:syclfrom
cperkinsintel:cperkins-zero-global-size-fix
Open

[SYCL] global size zero assertion narrowed#22957
cperkinsintel wants to merge 5 commits into
intel:syclfrom
cperkinsintel:cperkins-zero-global-size-fix

Conversation

@cperkinsintel

Copy link
Copy Markdown
Contributor

The SYCL 2020 spec states that "When the global size is zero, the kernel function is not executed, the local size is ignored, and any dependencies are satisfied"

But we have an assert that is a bit too wide and is tripping up PyTorch. Fix is simply to narrow the assertion.

@cperkinsintel
cperkinsintel requested a review from a team as a code owner August 17, 2026 22:18
// In pfwg mode NumWorkGroups is the only field the user sets; GlobalSize
// and LocalSize must both be zero (see NDRDescT contract in
// ndrange_desc.hpp).
assert(NDR.GlobalSize[0] == 0 && NDR.LocalSize[0] == 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_work_group_data_parallel_kernels: "When the global size is zero, the kernel function is not executed, the local size is ignored, and any dependencies are satisfied."

But the modified code doesn't ignore the local size: it checks it. And having a check wrapped in an assertion gives a problem that behavior will be different depending on how SYCL runtime was compiled. We can't assume that release builds will be done with disabled assertions. On the contrary, most if not all Linux distributions build projects with enabled assertions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe for the case nd_range(0, N) we won't reach this assert. check on line 2295 guarantees that for the all cases except parallel_for_work_group we exit early.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test and it includes this case, of both being zero.

@KseniyaTikhomirova KseniyaTikhomirova left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chris, could you please add a test for this? Since we haven't met this failure/assert before - it means we don't test this scenario.

It would be great to check that we send correct values to L0 and the backend handles zero global size correctly.

@KseniyaTikhomirova KseniyaTikhomirova left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

assert(NDR.LocalSize[0] == 0);
if (NDR.NumWorkGroups[0] == 0)
return; // Not parallel_for_work_group -- nothing to fill in.
// In pfwg mode NumWorkGroups is the only field the user sets; GlobalSize

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But non-zero LocalSize was coming from pytorch. This statement does not seem to be true.

// In pfwg mode NumWorkGroups is the only field the user sets; GlobalSize
// and LocalSize must both be zero (see NDRDescT contract in
// ndrange_desc.hpp).
assert(NDR.GlobalSize[0] == 0 && NDR.LocalSize[0] == 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we had assertion firing with NDR.LocalSize[0] != 0 which was coming from pytorch. Per my understanding the new assert will also fire. I will check this later today, but I have concerns if this change really fixes the reported issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried. Yes, I am getting assertion fired with the modified assertion (line number are different as I applied the change to sycl-rel-7_1 branch):

third_party/torch-xpu-ops/test/xpu/extended/test_ops_xpu.py python3: /home/dvrogozh/git/intel-llvm/sycl/source/detail/scheduler/commands.cpp:2323: void sycl::_V1::detail::adjustNDRangePerKernel(NDRDescT&, ur_kernel_handle_t, const device_impl&): Assertion `NDR.GlobalSize[0] == 0 && NDR.LocalSize[0] == 0' failed.
Fatal Python error: Aborted

If assertion can not be narrowed or we don't fully understand why/when execution may reach this place, maybe it would be better to just remove assert entirely till implementation will be clarified?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants