cudasuccess cleanupfalse error cudamemcpydb hb size

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ce data to host // Copy host vectors h_A and h_B to device vectors d_A and d_B error = cudaMemcpy(d_A, h_A, size, cudaMemcpyHostToDevice); if (error != cudaSuccess) Cleanup(false); error = cudaMemcpy(d_B, h_B, size, cudaMemcpyHostToDevice); if (error != cudaSuccess) Cleanup(false); // Invoke kernel AddVectors<<<dimGrid, dimBlock>>>(d_A, d_B, d_C, ValuesPerThread); error = cudaGetLastError(); if (error != cudaSuccess) Cleanup(false); // Copy result from device memory to host memory error = cudaMemcpy(h_C, d_C, size, cudaMemcpyDeviceToHost); if (error != cudaSuccess) Cleanup(false); device: kernel // Device code. // N: values per thread __global__ void AddVectors(const float* A, const float* B, float* C, int N) { int blockStartIndex = blockIdx.x * blockDim.x * N; int threadStartIndex = blockStartIndex + (threadIdx.x * N); int threadEndI...
View Full Document

This note was uploaded on 02/12/2014 for the course CS 475 taught by Professor Staff during the Fall '08 term at Colorado State.

Ask a homework question - tutors are online