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.

Vec<strong>to</strong>r Addition on the Device: main()<br />

// Copy inputs <strong>to</strong> device<br />

cudaMemcpy(d_a, a, size, cudaMemcpyHostToDevice);<br />

cudaMemcpy(d_b, b, size, cudaMemcpyHostToDevice);<br />

// Launch add() kernel on GPU with N blocks<br />

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

// Copy result back <strong>to</strong> host<br />

cudaMemcpy(c, d_c, size, cudaMemcpyDeviceToHost);<br />

}<br />

// Cleanup<br />

free(a); free(b); free(c);<br />

cudaFree(d_a); cudaFree(d_b); cudaFree(d_c);<br />

return 0;<br />

© NVIDIA Corporation 2011

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

Saved successfully!

Ooh no, something went wrong!