设置从函数返回的 Func 中的输入
Setting inputs in Func returned from function
我有一个 returns 和 Func
的函数,我想设置定义为 ImageParam
的输入缓冲区。我似乎无法从 github repo 中找到使用此类功能的 tutorial/test。我可以使用生成器在 AOT 中编译,然后 link 另一个程序,但我确信有一种更快的方法可以在同一实例中执行此操作而无需重新编译......我似乎无法找到正确的方法!
这是我使用的代码片段:
//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});
编辑:我发现了一个 "workaround",这意味着我将对 ImageParam
的引用作为输出参数传递,如下所示:
ImageParam p;
create_func(&p);
p.set(input);
但这似乎是作弊,不是吗?如果可能的话,我真的很想从 Func
本身提取输入参数...
您的变通方法不是作弊,我称之为通过引用传递的输入参数,而不是输出参数。预期用途是:
ImageParam input;
Func output = create_func(input);
... later
input.set(some_actual_image);
output.realize(...);
如果您只想取回一些输入公开为可设置属性的对象,您可以这样做:
struct MyPipeline {
ImageParam input1, input2;
Func output;
MyPipeline() {
output(x, y) = ...
}
};
MyPipeline p;
p.input1.set(foo);
p.output.realize(...);
这与仅使用生成器非常接近。
我有一个 returns 和 Func
的函数,我想设置定义为 ImageParam
的输入缓冲区。我似乎无法从 github repo 中找到使用此类功能的 tutorial/test。我可以使用生成器在 AOT 中编译,然后 link 另一个程序,但我确信有一种更快的方法可以在同一实例中执行此操作而无需重新编译......我似乎无法找到正确的方法!
这是我使用的代码片段:
//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});
编辑:我发现了一个 "workaround",这意味着我将对 ImageParam
的引用作为输出参数传递,如下所示:
ImageParam p;
create_func(&p);
p.set(input);
但这似乎是作弊,不是吗?如果可能的话,我真的很想从 Func
本身提取输入参数...
您的变通方法不是作弊,我称之为通过引用传递的输入参数,而不是输出参数。预期用途是:
ImageParam input;
Func output = create_func(input);
... later
input.set(some_actual_image);
output.realize(...);
如果您只想取回一些输入公开为可设置属性的对象,您可以这样做:
struct MyPipeline {
ImageParam input1, input2;
Func output;
MyPipeline() {
output(x, y) = ...
}
};
MyPipeline p;
p.input1.set(foo);
p.output.realize(...);
这与仅使用生成器非常接近。