26#include <cuda_runtime.h>
36static std::basic_ostream<char> &
operator<<(std::basic_ostream<char> &os,
38 os <<
"<" << dim.x <<
"," << dim.y <<
"," << dim.z <<
">";
42static std::basic_ostream<char> &
operator<<(std::basic_ostream<char> &os,
44 os <<
"CUDA error: \"" << cudaGetErrorString(CU_err) <<
"\"";
49 const char *function,
const char *file,
51 cudaError_t CU_err = cudaGetLastError();
52 if (CU_err != cudaSuccess) {
53 std::stringstream message;
54 message << CU_err <<
" while calling " << function
55 <<
" with block: " <<
block <<
", grid: " << grid <<
" in " << file
63 if (CU_err != cudaSuccess) {
64 std::stringstream message;
65 message << CU_err <<
" during memory operation in " << file <<
":" << line;
66 if (CU_err == cudaErrorInvalidValue)
67 message <<
". You may have tried to allocate zero memory";
71 CU_err = cudaGetLastError();
72 if (CU_err != cudaSuccess) {
73 std::stringstream message;
74 message << CU_err <<
" in " << file <<
":" << line <<
". Error found "
75 <<
"during memory operation. Possibly however from a failed "
76 "operation before the memory operation";
83 : m_msg(std::move(msg)), m_terminate_handler(&
errexit) {}
86 if (m_terminate_handler ==
nullptr or m_terminate_handler ==
errexit) {
87 fprintf(stderr,
"%s\n",
what());
89 ((m_terminate_handler ==
nullptr) ? &std::abort : m_terminate_handler)();
char const * what() const noexcept
cuda_fatal_error(std::string msg)
void terminate() noexcept
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.
static std::basic_ostream< char > & operator<<(std::basic_ostream< char > &os, const dim3 &dim)
static double * block(double *p, std::size_t index, std::size_t size)
void errexit()
exit ungracefully, core dump if switched on.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...