在 OpenCL 中使用 floatN 而不是 float 有什么优势吗?
例如
float3 position;
和
float posX, posY, posZ;
谢谢
最佳答案
这取决于硬件。
NVidia GPU 具有标量架构,因此与编写纯标量代码相比,向量几乎没有优势。引用 NVidia OpenCL best practices guide (PDF链接):
The CUDA architecture is a scalar architecture. Therefore, there is no performance benefit from using vector types and instructions. These should only be used for convenience. It is also in general better to have more work-items than fewer using large vectors.
使用 CPU 和 ATI GPU,您将从使用向量中获得更多好处,因为这些架构具有向量指令(尽管我听说这在最新的 Radeon 上可能有所不同 - 希望我有一个链接到我阅读这篇文章的地方)。
引用 ATI Stream OpenCL programming guide (PDF 链接),对于 CPU:
The SIMD floating point resources in a CPU (SSE) require the use of vectorized types (float4) to enable packed SSE code generation and extract good performance from the SIMD hardware.
This article提供了使用向量与纯标量类型编写的内核的 ATI GPU 的性能比较。
关于opencl - float VS float N,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8933604/