Skip to content

feat(miopen): fused single-layer LSTM forward-inference kernel (flagged) - #8915

Merged
fjankovi merged 8 commits into
developfrom
users/aivakhne/miopen-fused-lstm-inference
Aug 31, 2026
Merged

fjankovi merged 8 commits into
developfrom
users/aivakhne/miopen-fused-lstm-inference

Conversation

@ialex2004

@ialex2004 ialex2004 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

Kokoro-82M TTS inference on gfx1201 (Navi48) is dominated by the bidirectional nn.LSTM in the decoder. At batch=1 the per-timestep recurrence issues roughly 45k tiny serial GEMM + elementwise dispatches, leaving the GPU idle ~94% of the LSTM and making the workload launch-latency-bound rather than compute-bound.

This PR adds an experimental cooperative-grid fused single-layer LSTM forward-inference kernel (one launch per direction) that walks the whole sequence on-device with a grid-wide barrier per timestep. It reuses MIOpen's existing batched input-projection workspace and adds only the recurrent W_hh * h_{t-1} term and the LSTM cell update, collapsing the per-timestep host dispatch loop in RNNForwardInferencePacked.

Safety / scope

  • Strictly opt-in behind MIOPEN_DEBUG_RNN_FUSED_INFERENCE. Default behavior is unchanged — the flag defaults off because enabling such fusion unconditionally could change results for other models.
  • Gated to the validated case only: single layer, LSTM, miopenRNNdefault, fp32, no dropout, packed, linear input, uniform batch. Every other configuration falls back to the existing path.
  • The kernel honors the caller's initial hidden/cell state (hx/cx) and writes the final hy/cy, matching the stock path. Uniform batch > 1 is supported.

Testing

test/gtest/lstm_fused_inference_test.cpp drives miopenRNNForwardInference twice in-process — flag off (stock reference) and flag on (fused) — and requires the GPU output plus hy/cy to agree to 1e-5. Because both paths share the input-projection GEMM and differ only in the recurrence, the tolerance is tight and any logic bug (gate order, cell update, direction offset, batch indexing, initial-state handling) trips the assertion. Cases cover unidirectional + bidirectional, N=1 and uniform batch > 1, fp32, including the single-timestep edge case.

The debug flag is registered in the MIOPEN_BUILD_TESTING env registry (env_debug.cpp) so ScopedEnvironment can toggle it from the test. Real Kokoro LSTM outputs match the stock path to ~1e-6 end-to-end.

All 12 gtest cases pass on gfx1201; they fail prior to the kernel fixes, confirming the test has teeth.

Related

JIRA ID : AIRADSW-142

Checklist

  • I have added automated tests relevant to the introduced functionality
  • I have sufficient test coverage for the changes, and code coverage hasn't decreased as a result of my PR
  • I have ran the tests, and they are all passing locally
  • I have added relevant documentation for the changes
  • I have removed the stale documentation which is no longer relevant after this pull request
  • I have ran make format & make check_format to ensure the changes have been formatted

@therock-pr-bot

therock-pr-bot Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass —
🔎 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 Jun 29, 2026 •

Copy link
Copy Markdown

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

@ialex2004
ialex2004 force-pushed the users/aivakhne/miopen-fused-lstm-inference branch from 05f448a to 38457d1 Compare June 29, 2026 19:02
@ialex2004 ialex2004 changed the title [MIOpen] Add fused single-layer LSTM forward-inference kernel (feature-flagged) feat(miopen): fused single-layer LSTM forward-inference kernel (flagged) Jun 29, 2026
Kokoro-82M TTS inference on gfx1201 (navi48) is dominated by the bidirectional
nn.LSTM in the decoder: at batch=1 the per-timestep recurrence issues ~45k
tiny serial GEMM + elementwise dispatches, leaving the GPU idle ~94% of the
LSTM and making the workload launch-latency-bound rather than compute-bound.

Add a cooperative-grid fused inference kernel (one launch per direction) that
walks the whole sequence on-device with a grid-wide barrier per timestep,
reusing MIOpen's existing batched input-projection workspace and adding only
the recurrent W_hh*h_{t-1} term and the LSTM cell update. This collapses the
per-timestep host dispatch loop in RNNForwardInferencePacked.

Strictly opt-in behind MIOPEN_DEBUG_RNN_FUSED_INFERENCE and gated to the
validated case (single layer, LSTM, miopenRNNdefault, fp32, no dropout,
packed, linear input, uniform batch); every other configuration falls back to
the existing path unchanged. Default behavior is identical to before -- the
flag defaults off because enabling such fusion unconditionally could change
results for other models.

The kernel honors the caller's initial hidden/cell state (hx/cx) and writes
the final hy/cy, matching the stock path; uniform batch>1 is supported.

Test: test/gtest/lstm_fused_inference_test.cpp drives miopenRNNForwardInference
twice in-process (flag off = stock reference, flag on = fused) and requires
the GPU output and hy/cy to agree to 1e-5, giving the comparison real teeth.
Covers uni+bi, N=1 and uniform batch>1, fp32, including the single-timestep
edge case. The debug flag is registered in the MIOPEN_BUILD_TESTING env
registry so ScopedEnvironment can toggle it. Real Kokoro LSTM outputs match
the stock path to ~1e-6.

JIRA ID : AIRADSW-142
@ialex2004
ialex2004 force-pushed the users/aivakhne/miopen-fused-lstm-inference branch from c51028d to e614908 Compare June 29, 2026 23:06
@ialex2004
ialex2004 marked this pull request as ready for review July 10, 2026 09:56
@ialex2004
ialex2004 requested a review from a team as a code owner July 10, 2026 09:56
@ialex2004
ialex2004 marked this pull request as draft July 10, 2026 10:10
Resolve env_debug.cpp conflict: upstream removed
MIOPEN_DEBUG_OPENCL_CONVOLUTIONS (gone tree-wide); keep our added
MIOPEN_DEBUG_RNN_FUSED_INFERENCE declaration + registry entry. Our fused
LSTM dispatch auto-merged into src/hip/rnnocl.cpp (upstream moved the file
from src/ocl/). Rebuilt + all 12 lstm_fused_inference_test cases pass.

JIRA ID : AIRADSW-142
@ialex2004
ialex2004 marked this pull request as ready for review July 10, 2026 10:23
@fjankovi
fjankovi requested a review from BradPepersAMD July 16, 2026 08:54
fjankovi added a commit that referenced this pull request Jul 20, 2026
…8916)

## Summary

Add tuned Tensile Equality logic entries for the fp32 GEMM shapes that
dominate Kokoro-82M TTS inference on gfx1201 (Navi48):

- **TN** (`Cijk_Alik_Bljk_S_B_Bias_HA_S_SAV_UserArgs`): LSTM
hidden-update N=1 matvecs + encoder shapes.
- **NN** (`Cijk_Ailk_Bljk_S_B_Bias_HA_S_SAV_UserArgs`): HiFi-GAN decoder
M-tall upsample GEMMs (skinny-N / large-M).

## Details

- Entries are **appended** to the existing per-(dtype, transpose)
superset logic files. **No stock solutions or exact-logic rows are
removed** — this is additions-only.
- Winners were selected by Tensile bench-and-merge and verified to
dispatch at runtime on gfx1201 during real Kokoro runs (every added
exact-logic key was confirmed reachable; no dead entries).
- fp32, `UseBias=1` / `ScaleAlphaVec` / `Activation` superset
`ProblemType`, matching the shapes the model actually issues.

## Validation

Ran the full Kokoro test matrix (stock / yaml-only / code-only / both).
The tuned logic is applied via the rebuilt hipBLASLt library and
dispatches the tuned kernels for the targeted shapes, with no regression
on untargeted shapes.

## Related

JIRA ID : AIRADSW-142

- Companion PR (MIOpen fused LSTM inference kernel for the same Kokoro
decoder): #8915

---------

Co-authored-by: Filip Jankovic <161825881+fjankovi@users.noreply.github.com>
assistant-librarian Bot pushed a commit to ROCm/hipBLASLt that referenced this pull request Jul 20, 2026
feat(hipblaslt): gfx1201 Tensile tunings for Kokoro-82M GEMM
 shapes (#8916)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

## Summary

Add tuned Tensile Equality logic entries for the fp32 GEMM shapes that
dominate Kokoro-82M TTS inference on gfx1201 (Navi48):

- **TN** (`Cijk_Alik_Bljk_S_B_Bias_HA_S_SAV_UserArgs`): LSTM
hidden-update N=1 matvecs + encoder shapes.
- **NN** (`Cijk_Ailk_Bljk_S_B_Bias_HA_S_SAV_UserArgs`): HiFi-GAN decoder
M-tall upsample GEMMs (skinny-N / large-M).

## Details

- Entries are **appended** to the existing per-(dtype, transpose)
superset logic files. **No stock solutions or exact-logic rows are
removed** — this is additions-only.
- Winners were selected by Tensile bench-and-merge and verified to
dispatch at runtime on gfx1201 during real Kokoro runs (every added
exact-logic key was confirmed reachable; no dead entries).
- fp32, `UseBias=1` / `ScaleAlphaVec` / `Activation` superset
`ProblemType`, matching the shapes the model actually issues.

## Validation

Ran the full Kokoro test matrix (stock / yaml-only / code-only / both).
The tuned logic is applied via the rebuilt hipBLASLt library and
dispatches the tuned kernels for the targeted shapes, with no regression
on untargeted shapes.

## Related

JIRA ID : AIRADSW-142

- Companion PR (MIOpen fused LSTM inference kernel for the same Kokoro
decoder): ROCm/rocm-libraries#8915
Comment thread projects/miopen/src/hip/rnnocl.cpp Resolved
Comment thread projects/miopen/src/hip/rnnocl.cpp Resolved
Comment thread projects/miopen/src/hip/rnnocl.cpp Resolved
Comment thread projects/miopen/src/hip/rnnocl.cpp Resolved

@BrianHarrisonAMD BrianHarrisonAMD 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 changes are properly behind a flag, and ill approve to allow this to move forward.
I think the comments should be fixed before merging, or as a separate follow-up if this needs to land right away.

@ialex2004

Copy link
Copy Markdown
Contributor Author

Addressed all seven review threads in f199760ce49.

Validation on Radeon RX 7900 XTX / ROCm 7.13:

  • MIOpen core + miopen_gtest built successfully (CK disabled only because the container's installed CK headers are incompatible with current develop; the touched RNN path is independent).
  • *LSTM_fused_infer*: 12/12 passed. The strengthened test clears/checks the exact fused-kernel cache key, proving the HIPRTC cooperative kernel actually dispatched.
  • Serial paired Kokoro fp32 evaluation (5 OFF/ON pairs): OFF median 143.47 samples/min, ON median 143.22 samples/min. Performance is neutral within run variance; flag-off behavior remains unchanged.

@ialex2004

Copy link
Copy Markdown
Contributor Author

Additional combined evaluation after deploying the freshly rebuilt current #8222 hipBLASLt (.so + nested gfx1100 .dat.zlib) with the reviewed #8915 MIOpen build:

The +0.77% median difference is within observed run variance and paired deltas are mixed, so I consider the feature performance-neutral rather than claiming an uplift. There is no reliable regression, and the correctness/dispatch tests remain 12/12 passing.

ialex2004 and others added 2 commits July 30, 2026 13:49
Keep the flagged path side-effect-free and cooperative-launch-safe, account for profiling, and strengthen the GPU test to prove fused dispatch while checking every API result.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been inactive for 25 days and will be marked as stale.

If you would like to keep this PR open, please:

  • Add new commits
  • Add a comment explaining why it should remain open

This PR will be automatically closed in 5 days if no further activity occurs.

@github-actions github-actions Bot added the Stale PR has no activity for 25+ days label Aug 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed due to inactivity (30 days with no updates).

If you'd like to continue working on this, feel free to reopen the PR or create a new one.

@github-actions github-actions Bot closed this Aug 30, 2026
@ialex2004 ialex2004 reopened this Aug 31, 2026
@fjankovi
fjankovi merged commit 0f11481 into develop Aug 31, 2026
85 of 89 checks passed
@fjankovi
fjankovi deleted the users/aivakhne/miopen-fused-lstm-inference branch August 31, 2026 11:18
@assistant-librarian

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

JonathanLichtnerAMD added a commit that referenced this pull request Sep 2, 2026
## Summary

Backfills the **MIOpen 3.6.1 / ROCm 10.1.0** changelog section with
externally-visible changes that landed since the `release/therock-10.0`
branch but weren't yet documented. All 43 MIOpen commits in that range
were reviewed; CI/build-infra, test-only, docs, version-bump, and
already-documented changes were excluded.

21 entries added:

### Added
* [RNN] Fused single-layer LSTM forward-inference kernel, gated behind
`MIOPEN_DEBUG_RNN_FUSED_INFERENCE` (#8915)
* [Conv] Naive reference kernel enabling 3D INT8 forward convolution
(#10051)
* [Conv] `ConvHipConv` solver backed by vendored hipconv kernels (#9746)
* [Conv] float8 vector type support + deduplicated math kernels (#10130)
* [Conv] Validated gfx1151 and gfx1200 (Navi) SystemDBs (#10050)
* [Conv] `MIOPEN_DEBUG_DISABLE_SYSTEM_DB` /
`MIOPEN_DEBUG_DISABLE_USER_DB` env vars (#10728)
* [Conv] CK depthwise convolution on RDNA wave32 GPUs (#9373)

### Changed
* [Conv] Winograd Rage RxS f2x3 on gfx950 + gfx942 v4_6_1/v4_9_1 kernels
(#9014)
* [Conv] Updated 3D AI heuristics for gfx942 & gfx950 (#8954)

### Optimized
* [Conv] Single GEMM for point (1x1) output convolution, all directions,
2D/3D (#10912)
* [Conv] Naive backward-data kernel work group widened to 1024 (#10684)

### Resolved Issues
* [Conv] Batch-split miscalculation on large WrW tensors — ROCM-26011
(#11188)
* [Conv] Conv failure on XNACK-unsupported gfx9 APUs (gfx90c) (#11211)
* [BatchNorm] Device heap-overflow in fwd spatial `FinalMeanVariance` —
ALMIOPEN-2424 (#11093)
* [Conv] Deterministic `SetNextValue` polarity for grouped Bwd/Wrw CK
solvers (#10240)
* [LRN][LayerNorm] Grid alignment + OOB threads on gfx1250 (#10251)
* [Conv] Stale gfx950 grouped-wrw SystemDB entries (#11130)
* [Conv][Windows] System-DB path resolution from the MIOpen module
(#10838)
* [Conv] System-DB fallback so MI308X (gfx942) resolves a usable DB
(#8802)
* JSON perf logs (`MIOPEN_PERFORMANCE_LOGS`) dropping the last solver
during Find (#11166)
* Build failure against GCC 15 libstdc++ under C++20 (#9642)

## Notes

Deliberately excluded: internal/default-off changes (#10219, #10088,
#10649, #10231), a near-duplicate of an existing 10.0.0 entry (#10188),
and CI/build-infra/test-only/docs commits.

Docs-only change; no code impact.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

organization: ROCm project: miopen Stale PR has no activity for 25+ days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants