OpenCL 用のミューテックスを作成しようとしています。アイデアは、すべての個々の作業項目がアトミックに処理できるようにすることです。現在のところ、ワープ内の 1 つのスレッドがロックを取得すると、スレッド ワープが続行できないことが問題である可能性があると考えています。
数値を合計するための、以下の私の現在の単純なカーネル。「numbers」は、入力としての float の配列です。sum は結果を格納する 1 要素配列、semaphore はセマフォを保持する 1 要素配列です。ここの例に大きく基づいています。
void acquire(__global int* semaphore) {
int occupied;
do {
occupied = atom_xchg(semaphore, 1);
} while (occupied>0);
}
void release(__global int* semaphore) {
atom_xchg(semaphore, 0); //the previous value, which is returned, is ignored
}
__kernel void test_kernel(__global float* numbers, __global float* sum, __global int* semaphore) {
int i = get_global_id(0);
acquire(semaphore);
*sum += numbers[i];
release(semaphore);
}
次のようにカーネルを効果的に呼び出しています。
int numof_dimensions = 1;
size_t offset_global[1] = {0};
size_t size_global[1] = {4000}; //the length of the numbers array
size_t* size_local = NULL;
clEnqueueNDRangeKernel(command_queue, kernel, numof_dimensions,offset_global,size_global,size_local, 0,NULL, NULL);
上記のように、実行中にグラフィックス カードがハングし、ドライバーが自動的に再起動します。そうならないようにするにはどうすれば直せますか?