【发布时间】:2016-07-05 20:44:11
【问题描述】:
最初我在我的代码中使用了 blockIdx.x,但我想删除它,取而代之的是一个全局值并在我的块中使用它而不是 blockidx.x。由于我的代码太大,并且当我以大输入大小运行它时它会挂起,我认为这会有所帮助。我以原子方式递增计数器,但是当我运行代码时它挂起。谁能看看我的代码,看看我是不是做错了什么?
__device__ int counter = 0;
__global__ void kernel(int * ginput, int * goutput)
{
const int tid = threadIdx.x;
const int id = threadIdx.x + blockIdx.x * blockDim.x;
in myval = ginput[id];
if (tid == 0) {
atomicAdd(&counter, 1);
}
__syncthreads();
if (counter == 0) {
goutput[tid] = ...;
}
if (counter > 0) {
...
}
}
如果我在代码中使用 blockIdx.x 而不是计数器,它可以工作,但我只想用计数器替换它
【问题讨论】:
标签: parallel-processing cuda atomic nvidia