Skip to content

Inliner doesn't properly handle all Expr args for define_extern() Funcs #7260

@steven-johnson

Description

@steven-johnson

Given something like this:

class MyGen {
  ...  
  Input<Buffer<float, 2>> arg_{"arg"};
  ...
};
void MyGen::generate() {
     for (int i = ...) {
      Expr arg_0 = arg_(i, 0);
      Expr arg_1 = arg_(i, 1);
      ...
      Func foo;
      foo.define_extern("foo", {arg_0, arg_1, ...}, ...);
}

...you'll fail to build with something like Symbol not found: arg_im.min.0.

After a bit of sleuthing, I think the issue here is that while we do correctly inline the arg_im function in schedule_functions(), we don't take into account that foo.extern_arguments() contains Exprs that refer to inlined functions. While validate_schedule() attempts to validate that none of the extern args are inlined, it only does so for Funcs... not for Exprs that reference inlined Funcs, like we have here.

There are ways to hack this into working (e.g. wrap arg_0 in a compute_root()'ed Func), but they are awkward.

(Genuinely surprised we've never seen this one before!)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions