Replies: 1 comment 3 replies
-
The way to do this in Halide is to exploit the following fact: If a Func's value is only used when some select condition is true, and that condition has the same value for the lifetime of the Func, then we place the evaluation of the Func inside an if statement and skip it when the condition is false. Here's an example:
If you look at the .stmt file, you should see the realization of f and g guarded by if statements. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
At my current work we are trying to port some OpenCL image processing algorithms. On one of them, we are trying to express an if/else, because depending on the value of the pixel (x, y), we either use one algorithm or another one.
Problem, if I look at the select() documentation, it says that " it always evaluates all arguments". Our issue is that both "branches" of the algorithm are quite expensive (N*N convolutions, etc), so we (probably ?) should avoid computing both.
So the question would be : what is the best way to express an if/else in Halide ?
So far, what I'm trying to do is to move the select() close to the smallest number of instructions (moving it to where its execution won't impact that much), but I am wondering if a better way exists.
(I know, premature optimizations are evil, but just looking at the code tell me performances will be horrible with the current implementation).
Beta Was this translation helpful? Give feedback.
All reactions