Halide 'select' without evaluating both arguments

1k views Asked by At

As you can know if you tried Halide select(x,y,z); is something similar to the ternary operator on C++ where x is the conditional y if true and z if false.

Imagine that y is just return 0 and z is a really costly function, it could have sense to skip evaluating z where x is false, unfortunatly Halide evaluates both terms even if I set select(x,likely(y),z); or at least it happens if I use compile_to_file (.h + .lib)

Any idea about this?

Thank you!

1

There are 1 answers

0
jrk On

The effect of the likely intrinsic is limited to loop peeling, not to anywhere a select might be used. That is, this only has an effect if the condition is closely related to the coordinates of the function definition in which the select appears (as in boundary conditions on an image, where the select is predicated on the x and y coordinates of the function). It does not turn arbitrary select expressions into full branching if/else statements.

You can see some examples in the tests for the intrinsic.

If you share an actual running piece of code it will be easier to discuss why loop peeling and the likely intrinsic do or don't apply in your particular case.