Skip to content

Fix out-of-bounds check silently skipped for shape-only kernel params - #1040

Open
inducer wants to merge 1 commit into
mainfrom
parametric-bounds-check
Open

Fix out-of-bounds check silently skipped for shape-only kernel params#1040
inducer wants to merge 1 commit into
mainfrom
parametric-bounds-check

Conversation

@inducer

@inducer inducer commented Aug 25, 2026

Copy link
Copy Markdown
Owner

check_bounds skipped the access-range-vs-shape subset test whenever an array's shape depended on a parameter that was not present in the instruction's domain space. A value arg that appears only in an argument shape (and not in the domain or in any instruction expression) is never a read dependency, so get_insn_domain never adds it to the domain, and the mapper's "shape_deps <= available_vars" guard bailed out without checking.

This let a kernel like

    { [i]: 0 <= i < 5 }   x[i, 0] = 5   x: shape (n, 2)

generate code even though the access is only in-bounds when n >= 5, and it did so without warning. ISL could not even express the needed premise because the parameter was absent from the space.

Fix in _AccessCheckMapper.map_subscript: when a shape dependency is missing from the domain space but is a read-only value arg of the kernel, add it as a free parameter and continue with the check. Other missing dependencies (e.g. temporaries) remain data-dependent and are still skipped. The result:

  • without an assumption, the check now correctly raises LoopyIndexError;
  • with the assumption n >= 5, it passes, as expected.

Also teach assume()'s string form to declare value-arg names (not just domain params) as assumption parameters, so lp.assume(knl, "n >= 5") works for shape-only params.

Add test_bounds_check_with_shape_only_param covering both the error and the assumption-pass cases.

Note: kernels where the shape param is a different domain param (e.g. domain 0<=i<m with shape (n,)) now fail unless an assumption such as m <= n is given -- the intended soundness improvement.

Assisted-by: Zed:Qwen3.8-27B-FP8

check_bounds skipped the access-range-vs-shape subset test whenever an
array's shape depended on a parameter that was not present in the
instruction's domain space. A value arg that appears only in an argument
shape (and not in the domain or in any instruction expression) is never
a
read dependency, so get_insn_domain never adds it to the domain, and the
mapper's "shape_deps <= available_vars" guard bailed out without
checking.

This let a kernel like
    { [i]: 0 <= i < 5 }   x[i, 0] = 5   x: shape (n, 2)
generate code even though the access is only in-bounds when n >= 5, and
it
did so without warning. ISL could not even express the needed premise
because the parameter was absent from the space.

Fix in _AccessCheckMapper.map_subscript: when a shape dependency is
missing
from the domain space but is a read-only value arg of the kernel, add it
as
a free parameter and continue with the check. Other missing dependencies
(e.g. temporaries) remain data-dependent and are still skipped. The
result:
  - without an assumption, the check now correctly raises
LoopyIndexError;
  - with the assumption n >= 5, it passes, as expected.

Also teach assume()'s string form to declare value-arg names (not just
domain params) as assumption parameters, so lp.assume(knl, "n >= 5")
works
for shape-only params.

Add test_bounds_check_with_shape_only_param covering both the error and
the
assumption-pass cases.

Note: kernels where the shape param is a different domain param (e.g.
domain 0<=i<m with shape (n,)) now fail unless an assumption such as
m <= n is given -- the intended soundness improvement.

Assisted-by: Zed:Qwen3.8-27B-FP8
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.

1 participant