Skip to content

fix(cutile): validate full tensor shapes before allocation - #1452

Merged
elibol merged 2 commits into
NVIDIA:mainfrom
uurl:fix/full-shape-overflow
Oct 31, 2026
Merged

elibol merged 2 commits into
NVIDIA:mainfrom
uurl:fix/full-shape-overflow

Conversation

@uurl

@uurl uurl commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Closes #1451

api::full currently uses unchecked multiplication to calculate its flattened element count. Invalid shapes can panic during construction or wrap before allocation and initialization, with shape validation occurring later during reshape.

Validate the element count with checked multiplication and reject zero dimensions and flattened lengths above i32::MAX. Invalid inputs return DeviceError::Internal when the operation executes, before GPU allocation or kernel execution. zeros and ones inherit the validation through full.

Add five host tests and three GPU tests covering overflow, zero dimensions, the i32 boundary, construction without panics, and valid tensor shapes and values. Preserve scalar shape [].

Validation

Run from cutile-rs:

cargo fmt --all -- --check
git diff --check
cargo test -p cutile --lib api::full_shape_tests
cargo test -p cutile --release --lib api::full_shape_tests
cargo test -p cutile --test gpu tensor_guards::full_
cargo test -p cutile --release --test gpu tensor_guards::full_
cargo clippy -p cutile --lib --test gpu -- -D warnings
RUST_TEST_THREADS=1 bash scripts/run_all.sh

All commands passed. The serial full run passed CPU and GPU tests, 24 examples, and all eight benchmark smoke tests. Three examples were skipped because they require newer Tile IR versions.

The default parallel run failed in warmup_composed::composed_builder_compile_terminal_warms_the_dispatched_specialization, with a JIT compile count of 17 instead of 18. That test passed in isolation, and all 16 warmup_suite tests passed serially. These results suggest a cache state or test ordering dependency; no warmup code is changed in this PR.

@uurl
uurl requested a review from elibol as a code owner October 8, 2026 07:50
@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@uurl
uurl force-pushed the fix/full-shape-overflow branch from 0437c81 to b7c0568 Compare October 30, 2026 06:40
@elibol elibol added this to the cutile rust v0.5.0 milestone Oct 30, 2026
@elibol

elibol commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 05a8be0

@elibol elibol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed 05a8be035dcbb1cf1a0c5c8c72497a112e51c8c4 after merging current main. The conflict resolution retains main's DType + DeviceCopy bound and this PR's checked shape calculation before allocation. The PR diff remains limited to the original two files. No additional correctness blockers found.

Validation on RTX 5090 / CUDA 13.3: all five shape unit tests and all three GPU regressions pass in both debug and release builds; formatting and strict Clippy pass. The full serial scripts/run_all.sh run also passes, including CPU/assembler tests, GPU tests, 27 examples (one expected toolkit-dependent skip), and all eight benchmarks.

Requested CI for this exact head with /ok to test; the fresh runs are pending. #1451 remains linked for automatic closure on merge and now carries the v0.5.0 milestone.

@elibol elibol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@elibol
elibol merged commit 0925800 into NVIDIA:main Oct 31, 2026
40 checks passed
elibol added a commit that referenced this pull request Oct 31, 2026
…#1684)

Older bindgen can emit a one-byte placeholder instead of the fields of a
forward-declared C struct when using libclang 22. This produces
incorrect CUDA bindings and failing layout checks. Upgrade
`cuda-bindings` to bindgen 0.72.1, which includes the upstream
type-completeness fix in
[rust-lang/rust-bindgen#3278](rust-lang/rust-bindgen#3278).

The regression test uses a self-contained C typedef chain and verifies
that both fields of the completed struct survive binding generation.
With bindgen 0.69.5 and libclang 22 it fails because only `_address` is
emitted; with 0.72.1 it passes. It runs as part of the existing
`cuda-bindings` test suite. Use libclang 22 to exercise the original
failure.

The large diff is generated lockfile maintenance: 263 affected
workspace/example lockfiles now resolve the updated shared bindings
dependency. Package additions are limited to the new bindgen and its
required rustc-hash version; obsolete transitive dependencies disappear.
Archived benchmarks that use separately published crates are unchanged.

Validation:

- The regression fails with bindgen 0.69.5/libclang 22 and passes with
0.72.1/libclang 22.
- Full `cuda-bindings` tests pass, including a CUDA 13.3/libclang 21
compatibility run. Bindgen now emits compile-time layout assertions, so
validation includes compiling the generated bindings rather than
filtering for old runtime layout-test names.
- Shared-host workspace all-target checks, Tile all-target checks, 108
SIMT host tests, and SIMT codegen/Cargo frontend checks pass.
- All 263 updated lockfiles resolve with `--offline --locked`; the
example lockfile consistency gate also passes after aligning six
existing rustc-hash pins with the other examples; dependency policy
checks pass for the host, Tile, SIMT, backend, and device-only
workspaces.
- Formatting, strict bindings Clippy, license inventory, shared-crate
pin, and SPDX checks pass.
- The new binding-generation regression remains required in the
CPU/build suite, which passes with libclang 22 (15 tests; two
live-driver cases filtered). The archive-only GPU runner excludes that
one compiler-dependent test because its image has no libclang.
Reproduced the unfiltered failure in the CI CUDA 13.3.0 image, then
verified all 16 runtime tests pass with the corrected filter, including
live CUDA/cuRAND.
- The head includes merged #1452; its five shape unit tests and three
GPU regressions pass on the combined branch.

Target: cuTile Rust v0.5.0.

---------

Signed-off-by: Melih Elibol <[email protected]>
Co-authored-by: Melih Elibol <[email protected]>
@uurl
uurl deleted the fix/full-shape-overflow branch November 21, 2026 03:30
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.

cutile: unchecked shape products in api::full can overflow

2 participants