title: How to insert some calculating in middle level loop?
body: <p>i am a new guy tring Halide programming. I met an issue when porting some halide code into android via Halide::Generator. Below is my code:</p>
  
  <pre><code>#include "Halide.h"
  #include &lt;string&gt;
  #include &lt;stdio.h&gt;
  
  using namespace Halide;
  using namespace Halide::ConciseCasts;
  using namespace std;
  
  
  class TestGenerator : public Halide::Generator&lt;TestGenerator&gt; 
  { 
  public:
      Input&lt;Buffer&lt;uint16_t&gt;&gt; imgs{"imgs", 3};
  
      void generate() 
      {   
          Func imgs_mirror = BoundaryConditions::mirror_interior(imgs, 0, imgs.width(), 0, imgs.height());
          Func F1("F1");
  
          RDom r0(0, 16, 0, 16);       
          Var ix, iy, tx_m, ty_m, n_m; 
          Buffer&lt;uint16_t&gt; ref_val(16, 16), alt_val(16, 16);
          ref_val(r0.x, r0.y) = imgs_mirror(tx_m*16+r0.x, ty_m*16+r0.y, 0);
          alt_val(r0.x, r0.y) = imgs_mirror(al_x, al_y, 1);
  
          ... //process
  
          Var ix2, iy2;
          RDom r2(0, 16, 0, 16); 
  
          F1(ix2, iy2, tx_m, ty_m) = ref_val(r2.x, r2.y);
  
          F1.compute_root();
      }
  };
  
  HALIDE_REGISTER_GENERATOR(TestGenerator, test_generator)
  </code></pre>
  
  <p>The expected process is that:
  1. tx_m and ty_m handle top level(outer) loop
  2. ix and iy handle bottom level(inner) loop(which are fixed as block of 16x16)
  3. use a Buffer:ref_val and alt_val of 16x16 to accept iterating result for ix and iy, then do some calculating, fill the result into ref_val
  4. feed ref_val back into the same position(ix2, iy2, tx_m, ty_m) of a Func.</p>
  
  <p>When i compile and run it, i got below error:
  In pure definition of Func "F1":
  Reduction domain referenced in pure function definition.
  Aborted (core dumped)</p>
  
  <p>I also tried below:
      F1(ix2, iy2, tx_m, ty_m) = ref_val(ix2, iy2);
  The compiling and run is Ok, and the static library is generated successfully, but when i run it in android, it will crash with below overflow issue:
  I halide  : Error: Input buffer ref_val_bf is accessed at 31, which is beyond the max (15) in dimension 0 </p>
  
  <p>Could anyone give me a hand?</p>
  
  <p>Thanks very much!</p>