cuda プログラムの最適化戦略を探しています。カーネルの for ループ内の反復ごとに、各スレッドがスコアを生成します。ブロックごとにスコアの上位 k を維持するために、スコアの共有優先度キューを維持しています。以下の疑似コードを参照してください。
__global__ gpuCompute(... arguments)
{
__shared__ myPriorityQueue[k]; //To maintain top k scores ( k < #threads in this block)
__shared__ scoresToInsertInQueue[#threadsInBlock];
__shared__ counter;
for(...) //About 1-100 million iterations
{
int score = calculate_score(...);
if(score > Minimum element of P. Queue && ...)
{
ATOMIC Operation : localCounter = counter++;
scoresToInsertInQueue[localCounter] = score;
}
__syncthreads();
//Merge scores from scoresToInsertInQueue to myPriorityQueue
while(counter>0)
{
//Parallel insertion of scoresToInsertInQueue[counter] to myPriorityQueue using the participation of k threads in this block
counter--;
__syncthreads();
}
__syncthreads();
}
}
上記のコードが皆さんにとって意味のあるものであることを願っています。今、アトミック操作のオーバーヘッドを削除する方法を探しています。各スレッドは、値が優先キューに送られるかどうかに応じて「1」または「0」を保存します。'1000000000100000000' を '11000000000000000000' バッファーに減らして (または '1' のインデックスを知って)、最終的に '1' に対応するスコアをキューに挿入できるように、カーネル内にストリーム圧縮の実装があるかどうか疑問に思っています。
この場合、「1」は非常にまばらになることに注意してください。