Skip to content

[GPU] add oneDNN SDPA primitive as a debug feature#36342

Open
wilson-seok wants to merge 7 commits into
openvinotoolkit:masterfrom
wilson-seok:onednn_sdpa_implementation
Open

[GPU] add oneDNN SDPA primitive as a debug feature#36342
wilson-seok wants to merge 7 commits into
openvinotoolkit:masterfrom
wilson-seok:onednn_sdpa_implementation

Conversation

@wilson-seok

@wilson-seok wilson-seok commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a oneDNN GPU implementation for scaled_dot_product_attention for debugging feature.
  • Register onednn::sdpa ahead of OCL SDPA implementations while preserving OCL fallback.
  • Gate selection behind internal GPU property ov::intel_gpu::enable_onednn_sdpa_primitive / OV_GPU_ENABLE_ONEDNN_SDPA_PRIMITIVE.
  • Add focused GPU unit coverage that compares oneDNN SDPA output against the OCL reference path on GPU.1.

Validation

  • cmake --build . --target ov_gpu_unit_tests -j23 -- -s
  • cmake --build . --target openvino_intel_gpu_plugin -j23 -- -s
  • ./bin/intel64/Release/ov_gpu_unit_tests --gtest_filter='*onednn_sdpa*' --device_suffix=1

@wilson-seok
wilson-seok requested review from a team as code owners June 10, 2026 14:39
@github-actions github-actions Bot added the category: GPU OpenVINO GPU plugin label Jun 10, 2026
@wilson-seok wilson-seok changed the title GPU: add preview oneDNN SDPA primitive [Do Not Review][GPU] add preview oneDNN SDPA primitive Jun 10, 2026
@wilson-seok
wilson-seok requested a review from Copilot June 10, 2026 14:52

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.

Pull request overview

Adds a preview oneDNN GPU implementation for scaled_dot_product_attention in the Intel GPU plugin, with opt-in selection via a new internal property and a GPU unit test that compares oneDNN output against the existing OCL reference implementation.

Changes:

  • Register a new oneDNN-based SDPA implementation manager ahead of existing OCL SDPA implementations (with fallback preserved via validation/property gating).
  • Gate oneDNN SDPA selection behind internal property ov::intel_gpu::enable_onednn_sdpa_primitive / OV_GPU_ENABLE_ONEDNN_SDPA_PRIMITIVE, and enable the primitive in the layout optimizer when configured.
  • Add a focused GPU unit test validating selection of oneDNN SDPA and numerical agreement vs OCL reference.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/plugins/intel_gpu/tests/unit/test_cases/sdpa_gpu_test.cpp Adds parameterized unit test comparing oneDNN SDPA vs OCL ref and asserts oneDNN impl selection.
src/plugins/intel_gpu/src/graph/registry/sdpa_impls.cpp Registers the oneDNN SDPA implementation manager before OCL SDPA implementations.
src/plugins/intel_gpu/src/graph/program.cpp Enables oneDNN SDPA via layout_optimizer when the new config property is set.
src/plugins/intel_gpu/src/graph/layout_optimizer.cpp Adds SDPA inst header include needed for enabling oneDNN for SDPA in layout optimizer flow.
src/plugins/intel_gpu/src/graph/impls/onednn/sdpa_onednn.hpp Introduces oneDNN SDPA implementation manager with capability/shape/type validation.
src/plugins/intel_gpu/src/graph/impls/onednn/sdpa_onednn.cpp Implements oneDNN SDPA primitive creation, argument binding, and (de)serialization support.
src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl Adds internal option declaration for enabling the oneDNN SDPA primitive.
src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp Adds internal property key GPU_ENABLE_ONEDNN_SDPA_PRIMITIVE.

Comment thread src/plugins/intel_gpu/tests/unit/test_cases/sdpa_gpu_test.cpp Outdated
Comment thread src/plugins/intel_gpu/tests/unit/test_cases/sdpa_gpu_test.cpp Outdated

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.

Pull request overview

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

Comment thread src/plugins/intel_gpu/src/graph/impls/onednn/sdpa_onednn.hpp
Comment thread src/plugins/intel_gpu/src/graph/impls/onednn/sdpa_onednn.hpp
Comment thread src/plugins/intel_gpu/tests/unit/test_cases/sdpa_gpu_test.cpp
Comment thread src/plugins/intel_gpu/tests/unit/test_cases/sdpa_gpu_test.cpp Outdated
@wilson-seok
wilson-seok force-pushed the onednn_sdpa_implementation branch from 98bd57e to 1bcfe47 Compare June 15, 2026 01:12
@wilson-seok wilson-seok changed the title [Do Not Review][GPU] add preview oneDNN SDPA primitive [GPU] add preview oneDNN SDPA primitive Jun 15, 2026
wilson-seok and others added 4 commits June 15, 2026 10:13
Enable oneDNN SDPA to work correctly with real LLM inference where
K/V buffers have upper padding from KV-cache pre-allocation and shapes
are dynamic.

Key changes:
- Use explicit strides from layout::get_pitches() when creating oneDNN
  memory descriptors for padded layouts, instead of assuming contiguous
  format tags. This fixes accuracy issues where oneDNN read wrong data
  for heads beyond the first due to stride mismatch.
- Add dynamic shape support: create() returns unconfigured impl for
  dynamic shapes; update() calls configure() at runtime with actual
  shapes/strides.
- Register dynamic_shape variant in sdpa_impls.cpp so the impl is
  selected for IndirectSDPA nodes with dynamic dimensions.
- Add support_shapes() override with beam_table check for IndirectSDPA
  and shared validate_common() for both graph-build and runtime checks.
- Add runtime attention mask support with proper descriptor creation
  and argument binding.
- Extend unit tests with dynamic shape and runtime mask/scale variants.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@isanghao isanghao changed the title [GPU] add preview oneDNN SDPA primitive [GPU] add oneDNN SDPA primitive as a debug feature Jun 18, 2026
Comment thread src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl Outdated
…ync, instrumentation

Tooling + workarounds from the llama-3.1 Xe3p PagedAttention INT4-KV micro-kernel
nan/inf accuracy investigation:

- Add OV_GPU_DISABLE_SDPA_MICRO knob (internal_properties.hpp, options.inl) and
  wire it into both SDPA backends: PagedAttentionOpt::supports_micro_sdpa
  (paged_attention_opt.cpp) and SDPAOpt::supports_micro_sdpa (sdpa_opt.cpp).
  When set, forces SDPA onto the OCL sdpa_opt path instead of the oneDNN-derived
  micro kernel -- proven accuracy workaround for the Xe3p corruption, no rebuild.
- Sync choose_config_xe3p in sdpa_gen_micro.cpp to faithfully mirror oneDNN's
  data-driven xe3p config table (configs.cpp): head_size ceiling match + exact
  second_token/quantized match + xe3p->xe2 fallback, fma rows folded in.
- Add deduped [choose_config] + [micro_selected] diagnostic dumps in
  sdpa_gen_micro.cpp to capture the resolved tuning hint and the actual selected
  microkernel strategy per model/phase.
- Keep the xe3p head_size<=64 micro-SDPA WA (load-bearing for gpt-oss accuracy).
- CMakeLists.txt: gate DX11/DX12 remote-tensor interop tests on <atlbase.h> so
  environments without the VS ATL workload don't break the build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the category: build OpenVINO cmake script / infra label Jun 24, 2026
@wilson-seok
wilson-seok requested a review from Copilot June 25, 2026 05:32
Rename the opt-in property to use_onednn_sdpa and expose it as the debug-only OV_GPU_USE_ONEDNN_SDPA option.

Guard oneDNN SDPA selection and related tests when debug caps are disabled.

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Comment thread src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_opt.cpp
Comment thread src/plugins/intel_gpu/src/graph/impls/ocl_v2/sdpa/sdpa_gen_micro.cpp Outdated
Comment thread src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl
Address Copilot review comments on PR openvinotoolkit#36342:
- Route DISABLE_SDPA_MICRO knob messages through GPU verbose infra
- Wrap choose_config/micro_selected logging in GPU_DEBUG_IF guard
- Add comment explaining why PA skips xe3p tuning table
- Remove unused <iostream>/<mutex> includes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@isanghao

isanghao commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Please consider PR-36705. It will conflict this this PR: #36705

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: build OpenVINO cmake script / infra category: GPU OpenVINO GPU plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants