0

I have a function that returns a Func and I'd like to set the input buffers that are defined as ImageParams. I can't seem to find a tutorial/test from the github repo that uses this sort of feature. I could use generators to compile in AOT and then link another program to it, but I'm sure there's a faster way to do that in the same instance without recompiling... I just can't seem to find the right way!

Here's the piece of code I use:

//header
Func create_func();

//usage
Func f = create_func();

Buffer<uint8_t> input; //initialized somewhere
Buffer<uint8_t> output0; //initialized somewhere
Buffer<uint8_t> output1; //initialized somewhere

f.in(0).set(input); // I need to set the buffer here right?

f.realize({output0, output1});

Edit: I found a "workaround" that implies I pass the reference to the ImageParam as an out parameter like so:

ImageParam p;
create_func(&p);
p.set(input);

But this seems like cheating doesn't it? I'd really like to pull the input parameters from the Func itself if possible...

Philippe Paré
  • 4,279
  • 5
  • 36
  • 56
  • How is `create_func()` defined? What input does the returned `Func` use? It should look something like `Func create_func( Func input ) { Func result("myFunc"); result( x, y ) = input( x, y ); return result; }` or you can create an empty Func `result` and pass it into create_func so that every result can have it's own name. – Khouri Giordano Mar 20 '17 at 19:13

1 Answers1

1

Your workaround isn't cheating, and I'd call that an in param passed by reference, not an out param. The intended use is:

   ImageParam input;
   Func output = create_func(input);

   ... later

   input.set(some_actual_image);
   output.realize(...);

If you'd rather just get back some object with its inputs exposed as settable properties, you could do this:

struct MyPipeline {
  ImageParam input1, input2;
  Func output;

  MyPipeline() {
    output(x, y) = ...
  }
};

MyPipeline p;
p.input1.set(foo);
p.output.realize(...);

That's very close to just using a Generator.

Andrew Adams
  • 1,396
  • 7
  • 3