Search code examples
halide

Halide internal error issue


Here's the code. I'm using Halide on VS2013, Win64 trunk of Aug 5, 2015. When I execute diag.compile_to_lowered_stmt("diag.html", {}, HTML) (with a 16MB stack), I get the following error message:

"Internal error at E:\Code\Halide\src\IR.cpp:160
Condition failed: a.type() == b.type()
LT of mismatched types"

I have confirmed that the error occurs because of the line:

diag(x, y, c) = select(m135(x, y) > m45(x, y), f45(x, y, c), select(m45(x, y) > m135(x, y), f135(x, y, c), f4x4(x, y, c)));

The only way I've been able to remove the error is to remove both selects (the function is unusable in that case, of course.) I've tried converting the condition to an Expr, and I've also checked the types of m45 and m135 (by assigning them to an Expr t1, and then looking at t1.type().) I note that changing the ">" to an "<" or even ">=" does NOT change the error message from "LT".

Any ideas?

Code is still the same as my previous post:

Image<uint8_t> orig_uint = Tools::load_image("../foo.ppm");

Var x, y, c;
Func orig("orig"), orig_lum("orig_lum"), m45("m45"), m135("m135"), f45("f45"), f135("f135"), f4x4_horiz("f4x4_horiz"), f4x4("f4x4"), diag("diag");

Func orig_clamped = BoundaryConditions::repeat_edge(orig_uint);

const float wta = 1.0f, wtb = 3.0f, wt0 = wta * wta, wt1 = wta * wtb, wt2 = wtb * wtb;

orig(x, y, c) = cast<float_t>(orig_clamped(x, y, c));

orig_lum(x, y) = 0.299f * orig(x, y, 0) + 0.587f * orig(x, y, 1) + 0.114f * orig(x, y, 2);

m45(x, y) = abs(orig_lum(x - 1, y - 1) - orig_lum(x, y)) + abs(orig_lum(x, y) - orig_lum(x + 1, y + 1)) + abs(orig_lum(x + 1, y + 1) - orig_lum(x + 2, y + 2));

m135(x, y) = abs(orig_lum(x + 2, y - 1) - orig_lum(x + 1, y)) + abs(orig_lum(x + 1, y) - orig_lum(x, y + 1)) + abs(orig_lum(x, y + 1) - orig_lum(x - 1, y + 2));

f45(x, y, c) = wta * (orig(x - 1, y - 1, c) + orig(x + 2, y + 2, c)) + wtb * (orig(x, y, c) + orig(x + 1, y + 1, c));

f135(x, y, c) = wta * (orig(x - 1, y + 2, c) + orig(x + 2, y - 1, c)) + wtb * (orig(x, y + 1, c) + orig(x + 1, y, c));

f4x4_horiz(x, y, c) = wta * (orig(x - 1, y, c) + orig(x + 2, y, c)) + wtb * (orig(x, y, c) + orig(x + 1, y, c));

f4x4(x, y, c) = wta * (f4x4_horiz(x, y - 1, c) + f4x4_horiz(x, y + 2, c)) + wtb * (f4x4_horiz(x, y, c) + f4x4_horiz(x, y + 1, c));

diag(x, y, c) = select(m135(x, y) > m45(x, y), f45(x, y, c), select(m45(x, y) > m135(x, y), f135(x, y, c), f4x4(x, y, c)));

// schedule
orig_lum.compute_root();
m45.compute_root().bound(x, 0, orig_uint.width()).bound(y, 0, orig_uint.height());
m135.compute_root().bound(x, 0, orig_uint.width()).bound(y, 0, orig_uint.height());
f45.compute_at(diag, x);
f135.compute_at(diag, x);
f4x4.compute_at(diag, x);
diag.compute_root();

// compile so we can take a look at the code
diag.compile_to_lowered_stmt("diag.html", {}, HTML);    // stack oflo here

Solution

  • It's a bug in Halide. Fix pushed by Andrew Adams an hour ago (thanks!)