Fix LinearAttention on GPUs with limited shared memory - #31982
Merged
Conversation
Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
Tianlei Wu (tianleiwu)
August 11, 2026 15:18
View session
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the CUDA LinearAttention kernel dispatch to avoid failing on GPUs whose opt-in per-block shared-memory limit is below the recurrent kernel’s shared-memory requirement. It does so by detecting the over-limit case up front, routing eligible shapes to the column-parallel kernel, and producing a clear failure when no compatible fallback exists.
Changes:
- Pass the device opt-in shared-memory limit (
sharedMemPerBlockOptin) into the CUDA LinearAttention kernel launcher. - Detect when the recurrent kernel’s dynamic shared-memory requirement exceeds the device limit and preferentially select the column-parallel kernel for supported shapes.
- Update test commentary to reflect the new “recurrent-or-column-fallback” behavior for the fixed-shape prefill case.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| onnxruntime/test/contrib_ops/linear_attention_op_test.cc | Updates test comment to reflect shared-memory-based fallback behavior. |
| onnxruntime/contrib_ops/cuda/bert/linear_attention.cc | Plumbs the device opt-in shared-memory limit into the kernel dispatcher. |
| onnxruntime/contrib_ops/cuda/bert/linear_attention_impl.h | Extends LaunchLinearAttentionKernel signature with max_shared_memory_per_block. |
| onnxruntime/contrib_ops/cuda/bert/linear_attention_impl.cu | Adds shared-memory limit checks and routes to column kernels or returns an error when needed. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
kunal-vaishnavi
approved these changes
Aug 11, 2026
kunal-vaishnavi
enabled auto-merge (squash)
August 11, 2026 17:56
This was referenced Aug 12, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Motivation and Context
The fixed-shape LinearAttention kernel requested 66,560 bytes of shared memory, exceeding the 65,536-byte limit on some GPUs.
cudaFuncSetAttributeconsequently failed withcudaErrorInvalidValue.