Skip to content

Instantly share code, notes, and snippets.

@alifahrri
Created October 7, 2018 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alifahrri/bdd76b0e3729b1bb56d8672c13725292 to your computer and use it in GitHub Desktop.
Save alifahrri/bdd76b0e3729b1bb56d8672c13725292 to your computer and use it in GitHub Desktop.
Error check for cuda code
#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() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment