Reputation: 551
I have gone through the CUDA programming guide and I cannot understand the thread allocation method shown below:
dim3 dimGrid( 2, 2, 1 );
dim3 dimBlock( 4, 2, 2 );
KernelFunction<<< dimGrid, dimBlock >>>(. . .);
Can some explain how threads are allocated for the above condition?
Upvotes: 1
Views: 476
Reputation: 78538
An intuitive way to think about grid and block is to visualize them:
Your dimBlock( 4, 2, 2 )
means that each block has 4 x 2 x 2 = 16
threads.
Your dimGrid( 2, 2, 1 )
means that the grid has 2 x 2 x 1 = 4
blocks.
Thus, your kernel is launched on a grid of 4 blocks, where each block has 16 threads. To conclude, your kernel will be launched with 16 x 4 = 64
threads.
Upvotes: 5