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!
The effect of the
likely
intrinsic is limited to loop peeling, not to anywhere aselect
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 theselect
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 arbitraryselect
expressions into full branchingif/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.