Skip to content

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

Open
uurl wants to merge 1 commit into
NVIDIA:mainfrom
uurl:fix/full-shape-overflow
Open

uurl wants to merge 1 commit 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.

Signed-off-by: Raul Estrada <raulestradaa@gmail.com>
@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.

This branch has not been deployed

No deployments
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

1 participant