22#if !defined(__CUDACC__)
23#error Do not include CUDA headers in normal C++-code!!!
38 std::string error_message(cudaError_t error) {
39 const char *cuda_error = cudaGetErrorString(error);
40 return std::string(
"CUDA error: ") + cuda_error;
45#define CUDA_CHECK(statement) \
47 cudaError_t const error_code = (statement); \
48 if (error_code != cudaSuccess) { \
49 throw cuda_runtime_error_cuda(error_code); \
54extern cudaStream_t
stream[1];
68 const char *function,
const char *file,
71#define cuda_safe_mem(a) cuda_safe_mem_exit((a), __FILE__, __LINE__)
73#define KERNELCALL_shared(_function, _grid, _block, _stream, ...) \
74 _function<<<_grid, _block, _stream, stream[0]>>>(__VA_ARGS__); \
75 cuda_check_errors_exit(_grid, _block, #_function, __FILE__, __LINE__);
77#define KERNELCALL(_function, _grid, _block, ...) \
78 KERNELCALL_shared(_function, _grid, _block, 0, ##__VA_ARGS__)
cuda_runtime_error_cuda(cudaError_t error)
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.