1 #ifndef CAFFE2_CORE_LOGGING_IS_NOT_GOOGLE_GLOG_H_ 2 #define CAFFE2_CORE_LOGGING_IS_NOT_GOOGLE_GLOG_H_ 18 #if !defined(_MSC_VER) || !defined(ERROR) 25 const int WARNING = 1;
27 const char CAFFE2_SEVERITY_PREFIX[] =
"FEWIV";
35 std::stringstream &stream() {
return stream_; }
39 void DealWithFatal() { abort(); }
42 std::stringstream stream_;
54 void operator&(
const std::ostream &s) { }
59 void LogMessageFatal(
const char *file,
int line,
const T &message) {
66 T& CheckNotNullCommon(
const char *file,
int line,
const char *names, T& t) {
68 LogMessageFatal(file, line, std::string(names));
74 T* CheckNotNull(
const char *file,
int line,
const char *names, T* t) {
75 return CheckNotNullCommon(file, line, names, t);
79 T& CheckNotNull(
const char *file,
int line,
const char *names, T& t) {
80 return CheckNotNullCommon(file, line, names, t);
87 static_assert(CAFFE2_LOG_THRESHOLD <= FATAL,
88 "CAFFE2_LOG_THRESHOLD should at most be FATAL.");
92 if (n >= CAFFE2_LOG_THRESHOLD) \ 93 ::caffe2::MessageLogger((char*)__FILE__, __LINE__, n).stream() 94 #define VLOG(n) LOG((-n)) 96 #define LOG_IF(n, condition) \ 97 if (n >= CAFFE2_LOG_THRESHOLD && (condition)) \ 98 ::caffe2::MessageLogger((char*)__FILE__, __LINE__, n).stream() 99 #define VLOG_IF(n, condition) LOG_IF((-n), (condition)) 102 #define FATAL_IF(condition) \ 103 condition ? (void) 0 : ::caffe2::LoggerVoidify() & \ 104 ::caffe2::MessageLogger((char*)__FILE__, __LINE__, FATAL).stream() 107 #define CHECK(condition) FATAL_IF(condition) \ 108 << "Check failed: " #condition " " 112 #define DCHECK(condition) FATAL_IF(condition) \ 113 << "Check failed: " #condition " " 116 #define DCHECK(condition) if(false) CHECK(condition) 119 #define CHECK_OP(val1, val2, op) FATAL_IF((val1 op val2)) \ 120 << "Check failed: " #val1 " " #op " " #val2 " " 123 #define CHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==) 124 #define CHECK_NE(val1, val2) CHECK_OP(val1, val2, !=) 125 #define CHECK_LE(val1, val2) CHECK_OP(val1, val2, <=) 126 #define CHECK_LT(val1, val2) CHECK_OP(val1, val2, <) 127 #define CHECK_GE(val1, val2) CHECK_OP(val1, val2, >=) 128 #define CHECK_GT(val1, val2) CHECK_OP(val1, val2, >) 132 #define DCHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==) 133 #define DCHECK_NE(val1, val2) CHECK_OP(val1, val2, !=) 134 #define DCHECK_LE(val1, val2) CHECK_OP(val1, val2, <=) 135 #define DCHECK_LT(val1, val2) CHECK_OP(val1, val2, <) 136 #define DCHECK_GE(val1, val2) CHECK_OP(val1, val2, >=) 137 #define DCHECK_GT(val1, val2) CHECK_OP(val1, val2, >) 140 #define DCHECK_EQ(val1, val2) if(false) CHECK_OP(val1, val2, ==) 141 #define DCHECK_NE(val1, val2) if(false) CHECK_OP(val1, val2, !=) 142 #define DCHECK_LE(val1, val2) if(false) CHECK_OP(val1, val2, <=) 143 #define DCHECK_LT(val1, val2) if(false) CHECK_OP(val1, val2, <) 144 #define DCHECK_GE(val1, val2) if(false) CHECK_OP(val1, val2, >=) 145 #define DCHECK_GT(val1, val2) if(false) CHECK_OP(val1, val2, >) 149 #define CHECK_NOTNULL(val) \ 150 ::caffe2::CheckNotNull( \ 151 __FILE__, __LINE__, "Check failed: '" #val "' Must be non NULL", (val)) 155 #define DCHECK_NOTNULL(val) \ 156 ::caffe2::CheckNotNull( \ 157 __FILE__, __LINE__, "Check failed: '" #val "' Must be non NULL", (val)) 160 #define DCHECK_NOTNULL(val) if (false) CHECK_NOTNULL(val) 171 template<
class First,
class Second>
172 std::ostream& operator<<(
173 std::ostream& out,
const std::pair<First, Second>& p);
174 template <
class Iter>
175 void PrintSequence(std::ostream& ss, Iter begin, Iter end);
177 #define INSTANTIATE_FOR_CONTAINER(container) \ 178 template <class... Types> \ 179 std::ostream& operator<<( \ 180 std::ostream& out, const container<Types...>& seq) { \ 181 PrintSequence(out, seq.begin(), seq.end()); \ 185 INSTANTIATE_FOR_CONTAINER(std::vector)
186 INSTANTIATE_FOR_CONTAINER(std::map)
187 INSTANTIATE_FOR_CONTAINER(std::set)
188 #undef INSTANTIATE_FOR_CONTAINER 190 template<
class First,
class Second>
191 inline std::ostream& operator<<(
192 std::ostream& out,
const std::pair<First, Second>& p) {
193 out <<
'(' << p.first <<
", " << p.second <<
')';
197 template <
class Iter>
198 inline void PrintSequence(std::ostream& out, Iter begin, Iter end) {
200 for (
int i = 0; begin != end && i < 100; ++i, ++begin) {
201 if (i > 0) out <<
' ';
210 #endif // CAFFE2_CORE_LOGGING_IS_NOT_GOOGLE_GLOG_H_ Simple registry implementation in Caffe2 that uses static variables to register object creators durin...
Commandline flags support for Caffe2.