Skip to content

XPU oneDNN: bind matmul execution to live SYCL queue (graph-capture safe) - #2280

Open
luoyu-intel with Copilot wants to merge 7 commits into
mainfrom
copilot/fix-2206-onednn-stream-compatibility
Open

XPU oneDNN: bind matmul execution to live SYCL queue (graph-capture safe)#2280
luoyu-intel with Copilot wants to merge 7 commits into
mainfrom
copilot/fix-2206-onednn-stream-compatibility

Conversation

Copilot AI commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Description

Issue #2206 reports that XPU oneDNN stream caching was keyed too coarsely (device UUID), so later calls could execute on a stale queue instead of the active torch.xpu graph-capture queue; m > 1 WOQ GEMM then escaped capture and replay produced frozen/zero outputs.
This PR makes oneDNN execution queue-correct while preserving engine reuse.

  • Root cause / scope

    • DnnlContext cached dnnl::stream per device; stream stayed bound to first queue seen.
    • woq_gemm (m > 1, fp16/fp32 oneDNN path) executed via that stale stream.
  • Queue-correct execution model

    • Reworked DnnlContext:
      • cache engine by (device, sycl::context) (reused for performance),
      • construct stream from the current call queue (live queue binding).
    • Scratch buffer keying aligned to context-aware identity to avoid cross-context reuse.
  • Call-chain cleanup

    • Removed implicit GETCTX() usage from active oneDNN GEMM/quant paths.
    • gemm/dyn_quant_s8/igemm_s8s8 now explicitly derive engine+stream from passed q.
  • Regression coverage

    • Added XPU test: eager warmup on one queue, graph capture on another queue, m > 1, replay with changed inputs; replay output must track eager reference (not frozen).
auto& eng = *DnnlContext::Instance()->get_eng(q);
auto stream = DnnlContext::Instance()->get_stream(q);  // bound to live queue
matmul_prim.execute(stream, matmul_args);

Type of Change

Bug fix

Related Issues

Tracked in repository issue tracker (auto-linking handled by system).

Checklist Before Submitting

  • My code has been tested locally.
  • Documentation has been updated as needed.
  • New or updated tests are included where applicable.
  • The CUDA CI has passed. You can trigger it by commenting /azp run Unit-Test-CUDA-AutoRound.

Co-authored-by: luoyu-intel <108715795+luoyu-intel@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix oneDNN cached stream and torch.xpu graph compatibility issue XPU oneDNN: bind matmul execution to live SYCL queue (graph-capture safe) Sep 2, 2026
Copilot AI requested a review from luoyu-intel September 2, 2026 08:35
@luoyu-intel
luoyu-intel marked this pull request as ready for review September 2, 2026 08:45
@luoyu-intel
luoyu-intel requested a lite review from Copilot September 2, 2026 08:45

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Fixes XPU oneDNN graph-capture correctness by ensuring oneDNN execution is bound to the live SYCL queue (avoiding stale cached streams) while keeping engine reuse, and adds a regression test to prevent frozen outputs on replay.

Changes:

  • Reworked DnnlContext to cache engines per (device, sycl::context) and create streams from the current queue.
  • Aligned scratch-buffer keying to be context-aware to avoid cross-context reuse.
  • Added an XPU regression test covering warmup-on-one-queue + capture-on-another + replay-with-new-inputs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
auto_round_extension/ark/test/test_weightonly.py Adds a regression test ensuring WOQ GEMM graph capture uses the live queue and replay updates outputs.
auto_round_extension/ark/auto_round_kernel/wrapper/include/utils.hpp Refactors oneDNN engine/stream management to be queue-correct and context-aware, plus scratch-key changes.
auto_round_extension/ark/auto_round_kernel/wrapper/include/dnnl_wrapper.hpp Removes GETCTX() macro and explicitly derives engine + live stream from the passed queue.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread auto_round_extension/ark/auto_round_kernel/wrapper/include/utils.hpp Outdated
Comment thread auto_round_extension/ark/test/test_weightonly.py Outdated
return ark.woqgemm(x, packw, bias, n, k, blocksize, compute_type, weight_type, scale_type, asym)

eager_input = torch.randn(m, k, dtype=torch.float16, device="xpu") - 0.5
replay_input = torch.randn(m, k, dtype=torch.float16, device="xpu") + 0.25

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.

@copilot Updated the regression test to use deterministic inputs. The replay input is derived from the eager input with a fixed offset (replay_input = eager_input + 0.75), avoiding unseeded randomness while ensuring the two replay cases are observably different.

@AutoRoundBot

Copy link
Copy Markdown
Collaborator

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI and others added 2 commits September 3, 2026 02:06
Co-authored-by: luoyu-intel <108715795+luoyu-intel@users.noreply.github.com>
Co-authored-by: luoyu-intel <108715795+luoyu-intel@users.noreply.github.com>
Co-authored-by: luoyu-intel <108715795+luoyu-intel@users.noreply.github.com>
@AutoRoundBot

Copy link
Copy Markdown
Collaborator

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

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.

4 participants