This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 80cc480 Refactor diagnostic to avoid circular dependencies (#6692)
80cc480 is described below
commit 80cc4802369f12c3e6a4cc186978d0685521159d
Author: Robert Kimball <[email protected]>
AuthorDate: Sat Oct 17 17:42:38 2020 -0700
Refactor diagnostic to avoid circular dependencies (#6692)
---
include/tvm/ir/diagnostic.h | 48 +--------------------------------------
include/tvm/ir/type_relation.h | 1 +
include/tvm/relay/analysis.h | 2 +-
include/tvm/runtime/object.h | 16 ++++++-------
include/tvm/support/logging.h | 46 +++++++++++++++++++++++++++++++++++++
src/ir/diagnostic.cc | 11 ++-------
src/parser/parser.cc | 2 +-
src/parser/span_check.h | 2 +-
src/relay/analysis/well_formed.cc | 2 +-
src/relay/op/nn/convolution.h | 2 +-
10 files changed, 63 insertions(+), 69 deletions(-)
diff --git a/include/tvm/ir/diagnostic.h b/include/tvm/ir/diagnostic.h
index 6b98074..2a2a6cd 100644
--- a/include/tvm/ir/diagnostic.h
+++ b/include/tvm/ir/diagnostic.h
@@ -21,68 +21,22 @@
* \file diagnostic.h
* \brief A new diagnostic interface for TVM error reporting.
*
- * A prototype of the new diagnostic reporting interface for TVM.
- *
- * Eventually we hope to promote this file to the top-level and
- * replace the existing errors.h.
*/
#ifndef TVM_IR_DIAGNOSTIC_H_
#define TVM_IR_DIAGNOSTIC_H_
#include <tvm/ir/module.h>
-#include <tvm/ir/span.h>
#include <tvm/parser/source_map.h>
-#include <tvm/runtime/container.h>
-#include <tvm/runtime/object.h>
-#include <tvm/support/logging.h>
-#include <fstream>
+#include <sstream>
#include <string>
-#include <utility>
-#include <vector>
namespace tvm {
using tvm::parser::SourceMap;
using tvm::runtime::TypedPackedFunc;
-extern const char* kTVM_INTERNAL_ERROR_MESSAGE;
-
-#define ICHECK_INDENT " "
-
-#define ICHECK_BINARY_OP(name, op, x, y) \
- if (dmlc::LogCheckError _check_err = dmlc::LogCheck##name(x, y)) \
- dmlc::LogMessageFatal(__FILE__, __LINE__).stream() \
- << kTVM_INTERNAL_ERROR_MESSAGE << std::endl \
- << ICHECK_INDENT << "Check failed: " << #x " " #op " " #y <<
*(_check_err.str) << ": "
-
-#define ICHECK(x) \
- if (!(x)) \
- dmlc::LogMessageFatal(__FILE__, __LINE__).stream() \
- << kTVM_INTERNAL_ERROR_MESSAGE << ICHECK_INDENT << "Check failed: " #x
<< " == false: "
-
-#define ICHECK_LT(x, y) ICHECK_BINARY_OP(_LT, <, x, y)
-#define ICHECK_GT(x, y) ICHECK_BINARY_OP(_GT, >, x, y)
-#define ICHECK_LE(x, y) ICHECK_BINARY_OP(_LE, <=, x, y)
-#define ICHECK_GE(x, y) ICHECK_BINARY_OP(_GE, >=, x, y)
-#define ICHECK_EQ(x, y) ICHECK_BINARY_OP(_EQ, ==, x, y)
-#define ICHECK_NE(x, y) ICHECK_BINARY_OP(_NE, !=, x, y)
-#define ICHECK_NOTNULL(x)
\
- ((x) == nullptr ? dmlc::LogMessageFatal(__FILE__, __LINE__).stream()
\
- << kTVM_INTERNAL_ERROR_MESSAGE << __INDENT << "Check
not null: " #x \
- << ' ',
\
- (x) : (x)) // NOLINT(*)
-
-/*! \brief The diagnostic level, controls the printing of the message. */
-enum class DiagnosticLevel : int {
- kBug = 10,
- kError = 20,
- kWarning = 30,
- kNote = 40,
- kHelp = 50,
-};
-
class DiagnosticBuilder;
/*! \brief A compiler diagnostic. */
diff --git a/include/tvm/ir/type_relation.h b/include/tvm/ir/type_relation.h
index 83323b0..4625880 100644
--- a/include/tvm/ir/type_relation.h
+++ b/include/tvm/ir/type_relation.h
@@ -29,6 +29,7 @@
#include <tvm/ir/env_func.h>
#include <tvm/ir/module.h>
#include <tvm/ir/type.h>
+#include <tvm/support/logging.h>
namespace tvm {
diff --git a/include/tvm/relay/analysis.h b/include/tvm/relay/analysis.h
index 26e5a65..5dd8370 100644
--- a/include/tvm/relay/analysis.h
+++ b/include/tvm/relay/analysis.h
@@ -24,12 +24,12 @@
#ifndef TVM_RELAY_ANALYSIS_H_
#define TVM_RELAY_ANALYSIS_H_
-#include <tvm/ir/diagnostic.h>
#include <tvm/ir/module.h>
#include <tvm/relay/adt.h>
#include <tvm/relay/expr.h>
#include <tvm/relay/function.h>
#include <tvm/relay/type.h>
+#include <tvm/support/logging.h>
#include <string>
#include <unordered_map>
diff --git a/include/tvm/runtime/object.h b/include/tvm/runtime/object.h
index e6ca832..b5cf77d 100644
--- a/include/tvm/runtime/object.h
+++ b/include/tvm/runtime/object.h
@@ -23,8 +23,8 @@
#ifndef TVM_RUNTIME_OBJECT_H_
#define TVM_RUNTIME_OBJECT_H_
-#include <dmlc/logging.h>
#include <tvm/runtime/c_runtime_api.h>
+#include <tvm/support/logging.h>
#include <string>
#include <type_traits>
@@ -153,9 +153,9 @@ struct TypeIndex {
* ObjectRef leaf_ref(make_object<LeafObj>());
* // cast to a specific instance
* const LeafObj* leaf_ptr = leaf_ref.as<LeafObj>();
- * CHECK(leaf_ptr != nullptr);
+ * ICHECK(leaf_ptr != nullptr);
* // can also cast to the base class.
- * CHECK(leaf_ref.as<BaseObj>() != nullptr);
+ * ICHECK(leaf_ref.as<BaseObj>() != nullptr);
* }
*
* \endcode
@@ -756,7 +756,7 @@ struct ObjectPtrEqual {
*/
#define TVM_DEFINE_OBJECT_REF_COW_METHOD(ObjectName) \
ObjectName* CopyOnWrite() { \
- CHECK(data_ != nullptr); \
+ ICHECK(data_ != nullptr); \
if (!data_.unique()) { \
auto n = make_object<ObjectName>(*(operator->())); \
ObjectPtr<Object>(std::move(n)).swap(data_); \
@@ -845,7 +845,7 @@ inline RefType GetRef(const ObjType* ptr) {
static_assert(std::is_base_of<typename RefType::ContainerType,
ObjType>::value,
"Can only cast to the ref of same container type");
if (!RefType::_type_is_nullable) {
- CHECK(ptr != nullptr);
+ ICHECK(ptr != nullptr);
}
return RefType(ObjectPtr<Object>(const_cast<Object*>(static_cast<const
Object*>(ptr))));
}
@@ -860,12 +860,12 @@ inline ObjectPtr<BaseType> GetObjectPtr(ObjType* ptr) {
template <typename SubRef, typename BaseRef>
inline SubRef Downcast(BaseRef ref) {
if (ref.defined()) {
- CHECK(ref->template IsInstance<typename SubRef::ContainerType>())
+ ICHECK(ref->template IsInstance<typename SubRef::ContainerType>())
<< "Downcast from " << ref->GetTypeKey() << " to " <<
SubRef::ContainerType::_type_key
<< " failed.";
} else {
- CHECK(SubRef::_type_is_nullable) << "Downcast from nullptr to not nullable
reference of "
- << SubRef::ContainerType::_type_key;
+ ICHECK(SubRef::_type_is_nullable) << "Downcast from nullptr to not
nullable reference of "
+ << SubRef::ContainerType::_type_key;
}
return SubRef(std::move(ref.data_));
}
diff --git a/include/tvm/support/logging.h b/include/tvm/support/logging.h
index c318b89..4322435 100644
--- a/include/tvm/support/logging.h
+++ b/include/tvm/support/logging.h
@@ -24,6 +24,8 @@
#ifndef TVM_SUPPORT_LOGGING_H_
#define TVM_SUPPORT_LOGGING_H_
+#include <dmlc/logging.h>
+
// a technique that enables overriding macro names on the number of
parameters. This is used
// to define other macros below
#define GET_MACRO(_1, _2, _3, _4, _5, NAME, ...) NAME
@@ -109,4 +111,48 @@
#define COND_CHECK_2(quit_on_assert, x) COND_CHECK_3(quit_on_assert, x, return
false)
#define COND_LOG_2(quit_on_assert, x) COND_LOG_3(quit_on_assert, x, return
false)
+namespace tvm {
+
+constexpr const char* kTVM_INTERNAL_ERROR_MESSAGE =
+ "\n---------------------------------------------------------------\n"
+ "An internal invariant was violated during the execution of TVM.\n"
+ "Please read TVM's error reporting guidelines.\n"
+ "More details can be found here:
https://discuss.tvm.ai/t/error-reporting/7793.\n"
+ "---------------------------------------------------------------\n";
+
+#define ICHECK_INDENT " "
+
+#define ICHECK_BINARY_OP(name, op, x, y) \
+ if (dmlc::LogCheckError _check_err = dmlc::LogCheck##name(x, y)) \
+ dmlc::LogMessageFatal(__FILE__, __LINE__).stream() \
+ << kTVM_INTERNAL_ERROR_MESSAGE << std::endl \
+ << ICHECK_INDENT << "Check failed: " << #x " " #op " " #y <<
*(_check_err.str) << ": "
+
+#define ICHECK(x) \
+ if (!(x)) \
+ dmlc::LogMessageFatal(__FILE__, __LINE__).stream() \
+ << kTVM_INTERNAL_ERROR_MESSAGE << ICHECK_INDENT << "Check failed: " #x
<< " == false: "
+
+#define ICHECK_LT(x, y) ICHECK_BINARY_OP(_LT, <, x, y)
+#define ICHECK_GT(x, y) ICHECK_BINARY_OP(_GT, >, x, y)
+#define ICHECK_LE(x, y) ICHECK_BINARY_OP(_LE, <=, x, y)
+#define ICHECK_GE(x, y) ICHECK_BINARY_OP(_GE, >=, x, y)
+#define ICHECK_EQ(x, y) ICHECK_BINARY_OP(_EQ, ==, x, y)
+#define ICHECK_NE(x, y) ICHECK_BINARY_OP(_NE, !=, x, y)
+#define ICHECK_NOTNULL(x)
\
+ ((x) == nullptr ? dmlc::LogMessageFatal(__FILE__, __LINE__).stream()
\
+ << kTVM_INTERNAL_ERROR_MESSAGE << __INDENT << "Check
not null: " #x \
+ << ' ',
\
+ (x) : (x)) // NOLINT(*)
+
+/*! \brief The diagnostic level, controls the printing of the message. */
+enum class DiagnosticLevel : int {
+ kBug = 10,
+ kError = 20,
+ kWarning = 30,
+ kNote = 40,
+ kHelp = 50,
+};
+
+} // namespace tvm
#endif // TVM_SUPPORT_LOGGING_H_
diff --git a/src/ir/diagnostic.cc b/src/ir/diagnostic.cc
index ceadf78..148831d 100644
--- a/src/ir/diagnostic.cc
+++ b/src/ir/diagnostic.cc
@@ -18,8 +18,8 @@
*/
/*!
- * \file src/ir/transform.cc
- * \brief Infrastructure for transformation passes.
+ * \file src/ir/diagnostic.cc
+ * \brief Implementation of DiagnosticContext and friends.
*/
#include <tvm/ir/diagnostic.h>
#include <tvm/parser/source_map.h>
@@ -30,13 +30,6 @@ namespace tvm {
using tvm::parser::Source;
-const char* kTVM_INTERNAL_ERROR_MESSAGE =
- "\n---------------------------------------------------------------\n"
- "An internal invariant was violated during the execution of TVM.\n"
- "Please read TVM's error reporting guidelines.\n"
- "More details can be found here:
https://discuss.tvm.ai/t/error-reporting/7793.\n"
- "---------------------------------------------------------------\n";
-
// failed to check to argument arg0.dims[0] != 0
/* Diagnostic */
diff --git a/src/parser/parser.cc b/src/parser/parser.cc
index 7dc55b0..9c9965c 100644
--- a/src/parser/parser.cc
+++ b/src/parser/parser.cc
@@ -21,7 +21,6 @@
* \file parser.cc
* \brief A parser for TVM IR.
*/
-#include <tvm/ir/diagnostic.h>
#include <tvm/ir/module.h>
#include <tvm/node/reflection.h>
#include <tvm/parser/parser.h>
@@ -31,6 +30,7 @@
#include <tvm/relay/transform.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/registry.h>
+#include <tvm/support/logging.h>
#include <fstream>
diff --git a/src/parser/span_check.h b/src/parser/span_check.h
index b9ba76d..9a88747 100644
--- a/src/parser/span_check.h
+++ b/src/parser/span_check.h
@@ -25,13 +25,13 @@
#ifndef TVM_PARSER_SPAN_CHECK_H_
#define TVM_PARSER_SPAN_CHECK_H_
-#include <tvm/ir/diagnostic.h>
#include <tvm/ir/transform.h>
#include <tvm/ir/type_functor.h>
#include <tvm/relay/expr.h>
#include <tvm/relay/expr_functor.h>
#include <tvm/runtime/container.h>
#include <tvm/runtime/object.h>
+#include <tvm/support/logging.h>
#include <fstream>
#include <string>
diff --git a/src/relay/analysis/well_formed.cc
b/src/relay/analysis/well_formed.cc
index 5abbbc9..0b6e043 100644
--- a/src/relay/analysis/well_formed.cc
+++ b/src/relay/analysis/well_formed.cc
@@ -21,10 +21,10 @@
* \file well_formed.cc
* \brief check that expression is well formed.
*/
-#include <tvm/ir/diagnostic.h>
#include <tvm/relay/analysis.h>
#include <tvm/relay/expr_functor.h>
#include <tvm/relay/pattern_functor.h>
+#include <tvm/support/logging.h>
#include <unordered_set>
diff --git a/src/relay/op/nn/convolution.h b/src/relay/op/nn/convolution.h
index cd334d7..935058c 100644
--- a/src/relay/op/nn/convolution.h
+++ b/src/relay/op/nn/convolution.h
@@ -24,7 +24,7 @@
#ifndef TVM_RELAY_OP_NN_CONVOLUTION_H_
#define TVM_RELAY_OP_NN_CONVOLUTION_H_
-#include <tvm/ir/diagnostic.h>
+#include <tvm/support/logging.h>
#include <tvm/tir/analysis.h>
#include <string>