Skip to content
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

Hoist vector slices using rewrite rules #7243

Merged
merged 10 commits into from
Jan 21, 2023
Merged

Conversation

abadams
Copy link
Member

@abadams abadams commented Dec 14, 2022

This lets us add associative variants more easily, which are helpful in the work on staging strided loads.

This lets us add associative variants more easily, which are helpful in
the work on staging strided loads.
@rootjalex
Copy link
Member

correctness_intrinsics is giving me an infinite loop:

    frame #146848: 0x00000001087776c0 libHalide.dylib`Halide::Internal::(anonymous namespace)::deinterleave(Halide::Expr, int, int, int, Halide::Internal::Scope<void> const&) + 364
    frame #146849: 0x0000000108777b8c libHalide.dylib`Halide::Internal::extract_lane(Halide::Expr const&, int) + 92
    frame #146850: 0x0000000108c6397c libHalide.dylib`Halide::Internal::Simplify::visit(Halide::Internal::Shuffle const*, Halide::Internal::Simplify::ExprInfo*) + 1340
    frame #146851: 0x0000000108c1cfb8 libHalide.dylib`Halide::Internal::Simplify::visit(Halide::Internal::Mul const*, Halide::Internal::Simplify::ExprInfo*) + 9128
    frame #146852: 0x0000000108b29694 libHalide.dylib`Halide::Expr Halide::Internal::Simplify::simplify_let<Halide::Internal::Let, Halide::Expr>(Halide::Internal::Let const*, Halide::Internal::Simplify::ExprInfo*) + 9456
    frame #146853: 0x0000000108a8f500 libHalide.dylib`Halide::Internal::simplify(Halide::Expr const&, bool, Halide::Internal::Scope<Halide::Internal::Interval> const&, Halide::Internal::Scope<Halide::Internal::ModulusRemainder> const&) + 56
    frame #146854: 0x00000001087776c0 libHalide.dylib`Halide::Internal::(anonymous namespace)::deinterleave(Halide::Expr, int, int, int, Halide::Internal::Scope<void> const&) + 364
<repeated>

src/Simplify_Add.cpp Outdated Show resolved Hide resolved
@abadams
Copy link
Member Author

abadams commented Dec 15, 2022

Turns out the shuffle visitor wants to sink extract_element calls, and extract_element counts as a degenerate slice_vector, so it was also being hoisted. I restricted my rewrite rules to non-degenerate slice_vectors

Copy link
Member

@rootjalex rootjalex left a comment

Choose a reason for hiding this comment

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

Lgtm pending green

@rootjalex
Copy link
Member

Turns out the shuffle visitor wants to sink extract_element calls, and extract_element counts as a degenerate slice_vector, so it was also being hoisted. I restricted my rewrite rules to non-degenerate slice_vectors

Might be worth adding a comment about this on this above the rules.

src/Simplify_Add.cpp Outdated Show resolved Hide resolved
@steven-johnson
Copy link
Contributor

Any update on this PR?

@abadams
Copy link
Member Author

abadams commented Jan 9, 2023

If the bots go green it's good to merge. Otherwise I'll need to make time to debug after the siggraph deadline.

@steven-johnson
Copy link
Contributor

How risky do you think this is? Does it need a preflight test inside google?

@abadams
Copy link
Member Author

abadams commented Jan 9, 2023

It's probably worth a preflight test.

@steven-johnson
Copy link
Contributor

steven-johnson commented Jan 10, 2023

At least one failure inside google:

Internal Error at third_party/halide/halide/src/IR.cpp:42 triggered by user code at : Condition failed: a.type() == b.type(): Add of mismatched types
*** SIGABRT received by PID 424 (TID 424) on cpu 30 from PID 424; stack trace: ***
PC: @     0x7fa7c0bf1347  (unknown)  gsignal
    @     0x7fa6bfc876dd        256  base/process_state.cc:1202 FailureSignalHandler()
    @     0x7fa801f071c0  (unknown)  (unknown)
    @     0x7fa77537b003        160  third_party/halide/halide/src/Error.cpp:221 Halide::Internal::ErrorReport::~ErrorReport()
    @     0x7fa775567736        160  third_party/halide/halide/src/IR.cpp:42 Halide::Internal::Add::make()
    @     0x7fa77588f0ea        192  third_party/halide/halide/src/IRMatch.h:736 Halide::Internal::IRMatcher::Rewriter<>::build_replacement<>()
    @     0x7fa775860dd9        224  third_party/halide/halide/src/IRMatch.h:2916 Halide::Internal::Simplify::visit()::$_0::operator()()
    @     0x7fa775857cfa        256  third_party/halide/halide/src/Simplify_Add.cpp:40 Halide::Internal::Simplify::visit()
    @     0x7fa775838a2f        128  third_party/halide/halide/src/IRVisitor.h:184 Halide::Internal::VariadicVisitor<>::dispatch_expr<>()
    @     0x7fa775b875f1        224  third_party/halide/halide/src/IRVisitor.h:341 Halide::Internal::Simplify::visit()
    @     0x7fa775838a51        128  third_party/halide/halide/src/IRVisitor.h:186 Halide::Internal::VariadicVisitor<>::dispatch_expr<>()
    @     0x7fa775af8143        288  third_party/halide/halide/src/IRVisitor.h:341 Halide::Internal::Simplify::visit()
    @     0x7fa775838a95        128  third_party/halide/halide/src/IRVisitor.h:190 Halide::Internal::VariadicVisitor<>::dispatch_expr<>()
    @     0x7fa77585771f        256  third_party/halide/halide/src/IRVisitor.h:341 Halide::Internal::Simplify::visit()
    @     0x7fa775838a2f        128  third_party/halide/halide/src/IRVisitor.h:184 Halide::Internal::VariadicVisitor<>::dispatch_expr<>()

EDIT: the mismatched types are float32x6 and float32x8

@rootjalex
Copy link
Member

Seems like all of the rules need a check that the lanes of x and y match

@abadams
Copy link
Member Author

abadams commented Jan 11, 2023

Good point, that's probably the issue.

@steven-johnson
Copy link
Contributor

(re-requested review so this doesn't accidentally get merged yet)

@rootjalex
Copy link
Member

@steven-johnson Could you check inside Google again, when you have the chance? I think the bug you're seeing should be fixed now.

@steven-johnson
Copy link
Contributor

will do

@steven-johnson
Copy link
Contributor

Running check now. Does this PR need a test?

@rootjalex
Copy link
Member

Running check now. Does this PR need a test?

Good point. I'll try to find time this afternoon to add a test for the improved hoisting and another one for the bug you found.

@abadams
Copy link
Member Author

abadams commented Jan 20, 2023

Thanks for taking this over, AJ.

@rootjalex
Copy link
Member

rootjalex commented Jan 20, 2023

Failures seem unrelated? One build failure and a mullapudi2016 issue (#7292). @steven-johnson is performance_inner_loop_parallel sometimes flaky? Or is that something I should investigate?

@steven-johnson
Copy link
Contributor

Both of those are known to be flaky, unfortunately We need to track them down but they aren't related.

@steven-johnson
Copy link
Contributor

Looks clean inside Google.

@rootjalex rootjalex merged commit 810bd0b into main Jan 21, 2023
@rootjalex rootjalex deleted the abadams/hoist_slice_refactor branch January 21, 2023 22:08
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
* Hoist slices using rewrite rules

This lets us add associative variants more easily, which are helpful in
the work on staging strided loads.

* Don't hoist extract_element shuffles

The Shuffle visitor wants to sink them

* Add some static asserts

* Add explanatory comment on shuffle hoisting

* Fix comment

* add lanes predicate to slice hoisting

* add vector slice hoisting test cases

Co-authored-by: Steven Johnson <srj@google.com>
Co-authored-by: Alexander <ajroot@stanford.edu>
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.

3 participants