正如标题所示,我正在对并行计算机视觉技术进行一些个人研究。使用 CUDA,我尝试实现 GPGPU 版本的霍夫变换。我遇到的唯一问题是在投票过程中。我调用atomicAdd() 来防止多个同时写入操作,但我似乎没有获得太多的性能效率。我在网上搜索过,但没有找到任何方法可以显着提高投票过程的性能。
如果您能提供有关投票过程的任何帮助,我们将不胜感激。
我不熟悉霍夫变换,因此发布一些伪代码可能会有所帮助。但如果您对投票感兴趣,您可以考虑使用 CUDA 投票内在指令来加速这一过程。
请注意,这需要 2.0 或更高版本的计算能力(Fermi 或更高版本)。
如果您想计算一个线程中的线程数block对于特定条件成立的情况,您可以使用__syncthreads_count()
.
bool condition = ...; // compute the condition
int blockCount = __syncthreads_count(condition); // must be in non-divergent code
如果您想计算一个线程中的线程数grid对于条件为 true 的情况,您可以执行以下操作atomicAdd
bool condition = ...; // compute the condition
int blockCount = __syncthreads_count(condition); // must be in non-divergent code
atomicAdd(totalCount, blockCount);
如果需要计算小于条件为 true 的块的组中的线程数,可以使用__ballot()
and __popc()
(人口统计)。
// get the count of threads within each warp for which the condition is true
bool condition = ...; // compute the condition in each thread
int warpCount = __popc(__ballot()); // see the CUDA programming guide for details
希望这可以帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)