title: How to make performant AOT blur with variable kernel size?
body: <p>What would be an effective single threaded scheduling for this type of code?
  I'm trying to define blur but with a variable kernel size in AOT. I tried <a href="https://github.com/halide/Halide/issues/180" rel="nofollow noreferrer">https://github.com/halide/Halide/issues/180</a> solution but I can't figure a good way to schedule it that would get me the same performance as making kernel size a GeneratorParam and pre compiling with different values.</p>
  
  <p>Here is a snippet with the GeneratorParam:</p>
  
  <pre class="lang-c++ prettyprint-override"><code>// GeneratorParam&lt;int32_t&gt; kernelSize{"kernelOffset", 1};
  int32_t kernelSize = 2*kernelOffset + 1;
  {
     Halide::Expr sum = input(x, y);
     for (int i=1;i&lt;kernelSize;i++) {
        sum = sum + Halide::cast&lt;uint16_t&gt;(input(x, y+i));
     }
     blur_y(x, y) = sum/kernelSize;
  }
  {
     Halide::Expr sum = blur_y(x, y);
     for (int i=1;i&lt;kernelSize;i++) {
        sum = sum + blur_y(x+i, y);
     }
     blur_x(x, y) = sum/kernelSize;
  }
  
  ...
  
  // And the schedule
  
  
  blur_x.compute_root();
  blur_y.compute_at(blur_x, y);
  output.vectorize(x, 16);
  </code></pre>
  
  <p>And using <a href="https://github.com/halide/Halide/issues/180" rel="nofollow noreferrer">https://github.com/halide/Halide/issues/180</a> solution</p>
  
  <pre class="lang-c++ prettyprint-override"><code>Halide::RDom box (0, kernelSize, "box");
  blur_y(x, y) = Halide::undef&lt;uint16_t&gt;();
  {
      Halide::RDom ry (yMin+1, yMax-yMin, "ry");
      blur_y(x, yMin) = Halide::cast&lt;uint16_t&gt;(0);
      blur_y(x, yMin) += Halide::cast&lt;uint16_t&gt;(input(x, yMin+box))/kernelSize;
      blur_y(x, ry) = blur_y(x, ry-1) + input_uint16(x, ry+kernelOffset-1)/kernelSize - input_uint16(x, ry-1-kernelOffset)/kernelSize;
  }
  
  blur_x(x, y) = Halide::undef&lt;uint16_t&gt;();
  {
      Halide::RDom rx (xMin+1, xMax-xMin, "rx");
      blur_x(xMin, y) = Halide::cast&lt;uint16_t&gt;(0);
      blur_x(xMin, y) += blur_y(xMin+box, y)/kernelSize;
      blur_x(rx, y) = blur_x(rx-1, y) + blur_y(rx+kernelOffset, y)/kernelSize - blur_y(rx-1-kernelOffset, y)/kernelSize;
  }
  </code></pre>