halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.77k stars 1.07k forks source link

Error out when calling rfactor() after fusing a pure var #8268

Open alexreinking opened 4 weeks ago

alexreinking commented 4 weeks ago

Fixes #7854

alexreinking commented 4 weeks ago

This needs more work.

  1. It doesn't handle a pure var higher up in a tree of fusions; that needs to be fixed somehow
  2. I discovered a secondary bug, as follows:
#include "Halide.h"

using namespace Halide;

int main(int argc, char **argv) {
    Func f{"f"};
    RDom r({{0, 5}, {0, 5}, {0, 5}}, "r");
    Var x{"x"}, y{"y"};
    f(x, y) = 0;
    f(x, y) += r.x + r.y + r.z;

    RVar rxy{"rxy"}, yrz{"yrz"};
    Var z{"z"};

    // Error: In schedule for f.update(0), could not find remove dimension: r$z
    // Vars: r$x.rxy r$z.yrz x __outermost
    f.update()
        .fuse(r.x, r.y, rxy)
        .fuse(r.z, y, yrz)
        .rfactor(rxy, z);

    f.print_loop_nest();

    printf("Success!\n");
    return 0;
}