Search code examples
halide

How to name Multiple Outputs of a Function (Tuple)?


Say I have a Generator for generating Ahead of Time compiled function something like the following.

Halide::Func build(){
   Halide::Func func1("func1"), func2("func2"), func3("func3");
   Halide::Func result("result");
   func1(x,y) = input(x,y) * 3; func2(x,y) = y; func3(x,y) = x + y;
   result(x,y) = Halide::Tuple({func1(x,y), func2(x,y), func3(x,y)});
   return result;
}

After compiling to object and header files, the signature of the generator looks something like below.

int myFunction(buffer_t * input, buffer_t * result_0_buffer, buffer_t * result_1_buffer, buffer_t * result_2_buffer);

How can I rename the output arguments of myFunction ?

result_0_buffer => func1

result_1_buffer => func2

result_2_buffer => func3

Thanks


Solution

  • If you compile a Pipeline and add individual Funcs to the Pipeline as outputs rather than using a Tuple, the result parameters should take the names of the Funcs added to the Pipeline. I haven't tested this, but it looks like so: Halide::Pipeline pipeline({func1, func2, func3}); pipeline.compile_to(...);

    The Pipeline is also more flexible in that the outputs can have different shapes/dimensions.