Validate CUDA QDQ element counts - #32029
Merged
Akshay Sonawane (apsonawane) merged 3 commits intoAug 14, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
requested review from
Tianlei Wu (tianleiwu)
and
a lite review from Copilot
August 12, 2026 16:37
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 16:40
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 16:41
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a CUDA-side guard for QuantizeLinear/DequantizeLinear to prevent launching kernels with element counts that would overflow 32-bit indexing/casts, and introduces a small unit test for the new validation helper.
Changes:
- Added
cuda::ValidateQDQElementCount(size_t)to enforce<= INT32_MAXelement count. - Called the new validation from CUDA
QuantizeLinearandDequantizeLinearComputeInternalpaths before output allocation / kernel launch. - Added a CUDA-only unit test to validate boundary behavior of the helper.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| onnxruntime/core/providers/cuda/tensor/quantize_linear.h | Introduces ValidateQDQElementCount helper used by CUDA Q/DQ kernels. |
| onnxruntime/core/providers/cuda/tensor/quantize_linear.cc | Enforces the element-count validation in ComputeInternal for both Quantize and Dequantize. |
| onnxruntime/test/providers/cpu/tensor/quantize_linear_test.cc | Adds a CUDA-only unit test covering the validation boundary conditions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
previously approved these changes
Aug 13, 2026
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 14, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/cuda-qdq-element-count-range
branch
August 14, 2026 17:35
This was referenced Sep 10, 2026
This was referenced Sep 14, 2026
Open
Closed
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.
This pull request introduces an element count validation for CUDA
QuantizeLinearandDequantizeLinearoperators to ensure they do not process more thanINT32_MAXelements, preventing potential overflows and undefined behavior. It also adds corresponding unit tests to verify this constraint.Element Count Validation:
ValidateQDQElementCountinquantize_linear.hto check that the number of elements does not exceedINT32_MAX, returning an error if the limit is exceeded.ValidateQDQElementCountinto bothQuantizeLinear<T, U>::ComputeInternalandDequantizeLinear<T, U>::ComputeInternalto enforce the element count constraint during operator execution. [1] [2]Testing:
CudaElementCountRangeinquantize_linear_test.ccto confirm thatValidateQDQElementCountaccepts the maximum allowed value and rejects values above the limit.