29.01.2013 Views

Tutorial CUDA

Tutorial CUDA

Tutorial CUDA

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example: Host Code<br />

// allocate host memory<br />

unsigned int numBytes = N * sizeof(float)<br />

float* h_A = (float*) malloc(numBytes);<br />

// allocate device memory<br />

float* d_A = 0;<br />

cudaMalloc((void**)&d_A, numbytes);<br />

// copy data from host to device<br />

cudaMemcpy(d_A, h_A, numBytes, cudaMemcpyHostToDevice);<br />

// execute the kernel<br />

increment_gpu>(d_A, b);<br />

// copy data from device back to host<br />

cudaMemcpy(h_A, d_A, numBytes, cudaMemcpyDeviceToHost);<br />

// free device memory<br />

cudaFree(d_A);<br />

© NVIDIA Corporation 2008 27

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

Saved successfully!

Ooh no, something went wrong!