Anyone want to take a stab at explaining the differences between blockIdx, blockDim and threadIdx? This is important when writing complex CUDA kernels, which you'll do in assignment 2!
sam
blockDim gives the number of threads in a block .For example in above figure( orange one),block
dimension is 4 in X direction and 3 in Y direction.
blockIdx gives the index of the block in a grid. For example in the above figure(green one)
grid has 6 blocks. So index of first block is (0,0) , second is (0,1) and so on..
threadIdx gives the index of a thread in a block. For example in the above figure(orange one) a block has 12 threads with indexes (0,0) for 1st thread , (0,1) for second and so on..
zhanpenf
@sam Is your answer "40 threads in x direction and 50 threads in y direction" incorrect? I think there should be 12 threads in x direction and 6 threads in y direction.
sam
@zhanpenf yeah that was wrong ...I just removed that line...That was a typo.. In a block shown above in orange the no. of threads in x direction are 4 and 3 in y direction.
kayvonf
Students helping each other, yay!
kayvonf
Sometimes it's simply more natural to use multi-dimensional thread indexing. For example, in the 2D convolution example (or the 2D grid solver example), it might make the program clearer to use 2D indexing. (Assignment 2 might be a another example, depending on your chosen implementation.)
Anyone want to take a stab at explaining the differences between
blockIdx
,blockDim
andthreadIdx
? This is important when writing complex CUDA kernels, which you'll do in assignment 2!blockDim
gives the number of threads in a block .For example in above figure( orange one),block dimension is 4 in X direction and 3 in Y direction.blockIdx
gives the index of the block in a grid. For example in the above figure(green one) grid has 6 blocks. So index of first block is (0,0) , second is (0,1) and so on..threadIdx
gives the index of a thread in a block. For example in the above figure(orange one) a block has 12 threads with indexes (0,0) for 1st thread , (0,1) for second and so on..@sam Is your answer "40 threads in x direction and 50 threads in y direction" incorrect? I think there should be 12 threads in x direction and 6 threads in y direction.
@zhanpenf yeah that was wrong ...I just removed that line...That was a typo.. In a block shown above in orange the no. of threads in x direction are 4 and 3 in y direction.
Students helping each other, yay!
Sometimes it's simply more natural to use multi-dimensional thread indexing. For example, in the 2D convolution example (or the 2D grid solver example), it might make the program clearer to use 2D indexing. (Assignment 2 might be a another example, depending on your chosen implementation.)