22#if !defined(__CUDACC__)
23#error Do not include CUDA headers in normal C++-code!!!
29#include <cuda_runtime.h>
39 std::string error_message(cudaError_t error) {
40 const char *cuda_error = cudaGetErrorString(error);
41 return std::string(
"CUDA error: ") + cuda_error;
46#define CUDA_CHECK(statement) \
48 cudaError_t const error_code = (statement); \
49 if (error_code != cudaSuccess) { \
50 static_cast<void>(cudaGetLastError()); \
51 throw cuda_runtime_error_cuda(error_code); \
56extern cudaStream_t
stream[1];
70 const char *function,
const char *file,
73#define cuda_safe_mem(a) cuda_safe_mem_exit((a), __FILE__, __LINE__)
75#define KERNELCALL_shared(_function, _grid, _block, _stream, ...) \
76 _function<<<_grid, _block, _stream, stream[0]>>>(__VA_ARGS__); \
77 cuda_check_errors_exit(_grid, _block, #_function, __FILE__, __LINE__);
79#define KERNELCALL(_function, _grid, _block, ...) \
80 KERNELCALL_shared(_function, _grid, _block, 0, ##__VA_ARGS__)
cuda_runtime_error_cuda(cudaError_t error)
Wrapper for CUDA runtime exceptions.
static double * block(double *p, std::size_t index, std::size_t size)
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
void cuda_check_errors_exit(const dim3 &block, const dim3 &grid, const char *function, const char *file, unsigned int line)
In case of error during a CUDA operation, print the error message and exit.
void cuda_safe_mem_exit(cudaError_t CU_err, const char *file, unsigned int line)
In case of error during CUDA memory allocation and memory copy, print the error message and exit.