我总是得到blockdim.y == 1。无论我在numBlocks中设置什么值,我总是会得到相同的结果。
__global__ void CalcVideo(unsigned char *original, unsigned char *candidate, int *answer)
{
printf("block id.x = %d blockid.y=%d blockdim.x = %d blockdim.y = %d Thread id= %d \n",
blockIdx.x, blockIdx.y, blockDim.x, blockDim.y, threadIdx.x );
}
int ORIGINAL_FRAMES = 3;
int CANDIDATE_FRAMES = 2;
int FRAME_LENGHT = 3;
dim3 numBlocks(ORIGINAL_FRAMES, CANDIDATE_FRAMES);
dim3 threadsPerBlock(3); // 64 threads
CalcVideo << <numBlocks, threadsPerBlock >> >(original_device, candidate_device, answer_device);
y.blokcs的数量正确执行,但是为什么程序给我的blockdim.y大小错误?
block id.x = 1 blockid.y=0 blockdim.x = 3 blockdim.y = 1 Thread id= 0
block id.x = 1 blockid.y=0 blockdim.x = 3 blockdim.y = 1 Thread id= 1
block id.x = 1 blockid.y=0 blockdim.x = 3 blockdim.y = 1 Thread id= 2
block id.x = 1 blockid.y=1 blockdim.x = 3 blockdim.y = 1 Thread id= 0
block id.x = 1 blockid.y=1 blockdim.x = 3 blockdim.y = 1 Thread id= 1
block id.x = 1 blockid.y=1 blockdim.x = 3 blockdim.y = 1 Thread id= 2
block id.x = 0 blockid.y=1 blockdim.x = 3 blockdim.y = 1 Thread id= 0
block id.x = 0 blockid.y=1 blockdim.x = 3 blockdim.y = 1 Thread id= 1
block id.x = 0 blockid.y=1 blockdim.x = 3 blockdim.y = 1 Thread id= 2
block id.x = 0 blockid.y=0 blockdim.x = 3 blockdim.y = 1 Thread id= 0
block id.x = 0 blockid.y=0 blockdim.x = 3 blockdim.y = 1 Thread id= 1
block id.x = 0 blockid.y=0 blockdim.x = 3 blockdim.y = 1 Thread id= 2
block id.x = 2 blockid.y=1 blockdim.x = 3 blockdim.y = 1 Thread id= 0
block id.x = 2 blockid.y=1 blockdim.x = 3 blockdim.y = 1 Thread id= 1
block id.x = 2 blockid.y=1 blockdim.x = 3 blockdim.y = 1 Thread id= 2
block id.x = 2 blockid.y=0 blockdim.x = 3 blockdim.y = 1 Thread id= 0
block id.x = 2 blockid.y=0 blockdim.x = 3 blockdim.y = 1 Thread id= 1
block id.x = 2 blockid.y=0 blockdim.x = 3 blockdim.y = 1 Thread id= 2
最佳答案
blockDim
存储一个块的尺寸。在您的情况下,您要传递threadsPerBlock
作为块维度,从而使其成为3 x 1 x 1
。内核调用的第一个参数numBlocks
(在您的情况下)控制块网格的尺寸-您可以在内核中以gridDim
的形式访问它。
旁注:我认为问题中块的数量和数量极少,仅用于测试目的,因为它们会使实践中的GPU使用率极低。
关于c++ - CUDA blockDim.y始终== 1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34197497/