Halide:安排没有内联的多级管道

时间:2016-03-23 00:21:04

标签: c++ halide

我正在尝试编写模块化多阶段处理管道,但是我在安排它时遇到了麻烦。

代码结构如下:

#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部分时,生成器函数被内联,我没有看到任何问题。

我尝试在计划功能中添加.bound约束,但这没有帮助。有人可以帮我弄清楚这个错误意味着什么吗?

0 个答案:

没有答案