Skip to content

Validate tile_view() extent against the parent tile - #1750

Open
nileshpatil6 wants to merge 1 commit into
NVIDIA:mainfrom
nileshpatil6:nileshpatil6/tile-view-extent-bounds
Open

Validate tile_view() extent against the parent tile#1750
nileshpatil6 wants to merge 1 commit into
NVIDIA:mainfrom
nileshpatil6:nileshpatil6/tile-view-extent-bounds

Conversation

@nileshpatil6

@nileshpatil6 nileshpatil6 commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #1745.

tile_view() already range-checks the origin, but nothing checked that offset + shape actually fits in the source tile. Since the view just forms an aliased pointer into the parent storage, an extent that runs past the end of an axis was accepted and silently read, or wrote through, whatever shared memory follows. The slice form can't hit this because its extents get clamped to the parent, so it only affects the explicit shape= path.

The check goes right after the existing rank check and mirrors the origin check just above it, same Var.constant unwrapping and same message style. Only constant offsets and extents can be resolved at code-gen time; runtime values fall through to the debug-only bounds check as before.

Testing

Added test_tile_view_shape_oob_rejected next to the existing test_tile_view_offset_oob_rejected, covering a 1D overrun, a 2D overrun on the last axis, and a positive control where the view exactly reaches the end of every axis.

Run on an RTX 3050 laptop GPU, so both cpu and cuda:0 were exercised:

  • test_tile_view: 96 passed
  • test_tile: 126 passed
  • test_tile_load: 30 passed
  • test_tile_reduce: 70 passed
  • test_tile_shared_memory: 32 passed
  • test_tile_mathdx: 6 passed
  • ruff check and ruff format --check clean on both changed files

I also confirmed the new test actually catches the bug rather than just passing: reverting only the builtins.py change makes both overrun cases fail with "not raised" on cpu and cuda:0, since the out-of-bounds view is accepted today.

One note on the positive control, it spells the shape with literals rather than TILE_M - 1 / TILE_N - 2. Arithmetic on module-level constants isn't folded at code-gen time, so the extent comes through unresolved and tile() fails on self.size *= s. That's pre-existing and unrelated to this change, it reproduces on an unpatched tree, but it did seem worth mentioning since it's a sharp edge if anyone writes a similar test.

Summary by CodeRabbit

  • Bug Fixes

    • Added validation to reject tile views whose constant offsets and shapes extend beyond the source tile.
    • Preserved support for views that fit exactly within the source tile.
    • Improved consistency of validation errors for invalid tile views.
  • Tests

    • Added coverage for invalid one- and two-dimensional views and valid exactly fitting views.

tile_view() range-checked the origin but never checked that offset + shape
fits inside the source tile. Because the view just forms an aliased pointer
into the parent storage, an extent reaching past the end of an axis was
accepted and silently read, or wrote through, the shared memory that
follows. The slice form cannot hit this since its extents are clamped to
the parent.

Constant offsets and extents are now checked at code-gen time, matching the
existing origin check. Runtime values still fall through to the debug-only
bounds check.

Fixes NVIDIA#1745

Signed-off-by: nileshpatil6 <technil6436@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 7, 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.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

tile_view() now rejects constant-shape views that extend beyond the source tile. Tests cover 1D and 2D out-of-bounds shapes, exact-fit views, and test-suite registration. A changelog entry documents the validation behavior.

Changes

tile_view bounds validation

Layer / File(s) Summary
Validate explicit shape bounds
warp/_src/builtins.py
The shape-based tile_view() path checks each constant offset and extent against the corresponding source-tile axis. Runtime values continue to use runtime bounds checks.
Test and document bounds validation
warp/tests/tile/test_tile_view.py, changelog/1745.fixed.md
Tests reject out-of-bounds 1D and 2D views and verify an exact-fit view. The changelog documents the code-generation-time validation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: daedalus5, shi-eric

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: validating explicit tile_view() extents against the parent tile.
Linked Issues check ✅ Passed The changes implement issue #1745 by validating constant offset-plus-shape bounds and adding 1D and 2D regression tests.
Out of Scope Changes check ✅ Passed The changelog entry, code change, and regression tests directly support the linked issue and contain no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds code-generation-time validation that constant explicit tile_view() extents fit within their parent tile and adds CPU/CUDA coverage for one- and two-dimensional overruns plus exact-fit views.

  • Rejects constant offset + shape values beyond a parent axis.
  • Adds regression and positive-control tests for explicit tile-view shapes.
  • Documents the fix in the changelog.

Confidence Score: 4/5

The PR appears safe to merge, with a non-blocking correction needed for the misleading claim that runtime offsets receive a debug-only bounds check.

The constant extent validation and regression tests cover the stated fix, while the only accepted issue is inaccurate commentary about protection on the unchanged runtime-offset path.

Files Needing Attention: warp/_src/builtins.py

Important Files Changed

Filename Overview
warp/_src/builtins.py Adds the intended constant extent check, but its new comment inaccurately describes a nonexistent debug-only fallback for runtime offsets.
warp/tests/tile/test_tile_view.py Adds focused per-device tests for constant one- and two-dimensional overruns and an exact-fit positive case.
changelog/1745.fixed.md Accurately documents the compile-time validation added for constant offsets and explicit shapes.

Reviews (1): Last reviewed commit: "Validate tile_view() extent against the ..." | Re-trigger Greptile

Comment thread warp/_src/builtins.py
Comment on lines +4240 to +4241
# constant offsets can be checked here; runtime offsets fall through to the
# debug-only bounds check.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Misstated runtime bounds fallback

The new comment says unresolved runtime offsets fall through to a debug-only bounds check, but native tile_view directly forms the aliased pointer without such a guard. This obscures the existing runtime-offset validation gap and can mislead future maintenance of this safety check.

Knowledge Base Used: Codegen and Execution Pipeline

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@changelog/1745.fixed.md`:
- Around line 1-3: Update the changelog entry to state that constant
offset-plus-shape combinations are validated at code-generation time, while
preserving that origin validation already existed; avoid wording that implies
the new check validates origins or offsets alone.

In `@warp/_src/builtins.py`:
- Around line 4242-4247: Update the explicit shape validation loop around shape,
offset, and parent_shape to reject any integer extent less than or equal to zero
before checking const + extent against the parent dimension. Preserve the
existing handling of non-integer values and upper-bound rejection, and add a
regression test covering zero and negative explicit extents passed through the
tile path.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 40c0ac53-a15a-4e85-8c01-bbbbe71ca123

📥 Commits

Reviewing files that changed from the base of the PR and between 444b55f and e0bd74d.

📒 Files selected for processing (3)
  • changelog/1745.fixed.md
  • warp/_src/builtins.py
  • warp/tests/tile/test_tile_view.py

Comment thread changelog/1745.fixed.md
Comment on lines +1 to +3
Reject `wp.tile_view()` calls whose explicit `shape` reaches past the end of the source tile. The origin was already
range-checked, but `offset + shape` was not, so a view could silently alias the shared memory following its parent.
Constant offsets are now validated at code-gen time with the same message style as the existing origin check.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Clarify that the new check validates offset + shape.

Line 3 says that constant offsets are now validated, but the origin was already range-checked. The new behavior validates constant offset-and-shape combinations. Update the wording to avoid implying that origin validation was added.

Proposed wording
-Constant offsets are now validated at code-gen time with the same message style as the existing origin check.
+Constant offset-and-shape combinations are now validated at code-gen time with the same message style as the existing origin check.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Reject `wp.tile_view()` calls whose explicit `shape` reaches past the end of the source tile. The origin was already
range-checked, but `offset + shape` was not, so a view could silently alias the shared memory following its parent.
Constant offsets are now validated at code-gen time with the same message style as the existing origin check.
Reject `wp.tile_view()` calls whose explicit `shape` reaches past the end of the source tile. The origin was already
range-checked, but `offset + shape` was not, so a view could silently alias the shared memory following its parent.
Constant offset-and-shape combinations are now validated at code-gen time with the same message style as the existing origin check.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@changelog/1745.fixed.md` around lines 1 - 3, Update the changelog entry to
state that constant offset-plus-shape combinations are validated at
code-generation time, while preserving that origin validation already existed;
avoid wording that implies the new check validates origins or offsets alone.

Comment thread warp/_src/builtins.py
Comment on lines +4242 to +4247
for dim, extent in enumerate(shape):
entry = offset[dim] if dim < len(offset) else 0
const = entry.constant if isinstance(entry, Var) else entry
if not isinstance(const, int) or not isinstance(extent, int):
continue
if const + extent > parent_shape[dim]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject non-positive explicit extents.

This check only rejects const + extent > parent_shape[dim]. It accepts zero and negative extents. The slice path already rejects zero-length axes at Line 4216, and the explicit shape= path passes these values to tile(...) below. Reject extent <= 0 before the upper-bound check and add a regression test.

Proposed fix
 for dim, extent in enumerate(shape):
     entry = offset[dim] if dim < len(offset) else 0
     const = entry.constant if isinstance(entry, Var) else entry
-    if not isinstance(const, int) or not isinstance(extent, int):
+    if not isinstance(extent, int):
         continue
+    if extent <= 0:
+        raise ValueError(f"tile_view() shape dimension {dim} must be positive, got {extent}.")
+    if not isinstance(const, int):
+        continue
     if const + extent > parent_shape[dim]:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for dim, extent in enumerate(shape):
entry = offset[dim] if dim < len(offset) else 0
const = entry.constant if isinstance(entry, Var) else entry
if not isinstance(const, int) or not isinstance(extent, int):
continue
if const + extent > parent_shape[dim]:
for dim, extent in enumerate(shape):
entry = offset[dim] if dim < len(offset) else 0
const = entry.constant if isinstance(entry, Var) else entry
if not isinstance(extent, int):
continue
if extent <= 0:
raise ValueError(f"tile_view() shape dimension {dim} must be positive, got {extent}.")
if not isinstance(const, int):
continue
if const + extent > parent_shape[dim]:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@warp/_src/builtins.py` around lines 4242 - 4247, Update the explicit shape
validation loop around shape, offset, and parent_shape to reject any integer
extent less than or equal to zero before checking const + extent against the
parent dimension. Preserve the existing handling of non-integer values and
upper-bound rejection, and add a regression test covering zero and negative
explicit extents passed through the tile path.

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.

tile_view() does not validate the view extent against the parent tile

1 participant