Skip to content

Comments

Fix read-after-write hazard analysis in storage folding#7910

Merged
abadams merged 3 commits intomainfrom
abadams/fix_7909
Oct 24, 2023
Merged

Fix read-after-write hazard analysis in storage folding#7910
abadams merged 3 commits intomainfrom
abadams/fix_7909

Conversation

@abadams
Copy link
Member

@abadams abadams commented Oct 19, 2023

Explicitly mark which loops get loop-carry-dependencies inserted by
sliding window to assist storage folding.

Storage folding needs to know about this so it doesn't try to fold in a
way that invalidates these read-after-write dependencies. It currently
tries to prove the absence of hazards with box_contains(box_provided,
box_required), but this is sometimes incorrect because box_provided
could be conservatively large, and the code it analyses might not
actually provide (store to) all the required (loaded from) values.

It's simpler for sliding window to just tell storage folding when it
inserts loop-carry-dependencies, and this is most simply done directly
in the IR itself.

Fixes #7909

Built on #7908 to avoid a merge conflict in the fuzz_schedule.cpp test

In the following code:

let a = b in
  X
let a = c in
  Y

If Stmt X successfully had stores interleaved, it was re-nesting it like
so:

let a = b in
  X
  let a = c in
    Y

This introduces a shadowed variable 'a', which is illegal at this stage
of lowering.

Fixes #7906

Also some drive-by fixes to earlier tests that had debugging code left
in.
Explicitly mark which loops get loop-carry-dependencies inserted by
sliding window to assist storage folding.

Storage folding needs to know about this so it doesn't try to fold in a
way that invalidates these read-after-write dependencies. It currently
tries to prove the absence of hazards with box_contains(box_provided,
box_required), but this is sometimes incorrect because box_provided
could be conservatively large, and the code it analyses might not
actually provide (store to) all the required (loaded from) values.

It's simpler for sliding window to just tell storage folding when it
inserts loop-carry-dependencies, and this is most simply done directly
in the IR itself.

Fixes #7909
Copy link
Contributor

@TH3CHARLie TH3CHARLie left a comment

Choose a reason for hiding this comment

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

LGTM, failures are related to webGPU and LLVM

@abadams
Copy link
Member Author

abadams commented Oct 24, 2023

LLVM failure opened as a bug here: llvm/llvm-project#69950

@abadams abadams merged commit fffb8bd into main Oct 24, 2023
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
Explicitly mark which loops get loop-carry-dependencies inserted by
sliding window to assist storage folding.

Storage folding needs to know about this so it doesn't try to fold in a
way that invalidates these read-after-write dependencies. It currently
tries to prove the absence of hazards with box_contains(box_provided,
box_required), but this is sometimes incorrect because box_provided
could be conservatively large, and the code it analyses might not
actually provide (store to) all the required (loaded from) values.

It's simpler for sliding window to just tell storage folding when it
inserts loop-carry-dependencies, and this is most simply done directly
in the IR itself.

Fixes halide#7909
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.

wrong results with a sliding window chain

2 participants