1

I'm trying to use Halide for brute-force descriptor (e.g SIFT) matching. I'd like to try rfactor in the schedule, but I can't seem to get the associativity prover to oblige. So far I have the following:

Var c("c"), i("i");

Func diff("diff"), diffSq("diffSq"), dotp("dotp"), out("out"),
     inp1("inp1"), inp2("inp2"), minVal("minVal");

inp1(c,x) = input1(c,x);
inp2(c,y) = input2(c,y);

diff(x,y,c) = inp1(c, x) - inp2(c, y);
diffSq(x,y,c) = diff(x,y,c) * diff(x,y,c);

RDom rc(0,128);
dotp(x, y) = 0.f;
dotp(x, y) += diffSq(x, y, rc);

// Argmin, see https://github.com/halide/Halide/blob/master/test/correctness/rfactor.cpp#L804
RDom ry(0, input2.height(), "ry");
minVal(x) = {-1, std::numeric_limits<float>::max()};
minVal(x) = {
    select(minVal(x)[1] < dotp(x, ry)
          ,minVal(x)[0]
          ,ry),
    min(minVal(x)[1], dotp(x, ry))
};

out(x) = minVal(x)[0];

// Schedule
RVar ryo("ryo"), ryi("ryi");
Var yy("yy");
Func intermediate("inter");

dotp.compute_root();

minVal.update(0).split(ry, ryo, ryi, 16);
//intermediate = minVal.update(0).rfactor(ryo, yy);

The last, uncommented line sadly fails with:

|| Failed to call rfactor() on minVal.update(0) since it can't prove associativity of the operator

Thanks for any pointers as to how I could resolve this!

  • Do you mind posting this to halide-dev@lists.csail.mit.edu? The person best qualified to answer does not participate in Stack Overflow at present. I can also forward the question if you prefer, but figured it might be easier for you to have a conversation if you did so yourself. If this doesn't work for you, I will try to get an answer tomorrow. (Posting a link to the question is fine of course.) – Zalman Stern Oct 26 '17 at 00:20
  • Thanks for your prompt reply Zalman! I've done as you suggested and posted to the mailing list. – Ulrich Mueller Oct 26 '17 at 17:50
  • For reference, the conversation can be found here: https://lists.csail.mit.edu/pipermail/halide-dev/2017-October/003116.html – zanbri Nov 05 '18 at 12:53

1 Answers1

0

Quick answer: only one order of the Tuple elements is matched. Flipping them should allow rfactor. There will be a more complete answer on the list and we'll look at generalizing the matcher. (Answering to make sure the SO side doesn't get forgotten.)

Zalman Stern
  • 3,161
  • 12
  • 18
  • Exactly, this resolved the main issue I was having. The other problems were related to me using the May release of Halide. Switching to a current nightly build resolved those (support for mixed type int/float reductions with rfactor). Thanks Zalman and @psuriana ! – Ulrich Mueller Oct 28 '17 at 09:57