onnxruntime
7fa20e3c - Fix CPU Range integer boundary counts and final increment overflow (#33399)

Commit
8 days ago
Fix CPU Range integer boundary counts and final increment overflow (#33399) ### Description Use exact unsigned span/step arithmetic for integer `Range` element counts in the CPU kernel and the `com.microsoft::Range` shape-inference path. This avoids losing small differences between large int64 endpoints when converting them separately to double. - Preserve empty/backward-range behavior, reject zero delta, and reject counts larger than INT64_MAX before conversion/allocation. - Avoid computing the unused value after the final emitted element, which can overflow even when every output is representable. - Add CPU-only regression coverage for int64 boundaries, cross-sign/extreme steps, int32/int64 final increments, contrib initializer inference, and invalid counts/delta. - Leave floating-point count behavior and CUDA implementation unchanged. The CUDA comment is updated so it no longer claims integer parity with CPU. ### Motivation and Context Fixes #33292. For example, `Range(INT64_MAX - 7, INT64_MAX, 2)` should emit four exact values; converting both endpoints to double first produces an empty result. The shared integer helper also handles spans larger than INT64_MAX and INT64_MIN step magnitudes without signed subtraction/negation. ### Validation Linux x86_64, GCC 14.2.0, Release CPU build. Initial submission build and 46-test run performed against upstream 648f708a73450c2f484f56c83ef9b6621e3c2b6b plus this patch on October 15, 2026. - Built `onnxruntime_provider_test` and ran `--gtest_filter='RangeTest.*:ConstantOfShape.*:EyeLikeOpTest.*'`: **46 passed** (34 Range, 12 neighboring generator tests). - Before-fix check on upstream 9cdf0f1 with the new regression tests retained: **30 passed, 4 failed**. Restoring this patch makes all 34 Range tests pass. - On upstream 122c193 plus this patch, a separately rebuilt executable with signed-overflow instrumentation on the actual CPU `range.cc` translation unit passed all **34 Range tests**. Restoring the upstream CPU translation unit detects signed overflow in the final-increment regression. This is not whole-program sanitizer coverage. - Configured clang-format 20.1.8 checks for all five changed files and `git diff --check` passed. No local CUDA execution, Windows/macOS testing, full repository test suite, or performance benchmark was run. Standard ONNX static inference for extreme cross-sign constant inputs is a separate upstream limitation; those cases use standard runtime inputs and contrib initializers here. ### Windows build follow-up (October 16, 2026) The initial Windows builds reported MSVC C4702 (treated as an error) because the floating-point calculation remained instantiated after the integral `if constexpr` branch returned. Commit 45096b2 places that unchanged calculation in the corresponding `else`, so integral instantiations discard it. Rebuilt the affected `range_schema_defs.cc` translation unit and `onnxruntime_provider_test` on Linux, then reran `RangeTest.*:ConstantOfShape.*:EyeLikeOpTest.*`: **46 passed**. Clang-format and `git diff --check` passed. Windows/MSVC confirmation is pending CI for the new commit, which currently requires maintainer approval; no local Windows pass is claimed. ### AI assistance OpenAI coding agents assisted with diagnosis, implementation, regression tests, code review, and this PR description. The test results above are from actual local execution; they do not assert independent human review.
Author
Parents
Loading