Fix out-of-bounds check silently skipped for shape-only kernel params - #1040
Open
inducer wants to merge 1 commit into
Open
Fix out-of-bounds check silently skipped for shape-only kernel params#1040inducer wants to merge 1 commit into
inducer wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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:
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