Optimize CUDA QSA sparse attention indexing - #32656
Draft
kunal-vaishnavi with Copilot wants to merge 20 commits into
Draft
kunal-vaishnavi with Copilot wants to merge 20 commits into
kunal-vaishnavi with Copilot wants to merge 20 commits into
Conversation
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
kunal-vaishnavi
September 16, 2026 20:20
View session
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
kunal-vaishnavi
changed the base branch from
main
to
copilot/copilotimplement-packed-sparse-attention-indexer
September 16, 2026 20:21
kunal-vaishnavi
added this pull request to stack #32530
September 16, 2026 20:21
kunal-vaishnavi
marked this pull request as ready for review
September 16, 2026 20:21
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The dense scoring kernel can exceed CUDA shared-memory limits, and TopK boundary coverage is incomplete.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Optimizes CUDA QSA scoring and deterministic TopK selection while reducing workspace usage.
Changes:
- Fuses query rotation into dense and packed scoring kernels.
- Adds single-pass TopK for up to 32 blocks.
- Updates CUDA tests and performance documentation.
File summaries
| File | Description |
|---|---|
sparse_attention_indexer_op_test.cc |
Adds focused TopK coverage. |
sparse_attention_indexer_impl.cu |
Optimizes dense CUDA QSA execution. |
sparse_attention_indexer_device_math.cuh |
Adds deterministic block TopK. |
packed_sparse_attention_indexer_impl.cu |
Applies optimizations to packed QSA. |
packed_sparse_attention_indexer.md |
Documents packed CUDA performance. |
cuda/sparse_attention_indexer.md |
Updates optimization limitations. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…sparse-attention-indexer' into copilot/copilotcopilotimplement-packed-sparse-attention-in Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
…sparse-attention-indexer' into copilot/copilotcopilotimplement-packed-sparse-attention-in Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Copilot stopped work on behalf of
kunal-vaishnavi due to an error
September 17, 2026 02:38
kunal-vaishnavi
marked this pull request as draft
September 17, 2026 09:57
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Comment on lines
760
to
764
| const SparseAttentionIndexerParams&, \ | ||
| const T*, const T*, const T*, const T*, const T*, \ | ||
| const bool*, const T*, int32_t*, T*, float*, int32_t*); \ | ||
| template Status LaunchCsaSparseAttentionIndexer<T>( \ | ||
| cudaStream_t, const SparseAttentionIndexerParams&, const T*, const T*, const T*, const T*, const T*, \ |
Contributor
There was a problem hiding this comment.
Suggested change
| const SparseAttentionIndexerParams&, \ | |
| const T*, const T*, const T*, const T*, const T*, \ | |
| const bool*, const T*, int32_t*, T*, float*, int32_t*); \ | |
| template Status LaunchCsaSparseAttentionIndexer<T>( \ | |
| cudaStream_t, const SparseAttentionIndexerParams&, const T*, const T*, const T*, const T*, const T*, \ | |
| const SparseAttentionIndexerParams&, \ | |
| const T*, const T*, const T*, const T*, const T*, \ | |
| const bool*, const T*, int32_t*, T*, float*, int32_t*); \ | |
| template Status LaunchCsaSparseAttentionIndexer<T>( \ | |
| cudaStream_t, const SparseAttentionIndexerParams&, const T*, const T*, const T*, const T*, const T*, \ |
| template Status LaunchQsaSparseAttentionIndexer<T>(cudaStream_t, const SparseAttentionIndexerParams&, \ | ||
| const T*, const T*, const T*, const T*, const T*, \ | ||
| const bool*, const T*, int32_t*, T*, float*, int32_t*); \ | ||
| #define INSTANTIATE_SPARSE_ATTENTION_INDEXER(T) \ |
Contributor
There was a problem hiding this comment.
Suggested change
| #define INSTANTIATE_SPARSE_ATTENTION_INDEXER(T) \ | |
| #define INSTANTIATE_SPARSE_ATTENTION_INDEXER(T) \ |
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Comment on lines
+8
to
+9
| import onnx | ||
| import onnxruntime as ort |
Contributor
There was a problem hiding this comment.
Suggested change
| import onnx | |
| import onnxruntime as ort | |
| import onnxruntime as ort | |
# Conflicts: # docs/contrib_ops/cuda/sparse_attention_indexer.md # onnxruntime/contrib_ops/cuda/sparse/packed_sparse_attention_indexer_impl.cu # onnxruntime/contrib_ops/cuda/sparse/sparse_attention_indexer_impl.cu # onnxruntime/contrib_ops/webgpu/bert/sparse_attention_indexer.cc # onnxruntime/test/contrib_ops/sparse_attention_indexer_op_test.cc
# Conflicts: # docs/ContribOperators.md # docs/contrib_ops/cuda/sparse_attention_indexer.md # docs/contrib_ops/webgpu/sparse_attention_indexer.md # onnxruntime/contrib_ops/cuda/sparse/sparse_attention_indexer.cc # onnxruntime/contrib_ops/cuda/sparse/sparse_attention_indexer_impl.cu # onnxruntime/contrib_ops/cuda/sparse/sparse_attention_indexer_impl.h # onnxruntime/contrib_ops/webgpu/bert/sparse_attention_indexer.cc # onnxruntime/core/graph/contrib_ops/bert_defs.cc # onnxruntime/test/contrib_ops/sparse_attention_indexer_op_test.cc
# Conflicts: # onnxruntime/contrib_ops/cuda/sparse/sparse_attention_indexer_impl.cu
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
SparseAttentionIndexer(policy_mode="qsa")repeatedly scanned all blocks for each TopK result and materialized rotated queries in FP32 workspace. These changes reduce selection work, workspace traffic, and kernel-launch overhead while preserving deterministic ordering and existing operator contracts.