forked from openvinotoolkit/model_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tf.patch
472 lines (448 loc) · 18.6 KB
/
tf.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
diff --git a/tensorflow/tools/proto_text/BUILD b/tensorflow/tools/proto_text/BUILD
index b2998173b53..afd5f4eabfe 100644
--- a/tensorflow/tools/proto_text/BUILD
+++ b/tensorflow/tools/proto_text/BUILD
@@ -39,7 +39,8 @@ cc_binary(
"//tensorflow/core:lib_proto_parsing",
"//tensorflow/tsl/platform:protobuf_compiler",
"@com_google_protobuf//:protobuf",
- ] + if_ios(["//tensorflow/core/platform:logging"]),
+ ] + ["//tensorflow/tsl/platform:logging",
+ "//tensorflow/tsl/platform/default:glog"],
)
cc_library(
diff --git a/tensorflow/tsl/platform/default/BUILD b/tensorflow/tsl/platform/default/BUILD
index 3542c8ae3e8..ea7b8e4db8f 100644
--- a/tensorflow/tsl/platform/default/BUILD
+++ b/tensorflow/tsl/platform/default/BUILD
@@ -229,6 +229,19 @@ cc_library(
],
)
+cc_library(
+ name = "log_macros",
+ hdrs = ["log_macros.h"],
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "glog",
+ #hdrs = ["@com_github_glog_glog//:glog/logging.h",]
+ visibility = ["//visibility:public"],
+ deps = ["@com_github_glog_glog//:glog",],
+)
+
cc_library(
name = "logging",
srcs = ["logging.cc"],
@@ -247,6 +260,8 @@ cc_library(
"//tensorflow/tsl/platform:types",
"@com_google_absl//absl/base",
"@com_google_absl//absl/strings",
+ ":glog",
+ ":log_macros",
],
)
diff --git a/tensorflow/tsl/platform/default/log_macros.h b/tensorflow/tsl/platform/default/log_macros.h
new file mode 100644
index 00000000000..31ba58594cc
--- /dev/null
+++ b/tensorflow/tsl/platform/default/log_macros.h
@@ -0,0 +1,99 @@
+#pragma once
+#define LOG(severity) _TF_LOG_##severity
+
+// An instance of `LOG_EVERY_N` increments a hidden zero-initialized counter
+// every time execution passes through it and logs the specified message when
+// the counter's value is a multiple of `n`, doing nothing otherwise. Each
+// instance has its own counter. The counter's value can be logged by streaming
+// the symbol `COUNTER`. `LOG_EVERY_N` is thread-safe.
+// Example:
+//
+// for (const auto& user : all_users) {
+// LOG_EVERY_N(INFO, 1000) << "Processing user #" << COUNTER;
+// ProcessUser(user);
+// }
+
+// CHECK dies with a fatal error if condition is not true. It is *not*
+// controlled by NDEBUG, so the check will be executed regardless of
+// compilation mode. Therefore, it is safe to do things like:
+// CHECK(fp->Write(x) == 4)
+#define CHECK(condition) \
+ if (TF_PREDICT_FALSE(!(condition))) \
+ LOG(FATAL) << "Check failed: " #condition " "
+// `LOG_FIRST_N` behaves like `LOG_EVERY_N` except that the specified message is
+// logged when the counter's value is less than `n`. `LOG_FIRST_N` is
+// thread-safe.
+
+#define VLOG(level) \
+ TF_PREDICT_TRUE(!VLOG_IS_ON(level)) \
+ ? (void)0 \
+ : ::tsl::internal::Voidifier() & \
+ ::tsl::internal::LogMessage(__FILE__, __LINE__, \
+ tensorflow::INFO)
+
+// `DVLOG` behaves like `VLOG` in debug mode (i.e. `#ifndef NDEBUG`).
+// Otherwise, it compiles away and does nothing.
+#ifndef NDEBUG
+#define DVLOG VLOG
+#else
+#ifndef DVLOG
+#define DVLOG(verbose_level) \
+ while (false && (verbose_level) > 0) ::tsl::internal::LogMessageNull()
+#endif
+#endif
+
+
+// In optimized mode, use CheckOpString to hint to compiler that
+// the while condition is unlikely.
+#ifndef CHECK_OP_LOG
+#define CHECK_OP_LOG(name, op, val1, val2) \
+ while (::tsl::internal::CheckOpString _result{ \
+ ::tsl::internal::name##Impl( \
+ ::tsl::internal::GetReferenceableValue(val1), \
+ ::tsl::internal::GetReferenceableValue(val2), \
+ #val1 " " #op " " #val2)}) \
+ ::tsl::internal::LogMessageFatal(__FILE__, __LINE__) << *(_result.str_)
+#endif
+#ifndef CHECK_OP
+#define CHECK_OP(name, op, val1, val2) CHECK_OP_LOG(name, op, val1, val2)
+#endif
+
+// CHECK_EQ/NE/...
+#define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2)
+#define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2)
+#define CHECK_LE(val1, val2) CHECK_OP(_LE, <=, val1, val2)
+#define CHECK_LT(val1, val2) CHECK_OP(_LT, < , val1, val2)
+#define CHECK_GE(val1, val2) CHECK_OP(_GE, >=, val1, val2)
+#define CHECK_GT(val1, val2) CHECK_OP(_GT, > , val1, val2)
+
+
+#ifndef NDEBUG
+// DCHECK_EQ/NE/...
+#define DCHECK(condition) CHECK(condition)
+#define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2)
+#define DCHECK_NE(val1, val2) CHECK_NE(val1, val2)
+#define DCHECK_LE(val1, val2) CHECK_LE(val1, val2)
+#define DCHECK_LT(val1, val2) CHECK_LT(val1, val2)
+#define DCHECK_GE(val1, val2) CHECK_GE(val1, val2)
+#define DCHECK_GT(val1, val2) CHECK_GT(val1, val2)
+
+#else
+
+#define DCHECK(condition) \
+ while (false && (condition)) LOG(FATAL)
+
+// NDEBUG is defined, so DCHECK_EQ(x, y) and so on do nothing.
+// However, we still want the compiler to parse x and y, because
+// we don't want to lose potentially useful errors and warnings.
+// _DCHECK_NOP is a helper, and should not be used outside of this file.
+#define _TF_DCHECK_NOP(x, y) \
+ while (false && ((void)(x), (void)(y), 0)) LOG(FATAL)
+
+#define DCHECK_EQ(x, y) _TF_DCHECK_NOP(x, y)
+#define DCHECK_NE(x, y) _TF_DCHECK_NOP(x, y)
+#define DCHECK_LE(x, y) _TF_DCHECK_NOP(x, y)
+#define DCHECK_LT(x, y) _TF_DCHECK_NOP(x, y)
+#define DCHECK_GE(x, y) _TF_DCHECK_NOP(x, y)
+#define DCHECK_GT(x, y) _TF_DCHECK_NOP(x, y)
+
+#endif
diff --git a/tensorflow/tsl/platform/default/logging.cc b/tensorflow/tsl/platform/default/logging.cc
index 9f978e29599..429190a6218 100644
--- a/tensorflow/tsl/platform/default/logging.cc
+++ b/tensorflow/tsl/platform/default/logging.cc
@@ -381,7 +381,6 @@ void LogString(const char* fname, int line, int severity,
LogMessage(fname, line, severity) << message;
}
-template <>
void MakeCheckOpValueString(std::ostream* os, const char& v) {
if (v >= 32 && v <= 126) {
(*os) << "'" << v << "'";
@@ -390,7 +389,6 @@ void MakeCheckOpValueString(std::ostream* os, const char& v) {
}
}
-template <>
void MakeCheckOpValueString(std::ostream* os, const signed char& v) {
if (v >= 32 && v <= 126) {
(*os) << "'" << v << "'";
@@ -399,7 +397,6 @@ void MakeCheckOpValueString(std::ostream* os, const signed char& v) {
}
}
-template <>
void MakeCheckOpValueString(std::ostream* os, const unsigned char& v) {
if (v >= 32 && v <= 126) {
(*os) << "'" << v << "'";
@@ -409,7 +406,6 @@ void MakeCheckOpValueString(std::ostream* os, const unsigned char& v) {
}
#if LANG_CXX11
-template <>
void MakeCheckOpValueString(std::ostream* os, const std::nullptr_t& v) {
(*os) << "nullptr";
}
diff --git a/tensorflow/tsl/platform/default/logging.h b/tensorflow/tsl/platform/default/logging.h
index 417d7d81f83..84f7e1d5c2f 100644
--- a/tensorflow/tsl/platform/default/logging.h
+++ b/tensorflow/tsl/platform/default/logging.h
@@ -43,6 +43,7 @@ limitations under the License.
// Undef everything in case we're being mixed with some other Google library
// which already defined them itself. Presumably all Google libraries will
// support the same syntax for these so it should not be a big deal if they
+#define COMPACT_GOOGLE_LOG_QFATAL COMPACT_GOOGLE_LOG_ERROR
// end up using our definitions instead.
#undef LOG
#undef VLOG
@@ -63,6 +64,15 @@ limitations under the License.
#undef DCHECK_GT
#undef DCHECK_GE
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsign-compare"
+#include "glog/logging.h"
+#pragma GCC diagnostic pop
+
+#ifndef LOG
+#include "log_macros.h"
+#endif
+
namespace tsl {
const int INFO = 0; // base_logging::INFO;
const int WARNING = 1; // base_logging::WARNING;
@@ -142,42 +152,6 @@ class LogMessageNull : public std::basic_ostringstream<char> {
#define _TF_LOG_QFATAL _TF_LOG_FATAL
-#define LOG(severity) _TF_LOG_##severity
-
-#ifdef IS_MOBILE_PLATFORM
-
-// Turn VLOG off when under mobile devices for considerations of binary size.
-#define VLOG_IS_ON(lvl) ((lvl) <= 0)
-
-#else
-
-// Otherwise, set TF_CPP_MAX_VLOG_LEVEL environment to update minimum log level
-// of VLOG, or TF_CPP_VMODULE to set the minimum log level for individual
-// translation units.
-#define VLOG_IS_ON(lvl) \
- (([](int level, const char* fname) { \
- static const bool vmodule_activated = \
- ::tsl::internal::LogMessage::VmoduleActivated(fname, level); \
- return vmodule_activated; \
- })(lvl, __FILE__))
-
-#endif
-
-#define VLOG(level) \
- TF_PREDICT_TRUE(!VLOG_IS_ON(level)) \
- ? (void)0 \
- : ::tsl::internal::Voidifier() & \
- ::tsl::internal::LogMessage(__FILE__, __LINE__, tsl::INFO)
-
-// `DVLOG` behaves like `VLOG` in debug mode (i.e. `#ifndef NDEBUG`).
-// Otherwise, it compiles away and does nothing.
-#ifndef NDEBUG
-#define DVLOG VLOG
-#else
-#define DVLOG(verbose_level) \
- while (false && (verbose_level) > 0) ::tsl::internal::LogMessageNull()
-#endif
-
class LogEveryNState {
public:
bool ShouldLog(int n);
@@ -244,26 +218,6 @@ class LogEveryNSecState {
logging_internal_stateful_condition_do_log; \
logging_internal_stateful_condition_do_log = false)
-// An instance of `LOG_EVERY_N` increments a hidden zero-initialized counter
-// every time execution passes through it and logs the specified message when
-// the counter's value is a multiple of `n`, doing nothing otherwise. Each
-// instance has its own counter. The counter's value can be logged by streaming
-// the symbol `COUNTER`. `LOG_EVERY_N` is thread-safe.
-// Example:
-//
-// for (const auto& user : all_users) {
-// LOG_EVERY_N(INFO, 1000) << "Processing user #" << COUNTER;
-// ProcessUser(user);
-// }
-#define LOG_EVERY_N(severity, n) \
- LOGGING_INTERNAL_STATEFUL_CONDITION(EveryN, true, n) \
- LOG(severity)
-// `LOG_FIRST_N` behaves like `LOG_EVERY_N` except that the specified message is
-// logged when the counter's value is less than `n`. `LOG_FIRST_N` is
-// thread-safe.
-#define LOG_FIRST_N(severity, n) \
- LOGGING_INTERNAL_STATEFUL_CONDITION(FirstN, true, n) \
- LOG(severity)
// `LOG_EVERY_POW_2` behaves like `LOG_EVERY_N` except that the specified
// message is logged when the counter's value is a power of 2.
// `LOG_EVERY_POW_2` is thread-safe.
@@ -281,13 +235,6 @@ class LogEveryNSecState {
LOGGING_INTERNAL_STATEFUL_CONDITION(EveryNSec, true, n_seconds) \
LOG(severity)
-// CHECK dies with a fatal error if condition is not true. It is *not*
-// controlled by NDEBUG, so the check will be executed regardless of
-// compilation mode. Therefore, it is safe to do things like:
-// CHECK(fp->Write(x) == 4)
-#define CHECK(condition) \
- if (TF_PREDICT_FALSE(!(condition))) \
- LOG(FATAL) << "Check failed: " #condition " "
// Function is overloaded for integral types to allow static const
// integrals declared in classes and not defined to be used as arguments to
@@ -306,28 +253,6 @@ inline unsigned int GetReferenceableValue(unsigned int t) { return t; }
inline int64_t GetReferenceableValue(int64_t t) { return t; }
inline uint64 GetReferenceableValue(uint64 t) { return t; }
-// This formats a value for a failing CHECK_XX statement. Ordinarily,
-// it uses the definition for operator<<, with a few special cases below.
-template <typename T>
-inline void MakeCheckOpValueString(std::ostream* os, const T& v) {
- (*os) << v;
-}
-
-// Overrides for char types provide readable values for unprintable
-// characters.
-template <>
-void MakeCheckOpValueString(std::ostream* os, const char& v);
-template <>
-void MakeCheckOpValueString(std::ostream* os, const signed char& v);
-template <>
-void MakeCheckOpValueString(std::ostream* os, const unsigned char& v);
-
-#if LANG_CXX11
-// We need an explicit specialization for std::nullptr_t.
-template <>
-void MakeCheckOpValueString(std::ostream* os, const std::nullptr_t& v);
-#endif
-
// A container for a string pointer which can be evaluated to a bool -
// true iff the pointer is non-NULL.
struct CheckOpString {
@@ -338,17 +263,6 @@ struct CheckOpString {
string* str_;
};
-// Build the error message string. Specify no inlining for code size.
-template <typename T1, typename T2>
-string* MakeCheckOpString(const T1& v1, const T2& v2,
- const char* exprtext) TF_ATTRIBUTE_NOINLINE;
-
-// A helper class for formatting "expr (V1 vs. V2)" in a CHECK_XX
-// statement. See MakeCheckOpString for sample usage. Other
-// approaches were considered: use of a template method (e.g.,
-// base::BuildCheckOpString(exprtext, base::Print<T1>, &v1,
-// base::Print<T2>, &v2), however this approach has complications
-// related to volatile arguments and function-pointer arguments).
class CheckOpMessageBuilder {
public:
// Inserts "exprtext" and " (" to the stream.
@@ -366,14 +280,6 @@ class CheckOpMessageBuilder {
std::ostringstream* stream_;
};
-template <typename T1, typename T2>
-string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext) {
- CheckOpMessageBuilder comb(exprtext);
- MakeCheckOpValueString(comb.ForVar1(), v1);
- MakeCheckOpValueString(comb.ForVar2(), v2);
- return comb.NewString();
-}
-
// Helper functions for CHECK_OP macro.
// We use the full name Check_EQ, Check_NE, etc. in case the file including
// base/logging.h provides its own #defines for the simpler names EQ, NE, etc.
@@ -389,7 +295,8 @@ string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext) {
if (TF_PREDICT_TRUE(v1 op v2)) \
return NULL; \
else \
- return ::tsl::internal::MakeCheckOpString(v1, v2, exprtext); \
+ /*return ::tsl::internal::MakeCheckOpString(v1, v2, exprtext);*/ \
+ return google::MakeCheckOpString(v1, v2, exprtext); \
} \
inline string* name##Impl(int v1, int v2, const char* exprtext) { \
return name##Impl<int, int>(v1, v2, exprtext); \
@@ -404,7 +311,7 @@ TF_DEFINE_CHECK_OP_IMPL(Check_EQ, ==)
inline string* Check_EQImpl(int v1, size_t v2, const char* exprtext) {
if (TF_PREDICT_FALSE(v1 < 0))
- ::tsl::internal::MakeCheckOpString(v1, v2, exprtext);
+ google::MakeCheckOpString(v1, v2, exprtext);
return Check_EQImpl(size_t(v1), v2, exprtext);
}
@@ -435,7 +342,7 @@ inline string* Check_LEImpl(int v1, size_t v2, const char* exprtext) {
inline string* Check_LEImpl(size_t v1, int v2, const char* exprtext) {
if (TF_PREDICT_FALSE(v2 < 0))
- return ::tsl::internal::MakeCheckOpString(v1, v2, exprtext);
+ return google::MakeCheckOpString(v1, v2, exprtext);
return Check_LEImpl(v1, size_t(v2), exprtext);
}
@@ -448,7 +355,7 @@ inline string* Check_LTImpl(int v1, size_t v2, const char* exprtext) {
}
inline string* Check_LTImpl(size_t v1, int v2, const char* exprtext) {
- if (v2 < 0) return ::tsl::internal::MakeCheckOpString(v1, v2, exprtext);
+ if (v2 < 0) return google::MakeCheckOpString(v1, v2, exprtext);
return Check_LTImpl(v1, size_t(v2), exprtext);
}
@@ -465,58 +372,6 @@ inline string* Check_GTImpl(const T1& v1, const T2& v2, const char* exprtext) {
#undef TF_DEFINE_CHECK_OP_IMPL
-// In optimized mode, use CheckOpString to hint to compiler that
-// the while condition is unlikely.
-#define CHECK_OP_LOG(name, op, val1, val2) \
- while (::tsl::internal::CheckOpString _result{::tsl::internal::name##Impl( \
- ::tsl::internal::GetReferenceableValue(val1), \
- ::tsl::internal::GetReferenceableValue(val2), #val1 " " #op " " #val2)}) \
- ::tsl::internal::LogMessageFatal(__FILE__, __LINE__) << *(_result.str_)
-
-#define CHECK_OP(name, op, val1, val2) CHECK_OP_LOG(name, op, val1, val2)
-
-// CHECK_EQ/NE/...
-#define CHECK_EQ(val1, val2) CHECK_OP(Check_EQ, ==, val1, val2)
-#define CHECK_NE(val1, val2) CHECK_OP(Check_NE, !=, val1, val2)
-#define CHECK_LE(val1, val2) CHECK_OP(Check_LE, <=, val1, val2)
-#define CHECK_LT(val1, val2) CHECK_OP(Check_LT, <, val1, val2)
-#define CHECK_GE(val1, val2) CHECK_OP(Check_GE, >=, val1, val2)
-#define CHECK_GT(val1, val2) CHECK_OP(Check_GT, >, val1, val2)
-#define CHECK_NOTNULL(val) \
- ::tsl::internal::CheckNotNull(__FILE__, __LINE__, \
- "'" #val "' Must be non NULL", (val))
-
-#ifndef NDEBUG
-// DCHECK_EQ/NE/...
-#define DCHECK(condition) CHECK(condition)
-#define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2)
-#define DCHECK_NE(val1, val2) CHECK_NE(val1, val2)
-#define DCHECK_LE(val1, val2) CHECK_LE(val1, val2)
-#define DCHECK_LT(val1, val2) CHECK_LT(val1, val2)
-#define DCHECK_GE(val1, val2) CHECK_GE(val1, val2)
-#define DCHECK_GT(val1, val2) CHECK_GT(val1, val2)
-
-#else
-
-#define DCHECK(condition) \
- while (false && (condition)) LOG(FATAL)
-
-// NDEBUG is defined, so DCHECK_EQ(x, y) and so on do nothing.
-// However, we still want the compiler to parse x and y, because
-// we don't want to lose potentially useful errors and warnings.
-// _DCHECK_NOP is a helper, and should not be used outside of this file.
-#define _TF_DCHECK_NOP(x, y) \
- while (false && ((void)(x), (void)(y), 0)) LOG(FATAL)
-
-#define DCHECK_EQ(x, y) _TF_DCHECK_NOP(x, y)
-#define DCHECK_NE(x, y) _TF_DCHECK_NOP(x, y)
-#define DCHECK_LE(x, y) _TF_DCHECK_NOP(x, y)
-#define DCHECK_LT(x, y) _TF_DCHECK_NOP(x, y)
-#define DCHECK_GE(x, y) _TF_DCHECK_NOP(x, y)
-#define DCHECK_GT(x, y) _TF_DCHECK_NOP(x, y)
-
-#endif
-
// These are for when you don't want a CHECK failure to print a verbose
// stack trace. The implementation of CHECK* in this file already doesn't.
#define QCHECK(condition) CHECK(condition)
diff --git a/tensorflow/tsl/platform/logging.h b/tensorflow/tsl/platform/logging.h
index 68c209fa491..dfe5c45700c 100644
--- a/tensorflow/tsl/platform/logging.h
+++ b/tensorflow/tsl/platform/logging.h
@@ -21,7 +21,8 @@ limitations under the License.
#if defined(PLATFORM_GOOGLE) || defined(PLATFORM_GOOGLE_ANDROID) || \
defined(PLATFORM_GOOGLE_IOS) || defined(GOOGLE_LOGGING) || \
defined(__EMSCRIPTEN__) || defined(PLATFORM_CHROMIUMOS)
-#include "tensorflow/tsl/platform/google/logging.h" // IWYU pragma: export
+#include "tensorflow/tsl/platform/default/logging.h" // IWYU pragma: export
+//#include "tensorflow/tsl/platform/google/logging.h" // IWYU pragma: export
#else
#include "tensorflow/tsl/platform/default/logging.h" // IWYU pragma: export
#endif