Skip to content

Commit

Permalink
[pytorch] strip out warning message ifdef STRIP_ERROR_MESSAGES (pytor…
Browse files Browse the repository at this point in the history
…ch#47827)

Summary:
Pull Request resolved: pytorch#47827

Similar to TORCH_CHECK_WITH_MSG, strip messages for TORCH_WARN/TORCH_WARN_ONCE.

Test Plan: Imported from OSS

Reviewed By: ezyang

Differential Revision: D24913586

Pulled By: ljk53

fbshipit-source-id: 00f0f2bf33a48d5d7008b70ff5820623586dfd4e
  • Loading branch information
ljk53 authored and facebook-github-bot committed Nov 13, 2020
1 parent 8ff0b6f commit a376d3d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion c10/util/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,30 @@ inline std::string if_empty_then(std::string x, std::string y) {
// Report a warning to the user. Accepts an arbitrary number of extra
// arguments which are concatenated into the warning message using operator<<
//
#ifdef STRIP_ERROR_MESSAGES
#define TORCH_WARN(...) \
::c10::Warning::warn({__func__, __FILE__, static_cast<uint32_t>(__LINE__)}, {}, false)
#else
#define TORCH_WARN(...) \
::c10::Warning::warn({__func__, __FILE__, static_cast<uint32_t>(__LINE__)}, ::c10::str(__VA_ARGS__), false)
#endif

// Report a warning to the user only once. Accepts an arbitrary number of extra
// arguments which are concatenated into the warning message using operator<<
//
#ifdef STRIP_ERROR_MESSAGES
#define TORCH_WARN_ONCE(...) \
C10_UNUSED static const auto C10_ANONYMOUS_VARIABLE(torch_warn_once_) = [&] { \
::c10::Warning::warn({__func__, __FILE__, static_cast<uint32_t>(__LINE__)}, {}, false); \
return true; \
}()
#else
#define TORCH_WARN_ONCE(...) \
C10_UNUSED static const auto C10_ANONYMOUS_VARIABLE(torch_warn_once_) = [&] { \
::c10::Warning::warn({__func__, __FILE__, static_cast<uint32_t>(__LINE__)}, ::c10::str(__VA_ARGS__), false); \
return true; \
}()

#endif

// ----------------------------------------------------------------------------
// Deprecated macros
Expand Down

0 comments on commit a376d3d

Please sign in to comment.