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

Specialize in order to unroll intermediate doesn't work with multiple outputs #7968

Closed
abadams opened this issue Nov 30, 2023 · 2 comments · Fixed by #7969
Closed

Specialize in order to unroll intermediate doesn't work with multiple outputs #7968

abadams opened this issue Nov 30, 2023 · 2 comments · Fixed by #7969

Comments

@abadams
Copy link
Member

abadams commented Nov 30, 2023

This schedule really ought to work:

#include "Halide.h"

using namespace Halide;

int main(int argc, char **argv) {
    Func intermediate("intermediate");

    Func output1("output1"), output2("output2");

    Var x("x"), y("y"), c("c");

    intermediate(x, y, c) = x + y + c;

    output1(x, y, c) = intermediate(x, y, c);
    output2(x, y, c) = intermediate(x, y, c);

    intermediate.compute_root()
        .specialize(
            output1.output_buffer().dim(2).extent() == 3 &&
            output1.output_buffer().dim(2).min() == 0 &&
            output2.output_buffer().dim(2).extent() == 3 &&
            output2.output_buffer().dim(2).min() == 0)
        .unroll(c);

    // Works
    output1.compile_jit();

    // Fails with:

    // Can only unroll for loops over a constant extent.
    // Loop over intermediate.s0.c has extent (max(output1.extent.2 + output1.min.2, output2.extent.2 + output2.min.2) - min(output1.min.2, output2.min.2)).

    Pipeline p{{output1, output2}};
    p.compile_jit();

    return 0;
}

@abadams
Copy link
Member Author

abadams commented Nov 30, 2023

Works if you explicit tell Halide the outputs have the same size in that dimension:


    output1.output_buffer().dim(2).set_bounds(output2.output_buffer().dim(2).min(),
                                              output2.output_buffer().dim(2).extent());

@abadams
Copy link
Member Author

abadams commented Nov 30, 2023

Alternatively:

intermediate.bound(c, 0, output1.output_buffer().dim(2).extent());

Still.. the original ought to work.

abadams added a commit that referenced this issue Dec 8, 2023
* Teach unrolling to exploit conditions in enclosing ifs

Fixes #7968

* Handle vectorization as well

* Remove unused usings

* Add missing print
ardier pushed a commit to ardier/Halide-mutation that referenced this issue Mar 3, 2024
* Teach unrolling to exploit conditions in enclosing ifs

Fixes halide#7968

* Handle vectorization as well

* Remove unused usings

* Add missing print
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 a pull request may close this issue.

1 participant