@@ -64,62 +64,8 @@ namespace c10 {
6464#define TORCH_CHECK_LT (val1, val2 ) TORCH_CHECK_OP(val1, val2, <)
6565#define TORCH_CHECK_GE (val1, val2 ) TORCH_CHECK_OP(val1, val2, >=)
6666#define TORCH_CHECK_GT (val1, val2 ) TORCH_CHECK_OP(val1, val2, >)
67-
68- #ifndef C10_UNLIKELY_OR_CONST
69- #if defined(__CUDACC__)
70- #define C10_UNLIKELY_OR_CONST (e ) e
71- #elif defined(__GNUC__) || defined(__clang__)
72- #define C10_UNLIKELY_OR_CONST (e ) (__builtin_expect(static_cast <bool >(e), 0 ))
73- #else
74- #define C10_UNLIKELY_OR_CONST (e ) e
75- #endif
76- #endif
77-
78- namespace detail {
79-
80- template <typename ... Args>
81- inline std::string stdTorchCheckMsgImpl (const char * /* msg*/ ,
82- const Args&... args) {
83- std::ostringstream oss;
84- ((oss << args), ...);
85- return oss.str ();
86- }
87-
88- inline const char * stdTorchCheckMsgImpl (const char * msg) { return msg; }
89-
90- inline const char * stdTorchCheckMsgImpl (const char * /* msg*/ , const char * args) {
91- return args;
92- }
93-
94- } // namespace detail
9567} // namespace c10
9668
97- #ifdef STRIP_ERROR_MESSAGES
98- #define STD_TORCH_CHECK_MSG (cond, type, ...) \
99- (#cond #type " CHECK FAILED at " C10_STRINGIZE(__FILE__))
100- #else
101- #define STD_TORCH_CHECK_MSG (cond, type, ...) \
102- (::c10::detail::stdTorchCheckMsgImpl( \
103- " Expected " #cond \
104- " to be true, but got false. " \
105- " (Could this error message be improved? If so, " \
106- " please report an enhancement request to PyTorch.)" , \
107- ##__VA_ARGS__))
108- #endif
109-
110- #define STD_TORCH_CHECK (cond, ...) \
111- if (C10_UNLIKELY_OR_CONST(!(cond))) { \
112- throw std::runtime_error (STD_TORCH_CHECK_MSG (cond, \
113- " " , \
114- __func__, \
115- " , " , \
116- __FILE__, \
117- " :" , \
118- __LINE__, \
119- " , " , \
120- ##__VA_ARGS__)); \
121- }
122-
12369enum class C10ErrorType {
12470 NotImplementedError,
12571 Error,
0 commit comments