Skip to content

[xpu][yaml] Migrate XPU ATen Ops registrations to native_functions.yaml - #181233

Closed
guangyey wants to merge 26 commits into
gh/guangyey/321/basefrom
gh/guangyey/321/head
Closed

guangyey wants to merge 26 commits into
gh/guangyey/321/basefrom
gh/guangyey/321/head

Conversation

@guangyey

@guangyey guangyey commented Apr 23, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Motivation

Currently, PyTorch XPU ATen ops are split across two locations:

The operations in PyTorch are declared and registered in pytorch/aten/src/ATen/native/native_functions.yaml, whereas the SYCL-based operations in torch-xpu-ops are declared and registered in yaml/native/native_functions.yaml.

This setup introduces a complication:
When building PyTorch with XPU support, torch-gen needs to be run twice:

  • once during the build of torch-xpu at here and
  • again during the build of torch-xpu-ops at here.

This solution introduces two issues (for more details, see Details):

  1. We need to maintain an additional native_functions.yaml in torch-xpu-ops, which may lead to unexpected behavior if it becomes out of sync with the one in PyTorch. For example, changes to codegen (e.g., Move at::Tag to headeronly, add library.def override to allow tags (#180190) #180190) may break XPU CI because XPU ATen kernel registrations are out-of-tree. This creates additional maintenance overhead for both PyTorch and torch-xpu-ops.
  2. It creates a build dependency; torch-xpu-ops must wait for the torch-cpu build to finish, which increases overall build time and complexity. It also retriggers the re-compile XPU (depends on libtorch_cpu.so) due to any CPU code change.

To resolve the issues mentioned above, we would like to migrate XPU ATen kernel registration to native_functions.yaml in PyTorch and reuse its codegen fully.

Solution

If we could move the ops declarations from torch-xpu-ops into torch’s native_functions.yaml, both problems would be resolved.
The key benefits:

  1. Single code generation pass – run torch-gen only once instead of twice, simple and more efficient build process
  2. Eliminate build dependency – enable parallel builds of torch-cpu and torch-xpu-ops
  3. Single source of truth – maintain only one native_functions.yaml file, prevent XPU CI break by torchgen and YAML changes.

Additional Context

Details

image

We have to maintain a very complicated build flow:

  • first torchgen in PyTorch, the left one of the picture, it will generate XPUFunctions_inl.h, oneDNN-based dispatch headers (e.g., addmm_xpu_dispatch.h), and some partial native declarations (e.g., dot_native.h). At this stage, SYCL-based ops (e.g., dot) are not included, and corresponding dispatch headers and declarations are not generated.
  • second torchgen in torch-xpu-ops, the right one of the picture, generates SYCL-based dispatch headers (e.g., dot_xpu_dispatch.h) and corresponding native declarations (e.g., dot_native.h).
  • After 2nd torchgen, we copy the newly generated files and declarations back into <Aten/ops> folders, and update the corresponding native headers, for example, dot_xpu_dispatch.h is copied into <Aten/ops> folder and update dot_native.h and XPUFunctions_inl.h accordingly.

We do this for two reasons:

  1. fully reusing torchgen;
  2. exposing Aten xpu ops header to public. So developers can include headers like <Aten/ops/dot_xpu_dispatch.h> when building C++ extensions (similar to CPU and CUDA).

However, building libtorch_cpu.so depends on dot_native.h, which is also updated during the second torchgen. As a result, we must wait for libtorch_cpu.so to finish building before running the second torchgen, otherwise, a read-write race may happen if dot_native.h is modified while still being used. This can lead to a build failure, especially on Windows. It also introduces an implicit dependency, causing unnecessary recompilation of XPU whenever CPU code changes.

Deprecated

  • _empty_affine_quantized
  • _empty_per_channel_affine_quantized
  • quantized_max_pool2d_xpu
  • _safe_softmax_xpu

@pytorch-bot

pytorch-bot Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/181233

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures, 4 Unrelated Failures, 3 Unclassified Failures

As of commit 6e29118 with merge base 2637e3b (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@guangyey
guangyey marked this pull request as draft April 23, 2026 09:19
@guangyey guangyey changed the title [xpu][codegen] Migrate XPU ATen kernel registrations to native_functions.yaml [xpu][yaml] Migrate XPU ATen kernel registrations to native_functions.yaml Apr 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Attention! native_functions.yaml was changed

If you are adding a new function or defaulted argument to native_functions.yaml, you cannot use it from pre-existing Python frontend code until our FC window passes (two weeks). Split your PR into two PRs, one which adds the new C++ functionality, and one that makes use of it from Python, and land them two weeks apart. See https://github.com/pytorch/pytorch/wiki/PyTorch's-Python-Frontend-Backward-and-Forward-Compatibility-Policy#forwards-compatibility-fc for more info.


Caused by:

@github-actions

Copy link
Copy Markdown
Contributor

Attention! PyTorch one of the C-stable API file was changed

You MUST NOT change existing function declarations in this, as this header defines a stable C ABI. If you need to change the signature for a function, introduce a new v2 version of the function and modify code generation to target the new version of the function.


Caused by:

guangyey added a commit that referenced this pull request Apr 23, 2026
guangyey added a commit that referenced this pull request Apr 23, 2026
guangyey added a commit that referenced this pull request Apr 23, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
guangyey added a commit that referenced this pull request Apr 24, 2026
@guangyey guangyey closed this Apr 24, 2026
[ghstack-poisoned]
@guangyey guangyey reopened this Apr 25, 2026
guangyey added a commit that referenced this pull request Apr 25, 2026
@guangyey guangyey added the ciflow/xpu Run XPU CI tasks label Apr 25, 2026
@guangyey guangyey added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 25, 2026
@guangyey guangyey closed this Apr 25, 2026
[ghstack-poisoned]
@guangyey guangyey reopened this Apr 27, 2026
guangyey added a commit that referenced this pull request Apr 27, 2026
[ghstack-poisoned]
[ghstack-poisoned]
guangyey added a commit to intel/torch-xpu-ops that referenced this pull request Jun 13, 2026
# Motivation
This PR will help fix the build when
pytorch/pytorch#181233 landed.
Will remove codegen from torch-xpu-ops in follow up PRs.
pytorchmergebot pushed a commit that referenced this pull request Jun 16, 2026
)

# Motivation
#184735 introduces AOTI lazy autotuning with the dual-wrapper mechanism, which uncovered some new XPU test failures in CI.

# Additonal Context
Fix #187124
Fix #187123
Fix #187035
Fix #187035
Fix #187036
Fix #187125
Fix #187121

This needs to be cherry-picked to the release branch.

Pull Request resolved: #187137
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: #181233
pytorchmergebot pushed a commit that referenced this pull request Jun 16, 2026
pytorchmergebot pushed a commit that referenced this pull request Jun 16, 2026
# Motivation
This PR reverts #182630 to fix #187277

Root cause is `ext_oneapi_wait_and_throw` will introduce SYCL Graph to sync an invalid queue.

# Additional Context

This needs to be cherry-picked to the release branch.

Why isn't it captured on CI?
This issue is only found on BMG (Xe2), and the current CI is on Data Center GPU (Xe).
Pull Request resolved: #187306
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: #181233, #187137, #187232
pytorchmergebot pushed a commit that referenced this pull request Jun 16, 2026
…187314)

# Motivation
When #184737 generalize `test_multiprocess.py`, it helps enable `TestMultiprocessingDeviceType` test on XPU. However, XPU doesn't support this test suite because lack of IPC support currently. So we would like to skip this test case and restore XPU CI to green.

Fixes #186585

Code originates from #186793
Co-authored-by: @xuhancn
Pull Request resolved: #187314
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: #181233, #187137, #187232, #187306
atalman pushed a commit that referenced this pull request Jun 16, 2026
…187416)

Skip TestMultiprocessingDeviceType on XPU due to lack of IPC support (#187314)

# Motivation
When #184737 generalize `test_multiprocess.py`, it helps enable `TestMultiprocessingDeviceType` test on XPU. However, XPU doesn't support this test suite because lack of IPC support currently. So we would like to skip this test case and restore XPU CI to green.

Fixes #186585

Code originates from #186793
Co-authored-by: @xuhancn
Pull Request resolved: #187314
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: #181233, #187137, #187232, #187306

(cherry picked from commit 4f26a57)

Co-authored-by: Yu, Guangye <[email protected]>
atalman pushed a commit that referenced this pull request Jun 16, 2026
)

[xpu][fix] Include kernel_compile_result.h in aoti xpu.h header (#187137)

# Motivation
#184735 introduces AOTI lazy autotuning with the dual-wrapper mechanism, which uncovered some new XPU test failures in CI.

# Additonal Context
Fix #187124
Fix #187123
Fix #187035
Fix #187035
Fix #187036
Fix #187125
Fix #187121

This needs to be cherry-picked to the release branch.

Pull Request resolved: #187137
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: #181233

(cherry picked from commit 6ec77b0)

Co-authored-by: Yu, Guangye <[email protected]>
atalman pushed a commit that referenced this pull request Jun 16, 2026
…o driver (#187422)

Handle pyzes import failures gracefully on machines without level zero driver (#187232)

# Motivation
Previously, we didn't handle pyzes import failures gracefully on machines without level zero driver.
Without this PR:
<img width="510" height="436" alt="image" src="https://github.com/user-attachments/assets/5c6db7ff-ee8d-4ebe-9177-db2ff80916c1" />

With this PR:
<img width="530" height="179" alt="image" src="https://github.com/user-attachments/assets/9239ac61-3722-42d7-8411-68f61abd2e0a" />

# Additional Context
<img width="1004" height="36" alt="image" src="https://github.com/user-attachments/assets/0035d2c6-2e49-4570-97de-3a4b48ae0575" />

This needs to be cherry-picked to the release branch.

Pull Request resolved: #187232
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: #181233, #187137

(cherry picked from commit fd79a5f)

Co-authored-by: Yu, Guangye <[email protected]>
guangyey added a commit to intel/torch-xpu-ops that referenced this pull request Jun 17, 2026
# Motivation
After pytorch/pytorch#181233 and
#3970 landed, we could
entirely remove separate codegen and its postprocess in torch-xpu-ops.
guangyey added a commit to intel/torch-xpu-ops that referenced this pull request Jun 17, 2026
# Motivation
After pytorch/pytorch#181233 and
#3970 landed, we could
entirely remove separate yaml/ folder in torch-xpu-ops.
daisyden pushed a commit to daisyden/torch-xpu-ops that referenced this pull request Jun 18, 2026
# Motivation
This PR will help fix the build when
pytorch/pytorch#181233 landed.
Will remove codegen from torch-xpu-ops in follow up PRs.
zxd1997066 pushed a commit to daisyden/pytorch that referenced this pull request Jun 18, 2026
…ml (pytorch#181233)

Currently, PyTorch XPU ATen ops are split across two locations:
- operations that call oneDNN (e.g., GEMM, convolution) reside in [ATen/native/mkldnn/xpu](https://github.com/pytorch/pytorch/tree/main/aten/src/ATen/native/mkldnn/xpu);
- while those implemented with SYCL are located [in torch-xpu-ops](https://github.com/intel/torch-xpu-ops/tree/main/src/ATen/native/xpu).

The operations in PyTorch are declared and registered in [pytorch/aten/src/ATen/native/native_functions.yaml](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/native_functions.yaml#L651), whereas the SYCL-based operations in torch-xpu-ops are declared and registered in [yaml/native/native_functions.yaml](https://github.com/intel/torch-xpu-ops/blob/main/yaml/native/native_functions.yaml#L87).

This setup introduces a complication:
When building PyTorch with XPU support, `torch-gen` needs to be run twice:
- once during the build of torch-xpu at [here](https://github.com/pytorch/pytorch/blob/5aac4cfce409ae24f7f0fe3e95f9a3cf5bdf4a28/cmake/Codegen.cmake#L232-L241) and
- again during the build of torch-xpu-ops at [here](https://github.com/intel/torch-xpu-ops/blob/8d373ba272f9fed348c7684bac4a0c2663844bbd/cmake/Codegen.cmake#L99-L125).

This solution introduces two issues (for more details, see [Details](#details)):
1.	We need to maintain an additional `native_functions.yaml` in torch-xpu-ops, which may lead to unexpected behavior if it becomes out of sync with the one in PyTorch. For example, changes to `codegen` (e.g., pytorch#180190) may break XPU CI because XPU ATen kernel registrations are out-of-tree. This creates additional maintenance overhead for both PyTorch and torch-xpu-ops.
2.	It creates a build dependency; torch-xpu-ops must wait for the torch-cpu build to finish, which increases overall build time and complexity. It also retriggers the re-compile XPU (depends on libtorch_cpu.so) due to any CPU code change.

To resolve the issues mentioned above, we would like to migrate XPU ATen kernel registration to `native_functions.yaml` in PyTorch and reuse its codegen fully.

If we could move the ops declarations from torch-xpu-ops into torch’s native_functions.yaml, both problems would be resolved.
The key benefits:
1. Single code generation pass – run torch-gen only once instead of twice, simple and more efficient build process
2. Eliminate build dependency – enable parallel builds of torch-cpu and torch-xpu-ops
3. Single source of truth – maintain only one `native_functions.yaml` file, prevent XPU CI break by torchgen and YAML changes.

<img width="1661" height="966" alt="image" src="https://github.com/user-attachments/assets/06574feb-1038-4d9a-bfdd-f4bb0444ecd2" />

We have to maintain a very complicated build flow:
- first `torchgen` in PyTorch, the left one of the picture, it will generate XPUFunctions_inl.h, oneDNN-based dispatch headers (e.g., `addmm_xpu_dispatch.h`), and some partial native declarations (e.g., `dot_native.h`). At this stage, SYCL-based ops (e.g., `dot`) are not included, and corresponding dispatch headers and declarations are not generated.
- second `torchgen` in torch-xpu-ops, the right one of the picture, generates SYCL-based dispatch headers (e.g., `dot_xpu_dispatch.h`) and corresponding native declarations (e.g., `dot_native.h`).
- After 2nd `torchgen`, we copy the newly generated files and declarations back into `<Aten/ops>` folders, and update the corresponding native headers, for example, `dot_xpu_dispatch.h` is copied into `<Aten/ops>` folder and update `dot_native.h` and `XPUFunctions_inl.h` accordingly.

We do this for two reasons:
1. fully reusing torchgen;
2. exposing Aten xpu ops header to public. So developers can include headers like `<Aten/ops/dot_xpu_dispatch.h>` when building C++ extensions (similar to CPU and CUDA).

However, building `libtorch_cpu.so` depends on `dot_native.h`, which is also updated during the second `torchgen`. As a result, we must wait for `libtorch_cpu.so` to finish building before running the second `torchgen`, otherwise, a read-write race may happen if `dot_native.h` is modified while still being used. This can lead to a build failure, especially on Windows. It also introduces an implicit dependency, causing unnecessary recompilation of XPU whenever CPU code changes.

- _empty_affine_quantized
- _empty_per_channel_affine_quantized
- quantized_max_pool2d_xpu
- _safe_softmax_xpu

Pull Request resolved: pytorch#181233
Approved by: https://github.com/EikanWang, https://github.com/albanD

(cherry picked from commit 7b04342)
atalman pushed a commit that referenced this pull request Jun 22, 2026
Revert XPU device-wide synchronization (#187306)

# Motivation
This PR reverts #182630 to fix #187277

Root cause is `ext_oneapi_wait_and_throw` will introduce SYCL Graph to sync an invalid queue.

# Additional Context

This needs to be cherry-picked to the release branch.

Why isn't it captured on CI?
This issue is only found on BMG (Xe2), and the current CI is on Data Center GPU (Xe).
Pull Request resolved: #187306
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: #181233, #187137, #187232

(cherry picked from commit 421abac)

Co-authored-by: Yu, Guangye <[email protected]>
@github-actions
github-actions Bot deleted the gh/guangyey/321/head branch July 14, 2026 02:22
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ml (pytorch#181233)

# Motivation
Currently, PyTorch XPU ATen ops are split across two locations:
- operations that call oneDNN (e.g., GEMM, convolution) reside in [ATen/native/mkldnn/xpu](https://github.com/pytorch/pytorch/tree/main/aten/src/ATen/native/mkldnn/xpu);
- while those implemented with SYCL are located [in torch-xpu-ops](https://github.com/intel/torch-xpu-ops/tree/main/src/ATen/native/xpu).

The operations in PyTorch are declared and registered in [pytorch/aten/src/ATen/native/native_functions.yaml](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/native_functions.yaml#L651), whereas the SYCL-based operations in torch-xpu-ops are declared and registered in [yaml/native/native_functions.yaml](https://github.com/intel/torch-xpu-ops/blob/main/yaml/native/native_functions.yaml#L87).

This setup introduces a complication:
When building PyTorch with XPU support, `torch-gen` needs to be run twice:
- once during the build of torch-xpu at [here](https://github.com/pytorch/pytorch/blob/5aac4cfce409ae24f7f0fe3e95f9a3cf5bdf4a28/cmake/Codegen.cmake#L232-L241) and
- again during the build of torch-xpu-ops at [here](https://github.com/intel/torch-xpu-ops/blob/8d373ba272f9fed348c7684bac4a0c2663844bbd/cmake/Codegen.cmake#L99-L125).

This solution introduces two issues (for more details, see [Details](#details)):
1.	We need to maintain an additional `native_functions.yaml` in torch-xpu-ops, which may lead to unexpected behavior if it becomes out of sync with the one in PyTorch. For example, changes to `codegen` (e.g., pytorch#180190) may break XPU CI because XPU ATen kernel registrations are out-of-tree. This creates additional maintenance overhead for both PyTorch and torch-xpu-ops.
2.	It creates a build dependency; torch-xpu-ops must wait for the torch-cpu build to finish, which increases overall build time and complexity. It also retriggers the re-compile XPU (depends on libtorch_cpu.so) due to any CPU code change.

To resolve the issues mentioned above, we would like to migrate XPU ATen kernel registration to `native_functions.yaml` in PyTorch and reuse its codegen fully.

# Solution
If we could move the ops declarations from torch-xpu-ops into torch’s native_functions.yaml, both problems would be resolved.
The key benefits:
1. Single code generation pass – run torch-gen only once instead of twice, simple and more efficient build process
2. Eliminate build dependency – enable parallel builds of torch-cpu and torch-xpu-ops
3. Single source of truth – maintain only one `native_functions.yaml` file, prevent XPU CI break by torchgen and YAML changes.

# Additional Context
## Details
<img width="1661" height="966" alt="image" src="https://github.com/user-attachments/assets/06574feb-1038-4d9a-bfdd-f4bb0444ecd2" />

We have to maintain a very complicated build flow:
- first `torchgen` in PyTorch, the left one of the picture, it will generate XPUFunctions_inl.h, oneDNN-based dispatch headers (e.g., `addmm_xpu_dispatch.h`), and some partial native declarations (e.g., `dot_native.h`). At this stage, SYCL-based ops (e.g., `dot`) are not included, and corresponding dispatch headers and declarations are not generated.
- second `torchgen` in torch-xpu-ops, the right one of the picture, generates SYCL-based dispatch headers (e.g., `dot_xpu_dispatch.h`) and corresponding native declarations (e.g., `dot_native.h`).
- After 2nd `torchgen`, we copy the newly generated files and declarations back into `<Aten/ops>` folders, and update the corresponding native headers, for example, `dot_xpu_dispatch.h` is copied into `<Aten/ops>` folder and update `dot_native.h` and `XPUFunctions_inl.h` accordingly.

We do this for two reasons:
1. fully reusing torchgen;
2. exposing Aten xpu ops header to public. So developers can include headers like `<Aten/ops/dot_xpu_dispatch.h>` when building C++ extensions (similar to CPU and CUDA).

However, building `libtorch_cpu.so` depends on `dot_native.h`, which is also updated during the second `torchgen`. As a result, we must wait for `libtorch_cpu.so` to finish building before running the second `torchgen`, otherwise, a read-write race may happen if `dot_native.h` is modified while still being used. This can lead to a build failure, especially on Windows. It also introduces an implicit dependency, causing unnecessary recompilation of XPU whenever CPU code changes.

## Deprecated
- _empty_affine_quantized
- _empty_per_channel_affine_quantized
- quantized_max_pool2d_xpu
- _safe_softmax_xpu

Pull Request resolved: pytorch#181233
Approved by: https://github.com/EikanWang, https://github.com/albanD
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…rch#187137)

# Motivation
pytorch#184735 introduces AOTI lazy autotuning with the dual-wrapper mechanism, which uncovered some new XPU test failures in CI.

# Additonal Context
Fix pytorch#187124
Fix pytorch#187123
Fix pytorch#187035
Fix pytorch#187035
Fix pytorch#187036
Fix pytorch#187125
Fix pytorch#187121

This needs to be cherry-picked to the release branch.

Pull Request resolved: pytorch#187137
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: pytorch#181233
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
# Motivation
This PR reverts pytorch#182630 to fix pytorch#187277

Root cause is `ext_oneapi_wait_and_throw` will introduce SYCL Graph to sync an invalid queue.

# Additional Context

This needs to be cherry-picked to the release branch.

Why isn't it captured on CI?
This issue is only found on BMG (Xe2), and the current CI is on Data Center GPU (Xe).
Pull Request resolved: pytorch#187306
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: pytorch#181233, pytorch#187137, pytorch#187232
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ytorch#187314)

# Motivation
When pytorch#184737 generalize `test_multiprocess.py`, it helps enable `TestMultiprocessingDeviceType` test on XPU. However, XPU doesn't support this test suite because lack of IPC support currently. So we would like to skip this test case and restore XPU CI to green.

Fixes pytorch#186585

Code originates from pytorch#186793
Co-authored-by: @xuhancn
Pull Request resolved: pytorch#187314
Approved by: https://github.com/EikanWang, https://github.com/atalman
ghstack dependencies: pytorch#181233, pytorch#187137, pytorch#187232, pytorch#187306
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ml (pytorch#181233)

# Motivation
Currently, PyTorch XPU ATen ops are split across two locations:
- operations that call oneDNN (e.g., GEMM, convolution) reside in [ATen/native/mkldnn/xpu](https://github.com/pytorch/pytorch/tree/main/aten/src/ATen/native/mkldnn/xpu);
- while those implemented with SYCL are located [in torch-xpu-ops](https://github.com/intel/torch-xpu-ops/tree/main/src/ATen/native/xpu).

The operations in PyTorch are declared and registered in [pytorch/aten/src/ATen/native/native_functions.yaml](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/native_functions.yaml#L651), whereas the SYCL-based operations in torch-xpu-ops are declared and registered in [yaml/native/native_functions.yaml](https://github.com/intel/torch-xpu-ops/blob/main/yaml/native/native_functions.yaml#L87).

This setup introduces a complication:
When building PyTorch with XPU support, `torch-gen` needs to be run twice:
- once during the build of torch-xpu at [here](https://github.com/pytorch/pytorch/blob/5aac4cfce409ae24f7f0fe3e95f9a3cf5bdf4a28/cmake/Codegen.cmake#L232-L241) and
- again during the build of torch-xpu-ops at [here](https://github.com/intel/torch-xpu-ops/blob/8d373ba272f9fed348c7684bac4a0c2663844bbd/cmake/Codegen.cmake#L99-L125).

This solution introduces two issues (for more details, see [Details](#details)):
1.	We need to maintain an additional `native_functions.yaml` in torch-xpu-ops, which may lead to unexpected behavior if it becomes out of sync with the one in PyTorch. For example, changes to `codegen` (e.g., pytorch#180190) may break XPU CI because XPU ATen kernel registrations are out-of-tree. This creates additional maintenance overhead for both PyTorch and torch-xpu-ops.
2.	It creates a build dependency; torch-xpu-ops must wait for the torch-cpu build to finish, which increases overall build time and complexity. It also retriggers the re-compile XPU (depends on libtorch_cpu.so) due to any CPU code change.

To resolve the issues mentioned above, we would like to migrate XPU ATen kernel registration to `native_functions.yaml` in PyTorch and reuse its codegen fully.

# Solution
If we could move the ops declarations from torch-xpu-ops into torch’s native_functions.yaml, both problems would be resolved.
The key benefits:
1. Single code generation pass – run torch-gen only once instead of twice, simple and more efficient build process
2. Eliminate build dependency – enable parallel builds of torch-cpu and torch-xpu-ops
3. Single source of truth – maintain only one `native_functions.yaml` file, prevent XPU CI break by torchgen and YAML changes.

# Additional Context
## Details
<img width="1661" height="966" alt="image" src="https://github.com/user-attachments/assets/06574feb-1038-4d9a-bfdd-f4bb0444ecd2" />

We have to maintain a very complicated build flow:
- first `torchgen` in PyTorch, the left one of the picture, it will generate XPUFunctions_inl.h, oneDNN-based dispatch headers (e.g., `addmm_xpu_dispatch.h`), and some partial native declarations (e.g., `dot_native.h`). At this stage, SYCL-based ops (e.g., `dot`) are not included, and corresponding dispatch headers and declarations are not generated.
- second `torchgen` in torch-xpu-ops, the right one of the picture, generates SYCL-based dispatch headers (e.g., `dot_xpu_dispatch.h`) and corresponding native declarations (e.g., `dot_native.h`).
- After 2nd `torchgen`, we copy the newly generated files and declarations back into `<Aten/ops>` folders, and update the corresponding native headers, for example, `dot_xpu_dispatch.h` is copied into `<Aten/ops>` folder and update `dot_native.h` and `XPUFunctions_inl.h` accordingly.

We do this for two reasons:
1. fully reusing torchgen;
2. exposing Aten xpu ops header to public. So developers can include headers like `<Aten/ops/dot_xpu_dispatch.h>` when building C++ extensions (similar to CPU and CUDA).

However, building `libtorch_cpu.so` depends on `dot_native.h`, which is also updated during the second `torchgen`. As a result, we must wait for `libtorch_cpu.so` to finish building before running the second `torchgen`, otherwise, a read-write race may happen if `dot_native.h` is modified while still being used. This can lead to a build failure, especially on Windows. It also introduces an implicit dependency, causing unnecessary recompilation of XPU whenever CPU code changes.

## Deprecated
- _empty_affine_quantized
- _empty_per_channel_affine_quantized
- quantized_max_pool2d_xpu
- _safe_softmax_xpu

Pull Request resolved: pytorch#181233
Approved by: https://github.com/EikanWang, https://github.com/albanD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

6 participants