本文介绍了OpenCL中的向量分量总和(类似于SSE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如在OpenCL中是否有一条指令来计算float4
的所有组件的总和?
Is there a single instruction to calculate the sum of all components of a float4
, e.g., in OpenCL?
float4 v;
float desiredResult = v.x + v.y + v.z + v.w;
推荐答案
float4 v;
float desiredResult = dot(v, (float4)(1.0f, 1.0f, 1.0f, 1.0f));
要做更多的工作,因为在添加每个组件之前先将它们乘以一个,但是有些GPU内置了点积指令.可能会慢一些.这取决于您的硬件.
It's a little more work, because you're multiplying each component by one before adding them, but some GPUs have a dot product instruction built in. So might be faster; might be slower. It depends on your hardware.
这篇关于OpenCL中的向量分量总和(类似于SSE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!