Repository navigation
[CUDA] Validate GEMM autotuning candidates using graph replay - #33085
Merged
Merged
Conversation
Contributor
|
Please resolve conflicts. |
Graph-enabled MatMul sessions replay interleaved L2-conditioned candidate timings before caching. Keep stream mode for non-graph sessions, separate cache keys, and retain ORT_CUDA_GEMM_GRAPH_REPLAY_TUNING=0 for legacy dispatch. Capture cleanup and completion are scoped to tuning; cached execution is unchanged. Measured result on H200: restricted M8 replay selects cuBLAS 3/3, avoiding the legacy small-N choice in one trial; hot replay 6.212 vs 6.640 us. TinyGemm2 stays selected where eligible with unchanged outputs/performance. About 10 ms added first-run cost. Twelve GPU tests and GenAI smoke pass; no broader accuracy or throughput claim. Candidate kept isolated, original plugin restored.
Tianlei Wu (tianleiwu)
force-pushed
the
tlwu/cuda-gemm-graph-replay-tuning
branch
from
October 5, 2026 03:56
18e327f to
b2566ce
Compare
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
CUDA graph timing affects kernel selection, while traditional CUDA EP and BF16 validation remain incomplete.
Review effort: Balanced
Findings: None
What changed in this PR
Adds CUDA graph replay-based validation for GEMM autotuning in graph-enabled sessions.
Changes:
- Measures and caches kernels using L2-conditioned CUDA graph replay.
- Separates stream and graph-replay cache entries and adds an opt-out.
- Propagates graph configuration to plugin kernels and adds regression tests.
| File | Description |
|---|---|
onnxruntime/​test/​providers/​cuda/​test_cases/​gemm_auto_tuner_test.cc |
Tests replay selection, cleanup, capture ownership, and cache separation. |
onnxruntime/​core/​providers/​cuda/​plugin/​cuda_kernel_adapter.h |
Exposes graph enablement to plugin kernels. |
onnxruntime/​core/​providers/​cuda/​plugin/​cuda_ep.cc |
Propagates the plugin graph setting. |
onnxruntime/​core/​providers/​cuda/​math/​matmul.h |
Stores replay-tuning policy in MatMul kernels. |
onnxruntime/​core/​providers/​cuda/​math/​matmul.cc |
Resolves replay policy and selects its cache key. |
onnxruntime/​core/​providers/​cuda/​math/​gemm_auto_tuner.h |
Extends tuning keys and timing interfaces. |
onnxruntime/​core/​providers/​cuda/​math/​gemm_auto_tuner.cc |
Implements graph capture, replay timing, and cleanup. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
David Fan (jiafatom)
approved these changes
Oct 5, 2026
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
Validate GEMM auto-tuning candidates using L2-conditioned CUDA graph replay before caching the selected kernel in graph-enabled sessions. This addresses cases where stream-based timing selects a candidate that is slower during subsequent graph replay, while retaining the existing default-cuBLAS speedup margin and a legacy-policy opt-out.
Stacked on #32901, with base branch
tlwu/cuda-gemm-tinygemm2. Only commit18e327f8a7belongs to this PR; it is a clean cherry-pick ofc3914243a960865ff2d7bdc70ac2661561db5a2d. Retarget tomainafter #32901 merges.Summary of Changes
enable_cuda_graphsetting to MatMul kernel configuration; use the existing provider setting for traditional CUDA EP routing.ORT_CUDA_GEMM_GRAPH_REPLAY_TUNING=0to restore legacy timing in graph-enabled sessions. Unset or1enables replay validation when both CUDA graphs and GEMM auto-tuning are enabled.Existing auto-tuning defaults and forced-kernel precedence are unchanged. Verbose logs identify
timing=streamortiming=cuda_graph_replay.Testing
The implementation patch was built and tested locally in the isolated current-main + #32901 integration worktree on H200. The submitted cherry-pick has the same stable patch ID; no new build was performed on the publication branch.
GemmAutoTunerTest.*: 12/12 passed, with no skipped or zero-match tests. Tests were rerun after formatting and through the archived build harness.lintrunner -apassed on this branch.Cost and Limitations
Replay validation added approximately 10 ms to first-run startup in the fixed-input diagnostic; no steady-state speedup is claimed where the selected candidate is unchanged. L2 conditioning approximates decoder cache state, but does not model every surrounding graph or cache history.
Local numerical measurements used real FP16 weights and synthetic activations. Traditional CUDA EP build validation, BF16 operator coverage, and broader model accuracy/acceptance validation remain to be completed before promotion. The installed runtime and serving models were not replaced.
Checklist