1

Let's say I want to do an operation (e.g. addition) between two images where each pixel in image Img1 has a corresponding pixel in image Img2. The correspondence vector is stored in a tuple Delta. Basically, something like this:

Img(x, y) = Img1(x, y) + Img2(x + Delta[0](x, y), y + Delta[1](x, y));

This is a memory gather operation. What would be the best way to do describe such a pattern in Halide? How to schedule it?

1
  • Instead of a tuple, you could pack the two delta values into another dimension: Delta( c, x, y ) = select( c == 0, xdelta, ydelta ); Delta.unroll(c); That at least puts the two values next to each other in memory. Mar 20, 2017 at 18:50

1 Answer 1

0

There isn't really a great way to schedule that. Gathers are slow, even where gather instructions exist. You probably still want to vectorize it over x so that the addressing math and the loads from Img1 and Delta are done using vectors though. I'd just use the obvious thing:

Img.vectorize(x, 8).parallel(y, 4);
1
  • Thanks, this definitely helps. I agree the gathers are expensive performance-wise. Even I have the HW support for it, probably it is wiser to fall back to to a single Delta value per tile. Mar 20, 2017 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.