Created
February 3, 2017 13:43
-
-
Save AndiH/2e2f6cd9bccd64ec73c3b1d2d18284e0 to your computer and use it in GitHub Desktop.
Error-Handling Macros for CUDA C/C++ and CUDA Fortran
This file contains 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 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 ); ) | |
*/ |
This file contains 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 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