LUT是否有任何限制:尺寸无限制

Are there any restrictions with LUT: unbounded way in dimension

当尝试 运行 下面的示例代码(类似于查找 table)时,它总是生成以下错误消息:"The pure definition of Function 'out' calls function 'color' in an unbounded way in dimension 0".

RDom r(0, 10, 0, 10);
Func label, color, out;
Var x,y,c;

label(x,y) = 0;
label(r.x,r.y) = 1;

color(c) = 0;
color(label(r.x,r.y)) = 255;

out(x,y) = color(label(x,y));

out.realize(10,10);

在调用 realize 之前,我尝试静态设置绑定,如下所示,但没有成功。

color.bound(c,0,10);
label.bound(x,0,10).bound(y,0,10);
out.bound(x,0,10).bound(y,0,10);

我也看了直方图的例子,但是有点不一样。

这是 Halide 中的某种限制吗?

Halide 通过分析您作为参数传递给 Func 的值的范围来防止任何越界访问(并决定计算什么)。如果这些值是无限的,它就不能那样做。使它们有界的方法是使用 clamp:

out(x, y) = color(clamp(label(x, y), 0, 9));

在这种情况下,它是无界的原因是标签有更新定义,这使得分析放弃。如果您改为这样写标签:

label(x, y) = select(x >= 0 && x < 10 && y >= 0 && y < 10, 1, 0);

那你就不需要夹子了。