0

我正在尝试编写一个模块化的多阶段处理管道,但我在调度它时遇到了麻烦。

代码结构如下:

#include <halide/Halide.h>

Halide::Var x, y, c;

Halide::Func producer(Halide::Func in) {
    Halide::Func producer("producer");
    producer(x, y, c) = in(x, y, c);
    return producer;
}

Halide::Func rectification(Halide::Func in, const Halide::Image<float>& rectificationMapBuffer)
{
    // Fractional pixel positions according to rectification map
    Halide::Expr x_in_frac("x_in_frac");
    Halide::Expr y_in_frac("y_in_frac");
    x_in_frac = rectificationMapBuffer(x * 2 + 0, y);
    y_in_frac = rectificationMapBuffer(x * 2 + 1, y);

    // Cast fractions down to integers. This allows to address the pixels
    // surrounding the fractional position
    Halide::Expr x_in("x_in");
    Halide::Expr y_in("y_in");
    x_in = Halide::cast(Halide::Int(32), x_in_frac);
    y_in = Halide::cast(Halide::Int(32), y_in_frac);

    // Linearly interpolate pixel values
    Halide::Func interpolate("interpolate");
    interpolate(x, y, c) =
        Halide::lerp(Halide::lerp(in(x_in + 0, y_in + 0, c), in(x_in + 1, y_in + 0, c),
                                  Halide::fract(x_in_frac)),
                     Halide::lerp(in(x_in + 0, y_in + 1, c), in(x_in + 1, y_in + 1, c),
                                  Halide::fract(x_in_frac)),
                     Halide::fract(y_in_frac));

    Halide::Func rectification("rectification");
    rectification(x, y, c) = Halide::cast(Halide::UInt(8), interpolate(x, y, c));

    return rectification;
}

Halide::Func schedule(const Halide::Image<uint8_t>& image, const Halide::Image<float>& rectificationMap) {
    Halide::Func clamped;
    clamped = Halide::BoundaryConditions::repeat_edge(image);

    Halide::Func producerFunc;
    producerFunc = producer(clamped);

    Halide::Func consumerFunc;
    consumerFunc = rectification(producerFunc, rectificationMap);

    producerFunc.compute_root();

    consumerFunc.compile_jit();

    return consumerFunc;
}

int main(int argc, char *argv[])
{
    int width = 100;
    int height = 100;
    int channels = 3;
    Halide::Image<uint8_t> input(width, height, channels);
    Halide::Image<float> rectificationMap(width * 2, height);
    Halide::Buffer output(Halide::UInt(8), width, height, channels, 0);

    Halide::Func f = schedule(input, rectificationMap);
    f.realize(output);
    return 0;
}

现在的问题是compute_root 语句。我得到错误:

The pure definition of Function rectification calls function producer in an 
unbounded way in dimension 0

当我删除 compute_root 部分时,生产者函数是内联的,我看不到任何问题。

我尝试在 schedule 函数中添加 .bound 约束,但这没有帮助。有人可以帮我弄清楚这个错误是什么意思吗?

4

0 回答 0