Created
October 5, 2017 12:10
-
-
Save waltner/ece68738c42d38c5e9bd1862c43b1146 to your computer and use it in GitHub Desktop.
CUDA call wrappers
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
| #ifndef CUDABASE_H_ | |
| #define CUDABASE_H_ | |
| #include <cuda.h> | |
| #include <iostream> | |
| #include <stdio.h> | |
| # define CUDA_SAFE_CALL_NO_SYNC( call) do { \ | |
| cudaError err = call; \ | |
| if( cudaSuccess != err) { \ | |
| fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \ | |
| __FILE__, __LINE__, cudaGetErrorString( err) ); \ | |
| exit(EXIT_FAILURE); \ | |
| } } while (0) | |
| # define CUDA_SAFE_CALL( call) do { \ | |
| CUDA_SAFE_CALL_NO_SYNC(call); \ | |
| cudaError err = cudaThreadSynchronize(); \ | |
| if( cudaSuccess != err) { \ | |
| fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \ | |
| __FILE__, __LINE__, cudaGetErrorString( err) ); \ | |
| exit(EXIT_FAILURE); \ | |
| } } while (0) | |
| //! Check for CUDA error | |
| # define CUT_CHECK_ERROR(errorMessage) do { \ | |
| cudaError_t err = cudaGetLastError(); \ | |
| if( cudaSuccess != err) { \ | |
| fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ | |
| errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ | |
| exit(EXIT_FAILURE); \ | |
| } \ | |
| err = cudaThreadSynchronize(); \ | |
| if( cudaSuccess != err) { \ | |
| fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \ | |
| errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\ | |
| exit(EXIT_FAILURE); \ | |
| } } while (0) | |
| #endif // end if CUDABASE_H_ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment