CUDA: thread-local stream override infrastructure for graph capture (stage 0, no functional change)#566
Open
riccardo-galbani wants to merge 1 commit into
Open
Conversation
Add ds4_current_stream()/ds4_capture_set_stream() (internal linkage, no ABI change) gated by DS4_CUDA_GRAPHS, and route all default-stream operations in the decode/prefill paths through ds4_current_stream(): 156 kernel launches, 3 cudaMemsetAsync, 9 cuBLAS gemm call sites (cublasSetStream), 7 MoE-profiling cudaEventRecord. With the flag unset, ds4_current_stream() returns the default stream: behavior is provably identical. No capture is performed yet; this is Stage 0 of the plan discussed in issue antirez#534. Two NOTE markers document Stage 2 blockers (sync memset in routed_moe, host-timed MoE profiling incompatible with capture).
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.
What
Infrastructure-only groundwork for CUDA graph capture in the decode path
(stage 0 of the plan discussed in #534):
ds4_current_stream()accessor, gated behindDS4_CUDA_GRAPHS=13
cudaMemsetAsync, 9cublasSetStreaminsertions, 7 profilingcudaEventRecord(DS4_CUDA_MOE_PROFILE)ds4_capture_set_stream()setter for later stages (currently unused)MoE counts clear; profiling/capture mutual exclusion)
ds4_gpu_*shim signatures untouchedWhy no functional change is guaranteed
No stream is ever created in this commit:
g_ds4_capture_streamisinitialized to stream 0 and
ds4_capture_set_stream()has no callers, sods4_current_stream()returns the legacy stream even with the flag on.Flag-ON behavior is a no-op by construction, not just empirically.
Verification
Bit-identical logits (
--dump-logitsdiff empty) and identical greedy40-token output, reference (main @ 80ebbc3) vs this branch, flag OFF and ON:
with and without MTP (draft=2)
Build:
make cuda CUDA_ARCH=sm_89andmake cuda-spark CUDA_ARCH=sm_121, clean.What this enables
Later stages (per-cluster capture/replay, following the approach validated
in Entrpi's decode-perf-tuning fork, +5.2–5.6% gen on GB10) can introduce
a real capture stream without touching launch sites again. Each stage will
come as a separate PR.