Repository navigation
Conversation
🔗 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 SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 2 New Failures, 4 Unrelated Failures, 3 Unclassified FailuresAs of commit 6e29118 with merge base 2637e3b ( 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. |
Attention! native_functions.yaml was changedIf 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: |
Attention! PyTorch one of the C-stable API file was changedYou 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: |
# Motivation This PR will help fix the build when pytorch/pytorch#181233 landed. Will remove codegen from torch-xpu-ops in follow up PRs.
) # 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
…o 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
# 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
…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
…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]>
) [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]>
…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]>
# Motivation After pytorch/pytorch#181233 and #3970 landed, we could entirely remove separate codegen and its postprocess in torch-xpu-ops.
# Motivation After pytorch/pytorch#181233 and #3970 landed, we could entirely remove separate yaml/ folder in torch-xpu-ops.
# Motivation This PR will help fix the build when pytorch/pytorch#181233 landed. Will remove codegen from torch-xpu-ops in follow up PRs.
…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)
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]>
…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
…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
…o driver (pytorch#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: pytorch#187232 Approved by: https://github.com/EikanWang, https://github.com/atalman ghstack dependencies: pytorch#181233, pytorch#187137
# 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
…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
…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
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-genneeds to be run twice:This solution introduces two issues (for more details, see Details):
native_functions.yamlin torch-xpu-ops, which may lead to unexpected behavior if it becomes out of sync with the one in PyTorch. For example, changes tocodegen(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.To resolve the issues mentioned above, we would like to migrate XPU ATen kernel registration to
native_functions.yamlin 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:
native_functions.yamlfile, prevent XPU CI break by torchgen and YAML changes.Additional Context
Details
We have to maintain a very complicated build flow:
torchgenin 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.torchgenin 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).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.his copied into<Aten/ops>folder and updatedot_native.handXPUFunctions_inl.haccordingly.We do this for two reasons:
<Aten/ops/dot_xpu_dispatch.h>when building C++ extensions (similar to CPU and CUDA).However, building
libtorch_cpu.sodepends ondot_native.h, which is also updated during the secondtorchgen. As a result, we must wait forlibtorch_cpu.soto finish building before running the secondtorchgen, otherwise, a read-write race may happen ifdot_native.his 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