Optimize TensorRT CUDA Graph/concurrency and add benchmark auto-tuning - #1219
Draft
zsqdx wants to merge 6 commits into
Draft
Optimize TensorRT CUDA Graph/concurrency and add benchmark auto-tuning#1219zsqdx wants to merge 6 commits into
zsqdx wants to merge 6 commits into
Conversation
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.
Summary
This started as a TensorRT CUDA Graph fix and now also includes an opt-in, bounded benchmark tuner for
nnMaxBatchSize.trtUseCudaGraph, with prewarmed graphs up totrtCudaGraphMaxBatchSize(default 16); larger batches still useenqueueV3.-max-batch-sizes <BATCHES> -threads <THREADS>.-tune-max-batch-size <MAX>and optional-tune-max-batch-profile-budget <N>(default 6).The new benchmark modes are opt-in. Existing benchmark behavior and inference arithmetic are unchanged.
TensorRT benchmark
RTX PRO 6000 Blackwell, CUDA 13.0, TensorRT 10.16.1, NHWC FP16,
b11c768h12nbt3tflrs-fson-silu, officialbenchmark -v 1600 -n 20 -t 16,32,64,128, fixed seed/symmetry, Graph cap 16. Cells arennEvals/s / avgBatch; 2NN Graph is the mean of two runs.The previous 2NN+Graph path had a repeatable feedback collapse at t32/t64/t128: 1341/2139/2539 evals/s with avgBatch 4.94/10.06/20.16. The new path reaches 2951/3286/3125 with avgBatch 9.43/19.73/40.41.
Same-condition CUDA reference:
This remains hardware-dependent; I would keep one server per GPU as the conservative default and let benchmark data decide where two consumers help.
Automatic max-batch tuning
A full forward+reverse calibration used exact B18-B22 and threads 48-72: 70 measured cells. Its paired best was B20/64 at 3389.81 nnEvals/s; B20 was effectively flat from 60-72, while B22 hit a clear tactic/profile cliff.
The automatic run was:
It performs a five-point global thread scout at the user-provided memory-safe MAX, tests nearby exact profiles with a three-thread stencil, ranks profiles by their three-point median, then confirms the top two as A-B-B-A using pooled
sum(nnEvals) / sum(seconds).It tested exact profiles
128,19,18,20,17,21and used 24 measured cases, 65.7% fewer than the paired grid:So it recovered the same B20 optimum in 299.7 seconds, including cached plan loads and one previously uncached exact profile. It prints the tested profiles, largest untested gap, boundary warnings, and a small explicit follow-up suggestion when adjacent threads are within 0.5%. The MAX is always explicit so the tuner cannot silently exceed the user's memory limit.
Memory and startup
Cached plan, 10 Hz sampling:
Compared with the old 2NN path, engine reuse saved 160 MiB GPU and 771 MiB peak RSS without Graphs; the 2NN Graph run saved 160 MiB GPU and about 1.45 GiB peak RSS.
Validation
runtestspass; dummy Release build, help snapshot, CLI conflict tests, andgit diff --checkalso pass.testgpuerrorpassed with two same-GPU NN servers, NHWC FP16, and Graphs. Closest FP16 margins were 0.297x / 0.222x of the limits. A rectangular quick run passed at 0.199x / 0.0963x.