ITCS 4/5010 CUDA Programming, UNC-Charlotte, B. Wilkinson, Jan 28, 2013, 3-DBlocks - PowerPoint PPT Presentation

1 / 9

Addressing 2-D grids with 3-D blocks Class Discussion Notes. ITCS 4/5010 CUDA Programming, UNC-Charlotte, B. Wilkinson, Jan 28, 2013, 3-DBlocks.ppt. General Approach. Given two-dimensional addressing, row, column Use the general 2-D to 1-D flattening equation: index = col + row * N col

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

ITCS 4/5010 CUDA Programming, UNC-Charlotte, B. Wilkinson, Jan 28, 2013, 3-DBlocks

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Addressing 2-D grids with 3-D blocks

Class Discussion Notes

ITCS 4/5010 CUDA Programming, UNC-Charlotte, B. Wilkinson, Jan 28, 2013,

3-DBlocks.ppt

General Approach

Use the general 2-D to 1-D flattening equation:

index = col + row * Ncol

where Ncol is the total number of columns in a row to get a unique ID.

Equation can be used multiple times in 2D/3D grids/blocks to get unique thread ID.

We have already considered 2-D grids and 2-D blocks

x

Grid

y

Block

blockIdx.y

blockIdx.x

Global thread ID – one approach

Applicable when mapping 2-D data array onto grid.

Then use:

ThreadID = col + row * N

where N = no of columns of threads in grid. N = blockDim.x * gridDim.x

Substituting we would get:

Global thread ID - Another approach

Using the general 2-D to 1-D flattening equation:

index = column + row * Ncolumn

Block ID within grid:

blockID = blockIdx.x + blockIdx.y * gridDim.x

Then substitute BlockthreadID and blockID into flattening equation again to get threadID

2-D Grids and 3-D blocks

Grid

Block

blockIdx.y

blockIdx.x

One approach

We have global thread ID not considering z direction.

Using the general 2-D to 1-D flattening equation:

index = col + row * Ncol