0% found this document useful (0 votes)
5 views12 pages

Basic Elements of A Program

Cuda -basic elements
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views12 pages

Basic Elements of A Program

Cuda -basic elements
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Basic elements of

a CUDA program
Basic steps of a CUDA program

• Initialization of data from CPU


• transfer data from CPU context to GPU context
•Kernel launch
Kernel launch with
with needed
needed grid/block
grid/block size size
• Transfer results back to CPU context from GPU context
• Reclaim the memory from both CPU and GPU
Elements of a CUDA program

• Host code (main function)


Code that is going to
run in CPU
• Device code

Code that is going to


run in GPU
function name argument list
return type

int hello_world (int x, float y, char * name)

__global__ void hello_cuda (int x - - - - -)


Grid is a collection of all the
Grid threads launch for a kernel

Block
Threads in a grid is organized in
to groups called thread blocks
Y Z

4 4

X
4
Kernel_name <<<
number_of_blocks,
thread_per_block >>> (arguments)
dim3 variable_name ( X, Y, Z)

variable_name.x
variable_name.y
variable_name.z
Z X

4
Y
32
dim3 block( 4, 1, 1)
dim3 grid( 8, 1, 1)
Kernel_name << grid, block >>>()
16
X
8

2
4
Y
dim3 block( 8, 2, 1)
dim3 grid( 2, 2, 1)
Kernel_name << grid, block >>>()
Limitation for block size
Z
X
y <= 1024
z < =64
Y x <= 1024

x * y * z < = 1024
Limitation for number of thread block
in each dimension

65536

65536
32
2 -1

You might also like