Skip to content

feat(rocke): add SDPA padding host adapter, mask spec, and oracle sup… - #13142

Closed
arai713 wants to merge 1 commit into
developfrom
users/arai/padding_mask
Closed

arai713 wants to merge 1 commit into
developfrom
users/arai/padding_mask

Conversation

@arai713

@arai713 arai713 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Padding-mask support on the SDPA path for gfx942/gfx950. The kernel-side masking has to land inside the stride shell, which doesn't exist yet, and the arbitrary-length buffer clipping it rides on is a separate ticket. This PR lands the host-side, non-blocked foundation so the kernel masking is a mechanical drop-in when the shell arrives: the oracle can express padding, the hipDNN length tensors are validated and normalized, and the exact mask the kernel must emit is specified and cross-checked.

Technical Details

  • dense_attention_reference gains optional seqlen_q / seqlen_kv. None keeps the exact unpadded arithmetic. When set, keys past seqlen_kv are masked, a row with no valid key yields O = 0, and padded query rows are zeroed.
  • _sdpa_seqlen.py: host adapter validating hipDNN SEQ_LEN_Q/KV at the boundary (integer dtype, per-batch count, 0 <= len <= S_max) and returning the flat per-batch int32 arrays the shell reads. The call signature is provisional until the shell kernargs freeze.
  • _sdpa_padding_mask.py: host specification of the kernel-side mask, keep_key and row_is_valid (the epilogue's padded-row zeroing). The live IR emitter is deferred to the shell, where it carries its byte-identity C++ mirror. This module is the host reference it must match.

Test Plan

  • Oracle padding tests (tests/test_numeric_references.py)
  • Adapter tests (library/tests/test_sdpa_seqlen.py)
  • Mask-spec tests incl. composition against the oracle (library/tests/test_sdpa_padding_mask.py)
  • Library layering guard (new kernel-layer files import downward only)
  • Byte-identity: N/A, no emission change

Test Result

  • 24 passed across the four suites above, no GPU and no torch. The mask spec's predicates are proven to reproduce dense_attention_reference's padded output exactly.

Related

JIRA ID: AICK-2518

Submission Checklist

@github-actions github-actions Bot added project: hip-kernel-provider rocke-lib: attention Touches rocKE library attention/FMHA kernels rocke: platform Touches rocKE platform labels Oct 6, 2026
@therock-pr-bot

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

Copy link
Copy Markdown

❌ PR Check — Action Required

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass —
🔎 pre-commit ❌ Fail Error: Check concluded with failure.
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —

⚠️ 1 policy check(s) failed. Please address the issues above before this PR can be Reviewed.

🚫 Please fix the failed policies

  • ❌ pre-commit

The Not ready to Review label was added to this PR. Once all policies pass, the label is removed automatically.

📖 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 6, 2026

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ PR Description

The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.

…port

- dense_attention_reference gains optional seqlen_q / seqlen_kv. None keeps
  the exact unpadded arithmetic. When set, keys past seqlen_kv are masked,
  a row with no valid key yields O = 0, and padded query rows are zeroed.
- _sdpa_seqlen.py: host adapter validating hipDNN's per-sequence lengths at
  the boundary (integer dtype, per-batch count, 0 <= len <= S_max) and
  returning the flat per-batch int32 arrays the shell reads.
- _sdpa_padding_mask.py: host specification of the kernel-side mask --
  keep_key (the shell's extra_mask_predicate hook) and row_is_valid (the
  epilogue's padded-row zeroing), with the emitter form documented. The
  live IR emitter is deferred to the shell, where it carries its
  byte-identity C++ mirror. This module is the host reference it must match,
  cross-checked against dense_attention_reference.

Kernel wiring and GPU validation wait on the shell (ST4) and the arbitrary-length
buffer clipping (ticket 8).
@arai713
arai713 force-pushed the users/arai/padding_mask branch from c5ea20c to ecc2c39 Compare October 6, 2026 19:19
@therock-pr-bot

therock-pr-bot Bot commented Oct 6, 2026

Copy link
Copy Markdown

Pre-commit check failed

⛔ pre-commit failed

Please run locally:

  • python -m pip install pre-commit
  • pre-commit install
  • pre-commit run --all-files --show-diff-on-failure

This repo uses .pre-commit-config.yaml.

@arai713
arai713 marked this pull request as ready for review October 15, 2026 19:17
@arai713
arai713 requested review from a team as code owners October 15, 2026 19:17
@arai713 arai713 closed this Oct 19, 2026
@arai713

arai713 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Moved to this PR: #13953

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.

1 participant