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

vectorize loops triggers name not in scope error #7779

Closed
TH3CHARLie opened this issue Aug 18, 2023 · 2 comments · Fixed by #7830
Closed

vectorize loops triggers name not in scope error #7779

TH3CHARLie opened this issue Aug 18, 2023 · 2 comments · Fixed by #7830
Assignees
Labels

Comments

@TH3CHARLie
Copy link
Contributor

TH3CHARLie commented Aug 18, 2023

A simple repro:

#include "Halide.h"

using namespace Halide;

int main(int argc, char **argv) {
    Var x("x"), y("y"), yo("yo"), yi("yi"), yoi("yoi"), yoio("yoio"), yoii("yoii");
    Func f("f");
    f(x, y) = x + y;
    f.split(y, yo, yi, 8, TailStrategy::Auto).split(yo, yo, yoi, 4, TailStrategy::RoundUp).vectorize(yoi).vectorize(yi).split(yoi, yoio, yoii, 2, TailStrategy::Auto);
    Pipeline p({f});
    std::cout << "before realize\n";
    Buffer<int> buf = p.realize({128, 128});
    std::cout << "realize done\n";
    return 0;
}

This code will trigger the following internal error under HL_DEBUG_CODEGEN=2

Vectorizing...
Subcontext threw exception. Rethrowing...
Internal Error at /home/xuanda/dev/Serializer/Halide-clean/src/Scope.h:134 triggered by user code at : Name not in Scope: f.s0.y.yo.widened.f.s0.y.yi
{
  f.s0.y.yi.base.widened.f.s0.y.yo.yoi.yoii
  f.s0.y.yo.widened.f.s0.y.yo.yoi.yoii
}
@TH3CHARLie TH3CHARLie changed the title vectorize loops triggers scope error vectorize loops triggers name not in scope error Aug 18, 2023
@abadams
Copy link
Member

abadams commented Aug 21, 2023

Something is going wrong in VectorizeLoops.cpp. The IR before vectorization is this:

  for (f.s0.y.yo.yoo, 0, (f.extent.1 + 31)/32) {
   vectorized (f.s0.y.yo.yoi.yoio, 0, 2) {
    vectorized (f.s0.y.yo.yoi.yoii, 0, 2) {
     let f.s0.y.yo = (f.s0.y.yo.yoo*4) + ((f.s0.y.yo.yoi.yoio*2) + f.s0.y.yo.yoi.yoii)
     let f.s0.y.yi.base = min(likely_if_innermost((f.s0.y.yo*8) + f.min.1), (f.extent.1 + f.min.1) + -8)
     vectorized (f.s0.y.yi, 0, 8) {
      for (f.s0.x, f.min.0, f.extent.0) {
       f[(((f.s0.y.yi + f.s0.y.yi.base)*f.stride.1) + f.s0.x) - ((f.min.1*f.stride.1) + f.min.0)] = (f.s0.y.yi + f.s0.y.yi.base) + f.s0.x
      }
     }
    }
   }
  

Note the let of f.s0.y.yo. The RHS depends on some vectorized vars, so it's a vector, but it's defined outside the innermost vectorized loop. vectorized lets are added to a vector_scope with a name determined by the original name + ".widened." + the name of the enclosing vectorized loop var. Lookup under this name fails inside the loop over f.so.y.yi, because the enclosing vectorized loop var is different.

The problem is that I don't understand why the name is tagged with the enclosing vectorized loop var. I think it must be related to the multiple vectorization work done by @vksnk, so maybe he can take a look?

@vksnk vksnk self-assigned this Aug 21, 2023
@vksnk
Copy link
Member

vksnk commented Aug 21, 2023

Yes, looks like a bug with the nested vectorization, I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants