Change ReinitializeTensor to use C10_LOG_FIRST_N (#18531)
authorJerry Zhang <jerryzh@fb.com>
Wed, 3 Apr 2019 03:54:28 +0000 (20:54 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 3 Apr 2019 04:03:37 +0000 (21:03 -0700)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18531

Currently we use C10_LOG_EVERY_MS to log the data type change, but it pollutes the log of some service,
we would like to change it to C10_LOG_FIRST_N to prevent that.

Reviewed By: dzhulgakov

Differential Revision: D14647704

fbshipit-source-id: b84e4002bd4aa94d616133cd1049c3d4ab05386e

c10/util/Logging.h
caffe2/core/tensor.cc

index 2d39d21..5833f35 100644 (file)
@@ -40,6 +40,13 @@ C10_DECLARE_bool(caffe2_use_fatal_for_enforce);
 #define C10_LOG_EVERY_MS(severity, ms) LOG(severity)
 #endif
 
+// Same for LOG_FIRST_N
+#ifdef LOG_FIRST_N
+#define C10_LOG_FIRST_N(severity, n) LOG_FIRST_N(severity, n)
+#else
+#define C10_LOG_FIRST_N(severity, n) LOG(severity)
+#endif
+
 namespace c10 {
 
 using std::string;
index e4278b6..182b156 100644 (file)
@@ -156,7 +156,7 @@ void ReinitializeTensor(
       if (tensor->dtype() == options.dtype()) {
         tensor->raw_mutable_data();
       } else {
-        C10_LOG_EVERY_MS(WARNING, 1000)
+        C10_LOG_FIRST_N(WARNING, 1)
             << "Changing the data type of Tensor is discouraged."
             << " Attempt to change data type from: " << tensor->dtype()
             << " to: " << options.dtype();