Instantly share code, notes, and snippets.

Embed
What would you like to do?
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