Skip to content

Request IEEE fp32 division for SYCL kernels - #752

Merged
sayakpaul merged 4 commits into
huggingface:mainfrom
jiqing-feng:xpu-fp32-prec-div
Aug 13, 2026
Merged

sayakpaul merged 4 commits into
huggingface:mainfrom
jiqing-feng:xpu-fp32-prec-div

Conversation

@jiqing-feng

Copy link
Copy Markdown
Contributor

Summary

Adds -foffload-fp32-prec-div and -foffload-fp32-prec-sqrt to the SYCL build
flags, matching how PyTorch builds its own XPU kernels in torch-xpu-ops.

Without them the compiler defaults to a fast floating-point model in which fp32
division is allowed several ULP of error and a / b is lowered to a * rcp(b).
Kernels built this way return results that differ from the eager PyTorch ones in
the last bit, which breaks kernel tests that compare against PyTorch exactly.

These flags affect the offload backend and only take effect when passed to both
the device compile and the device link step, so the per-kernel sycl-flags in
build.toml cannot substitute for them. Applied to the torch and tvm_ffi
preambles alike.

Validation

Verified with kernels-community/activation on Intel Arc Pro B60 with
torch 2.13.0+xpu and oneAPI 2026.0. Its silu_and_mul and mul_and_silu
operators go from 42 failures to a fully passing suite (396 cases), with no
change in measured throughput.

The SYCL compiler defaults to a fast floating-point model in which fp32
division is allowed several ULP of error and `a / b` is lowered to
`a * rcp(b)`. Kernels built this way return results that differ from the
eager PyTorch ones in the last bit, which breaks kernel tests that compare
against PyTorch exactly.

Add -foffload-fp32-prec-div and -foffload-fp32-prec-sqrt, matching how
PyTorch builds its own XPU kernels in torch-xpu-ops. These affect the
offload backend and only take effect when passed to both the device compile
and the device link step, so per-kernel `sycl-flags` in build.toml cannot
substitute for them.

Verified with the activation kernel on Intel Arc Pro B60: its silu_and_mul
and mul_and_silu operators go from 42 failures to a fully passing suite,
with no change in measured throughput.

@drbh drbh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm!

@sayakpaul
sayakpaul merged commit 3a5c09d into huggingface:main Aug 13, 2026
38 of 41 checks passed
danieldk pushed a commit to huggingface/kernels-community that referenced this pull request Aug 25, 2026
Implement the eleven activation operators in SYCL and register them under
the XPU dispatch key, so existing callers work unchanged on Intel GPUs.
Previously the kernel declared only cuda, rocm, metal and cpu, and could not
be loaded on XPU at all.

Gated operators map one work-group to one token; element-wise operators use
a flat grid-stride loop. Both use 128-bit vectorized accesses with a runtime
alignment check and a scalar fallback, which is what keeps the element-wise
operators on par with eager PyTorch, whose TensorIterator already vectorizes.

Parameterize tests/kernels/test_activation.py over the available accelerator
rather than hard-coding CUDA, so the existing suite runs unmodified on XPU.
It passes in full on Intel Arc Pro B60 with torch 2.13.0+xpu, including the
gated operators that are compared against eager PyTorch with zero tolerance.
Add two cases to the same file for shapes and alignments that force the
scalar path, and for empty inputs.

Requires huggingface/kernels#752, which makes kernel-builder request IEEE
correctly rounded fp32 division for SYCL kernels; without it silu_and_mul
and mul_and_silu differ from eager PyTorch by one ULP.
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