Created
May 10, 2012 11:16
-
-
Save ashwin/2652488 to your computer and use it in GitHub Desktop.
CUDA Error Checking Functions
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 this to turn on error checking | |
#define CUDA_ERROR_CHECK | |
#define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ ) | |
#define CudaCheckError() __cudaCheckError( __FILE__, __LINE__ ) | |
inline void __cudaSafeCall( cudaError err, const char *file, const int line ) | |
{ | |
#ifdef CUDA_ERROR_CHECK | |
if ( cudaSuccess != err ) | |
{ | |
fprintf( stderr, "cudaSafeCall() failed at %s:%i : %s\n", | |
file, line, cudaGetErrorString( err ) ); | |
exit( -1 ); | |
} | |
#endif | |
return; | |
} | |
inline void __cudaCheckError( const char *file, const int line ) | |
{ | |
#ifdef CUDA_ERROR_CHECK | |
cudaError err = cudaGetLastError(); | |
if ( cudaSuccess != err ) | |
{ | |
fprintf( stderr, "cudaCheckError() failed at %s:%i : %s\n", | |
file, line, cudaGetErrorString( err ) ); | |
exit( -1 ); | |
} | |
// More careful checking. However, this will affect performance. | |
// Comment away if needed. | |
err = cudaDeviceSynchronize(); | |
if( cudaSuccess != err ) | |
{ | |
fprintf( stderr, "cudaCheckError() with sync failed at %s:%i : %s\n", | |
file, line, cudaGetErrorString( err ) ); | |
exit( -1 ); | |
} | |
#endif | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment