在OpenCL中将变量转换为其他类型的成本是多少?OpenCL:类型转换开销
实施例:我想利用的,以便代替由自己在unvectorized方式实施dot()
的2个int3
载体(AFAIK dot()
未过载为int3
多个)点积,我要通过使用向量化的代码原产地dot()
为float3
。首先,我将2个矢量转换为float3
s,然后将结果转换为int
。
foo
和bar
这两个函数中的哪个函数耗时较少(以及为什么)?
inline int foo(int3 a, int3 b) {
return a.x*b.x + a.y*b.y + a.z*b.z;
}
inline int bar(int3 a, int3 b) {
return (int)dot(convert_float3(a), convert_float3(b));
}
优化的第一条规则:测量。第二优化规则:再次测量。这完全取决于硬件和架构。没有人可以对你的问题给出明确的答案。 –
@AndreasPapadopoulos我同意。顺便说一下,你是否知道一些更精细的剖析方法 - 即查看内核的每个单独命令(类似于Apple的Metal)的执行时间,而不是只看到整个内核的执行时间? – sarasvati
@AndreasPapadopoulos为了更好地说明这个想法,请在XCode中查看[this profiling session image](https://developer.apple.com/library/ios/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Art/xcode_gpu_overview_program_2x.png) 。它显示了每行代码花费的时间百分比。 – sarasvati