Skip to content

feat(hipdnn): add ragged tensor SDPA forward sample - #13095

Merged
iq136boy merged 4 commits into
developfrom
users/dfeng/ragged-sdpa-sample
Oct 28, 2026
Merged

iq136boy merged 4 commits into
developfrom
users/dfeng/ragged-sdpa-sample

Conversation

@iq136boy

@iq136boy iq136boy commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add samples/sdpa/SdpaRaggedFprop.cpp — end-to-end ragged SDPA forward sample per RFC 0014 §4.6.1
  • Register the new hipdnn_sample_sdpa_ragged_fprop target under HIPDNN_ENABLE_SDPA in samples/CMakeLists.txt

Description

Demonstrates user-side ragged tensor construction for scaled dot-product attention:

  • BSHD layout only (seqAxis=1) — the only ragged-legal layout
  • Both RaggedTensor construction forms: size-inference (Q, V, O read ragged_offset[B] from aux) and explicit physicalElementCount (K)
  • Aux sharing: K and V share a single kvRaggedOffset aux tensor and kvRaggedAttr graph attribute
  • rawDeviceData() wiring: ragged primaries and aux tensors use rawDeviceData() in the variant pack; dense seq_len tensors use .memory().deviceData() (non-ragged, as today)
  • Padding mask + seq_len: configures set_padding_mask(true), set_seq_len_q(), set_seq_len_kv() on SdpaAttributes
  • CPU validation: prints skip message (--verify-cpu); ragged CPU reference not yet wired

Dimensions: B=3, S_MAX=5, H=4, D=128, Q seq lens {2,5,3}, KV seq lens {3,5,4}, seqStride = H*D = 512.

Follows the structure of the existing SdpaFprop.cpp sample closely. Test registration is commented out, matching the existing dense SDPA sample pattern.

Test plan

  • ninja hipdnn_sample_sdpa_ragged_fprop builds with zero warnings under -Werror -Wall -Wextra -Wpedantic
  • Existing hipdnn_sample_sdpa_fprop still builds cleanly
  • pre-commit passes (clang-format, cmake-lint, trailing whitespace, end-of-file)
  • Run ./bin/hipdnn_sample_sdpa_ragged_fprop --dtype fp32 on a device with an SDPA engine — expect graph build + execute + first 10 output values (or graceful skip)

Tracking

JIRA ID: ALMIOPEN-2128

🤖 Generated with Claude Code

@iq136boy
iq136boy requested a review from a team as a code owner October 5, 2026 16:13
@therock-pr-bot

therock-pr-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/hipdnn/samples/sdpa/SdpaRaggedFprop.cpp; no test file found
🔎 pre-commit ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —
🤖 therock-pr-bot ✅ Pass —

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

therock-pr-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

@jerehartAMD jerehartAMD 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.

The layout comment should be addressed, but feel free to take the others as nits

iq136boy and others added 2 commits October 9, 2026 22:26
Demonstrate user-side ragged tensor construction for SDPA per RFC 0014
§4.6.1: size-inference and explicit-size RaggedTensor forms, aux sharing
across K/V, and rawDeviceData() wiring into the variant pack. Non-ragged
tensors (seq_len_q, seq_len_kv) are constructed as today.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…PA sample

Address review feedback on the ragged SDPA forward sample:
- Use BHSD logical dims [B, H, S_MAX, D] with BSHD physical strides
  [S_MAX*H*D, D, H*D, 1], and SDPA_SEQ_AXIS for the RaggedTensors.
- Express ragged offsets in token units and set
  ragged_offset_multiplier = H*D on Q, K, V, and O.
- Build the offset tables with reserve/push_back.

Co-Authored-By: Claude <noreply@anthropic.com>
@iq136boy
iq136boy force-pushed the users/dfeng/ragged-sdpa-sample branch from 60b42ea to eb6f04a Compare October 9, 2026 22:32
@iq136boy
iq136boy requested a review from jerehartAMD October 9, 2026 22:36
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #13095      +/-   ##
===========================================
- Coverage    75.95%   71.97%   -3.99%     
===========================================
  Files         2880     2885       +5     
  Lines       479055   478111     -944     
  Branches     71964    70688    -1276     
===========================================
- Hits        363860   344074   -19786     
- Misses       90337   110054   +19717     
+ Partials     24858    23983     -875     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 49.67% <ø> (+0.74%) ⬆️ Carriedforward from 80c1baf
TensileLite-Unit 83.44% <ø> (-0.24%) ⬇️ Carriedforward from 80c1baf
hipBLAS 90.62% <ø> (ø) Carriedforward from 80c1baf
hipBLASLt 42.71% <ø> (-21.72%) ⬇️ Carriedforward from 80c1baf
hipCUB 82.68% <ø> (ø) Carriedforward from 80c1baf
hipDNN 86.78% <ø> (-0.01%) ⬇️
hipFFT 42.58% <ø> (+0.58%) ⬆️ Carriedforward from 80c1baf
hipRAND 76.12% <ø> (ø) Carriedforward from 80c1baf
hipSOLVER 68.96% <ø> (-0.71%) ⬇️ Carriedforward from 80c1baf
hipSPARSE 86.99% <ø> (ø) Carriedforward from 80c1baf
rocBLAS 48.17% <ø> (-20.56%) ⬇️ Carriedforward from 80c1baf
rocFFT 46.51% <ø> (-1.59%) ⬇️ Carriedforward from 80c1baf
rocRAND 57.39% <ø> (+0.09%) ⬆️ Carriedforward from 80c1baf
rocSOLVER 76.83% <ø> (+0.09%) ⬆️ Carriedforward from 80c1baf
rocSPARSE 74.07% <ø> (-2.84%) ⬇️ Carriedforward from 80c1baf
rocThrust 93.15% <ø> (ø) Carriedforward from 80c1baf

*This pull request uses carry forward flags. Click here to find out more.
see 625 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iq136boy
iq136boy requested a review from a team as a code owner October 20, 2026 15:46
@iq136boy
iq136boy merged commit 0e604f5 into develop Oct 28, 2026
225 of 231 checks passed
@iq136boy
iq136boy deleted the users/dfeng/ragged-sdpa-sample branch October 28, 2026 15:45
@assistant-librarian

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants