如何在 Cg 中实现高效的并行 SIMD 比较和选择?
您如何有效地进行并行选择?
例如,鉴于此标量代码,是否可以编写它,因此CG编译器将使代码在并行 / SIMD中执行(并且还使用BranchFree Selection使用电位)。
Out.x = ( A.x <= threshold) ? B.x : C.x ;
Out.y = ( A.y <= threshold) ? B.y : C.y ;
Out.z = ( A.z <= threshold) ? B.z : C.z ;
Out.w = ( A.w <= threshold) ? B.w : C.w ;
How do you do parallel selection efficiently ?
For example, given this scalar code, is there a way to write it so the Cg compiler will make the code execute in parallel / SIMD (and potential using a branchfree selection as well).
Out.x = ( A.x <= threshold) ? B.x : C.x ;
Out.y = ( A.y <= threshold) ? B.y : C.y ;
Out.z = ( A.z <= threshold) ? B.z : C.z ;
Out.w = ( A.w <= threshold) ? B.w : C.w ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,我错过了 Cg 手册中的这些行:
所以我尝试了这个,它似乎有效:
我想我没想到最简单的解决方案会起作用!
我的图形程序员同事还建议,在某些平台上,Cg 编译器可能足够智能,可以为我优化原始源代码,但这并不能保证,并且如果可能的话,最好显式指定并行 SIMD 操作。
Apparently, I missed these line in the Cg manual:
So I tried this out and it seems to work:
I guess I didn't expect the simplest solution to just work!
My coworker who is a graphics programmer also suggested that on some platforms, the Cg compiler might be intelligent enough to optimize the original source code for me but that it's not guaranteed and it is always better to explicitly specify parallel SIMD operations if possible.