Skip to content

Validate CUDA QDQ element counts - #32029

Merged
Akshay Sonawane (apsonawane) merged 3 commits into
mainfrom
fix/cuda-qdq-element-count-range
Aug 14, 2026
Merged

Akshay Sonawane (apsonawane) merged 3 commits into
mainfrom
fix/cuda-qdq-element-count-range

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request introduces an element count validation for CUDA QuantizeLinear and DequantizeLinear operators to ensure they do not process more than INT32_MAX elements, preventing potential overflows and undefined behavior. It also adds corresponding unit tests to verify this constraint.

Element Count Validation:

  • Added a new function ValidateQDQElementCount in quantize_linear.h to check that the number of elements does not exceed INT32_MAX, returning an error if the limit is exceeded.
  • Integrated ValidateQDQElementCount into both QuantizeLinear<T, U>::ComputeInternal and DequantizeLinear<T, U>::ComputeInternal to enforce the element count constraint during operator execution. [1] [2]

Testing:

  • Added a unit test CudaElementCountRange in quantize_linear_test.cc to confirm that ValidateQDQElementCount accepts the maximum allowed value and rejects values above the limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_MAX element count.
  • Called the new validation from CUDA QuantizeLinear and DequantizeLinear ComputeInternal paths 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.

Comment thread onnxruntime/test/providers/cpu/tensor/quantize_linear_test.cc
@apsonawane
Akshay Sonawane (apsonawane) merged commit 6a86c06 into main Aug 14, 2026
101 of 104 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the fix/cuda-qdq-element-count-range branch August 14, 2026 17:35
This was referenced Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants