0
代碼不起作用。但是,當我在以下代碼中評論atomicAdd
時,代碼有效。cuda中的直方圖計算
這是什麼原因?
從哪裏可以獲得浮點數組的直方圖代碼?
__global__ void calculateHistogram(float *devD, int* retHis)
{
int globalLi = getCurrentThread(); //get the thread ID
if(globalLi>=0 && globalLi<Rd*Cd*Dd)
{
int r=0,c=0,d=0;
GetInd2Sub(globalLi, Rd, Cd, r, c, d); //some calculations to get r,c,d
if(r>=stYd && r<edYd && c>=stXd && c<edXd && d>=stZd && d<edZd)
{
//calculate the histogram
int indexInHis = GetBinNo(devD[globalLi]); //get the bin number in the histogram
atomicAdd(&retHis[indexInHis],1); //when I comment this line the code works
}
}
}
您可能要檢查'indexInHis'有效前夕到'atomicAdd'。 –
你是什麼意思,不起作用?它是否編譯?您的硬件是否支持全局原子添加(Cuda Capabiltiy> 1.0)?你是否在內核代碼中包含了雜注? –
我檢查了indexInHis它是正確的。我的cuda能力是1.1。 – user570593