Skip to content

Instantly share code, notes, and snippets.

@antoni
Last active September 24, 2015 15:22
Show Gist options
  • Select an option

  • Save antoni/a0bed5d822baa83e26bf to your computer and use it in GitHub Desktop.

Select an option

Save antoni/a0bed5d822baa83e26bf to your computer and use it in GitHub Desktop.
Error handling in CUDA
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
gpuErrchk( cudaMalloc(&a_d, size*sizeof(int)) );
kernel<<<1,1>>>(a);
gpuErrchk( cudaPeekAtLastError() );
gpuErrchk( cudaDeviceSynchronize() );
kernel<<<1,1>>>(a_d);
gpuErrchk( cudaPeekAtLastError() );
gpuErrchk( cudaMemcpy(a_h, a_d, size * sizeof(int), cudaMemcpyDeviceToHost) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment