未验证 提交 b33f95b0 编写于 作者: H HongyuJia 提交者: GitHub

[Decouple enforce.h] Move LOG from enforce.h to enforce.cc (#52883)

* [Decouple enforce.h] Move LOG from enforce.h to enforce.cc

* update cmake of device_context.cc, solve cuda_device_context_allocator.h compile error

* add namespace inside macro
上级 b66c833f
......@@ -132,7 +132,8 @@ cc_library(
${MLU_CTX_DEPS}
phi_backends
phi_device_context
generator)
generator
phi_enforce)
cc_library(
collective_helper
......
......@@ -20,6 +20,7 @@ limitations under the License. */
#include <vector>
#include "gflags/gflags.h"
#include "glog/logging.h"
#include "paddle/phi/common/scalar.h"
#include "paddle/utils/blank.h"
......@@ -168,6 +169,10 @@ std::string GetCurrentTraceBackString(bool for_signal) {
return sout.str();
}
void ThrowWarnInternal(const std::string& msg) {
LOG(WARNING) << "WARNING :" << msg;
}
std::string SimplifyErrorTypeFormat(const std::string& str) {
std::ostringstream sout;
size_t type_end_pos = str.find(":", 0);
......
......@@ -282,10 +282,16 @@ inline bool is_error(bool stat) { return !stat; }
END_HANDLE_THE_ERROR \
} while (0)
#define __THROW_WARN_INTERNAL__(__MSG__) \
do { \
LOG(WARNING) << "WARNING :" << __MSG__; \
} while (0)
/**
* [Why declare function ThrowWarnInternal instead of defining macro
* __THROW_WARN_INTERNAL__?]
* ThrowWarnInternal uses `LOG` macro to display warning message, which depends
* on third-party header file "logging.h". However, "logging.h" has not been
* exposed to site-package yet, so that error will occur when we include
* "enforce.h" header file. Hence, we declare function in enforce.h and define
* it in enforce.cc file.
*/
void ThrowWarnInternal(const std::string& message);
/** ENFORCE EXCEPTION AND MACROS **/
......@@ -428,7 +434,7 @@ struct EnforceNotMet : public std::exception {
auto __message__ = ::paddle::string::Sprintf( \
"%s\n [Hint: " #__VAL " should not be null.]", \
__summary__.error_message()); \
__THROW_WARN_INTERNAL__(__message__); \
::phi::enforce::ThrowWarnInternal(__message__); \
} \
} while (0)
......@@ -770,7 +776,7 @@ inline std::string build_nvidia_error_msg(ncclResult_t nccl_result) {
::phi::enforce::details::ExternalApiType< \
__CUDA_STATUS_TYPE__>::kSuccess; \
if (UNLIKELY(__cond__ != __success_type__)) { \
__THROW_WARN_INTERNAL__( \
::phi::enforce::ThrowWarnInternal( \
::phi::enforce::build_nvidia_error_msg(__cond__)); \
} \
} while (0)
......@@ -981,16 +987,17 @@ DEFINE_EXTERNAL_API_TYPE(ncclResult_t, ncclSuccess);
} \
} while (0)
#define PADDLE_WARN_GPU_SUCCESS(COND) \
do { \
auto __cond__ = (COND); \
using __CUDA_STATUS_TYPE__ = decltype(__cond__); \
constexpr auto __success_type__ = \
::phi::enforce::details::ExternalApiType< \
__CUDA_STATUS_TYPE__>::kSuccess; \
if (UNLIKELY(__cond__ != __success_type__)) { \
__THROW_WARN_INTERNAL__(::phi::enforce::build_rocm_error_msg(__cond__)); \
} \
#define PADDLE_WARN_GPU_SUCCESS(COND) \
do { \
auto __cond__ = (COND); \
using __CUDA_STATUS_TYPE__ = decltype(__cond__); \
constexpr auto __success_type__ = \
::phi::enforce::details::ExternalApiType< \
__CUDA_STATUS_TYPE__>::kSuccess; \
if (UNLIKELY(__cond__ != __success_type__)) { \
::phi::enforce::ThrowWarnInternal( \
::phi::enforce::build_rocm_error_msg(__cond__)); \
} \
} while (0)
inline void retry_sleep(unsigned millisecond) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册