Skip to content

Instantly share code, notes, and snippets.

@AndiH
Created February 3, 2017 13:43
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 AndiH/2e2f6cd9bccd64ec73c3b1d2d18284e0 to your computer and use it in GitHub Desktop.
Save AndiH/2e2f6cd9bccd64ec73c3b1d2d18284e0 to your computer and use it in GitHub Desktop.
Error-Handling Macros for CUDA C/C++ and CUDA Fortran
#define CUDA_CALL( call ) \
{ \
cudaError_t result = call; \
if ( cudaSuccess != result ) \
std::cerr << "CUDA error " << result << " in " << __FILE__ << ":" << __LINE__ << ": " << cudaGetErrorString( result ) << " (" << #call << ")" << std::endl; \
}
/*
Usage:
CUDA_CALL( cudaMalloc( (void**)&ad, csize ); )
*/
#define CUDA_SUCCESS 0
#define CUDA_CALL__(e,fmt,c) \
e=c; \
if(e/=CUDA_SUCCESS) \
write(*,fmt) "CUDA Error ",e," in ",__FILE__,":",__LINE__,": ",trim(cudaGetErrorString(e))," (",#c,")"
#define CUDA_CALL(c) CUDA_CALL__(gpuStatus,fmt,c)
module debug
character(len=27) :: fmt = "(A,I0,A,A,A,I0,A,A,A,A,A,A)"
integer :: gpuStatus
end module debug
! Usage:
!
! use debug
! CUDA_CALL( cudaEventRecord(startEvent, 0) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment