Last active
September 24, 2015 15:22
-
-
Save antoni/a0bed5d822baa83e26bf to your computer and use it in GitHub Desktop.
Error handling in CUDA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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