私はハフ変換に慣れていないので、疑似コードを投稿するとここに役立つかもしれません。ただし、投票に関心がある場合は、CUDA 投票組み込み命令を使用して投票を加速することを検討してください。
これには 2.0 以降のコンピューティング機能 (Fermi 以降) が必要であることに注意してください。
特定の条件が真であるブロック内のスレッドの数を数えたい場合は、単に を使用できます__syncthreads_count()
。
bool condition = ...; // compute the condition
int blockCount = __syncthreads_count(condition); // must be in non-divergent code
条件が真であるグリッド内のスレッドの数を数えたい場合は、次のように実行できます。atomicAdd
bool condition = ...; // compute the condition
int blockCount = __syncthreads_count(condition); // must be in non-divergent code
atomicAdd(totalCount, blockCount);
条件が true であるブロックよりも小さいグループ内のスレッドの数をカウントする必要がある場合は、__ballot()
and __popc()
(population count) を使用できます。
// 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
お役に立てれば。