Addressing 2-D grids with 3-D blocks
This presentation is the property of its rightful owner.
Sponsored Links
1 / 9

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


  • 82 Views
  • Uploaded on
  • Presentation posted in: General

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

Download Presentation

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

An Image/Link below is provided (as is) to download presentation

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


Itcs 4 5010 cuda programming unc charlotte b wilkinson jan 28 2013 3 dblocks

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


Itcs 4 5010 cuda programming unc charlotte b wilkinson jan 28 2013 3 dblocks

General Approach

Given two-dimensional addressing, row, column

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.


Itcs 4 5010 cuda programming unc charlotte b wilkinson jan 28 2013 3 dblocks

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

x

Grid

y

Block

blockIdx.y

blockIdx.x

threadID.y

threadID.x

Thread


Itcs 4 5010 cuda programming unc charlotte b wilkinson jan 28 2013 3 dblocks

Global thread ID – one approach

Applicable when mapping 2-D data array onto grid.

Determine number of threads 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 = no of columns of threads in grid. N = blockDim.x * gridDim.x

Substituting we would get:

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


Itcs 4 5010 cuda programming unc charlotte b wilkinson jan 28 2013 3 dblocks

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

Thread ID within block:

BlockthreadID = threadIdx.x + threadIdx.y * blockDim.x

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


Itcs 4 5010 cuda programming unc charlotte b wilkinson jan 28 2013 3 dblocks

2-D Grids and 3-D blocks

Grid

Block

blockIdx.y

blockIdx.x

threadID.y

threadID.x

threadID.z

Thread


Itcs 4 5010 cuda programming unc charlotte b wilkinson jan 28 2013 3 dblocks

3D Global thread ID

One approach

We have global thread ID not considering z direction.

Call it threadIDxy

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

index = col + row * Ncol

threadID = threadID.z + threadIDxy * blockDim.z


Itcs 4 5010 cuda programming unc charlotte b wilkinson jan 28 2013 3 dblocks

3D Global thread ID

Another approach

2-D Address, (x, y) and block sizes Dx and Dy

Unique global thread ID = x + y Dx

3-D Address, (x, y, z) and block sizes Dx, Dy, and Dz.

Unique global thread ID = x + y Dx + zDxDy


Itcs 4 5010 cuda programming unc charlotte b wilkinson jan 28 2013 3 dblocks

Questions


  • Login