0

I am writing a Halide program which takes different image sizes. When I optimize I split a loop in a number of "sub loops" so I can parallelize this with a given factor. For small images however, this can be a problem if the image is smaller than the split factor. Or, to be more accurate, when the number of iterations in the loop is smaller than the splitfactor.

Reading out of bounds is handled using the Halide::BoundaryConditions, Sure I can manually check the split factor with an if statement, but does Halide have something similar to the BoundaryConditions for the optimizations?

1 Answers1

0

If I understand correctly what you're saying, then this is what Func::specialize is for. You can do something like:

// Only vectorize if output is large enough
f.specialize(f.output_buffer().width() > 8).vectorize(x, 8);

The Halide sgemm uses this a bunch: https://github.com/halide/Halide/blob/master/apps/linear_algebra/src/blas_l3_generators.cpp

Andrew Adams
  • 1,396
  • 7
  • 3
  • Yes, this'll do the job, but lets say I have a Func which I first split and vectorize in the x direction, and then I fuse the remaining part of x with y into xy. I then split xy with another factor and then parallelize this. Then the factor to split with is dependant on the size of the split in x as well as the image size. If I want to take this into consideration this makes a monster of an if statement. I was hoping for something like the way the clamping works on an image. You give it a number, but it would limit this to the maximum possible in the image. But I understand there is none. – pietervanderstar May 20 '16 at 07:27
  • I used the specialize with some calculations for the maximum value it should have and found specialize only takes an Expr. If I pass it a bool it complains it can only accept a bool: "argument passed to specialize must be of type bool". Is this a bug or am I doing something wrong? (note I got it working). – pietervanderstar May 20 '16 at 08:28