Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions transformer_engine/common/include/transformer_engine/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
" in function " + __func__ + ": " + x); \
} while (false)

#define NVTE_LIBRARY_ERROR(x, file, line, func) \
do { \
throw std::runtime_error(std::string(file ":") + std::to_string(line) + \
" in function " + func + ": " + x); \
} while (false)

#define NVTE_CHECK(x, ...) \
do { \
if (!(x)) { \
Expand All @@ -29,19 +35,19 @@

namespace {

inline void check_cuda_(cudaError_t status) {
inline void check_cuda_(cudaError_t status, const char *file, const int line, const char *func) {
if ( status != cudaSuccess ) {
NVTE_ERROR("CUDA Error: " + std::string(cudaGetErrorString(status)));
NVTE_LIBRARY_ERROR("CUDA Error: " + std::string(cudaGetErrorString(status)), file, line, func);
}
}

inline void check_cublas_(cublasStatus_t status) {
inline void check_cublas_(cublasStatus_t status, const char *file, const int line, const char *func) {
if ( status != CUBLAS_STATUS_SUCCESS ) {
NVTE_ERROR("CUBLAS Error: " + std::string(cublasGetStatusString(status)));
NVTE_LIBRARY_ERROR("CUBLAS Error: " + std::string(cublasGetStatusString(status)), file, line, func);
}
}

inline void check_cudnn_(cudnnStatus_t status) {
inline void check_cudnn_(cudnnStatus_t status, const char *file, const int line, const char *func) {
if ( status != CUDNN_STATUS_SUCCESS ) {
std::string message;
message.reserve(1024);
Expand All @@ -51,24 +57,24 @@ inline void check_cudnn_(cudnnStatus_t status) {
"For more information, enable cuDNN error logging "
"by setting CUDNN_LOGERR_DBG=1 and "
"CUDNN_LOGDEST_DBG=stderr in the environment.");
NVTE_ERROR(message);
NVTE_LIBRARY_ERROR(message, file, line, func);
}
}

inline void check_nvrtc_(nvrtcResult status) {
inline void check_nvrtc_(nvrtcResult status, const char *file, const int line, const char *func) {
if ( status != NVRTC_SUCCESS ) {
NVTE_ERROR("NVRTC Error: " + std::string(nvrtcGetErrorString(status)));
NVTE_LIBRARY_ERROR("NVRTC Error: " + std::string(nvrtcGetErrorString(status)), file, line, func);
}
}

} // namespace

#define NVTE_CHECK_CUDA(ans) { check_cuda_(ans); }
#define NVTE_CHECK_CUDA(ans) { check_cuda_(ans, __FILE__, __LINE__, __func__); }

#define NVTE_CHECK_CUBLAS(ans) { check_cublas_(ans); }
#define NVTE_CHECK_CUBLAS(ans) { check_cublas_(ans, __FILE__, __LINE__, __func__); }

#define NVTE_CHECK_CUDNN(ans) { check_cudnn_(ans); }
#define NVTE_CHECK_CUDNN(ans) { check_cudnn_(ans, __FILE__, __LINE__, __func__); }

#define NVTE_CHECK_NVRTC(ans) { check_nvrtc_(ans); }
#define NVTE_CHECK_NVRTC(ans) { check_nvrtc_(ans, __FILE__, __LINE__, __func__); }

#endif // TRANSFORMER_ENGINE_LOGGING_H_