Search code examples
halide

halide error: "Input buffer b0 is accessed at -1, which is before the min(0) in dimension 0"


I can't understand why the below Halide code occurs error. Please let me know what I mistake.

Buffer<uint8_t> input(small_width, small_height, small_depth);
Var x("x"), y("y"), z("z");
Func blur_y1, blur_y2, blur_x1, blur_x2, blur_z1, blur_z2;

blur_y1(x,y,z) = (input(x,y-1,z)   + input(x,y+1,z)   + 2*input(x,y,z)) / 4;
blur_y2(x,y,z) = (blur_y1(x,y-1,z) + blur_y1(x,y+1,z) + 2*blur_y1(x,y,z)) / 4;

blur_x1(x,y,z) = (blur_y2(x-1,y,z) + blur_y2(x+1,y,z) + 2*blur_y2(x,y,z)) / 4;
blur_x2(x,y,z) = (blur_x1(x-1,y,z) + blur_x1(x+1,y,z) + 2*blur_x1(x,y,z)) / 4;

blur_z1(x,y,z) = (blur_x2(x,y,z-1) + blur_x2(x,y,z+1) + 2*blur_x2(x,y,z)) / 4;
blur_z2(x,y,z) = (blur_z1(x,y,z-1) + blur_z1(x,y,z+1) + 2*blur_z1(x,y,z)) / 4;

Buffer<uint8_t> out(small_width-2, small_height-2, small_depth-2);
out.set_min(1, 1, 1); 
blur_z2.realize(out);

Error: Input buffer b0 is accessed at -1, which is before the min (0) in dimension 0


Solution

  • It looks like the total footprint of your blur is two pixels in every direction, not one, so you need:

    Buffer<uint8_t> out(small_width-4, small_height-4, small_depth-4);
    out.set_min(2, 2, 2);