diff --git a/src/ARBDException.h b/src/ARBDException.h index d310a33857ff422f8da52359beeffe87f55fc539..e47bfe2a5af568de811fcfa8e16df01e8c50c234 100644 --- a/src/ARBDException.h +++ b/src/ARBDException.h @@ -11,15 +11,21 @@ #include <exception> #include "SignalManager.h" -enum ExceptionType { - UnspeficiedError, - NotImplementedError, - ValueError, - DivideByZeroError, - CUDARuntimeError, - FileIoError, - FileOpenError +struct ExceptionType { +public: + explicit constexpr ExceptionType(int value) noexcept : value{value} {}; + constexpr operator int() const { return value; }; +private: + const int value; }; +// inline constexpr ExceptionType const UnspecifiedError{0}; +constexpr ExceptionType const UnspecifiedError{0}; +constexpr ExceptionType const NotImplementedError{1}; +constexpr ExceptionType const ValueError{2}; +constexpr ExceptionType const DivideByZeroError{3}; +constexpr ExceptionType const CUDARuntimeError{4}; +constexpr ExceptionType const FileIoError{5}; +constexpr ExceptionType const FileOpenError{6}; class _ARBDException : public std::exception { @@ -29,7 +35,7 @@ class _ARBDException : public std::exception std::string sformat(const std::string &fmt, va_list &ap); static std::string type_to_str(ExceptionType type) { switch (type) { - case UnspeficiedError: + case UnspecifiedError: return "Error"; case NotImplementedError: return "NotImplementedError"; @@ -44,11 +50,12 @@ class _ARBDException : public std::exception }; // #include "common_macros.h" -#define S1(x) #x -#define S2(x) S1(x) -#define LOCATION __FILE__ "(" S2(__LINE__)")" - +#ifdef CUDACC #define Exception(...) throw _ARBDException(LOCATION, __VA_ARGS__) +#else +#define Exception(EXCPT,...) printf("Runtime CUDA exception at %s: ", LOCATION); \ + printf("%s %s\n", #EXCPT, __VA_ARGS__); +#endif //use illegal instruction to abort; used in functions defined both in __host__ and __device__ #if 0 #define CudaException(...) \ diff --git a/src/GPUManager.h b/src/GPUManager.h index 1650ae3f8fdecb5a3672172ff091889e14a657c7..24ffe5bfe4ffce38ab08e378d6e918fcf331df71 100644 --- a/src/GPUManager.h +++ b/src/GPUManager.h @@ -81,7 +81,7 @@ struct has_copy_to_cuda<T, decltype(std::declval<T>().copy_to_cuda(), void())> : #ifndef gpuErrchk #define delgpuErrchk #define gpuErrchk(code) { if ((code) != cudaSuccess) { \ - Exception(CUDARuntimeError, " ", cudaGetErrorString(code)); \ + Exception(CUDARuntimeError, cudaGetErrorString(code)); \ }} #endif /* diff --git a/src/SignalManager.h b/src/SignalManager.h index 704f39b26b9a6c6bcaeff1373ff73bab499608c0..57125838318199091c02bd5b395432afaa74d6fb 100644 --- a/src/SignalManager.h +++ b/src/SignalManager.h @@ -11,7 +11,22 @@ /* #define ARBD_LOG_ACTIVE_LEVEL 0 */ /* #include "logger.h" */ +#define S1(x) #x +#define S2(x) S1(x) +#define LOCATION __FILE__ "(" S2(__LINE__)")" /* mainly used by ARBDException */ + //* +#ifdef __CUDA_ARCH__ +// #define LOGHELPER(TYPE, FMT,...) printf("[%d,%d] [%s] [%s]: %s", blockIdx.x, threadIdx.x, TYPE, LOCATION, FMT); +#define LOGHELPER(TYPE, FMT,...) printf("[%s] [%s]: %s\n", TYPE, LOCATION, FMT); +#define LOGTRACE(...) LOGHELPER("trace", __VA_ARGS__) +#define LOGDEBUG(...) LOGHELPER("debug",__VA_ARGS__) +// #define DEBUG(...) spdlog::debug(__VA_ARGS__) +#define LOGINFO(...) LOGHELPER("info",__VA_ARGS__) +#define LOGWARN(...) LOGHELPER("warn",__VA_ARGS__) +#define LOGERROR(...) LOGHELPER("error",__VA_ARGS__) +#define LOGCRITICAL(...) LOGHELPER("critical",__VA_ARGS__) +#else #define FMT_HEADER_ONLY #include <spdlog/fmt/bundled/core.h> #include <spdlog/fmt/bundled/format.h> @@ -29,6 +44,7 @@ #define LOGERROR(...) SPDLOG_ERROR(__VA_ARGS__) #define LOGCRITICAL(...) SPDLOG_CRITICAL(__VA_ARGS__) // spdlog::set_level(spdlog::level::trace); +#endif //*/ /*