Previous | Next --- Slide 36 of 78
Back to Lecture Thumbnails
yey1

Is the block size defined by programmers?

bpr

@yey1, block size is defined by the programmer, up to a limit set by hardware.

acortes

Would there be an error if the programmer tried to have a larger block size?

bpr

@acortes, if the programmer tried a block size larger than the hardware limit, then yes there would be an error, usually a compiler error.

lusiliang93

When doing CUDA programming, I am a little bit confused with blockDim.x. If it is a 1D grid, why index equals blockIdx.x*blockDim.x +threadIdx.x? What if it is a 2D grid?

bpr

@lusiliang93, each thread block forms a grid in three dimensions: x, y, and z. Each thread receives three variables: blockIdx, blockDim, and threadIdx (and each variable has the three dimensions).

blockIdx - which block this thread is in blockDim - how large each block is threadIdx - the id of the thread in that block

This is similar to array indexing. If you look at the picture in the slide, what is the index of a thread in block(1,1)? Being 1 block away from the start, how large is each block? The blockIdx*blockDim accounts for the block positioning, and then threadIdx is the position in that block.

Each index is in an independent dimension and is computed independently from the three components.

hanzhoul

Since both block dimension and grid dimension are dim3 parameters, can we assume that we can build a 3D grid with each block has 3 dimensions?