Assertion failure for schedule with `gpu_blocks()`
The following snippet will assert-fail during Halide compilation:
Var x, y, p, d;
Func f1, f2;
f1(x, y, p) = 0;
f2(x, y, p) = 0;
RDom r(0, 10, 0, 10);
Func b1, b2;
b1(p) = 0.f;
b1(p) += f1(r.x, r.y, p);
b2(p) = 0.f;
b2(p) += f2(r.x, r.y, p);
Func d1, d2;
d1(p) = b1(p) - b2(p);
d2(p) = b2(p) - b1(p);
Func result;
result(d, p) = select(d == 0, d1(p), d2(p));
d2.compute_root().gpu_blocks(p);
result.compile_jit(Target("host-cuda"));
with:
Internal error at BoundsInference.cpp:318 triggered by user code:
Condition failed: iter != dims.end()
It's not yet clear to me what's failing. Adding compute_root() to b1 and b2 makes the failure go away.
Tagging @abadams and @psuriana who are more familiar with BoundsInference than I
I suspect I'm seeing this same bug in my real-time video pipeline when scheduling for CUDA - in an unsharp masking operator. The assertion is exactly the same. Also, adding compute_root() to the input of the unsharp operation avoids the assertion, at the cost of longer execution time.
I haven't been able to find a minimal example, yet. But the unsharp operation (with blur using a 7x7 kernel) looks quite similar to your example to me.
Problem seems to be that bounds inference expects the loop names to correspond to the dims lists in the schedule still, but they've been rewritten by canonicalize_gpu_vars. I'll try moving that pass much later.
Looks good. With commit b3499c7 applied to current master the compute_root() is not needed anymore in my pipeline.
Tests seem to be OK. Thanks for looking into this!