Created
November 3, 2017 16:00
-
-
Save ronen/d97f2a1efc48d24581fd1ac5f6e26079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Halide.h" | |
#include <stdio.h> | |
/* | |
Bounds inference bug? | |
Two versions of the same accumulation, one uses RDom the other defines a chain of Funcs. | |
Compile and run with -DUSE_RDOM=0 and it reports: | |
input: -2 -2 104 104 | |
dir: -1 -1 102 102 | |
But compile and run with -DUSE_RDOM=1 and it fails: | |
Error at bounds_inference_rdom.cpp:46: | |
Buffer dir may be accessed in an unbounded way in dimension 0 | |
*/ | |
using namespace Halide; | |
int main(int argc, char **argv) { | |
ImageParam input(Float(32), 2, "input"); | |
ImageParam dir(Float(32), 3, "dir"); | |
Var x, y, d; | |
Func cdir("cdir"); | |
cdir(x, y, d) = clamp(dir(x, y, d), -1.0f, 1.0f); | |
Func output("output"); | |
// Tuple structure accessors | |
#define S_VAL(t) (t)[0] | |
#define S_X(t) (t)[1] | |
#define S_Y(t) (t)[2] | |
Tuple start = Tuple(0.0f, cast<float>(x), cast<float>(y)); | |
// Get next tuple from this tuple | |
#define STEP(t) Tuple( \ | |
input(cast<int>(S_X(t)), cast<int>(S_Y(t))), \ | |
S_X(t) + cdir(cast<int>(S_X(t)), cast<int>(S_Y(t)), 0), \ | |
S_Y(t) + cdir(cast<int>(S_X(t)), cast<int>(S_Y(t)), 1) \ | |
) | |
#if USE_RDOM | |
Var j; | |
Func f("f"); | |
RDom r(1, 3, "r"); | |
f(j, x, y) = start; | |
f(r, x, y) = STEP(f(r-1, x, y)); | |
output(x, y) = sum(S_VAL(f(r, x, y))); | |
#else | |
Func f0("f0"), f1("f1"), f2("f2"), f3("f3"); | |
f0(x, y) = start; | |
f1(x, y) = STEP(f0(x, y)); | |
f2(x, y) = STEP(f1(x, y)); | |
f3(x, y) = STEP(f2(x, y)); | |
output(x, y) = S_VAL(f0(x, y)) + S_VAL(f1(x, y)) + S_VAL(f2(x, y)) + S_VAL(f3(x, y)); | |
#endif | |
output.infer_input_bounds(100, 100); | |
printf("input: %d %d %d %d\n", input.get().left(), input.get().top(), input.get().width(), input.get().height()); | |
printf(" dir: %d %d %d %d\n", dir.get().left(), dir.get().top(), dir.get().width(), dir.get().height()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment