CUDA: dim3

dim3 is an integer vector type that can be used in CUDA code. Its most common application is to pass the grid and block dimensions in a kernel invocation. It can also be used in any user code for holding values of 3 dimensions.

For example:

dim3 grid( 512 );         // 512 x 1 x 1
dim3 block( 1024, 1024 ); // 1024 x 1024 x 1
fooKernel<<< grid, block >>>();

The only facts to know about dim3 are:

  • dim3 is a simple structure that is defined in %CUDA_INC_PATH%/vector_types.h
  • dim3 has 3 elements x, y and z.
  • In C code, dim3 can be initialized as dim3 grid = { 512, 512, 1 };
  • In C++ code, dim3 can be initialized as dim3 grid( 512, 512, 1 );
  • Not all the 3 elements need to be provided. Any element not provided during initialization is initialized to 1. Please note that they are initialized to 1, not 0!
  • dim3 can be converted to and from uint3, another similar CUDA data type.

dim3 is modeled after similar vector types that are available in shader languages like Cg, GLSL or HLSL. However, unlike them dim3 is disappointingly simple and incapable of anything useful. It cannot be used directly in any arithmetic operations ( grid + block ) or in any sort of vector swizzling ( grid.xyz = block.zyx ). :-(

 

Tried with: CUDA 3.2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s