From fbb42173a99bd5978d1103eed696bb86ffce2718 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Mon, 30 Dec 2019 20:46:38 +0800 Subject: [PATCH] fix no hint problem when use ENFORCE for cuda, test=develop (#21994) --- paddle/fluid/platform/enforce.h | 44 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index d422b93cea..be25f2d014 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -207,6 +207,10 @@ inline std::string GetTraceBackString(StrType&& what, const char* file, inline bool is_error(bool stat) { return !stat; } +inline std::string build_ex_string(bool stat, const std::string& msg) { + return msg; +} + inline void throw_on_error(bool stat, const std::string& msg) { #ifndef REPLACE_ENFORCE_GLOG throw std::runtime_error(msg); @@ -215,14 +219,6 @@ inline void throw_on_error(bool stat, const std::string& msg) { #endif } -inline void throw_on_error(const platform::ErrorSummary& error) { -#ifndef REPLACE_ENFORCE_GLOG - throw std::runtime_error(error.ToString()); -#else - LOG(FATAL) << error.ToString(); -#endif -} - // Note: This Macro can only be used within enforce.h #define __THROW_ERROR_INTERNAL__(...) \ do { \ @@ -271,18 +267,21 @@ struct EnforceNotMet : public std::exception { } \ } while (0) #else -#define PADDLE_ENFORCE(COND, ...) \ - do { \ - auto __cond__ = (COND); \ - if (UNLIKELY(::paddle::platform::is_error(__cond__))) { \ - try { \ - ::paddle::platform::throw_on_error( \ - ::paddle::platform::ErrorSummary(__VA_ARGS__)); \ - } catch (...) { \ - throw ::paddle::platform::EnforceNotMet(std::current_exception(), \ - __FILE__, __LINE__); \ - } \ - } \ +#define PADDLE_ENFORCE(COND, ...) \ + do { \ + auto __cond__ = (COND); \ + if (UNLIKELY(::paddle::platform::is_error(__cond__))) { \ + try { \ + ::paddle::platform::throw_on_error( \ + __cond__, \ + ::paddle::platform::build_ex_string( \ + __cond__, \ + ::paddle::platform::ErrorSummary(__VA_ARGS__).ToString())); \ + } catch (...) { \ + throw ::paddle::platform::EnforceNotMet(std::current_exception(), \ + __FILE__, __LINE__); \ + } \ + } \ } while (0) #endif @@ -414,7 +413,8 @@ inline bool is_error(cudnnStatus_t stat) { } inline std::string build_ex_string(cudnnStatus_t stat, const std::string& msg) { - return msg + "\n [" + platform::dynload::cudnnGetErrorString(stat) + "]"; + return msg + "\n [Hint: " + platform::dynload::cudnnGetErrorString(stat) + + "]"; } inline void throw_on_error(cudnnStatus_t stat, const std::string& msg) { @@ -451,7 +451,7 @@ inline std::string build_ex_string(cublasStatus_t stat, } else if (stat == CUBLAS_STATUS_LICENSE_ERROR) { err = "CUBLAS: license error."; } - return msg + "\n [" + err + "]"; + return msg + "\n [Hint: " + err + "]"; } inline void throw_on_error(cublasStatus_t stat, const std::string& msg) { -- GitLab