卤化“选择"而不评估两个参数 [英] Halide 'select' without evaluating both arguments

查看:83
本文介绍了卤化“选择"而不评估两个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以知道是否尝试过Halide select(x,y,z);与C ++上的三元运算符类似,其中x是条件y(如果为true)和z(如果为false).

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.

想象一下y只是返回0并且z是一个真正昂贵的函数,可以跳过对x为假的z的求值,不幸的是,即使我设置了select(x,likely(y),z);或至少发生在我使用compile_to_file(.h + .lib)

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)

对此有任何想法吗?

谢谢!

推荐答案

可能内在函数的作用仅限于循环剥离,而不是 select 可能存在的任何地方.用过的.也就是说,仅当条件与 select 出现在其中的函数定义的坐标紧密相关时(如图像的边界条件,其中选择基于x进行定义),这才有效.和该函数的y坐标).它不会将任意 select 表达式转换为完整分支的 if/else 语句.

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.

您可以在内在测试中看到一些示例.

如果您共享一条实际运行的代码,则更容易讨论为什么循环剥离和可能内在在特定情况下适用或不适用.

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.

这篇关于卤化“选择"而不评估两个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆