Skip to content

Instantly share code, notes, and snippets.

@enp1s0
Last active August 27, 2022 02:39
Show Gist options
  • Save enp1s0/f74c3201143b549b5467c6139d06f357 to your computer and use it in GitHub Desktop.
Save enp1s0/f74c3201143b549b5467c6139d06f357 to your computer and use it in GitHub Desktop.
cuda_check_error
#include <sstream>
#include <stdexcept>
inline void cuda_check_error(cudaError_t error, const std::string filename, const std::size_t line, const std::string funcname, const std::string message = ""){
if(error != cudaSuccess){
std::stringstream ss;
ss << cudaGetErrorString( error );
if(message.length() != 0){
ss << " : " << message;
}
ss << " [" << filename << ":" << line << " in " << funcname << "]";
throw std::runtime_error(ss.str());
}
}
#ifndef CUDA_CHECK_ERROR
#define CUDA_CHECK_ERROR(status) cuda_check_error(status, __FILE__, __LINE__, __func__)
#endif
#ifndef CUDA_CHECK_ERROR_M
#define CUDA_CHECK_ERROR_M(status, message) cuda_check_error(status, __FILE__, __LINE__, __func__, message)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment