perf(trt): optimize YOLOv26 preprocessing pipeline - #479
Open
HaoyangZhuo wants to merge 1 commit into
Open
Conversation
wangzijian1010
requested changes
Sep 3, 2026
wangzijian1010
left a comment
Member
There was a problem hiding this comment.
You can integrate the code from benchmark.cpp into your YOLO26 test file instead of keeping it as a separate file.
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
Implementation
The optimized path submits the following operations to the same CUDA stream:
enqueueV3()The fused preprocessing kernel performs resize, letterbox padding, BGR-to-RGB conversion, normalization, and HWC-to-CHW conversion, writing directly into the TensorRT input buffer.
Three execution modes are available for benchmarking:
Baseline: CPU OpenCV preprocessing with pageable host buffersPinnedCpu: CPU preprocessing with reusable page-locked buffersOptimized: compact raw-image transfer with fused CUDA preprocessingThe default detection path uses CUDA preprocessing for
CV_8UC3input. Other supported three-channel image depths fall back to the CPU preprocessing path.Optimization resources also degrade safely:
Validation
Environment:
[1, 3, 640, 640][1, 300, 6]Build and run:
Correctness results:
Performance results over 200 measured iterations:
The optimized path achieved:
2.462949xspeedup over the baseline path2.268707xspeedup over the pinned CPU pathNotes
detect_with_timing()andcompare_preprocess()are intended for validation and benchmarking.TRTYoloV26instances retain reusable buffers and are not safe for concurrent inference calls from multiple threads.