Skip to content

: selection: bugfix reifying strided views #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shayne-fletcher
Copy link
Contributor

Summary:
fix two bugs

thanks go to pzhan9 for reporting these issues! (see D78298712)

(1) one in reify_view where views with strides were reified incorrectly. the old code assumed views could always be expressed as contiguous range(start..start + len) expressions, even when the view's stride differed from the base. this produced incorrect selections when the view was strided relative to the base layout.

the fix is to recognize when a view is layout-aligned; that is, when each of its strides is an integer multiple of the corresponding base stride, including the unitary case; and to reify such views using Range(start, Some(end), step) expressions that preserve both shape and layout. previously, only the unitary case (step = 1) was handled. this change extends support to non-unitary aligned views, such as step = 2, by correctly computing the step factor and corresponding end coordinate.

if any dimension is not layout-aligned — that is, if view_stride % base_stride ≠ 0 — we conservatively fall back to enumerating all selected coordinates explicitly.

(2) also fixes a bug in Shape::select() where the length of a strided range was computed using truncating division. this now correctly uses ceiling division to ensure all selected indices are included.

Differential Revision: D78315005

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 15, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D78315005

Summary:

**fix two bugs**

thanks go to pzhan9 for reporting these issues! (see D78298712)

(1) one in `reify_view` where views with strides were reified incorrectly. the old code assumed views could always be expressed as contiguous `range(start..start + len)` expressions, even when the view's stride differed from the base. this produced incorrect selections when the view was strided relative to the base layout.

the fix is to recognize when a view is layout-aligned; that is, when each of its strides is an integer multiple of the corresponding base stride, including the unitary case; and to reify such views using `Range(start, Some(end), step)` expressions that preserve both shape and layout. previously, only the unitary case (`step` = 1) was handled. this change extends support to non-unitary aligned views, such as `step` = 2, by correctly computing the step factor and corresponding end coordinate.

if any dimension is not layout-aligned — that is, if `view_stride` % `base_stride` ≠ 0 — we conservatively fall back to enumerating all selected coordinates explicitly.

(2) also fixes a bug in `Shape::select()` where the length of a strided range was computed using truncating division. this now correctly uses ceiling division to ensure all selected indices are included.

Differential Revision: D78315005
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D78315005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants