halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.78k stars 1.07k forks source link

Implement nested loop with indexing coordinates different from looping coordinates #8190

Open mcoduoza opened 2 months ago

mcoduoza commented 2 months ago

Hi,

I am trying to implement the following C++ equivalent code in Halide, whereby the coordinates used in the for loop are different from the coordinates used for assignment within the loop body (the assignment coordinates are computed inside the loop body):

`for (int ty = 0; ty < MAX_TY; ty++){

        for (int tx = 0; tx < MAX_TX; tx++){
            for (int yi = 0; yi < T_SIZE; yi++){
                for (int xi = 0; xi < T_SIZE; xi++){
                    int x = tx * T_SIZE/2 + xi;
                    int y = ty * T_SIZE/2 + yi;
                    output[y][x] += input[ty][tx][yi][xi];
                }
            }
        }
    }`

I tried to use the following Halide line to implement the loop:

output(tx * T_SIZE/2 + xi, ty * T_SIZE/2 + yi) += input(tx, ty, xi, yi)

whereby tx, ty, xi, and yi have been defined as Vars, and T_SIZE has been defined as a constant. However, running this code results in the following error: Undefined variable "tx" in definition of Func "output".

Why is this error message being thrown, and what would be an acceptable way to implement this nested for loop in Halide?

Thanks!