19.11.2014 Views

Introduction to CUDA C/C++

Introduction to CUDA C/C++

Introduction to CUDA C/C++

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>CUDA</strong> Threads<br />

• Terminology: a block can be split in<strong>to</strong> parallel threads<br />

• Let’s change add() <strong>to</strong> use parallel threads instead of parallel blocks<br />

Using blocks:<br />

__global__ __global__ void add(int void *a, add(int *b, *a, int *c) *b, { int *c) {<br />

c[blockIdx.x]<br />

c[blockIdx.x]<br />

= a[blockIdx.x]<br />

= a[blockIdx.x]<br />

+ b[blockIdx.x];<br />

+ b[blockIdx.x];<br />

}<br />

}<br />

add(d_a, d_b, d_c);<br />

Using threads:<br />

__global__ void add(int *a, int *b, int *c) {<br />

c[threadIdx.x] = a[threadIdx.x] + b[threadIdx.x];<br />

}<br />

add(d_a, d_b, d_c);<br />

© NVIDIA Corporation 2011

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!