我寫一個CUDA代碼,我使用蘋果牛9500 GT顯卡。如何計算塊編號
我試圖處理20000000個整數元素的陣列,並且我使用的線程數爲256
warp大小爲32。計算能力爲1.1
這是硬件http://www.geforce.com/hardware/desktop-gpus/geforce-9500-gt/specifications
現在,block num = 20000000/256 = 78125?
這種聲音不正確。我如何計算塊號? 任何幫助,將不勝感激。
我的CUDA內核函數如下。這個想法是每個塊會計算它的總和,然後最後的總和將通過加上每個塊的總和來計算。
__global__ static void calculateSum(int * num, int * result, int DATA_SIZE)
{
extern __shared__ int shared[];
const int tid = threadIdx.x;
const int bid = blockIdx.x;
shared[tid] = 0;
for (int i = bid * THREAD_NUM + tid; i < DATA_SIZE; i += BLOCK_NUM * THREAD_NUM) {
shared[tid] += num[i];
}
__syncthreads();
int offset = THREAD_NUM/2;
while (offset > 0) {
if (tid < offset) {
shared[tid] += shared[tid + offset];
}
offset >>= 1;
__syncthreads();
}
if (tid == 0) {
result[bid] = shared[0];
}
}
而且我把這種功能
calculateSum <<<BLOCK_NUM, THREAD_NUM, THREAD_NUM * sizeof(int)>>> (gpuarray, result, size);
其中THREAD_NUM = 256 和GPU數組大小的2000萬
在這裏,我只是用塊編號爲16,但不知道這是正確的? 如何確保達到最大並行度?
這裏是我的CUDA佔用計算器的輸出。它說,當塊號爲8時,我將擁有100%的佔用率。這意味着當塊號= 8和線程號= 256時,我將獲得最大效率。那是對的嗎?
感謝
您錯誤地解釋了佔用計算器的輸出。它表示每個多處理器的最佳塊數爲3(第18行)。因此(在這種情況下),每個多處理器* 4多處理器= 12塊需要3個塊才能實現該內核的最優並行性*。 – talonmies