Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ITCS 6/8010 CUDA Programming, UNC-Charlotte, B. Wilkinson, March 5, 2011, 3-DBlocks.ppt Addressing 2-D grids with 3-D blocks Class Discussion Notes.

Similar presentations


Presentation on theme: "1 ITCS 6/8010 CUDA Programming, UNC-Charlotte, B. Wilkinson, March 5, 2011, 3-DBlocks.ppt Addressing 2-D grids with 3-D blocks Class Discussion Notes."— Presentation transcript:

1 1 ITCS 6/8010 CUDA Programming, UNC-Charlotte, B. Wilkinson, March 5, 2011, 3-DBlocks.ppt Addressing 2-D grids with 3-D blocks Class Discussion Notes

2 2 Given two-dimensional addressing, row, column Use the general 2-D to 1-D flattening equation: index = col + row * N col where N col is the total number of columns in a row. Apply to 2-D addressing structures repeatedly if necessary. General Approach

3 3 Thread blockIdx.x blockIdx.y Block Grid threadID.x threadID.y x y We have already considered 2-D grids and 2-D blocks

4 4 Applicable when mapping 2-D data array onto grid. Determine number of threads there are to the chosen thread, row and column: col = blockIdx.x*blockDim.x+threadIdx.x row = blockIdx.y*blockDim.y+threadIdx.y Then use: ThreadID = col + row * N where N is the number of columns of threads in grid. N = blockDim.x * gridDim.x ThreadID = (blockIdx.x*blockDim.x+threadIdx.x) + (blockIdx.y*blockDim.y+threadIdx.y)* (blockDim.x * gridDim.x) = blockIdx.x*blockDim.x+threadIdx.x+ blockIdx.y*blockDim.y* blockDim.x * gridDim.x + threadIdx.y*blockDim.x *gridDim.x Global thread ID – one approach

5 5 Using the general 2-D to 1-D flattening equation: index = column + row * N column Block ID within grid: blockID = blockIdx.x + blockIdx.y * gridDim.x Thread ID within block: BlockthreadID = threadIdx.x + threadIdx.y * blockDim.x Then substitute BlockthreadID and blockID into flattening equation again to get threadID Global thread ID - Another approach

6 6 2-D Grids and 3-D blocks threadID.z Thread blockIdx.y Block Grid threadID.y threadID.x blockIdx.x

7 7 From the previous case, we have Thread ID not considering z direction. Call it now threadID xy Using the general 2-D to 1-D flattening equation: index = col + row * N col threadID = threadID.z + threadID xy * blockDim.z Global thread ID - One approach

8 Questions


Download ppt "1 ITCS 6/8010 CUDA Programming, UNC-Charlotte, B. Wilkinson, March 5, 2011, 3-DBlocks.ppt Addressing 2-D grids with 3-D blocks Class Discussion Notes."

Similar presentations


Ads by Google