Are there any restrictions with LUT: unbounded way in dimension

半世苍凉 提交于 2020-01-15 11:47:47

问题


When trying to run the sample code below (similar to a look up table), it always generates the following error message: "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);

Before calling realize, I have tried to statically set bound, like below, without success.

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

I also looked at the histogram examples, but they are a bit different.

Is this some kind of restrictions in Halide?


回答1:


Halide prevents any out of bounds access (and decides what to compute) by analyzing the range of the values you pass as arguments to a Func. If those values are unbounded, it can't do that. The way to make them bounded is with clamp:

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

In this case, the reason it's unbounded is that label has an update definition, which makes the analysis give up. If you wrote label like this instead:

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

Then you wouldn't need the clamp.



来源:https://stackoverflow.com/questions/44100896/are-there-any-restrictions-with-lut-unbounded-way-in-dimension

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!