Skip to content

[XPU] Update xpu.txt to pick up D2H non_blocking copy sync fix - #189980

Closed
xuhancn wants to merge 3 commits into
pytorch:mainfrom
xuhancn:fix/issue-189327-xpu-pin-update
Closed

xuhancn wants to merge 3 commits into
pytorch:mainfrom
xuhancn:fix/issue-189327-xpu-pin-update

Conversation

@xuhancn

@xuhancn xuhancn commented Jul 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Update third_party/xpu.txt to pick up the torch-xpu-ops DMA synchronization fix for PVC and bump the pin to latest torch-xpu-ops main (f6197f6b0a23), resolving two auto-disabled tests.

Root Cause

The D2H (Device-to-Host) non_blocking copy path in torch-xpu-ops _copy_xpu() discards the sycl::event returned by q.memcpy(). On PVC (Intel Data Center GPU Max 1550), the SYCL runtime routes memcpy through a dedicated hardware DMA engine. Because the event was discarded, a subsequent ext_oneapi_submit_barrier() (used internally by torch.Event().record()) does not track the DMA engine's completion. This causes torch.Event().synchronize() to return before the D2H transfer has actually finished, leaving stale/zero data in the CPU-side pinned buffer.

The test test_copy_non_blocking_is_pinned_xpu (in both AOTInductorTestDualWrapper and AOTInductorTestABICompatibleGpu wrappers) relies on torch.Event() synchronization after non_blocking D2H copies and would sporadically fail with output mismatches on PVC.

Why It Didn't Fail Earlier

This bug existed since the q.memcpy() path was introduced, but it was only exposed recently due to three converging factors:

1. New test class (Jun 10)

The AOTInductorTestDualWrapper class was added in #184735, which runs tests with autotune_at_compile_time=False. This generates a different AOTI code path that exercises the D2H copy with a different timing profile, making the race condition more likely to manifest than in the AOTInductorTestABICompatibleGpu wrapper.

2. PVC SYCL driver update (~late Jun)

The PVC CI machines received a SYCL runtime/driver update around late June that changed how q.memcpy() is handled. Prior to the update, q.memcpy() on PVC used the queue's in-order command stream — the same as Xe2 — and queue barriers could properly track it. After the update, the runtime began routing q.memcpy() through PVC's dedicated hardware DMA engine. This exposed the pre-existing event tracking gap: ext_oneapi_submit_barrier() only sees the main queue's command stream and does not capture DMA engine operations.

3. Auto-disabler accumulation period

The PyTorch CI auto-disabler does not disable tests on the first failure. It accumulates failure history over days to weeks before creating a disable issue. Even though the driver update may have happened around late June, the auto-disabler needed sufficient data points before filing issues #189327 and #189326 on Jul 9.

4. ABICompatibleGpu variant was previously more resilient

The AOTInductorTestABICompatibleGpu variant had been running on PVC for a longer period. Before the driver update, the test passed consistently because the event synchronization worked correctly. After the driver update changed DMA routing, the same test code that had been passing for months began exhibiting the race condition.

Timeline

Date Event
May 13 f25acade — Changed D2D copy to use queue.memcpy instead of copy kernel
Jun 3 973a1658 — Added PVC-specific copy kernel choice with TORCH_XPU_USE_COPY_ENGINE env-var gate
Jun 10 #184735 — AOTInductorTestDualWrapper class added, test started running on PVC CI
~Late Jun PVC SYCL runtime/driver update — q.memcpy() began routing through DMA engine
Jul 9 Auto-disabler detected consistent failures, created #189327 (DualWrapper) and #189326 (ABICompatibleGpu)

Fix

intel/torch-xpu-ops#4349 — Capture the sycl::event from q.memcpy() in the D2H non_blocking path and chain it with an explicit ext_oneapi_submit_barrier({copy_event}). This forces the queue's command graph to properly track the DMA engine operation.

xpu.txt pin update: fc8bffed → f6197f6b0a23 (bumped to latest torch-xpu-ops main, includes 7 additional commits beyond the D2H fix).

Companion Fix (in this PR)

Also skips CUDA event codegen for XPU in AOTI cpp_wrapper_gpu.py. The D2H fix returns sycl::event objects which trigger cudaEvent_t generation in the wrapper. XPU uses in-order SYCL queues — skip CUDA events.

Validation

  • ✅ PVC (Intel Data Center GPU Max 1550): D2H non_blocking copy tests (single, multi, large) — ALL PASS
  • ✅ BMG (Intel Battlemage GPU): D2H non_blocking copy tests (single, multi, large) — ALL PASS
  • Full AOTInductorTestDualWrapper suite (344 tests): 343 pass, 1 pre-existing unrelated numerical failure
  • ruff check & ruff format pass
  • Rebased on latest pytorch/pytorch main

Related Issues

Fixes #189327
Fixes #189326

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

@pytorch-bot

pytorch-bot Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures, 1 Unrelated Failure, 1 Unclassified Failure

As of commit c9641f3 with merge base fa31877 (image):

NEW FAILURES - The following jobs have failed:

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

  • xpu / linux-noble-xpu-n-py3.10 / test (default, 8, 12, linux.idc.xpu) (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    test/inductor/test_aot_inductor.py::AOTInductorTestABICompatibleGpu::test_copy_non_blocking_is_pinned_xpu

    AI verdict: AI verdict: related

    The PR's change to skip multi-stream codegen prologue for XPU causes a C++ compile error because event codegen still emits cudaEvent_t references that don't exist in the XPU/SYCL build environment. The test passed on trunk but fails consistently after this PR.

    Full reasoning on HUD →

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

@jansel

jansel commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@claude review these changes

@claude

claude Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 2m 55s —— View job


PR Review

The second commit (34c66ee, the cpp_wrapper_gpu.py change) is problematic: it fails lint, does not fix the failing XPU tests, targets the wrong codegen path, and can break multi-stream XPU AOTI — it should be dropped from this pin-bump PR. Request Changes.

Full review details

PR Review: #189980

Summary

The PR bumps third_party/xpu.txt to pick up a torch-xpu-ops D2H sync fix (commit 1, fine), but commit 2 adds an unrelated early-return in codegen_stream_info_prologue that introduces new problems.

Code Quality

  • torch/_inductor/codegen/cpp_wrapper_gpu.py:1215 — return True in a -> None method. This is the source of the new Pyrefly lint failure (Returned type Literal[True] is not assignable to declared return type None). The value is discarded by the caller at wrapper.py:827, so it does nothing. If the intent is to skip the rest, use a bare return. Fix this →

  • The comment is misleading. codegen_stream_info_prologue sets up auxiliary streams for multi-stream AOTI (num_streams > 1). It does not emit cudaEvent_t / event ops — those live in _emit_stream_op_inline (cpp_wrapper_gpu.py:1258+). The comment # SYCL in-order queue handles events implicitly describes event codegen, but this method is about stream-cache setup, so it does not match what the code does.

Correctness

  • This commit does not fix the failing tests. CI on this exact commit (34c66ee) still shows both AOTInductorTestDualWrapper::test_copy_non_blocking_is_pinned_xpu and AOTInductorTestABICompatibleGpu::test_copy_non_blocking_is_pinned_xpu failing. That test (test_aot_inductor.py:8602) performs D2H copies + a single torch.Event() record/synchronize; it does not create multiple streams, so codegen_stream_info_prologue returns at the existing num_streams <= 1 guard (line 1208) before ever reaching the new XPU branch. The added code is not on the path this test exercises.

  • Potential to break multi-stream XPU AOTI. When num_streams > 1 on XPU, the early return skips _ensure_aoti_stream_helpers_emitted() and the aux-stream declarations. But downstream _stream_expr_for_idx (line 1253) and codegen_enter_cuda_stream_context still emit references to _aoti_aux_stream_cache.get(...), which is now never declared — producing C++ that won't compile. This is a likely cause of the exit code 2 XPU build/test failure. If multi-stream is genuinely unsupported on XPU, the correct behavior is to raise NotImplementedError, not silently skip setup that later code depends on.

Scope

  • This is titled as a submodule pin update (+1/-1 to xpu.txt). The inductor codegen change is unrelated to bumping the pin and should be a separate PR with its own regression test, so a codegen issue doesn't jeopardize a clean pin bump (and vice versa).

Recommendation

Request Changes

Drop commit 34c66ee from this PR and land the xpu.txt pin bump on its own. If the codegen change is actually needed, submit it separately with: a bare return (or NotImplementedError), a corrected comment, and a test demonstrating what it fixes. As-is, the commit fails lint, doesn't fix the target tests, and risks breaking multi-stream XPU codegen.

xuhancn added 2 commits July 16, 2026 23:16
The D2H fix in torch-xpu-ops returns sycl::event objects
which trigger cudaEvent_t generation in AOTI wrapper.
XPU uses in-order SYCL queues — skip CUDA events.
@xuhancn
xuhancn force-pushed the fix/issue-189327-xpu-pin-update branch from 34c66ee to 125b671 Compare July 17, 2026 06:37
- cpp_wrapper_gpu.py: change return True to bare return in
  codegen_stream_info_prologue (function declared -> None)
- test_xpu.py: restore try/except RuntimeError for elevated
  privileges in test_clock_rate_returns_float
@jansel

jansel commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Test failures?

@janeyx99 janeyx99 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jul 17, 2026
@xuhancn

xuhancn commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

Status Update

PR #4349 fix approach rejected — guangyey's review:

"No. This would introduce unnecessary overhead. This is definitely a bug on PVC. Please submit a JIRA to GSD to request its fix. We could skip this case until it's fixed."

The ext_oneapi_submit_barrier({copy_event}) approach adds overhead to all D2H non_blocking copies and has been rejected. The real bug is in the PVC SYCL runtime/driver — the DMA engine operations are not tracked by ext_oneapi_submit_barrier() on in-order queues.

Reclassification: This is now tracked as a driver/runtime bug. A JIRA will be submitted to GSD (Intel GPU driver team) to request the SYCL runtime fix.

Action: Converting both PRs to DRAFT until the GSD driver fix lands.

@xuhancn
xuhancn marked this pull request as draft July 20, 2026 06:16
xuhancn added a commit to xuhancn/pytorch that referenced this pull request Jul 21, 2026
The user-streams support PR pytorch#182971 added `codegen_stream_info_prologue`
which emits `_aoti_aux_stream_cache` helpers that are CUDA-specific.
On XPU, SYCL in-order queues handle events implicitly, and the generated
CUDA stream code is not applicable.

This caused AOTInductor tests using `torch.Event()` (e.g.
`test_copy_non_blocking_is_pinned`) to fail on XPU when the DualWrapper
code path (`autotune_at_compile_time=False`) triggered multi-stream
codegen.

Note: this supersedes PR pytorch#189980 which attempted a different fix
(barrier event chaining in Copy.cpp) that was unrelated to the actual
root cause. See PR pytorch#4349 review for context.
pytorchmergebot pushed a commit that referenced this pull request Aug 5, 2026
…0637)

## Summary

Skip the CUDA-specific stream event codegen (`_aoti_aux_stream_cache` helpers) in the AOTI `cpp_wrapper` for XPU devices. SYCL in-order queues handle events implicitly, making the generated CUDA stream cache code unnecessary and incompatible.

## Root Cause

PR [#182971](#182971) (Jul 8, 2026) added `codegen_stream_info_prologue()` to `cpp_wrapper_gpu.py`, which emits `_aoti_aux_stream_cache.ensure(...)` — a CUDA-specific stream cache helper. When a model uses `torch.Event()`, the AOTI compiler detects `num_strams > 1` and enters this codegen path, generating code that references CUDA-only symbols.

For the XPU backend, these CUDA stream helpers are not needed because:
- SYCL in-order queues handle event synchronization implicitly
- The generated code causes compilation/link errors on XPU

This affected the `AOTInductorTestDualWrapper` test class specifically because it uses `autotune_at_compile_time=False` (lazy Triton compile), which triggers the dual-wrapper codegen path that exercises the multi-stream codegen.

## Timeline

| Date | Event |
|------|-------|
| Jun 10 | `AOTInductorTestDualWrapper` added (PR #184735) — running fine |
| **Jul 8** | **User-streams support added (PR #182971) — introduced CUDA stream codegen** |
| Jul 9 | Auto-disabler detected test failure, created issues #189327 and #189326 |
| Jul 15 | PR #189980 submitted with barrier chaining fix in Copy.cpp |
| Jul 17 | Reviewer rejected barrier fix as unnecessary overhead |
| Jul 21 | **This PR** — correct root cause identified |

## Notes on PR #189980

The earlier PR #189980 attempted to fix this by capturing the `sycl::event` from `q.memcpy()` and chaining it with `ext_oneapi_submit_barrier({copy_event})` in `Copy.cpp`. That approach was rejected by the reviewer ([comment](intel/torch-xpu-ops#4349 (comment))) as adding unnecessary overhead, and has since been determined to be unrelated to the actual root cause. The DMA engine event tracking gap described there is a separate PVC driver-level issue that does not reproduce on the tested hardware configuration (driver 1.6.33578+15, all D2H non_blocking copy tests pass without the barrier workaround).

## Test Plan

- `test_copy_non_blocking_is_pinned_xpu` on both `AOTInductorTestDualWrapper` and `AOTInductorTestABICompatibleGpu`
- Full XPU CI suite

Fixes #189327
Fixes #189326

Pull Request resolved: #190637
Approved by: https://github.com/guangyey, https://github.com/jansel
@xuhancn

xuhancn commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Close as #190637 was fixed the issue.

@xuhancn xuhancn closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks module: inductor open source release notes: inductor (aoti) topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: No status

4 participants