From d73742a508dbc3d28ba915bbbf255bf9d13dca81 Mon Sep 17 00:00:00 2001 From: Robert Kimball Date: Thu, 15 Oct 2020 13:21:45 -0700 Subject: [PATCH 1/7] Refactor diag to avoid circular dependencies --- include/tvm/ir/diagnostic.h | 190 +----------------------- include/tvm/ir/diagnostic_context.h | 221 ++++++++++++++++++++++++++++ include/tvm/ir/transform.h | 2 +- include/tvm/ir/type_relation.h | 1 + include/tvm/runtime/object.h | 16 +- src/ir/diagnostic.cc | 2 +- 6 files changed, 233 insertions(+), 199 deletions(-) create mode 100644 include/tvm/ir/diagnostic_context.h diff --git a/include/tvm/ir/diagnostic.h b/include/tvm/ir/diagnostic.h index 6b9807487bae..ea3e02fcf500 100644 --- a/include/tvm/ir/diagnostic.h +++ b/include/tvm/ir/diagnostic.h @@ -30,23 +30,10 @@ #ifndef TVM_IR_DIAGNOSTIC_H_ #define TVM_IR_DIAGNOSTIC_H_ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include +#include namespace tvm { -using tvm::parser::SourceMap; -using tvm::runtime::TypedPackedFunc; - extern const char* kTVM_INTERNAL_ERROR_MESSAGE; #define ICHECK_INDENT " " @@ -83,180 +70,5 @@ enum class DiagnosticLevel : int { kHelp = 50, }; -class DiagnosticBuilder; - -/*! \brief A compiler diagnostic. */ -class Diagnostic; - -/*! \brief A compiler diagnostic message. */ -class DiagnosticNode : public Object { - public: - /*! \brief The level. */ - DiagnosticLevel level; - /*! \brief The span at which to report an error. */ - Span span; - /*! \brief The diagnostic message. */ - String message; - - // override attr visitor - void VisitAttrs(AttrVisitor* v) { - v->Visit("level", &level); - v->Visit("span", &span); - v->Visit("message", &message); - } - - bool SEqualReduce(const DiagnosticNode* other, SEqualReducer equal) const { - return equal(this->level, other->level) && equal(this->span, other->span) && - equal(this->message, other->message); - } - - static constexpr const char* _type_key = "Diagnostic"; - TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticNode, Object); -}; - -class Diagnostic : public ObjectRef { - public: - TVM_DLL Diagnostic(DiagnosticLevel level, Span span, const std::string& message); - - static DiagnosticBuilder Bug(Span span); - static DiagnosticBuilder Error(Span span); - static DiagnosticBuilder Warning(Span span); - static DiagnosticBuilder Note(Span span); - static DiagnosticBuilder Help(Span span); - - TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Diagnostic, ObjectRef, DiagnosticNode); -}; - -/*! - * \brief A wrapper around std::stringstream to build a diagnostic. - */ -class DiagnosticBuilder { - public: - /*! \brief The level. */ - DiagnosticLevel level; - - /*! \brief The source name. */ - SourceName source_name; - - /*! \brief The span of the diagnostic. */ - Span span; - - template - DiagnosticBuilder& operator<<(const T& val) { // NOLINT(*) - stream_ << val; - return *this; - } - - DiagnosticBuilder() : level(DiagnosticLevel::kError), source_name(), span(Span()) {} - - DiagnosticBuilder(const DiagnosticBuilder& builder) - : level(builder.level), source_name(builder.source_name), span(builder.span) {} - - DiagnosticBuilder(DiagnosticLevel level, Span span) : level(level), span(span) {} - - operator Diagnostic() { return Diagnostic(this->level, this->span, this->stream_.str()); } - - private: - std::stringstream stream_; - friend class Diagnostic; -}; - -/*! - * \brief A diagnostic context for recording errors against a source file. - */ -class DiagnosticContext; - -/*! \brief Display diagnostics in a given display format. - * - * A diagnostic renderer is responsible for converting the - * raw diagnostics into consumable output. - * - * For example the terminal renderer will render a sequence - * of compiler diagnostics to std::out and std::err in - * a human readable form. - */ -class DiagnosticRendererNode : public Object { - public: - TypedPackedFunc renderer; - - // override attr visitor - void VisitAttrs(AttrVisitor* v) {} - - static constexpr const char* _type_key = "DiagnosticRenderer"; - TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticRendererNode, Object); -}; - -class DiagnosticRenderer : public ObjectRef { - public: - TVM_DLL DiagnosticRenderer(TypedPackedFunc render); - TVM_DLL DiagnosticRenderer() - : DiagnosticRenderer(TypedPackedFunc()) {} - - void Render(const DiagnosticContext& ctx); - - DiagnosticRendererNode* operator->() { - CHECK(get() != nullptr); - return static_cast(get_mutable()); - } - - TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(DiagnosticRenderer, ObjectRef, DiagnosticRendererNode); -}; - -class DiagnosticContextNode : public Object { - public: - /*! \brief The Module to report against. */ - IRModule module; - - /*! \brief The set of diagnostics to report. */ - Array diagnostics; - - /*! \brief The renderer set for the context. */ - DiagnosticRenderer renderer; - - void VisitAttrs(AttrVisitor* v) { - v->Visit("module", &module); - v->Visit("diagnostics", &diagnostics); - } - - bool SEqualReduce(const DiagnosticContextNode* other, SEqualReducer equal) const { - return equal(module, other->module) && equal(diagnostics, other->diagnostics); - } - - static constexpr const char* _type_key = "DiagnosticContext"; - TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticContextNode, Object); -}; - -class DiagnosticContext : public ObjectRef { - public: - TVM_DLL DiagnosticContext(const IRModule& module, const DiagnosticRenderer& renderer); - TVM_DLL static DiagnosticContext Default(const IRModule& source_map); - - /*! \brief Emit a diagnostic. - * \param diagnostic The diagnostic to emit. - */ - void Emit(const Diagnostic& diagnostic); - - /*! \brief Emit a diagnostic and then immediately attempt to render all errors. - * - * \param diagnostic The diagnostic to emit. - * - * Note: this will raise an exception if you would like to instead continue execution - * use the Emit method instead. - */ - void EmitFatal(const Diagnostic& diagnostic); - - /*! \brief Render the errors and raise a DiagnosticError exception. */ - void Render(); - - DiagnosticContextNode* operator->() { - CHECK(get() != nullptr); - return static_cast(get_mutable()); - } - - TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(DiagnosticContext, ObjectRef, DiagnosticContextNode); -}; - -DiagnosticRenderer TerminalRenderer(std::ostream& ostream); - } // namespace tvm #endif // TVM_IR_DIAGNOSTIC_H_ diff --git a/include/tvm/ir/diagnostic_context.h b/include/tvm/ir/diagnostic_context.h new file mode 100644 index 000000000000..4024dfd2fd39 --- /dev/null +++ b/include/tvm/ir/diagnostic_context.h @@ -0,0 +1,221 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \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_CONTEXT_H_ +#define TVM_IR_DIAGNOSTIC_CONTEXT_H_ + +#include +#include + +#include + +namespace tvm { + +using tvm::parser::SourceMap; +using tvm::runtime::TypedPackedFunc; + +extern const char* kTVM_INTERNAL_ERROR_MESSAGE; + +class DiagnosticBuilder; + +/*! \brief A compiler diagnostic. */ +class Diagnostic; + +/*! \brief A compiler diagnostic message. */ +class DiagnosticNode : public Object { + public: + /*! \brief The level. */ + DiagnosticLevel level; + /*! \brief The span at which to report an error. */ + Span span; + /*! \brief The diagnostic message. */ + String message; + + // override attr visitor + void VisitAttrs(AttrVisitor* v) { + v->Visit("level", &level); + v->Visit("span", &span); + v->Visit("message", &message); + } + + bool SEqualReduce(const DiagnosticNode* other, SEqualReducer equal) const { + return equal(this->level, other->level) && equal(this->span, other->span) && + equal(this->message, other->message); + } + + static constexpr const char* _type_key = "Diagnostic"; + TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticNode, Object); +}; + +class Diagnostic : public ObjectRef { + public: + TVM_DLL Diagnostic(DiagnosticLevel level, Span span, const std::string& message); + + static DiagnosticBuilder Bug(Span span); + static DiagnosticBuilder Error(Span span); + static DiagnosticBuilder Warning(Span span); + static DiagnosticBuilder Note(Span span); + static DiagnosticBuilder Help(Span span); + + TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Diagnostic, ObjectRef, DiagnosticNode); +}; + +/*! + * \brief A wrapper around std::stringstream to build a diagnostic. + */ +class DiagnosticBuilder { + public: + /*! \brief The level. */ + DiagnosticLevel level; + + /*! \brief The source name. */ + SourceName source_name; + + /*! \brief The span of the diagnostic. */ + Span span; + + template + DiagnosticBuilder& operator<<(const T& val) { // NOLINT(*) + stream_ << val; + return *this; + } + + DiagnosticBuilder() : level(DiagnosticLevel::kError), source_name(), span(Span()) {} + + DiagnosticBuilder(const DiagnosticBuilder& builder) + : level(builder.level), source_name(builder.source_name), span(builder.span) {} + + DiagnosticBuilder(DiagnosticLevel level, Span span) : level(level), span(span) {} + + operator Diagnostic() { return Diagnostic(this->level, this->span, this->stream_.str()); } + + private: + std::stringstream stream_; + friend class Diagnostic; +}; + +/*! + * \brief A diagnostic context for recording errors against a source file. + */ +class DiagnosticContext; + +/*! \brief Display diagnostics in a given display format. + * + * A diagnostic renderer is responsible for converting the + * raw diagnostics into consumable output. + * + * For example the terminal renderer will render a sequence + * of compiler diagnostics to std::out and std::err in + * a human readable form. + */ +class DiagnosticRendererNode : public Object { + public: + TypedPackedFunc renderer; + + // override attr visitor + void VisitAttrs(AttrVisitor* v) {} + + static constexpr const char* _type_key = "DiagnosticRenderer"; + TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticRendererNode, Object); +}; + +class DiagnosticRenderer : public ObjectRef { + public: + TVM_DLL DiagnosticRenderer(TypedPackedFunc render); + TVM_DLL DiagnosticRenderer() + : DiagnosticRenderer(TypedPackedFunc()) {} + + void Render(const DiagnosticContext& ctx); + + DiagnosticRendererNode* operator->() { + CHECK(get() != nullptr); + return static_cast(get_mutable()); + } + + TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(DiagnosticRenderer, ObjectRef, DiagnosticRendererNode); +}; + +class DiagnosticContextNode : public Object { + public: + /*! \brief The Module to report against. */ + IRModule module; + + /*! \brief The set of diagnostics to report. */ + Array diagnostics; + + /*! \brief The renderer set for the context. */ + DiagnosticRenderer renderer; + + void VisitAttrs(AttrVisitor* v) { + v->Visit("module", &module); + v->Visit("diagnostics", &diagnostics); + } + + bool SEqualReduce(const DiagnosticContextNode* other, SEqualReducer equal) const { + return equal(module, other->module) && equal(diagnostics, other->diagnostics); + } + + static constexpr const char* _type_key = "DiagnosticContext"; + TVM_DECLARE_FINAL_OBJECT_INFO(DiagnosticContextNode, Object); +}; + +class DiagnosticContext : public ObjectRef { + public: + TVM_DLL DiagnosticContext(const IRModule& module, const DiagnosticRenderer& renderer); + TVM_DLL static DiagnosticContext Default(const IRModule& source_map); + + /*! \brief Emit a diagnostic. + * \param diagnostic The diagnostic to emit. + */ + void Emit(const Diagnostic& diagnostic); + + /*! \brief Emit a diagnostic and then immediately attempt to render all errors. + * + * \param diagnostic The diagnostic to emit. + * + * Note: this will raise an exception if you would like to instead continue execution + * use the Emit method instead. + */ + void EmitFatal(const Diagnostic& diagnostic); + + /*! \brief Render the errors and raise a DiagnosticError exception. */ + void Render(); + + DiagnosticContextNode* operator->() { + CHECK(get() != nullptr); + return static_cast(get_mutable()); + } + + TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(DiagnosticContext, ObjectRef, DiagnosticContextNode); +}; + +DiagnosticRenderer TerminalRenderer(std::ostream& ostream); + +} // namespace tvm +#endif // TVM_IR_DIAGNOSTIC_H_ diff --git a/include/tvm/ir/transform.h b/include/tvm/ir/transform.h index 2bbf28311b30..575f21667ea8 100644 --- a/include/tvm/ir/transform.h +++ b/include/tvm/ir/transform.h @@ -56,7 +56,7 @@ #ifndef TVM_IR_TRANSFORM_H_ #define TVM_IR_TRANSFORM_H_ -#include +#include #include #include #include diff --git a/include/tvm/ir/type_relation.h b/include/tvm/ir/type_relation.h index 83323b01e419..4ecf44967577 100644 --- a/include/tvm/ir/type_relation.h +++ b/include/tvm/ir/type_relation.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include diff --git a/include/tvm/runtime/object.h b/include/tvm/runtime/object.h index e6ca832c70c2..11bab50f021c 100644 --- a/include/tvm/runtime/object.h +++ b/include/tvm/runtime/object.h @@ -23,7 +23,7 @@ #ifndef TVM_RUNTIME_OBJECT_H_ #define TVM_RUNTIME_OBJECT_H_ -#include +#include #include #include @@ -153,9 +153,9 @@ struct TypeIndex { * ObjectRef leaf_ref(make_object()); * // cast to a specific instance * const LeafObj* leaf_ptr = leaf_ref.as(); - * CHECK(leaf_ptr != nullptr); + * ICHECK(leaf_ptr != nullptr); * // can also cast to the base class. - * CHECK(leaf_ref.as() != nullptr); + * ICHECK(leaf_ref.as() != 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(*(operator->())); \ ObjectPtr(std::move(n)).swap(data_); \ @@ -845,7 +845,7 @@ inline RefType GetRef(const ObjType* ptr) { static_assert(std::is_base_of::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(const_cast(static_cast(ptr)))); } @@ -860,12 +860,12 @@ inline ObjectPtr GetObjectPtr(ObjType* ptr) { template inline SubRef Downcast(BaseRef ref) { if (ref.defined()) { - CHECK(ref->template IsInstance()) + ICHECK(ref->template IsInstance()) << "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/src/ir/diagnostic.cc b/src/ir/diagnostic.cc index ceadf78e2cfc..36afd976c288 100644 --- a/src/ir/diagnostic.cc +++ b/src/ir/diagnostic.cc @@ -21,7 +21,7 @@ * \file src/ir/transform.cc * \brief Infrastructure for transformation passes. */ -#include +#include #include #include From 45a697236f7ec94b7ee79a31ea4f2c90a7ab160d Mon Sep 17 00:00:00 2001 From: Robert Kimball Date: Thu, 15 Oct 2020 13:32:16 -0700 Subject: [PATCH 2/7] Fix formatting --- include/tvm/ir/diagnostic_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tvm/ir/diagnostic_context.h b/include/tvm/ir/diagnostic_context.h index 4024dfd2fd39..e0691478946c 100644 --- a/include/tvm/ir/diagnostic_context.h +++ b/include/tvm/ir/diagnostic_context.h @@ -218,4 +218,4 @@ class DiagnosticContext : public ObjectRef { DiagnosticRenderer TerminalRenderer(std::ostream& ostream); } // namespace tvm -#endif // TVM_IR_DIAGNOSTIC_H_ +#endif // TVM_IR_DIAGNOSTIC_CONTEXT_H_ From 4fc5cd8343392a6a144872de0db91ad6ba190f91 Mon Sep 17 00:00:00 2001 From: Robert Kimball Date: Thu, 15 Oct 2020 14:02:07 -0700 Subject: [PATCH 3/7] Add missing include --- include/tvm/ir/diagnostic_context.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/tvm/ir/diagnostic_context.h b/include/tvm/ir/diagnostic_context.h index e0691478946c..1ea967e34d66 100644 --- a/include/tvm/ir/diagnostic_context.h +++ b/include/tvm/ir/diagnostic_context.h @@ -34,6 +34,7 @@ #include #include +#include namespace tvm { From 2492c425cc5556a54b1d4e733d46c3d86a4df75b Mon Sep 17 00:00:00 2001 From: Robert Kimball Date: Fri, 16 Oct 2020 08:38:23 -0700 Subject: [PATCH 4/7] Address review comment --- include/tvm/ir/transform.h | 2 +- include/tvm/ir/type_relation.h | 4 ++-- include/tvm/relay/analysis.h | 2 +- include/tvm/runtime/object.h | 2 +- include/tvm/{ir => support}/diagnostic.h | 0 include/tvm/{ir => support}/diagnostic_context.h | 2 -- 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 +- src/{ir => support}/diagnostic.cc | 2 +- 11 files changed, 10 insertions(+), 12 deletions(-) rename include/tvm/{ir => support}/diagnostic.h (100%) rename include/tvm/{ir => support}/diagnostic_context.h (99%) rename src/{ir => support}/diagnostic.cc (99%) diff --git a/include/tvm/ir/transform.h b/include/tvm/ir/transform.h index 575f21667ea8..c7f666d1b579 100644 --- a/include/tvm/ir/transform.h +++ b/include/tvm/ir/transform.h @@ -56,11 +56,11 @@ #ifndef TVM_IR_TRANSFORM_H_ #define TVM_IR_TRANSFORM_H_ -#include #include #include #include #include +#include #include #include diff --git a/include/tvm/ir/type_relation.h b/include/tvm/ir/type_relation.h index 4ecf44967577..5dbc7f92f5e0 100644 --- a/include/tvm/ir/type_relation.h +++ b/include/tvm/ir/type_relation.h @@ -25,11 +25,11 @@ #define TVM_IR_TYPE_RELATION_H_ #include -#include -#include #include #include #include +#include +#include namespace tvm { diff --git a/include/tvm/relay/analysis.h b/include/tvm/relay/analysis.h index 26e5a65ddb5e..1c19a032764c 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 #include #include #include #include #include +#include #include #include diff --git a/include/tvm/runtime/object.h b/include/tvm/runtime/object.h index 11bab50f021c..c3ee79467728 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 #include +#include #include #include diff --git a/include/tvm/ir/diagnostic.h b/include/tvm/support/diagnostic.h similarity index 100% rename from include/tvm/ir/diagnostic.h rename to include/tvm/support/diagnostic.h diff --git a/include/tvm/ir/diagnostic_context.h b/include/tvm/support/diagnostic_context.h similarity index 99% rename from include/tvm/ir/diagnostic_context.h rename to include/tvm/support/diagnostic_context.h index 1ea967e34d66..57f397500f16 100644 --- a/include/tvm/ir/diagnostic_context.h +++ b/include/tvm/support/diagnostic_context.h @@ -41,8 +41,6 @@ namespace tvm { using tvm::parser::SourceMap; using tvm::runtime::TypedPackedFunc; -extern const char* kTVM_INTERNAL_ERROR_MESSAGE; - class DiagnosticBuilder; /*! \brief A compiler diagnostic. */ diff --git a/src/parser/parser.cc b/src/parser/parser.cc index 7dc55b0b519a..2ec4994dc19c 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 #include #include #include @@ -31,6 +30,7 @@ #include #include #include +#include #include diff --git a/src/parser/span_check.h b/src/parser/span_check.h index b9ba76df4b8f..3f44737a4c7e 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 #include #include #include #include #include #include +#include #include #include diff --git a/src/relay/analysis/well_formed.cc b/src/relay/analysis/well_formed.cc index 3e409d10b885..935b5fe9fce2 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 #include #include #include +#include #include diff --git a/src/relay/op/nn/convolution.h b/src/relay/op/nn/convolution.h index cd334d7269ab..f99d6d705562 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 +#include #include #include diff --git a/src/ir/diagnostic.cc b/src/support/diagnostic.cc similarity index 99% rename from src/ir/diagnostic.cc rename to src/support/diagnostic.cc index 36afd976c288..63ff0ca47fde 100644 --- a/src/ir/diagnostic.cc +++ b/src/support/diagnostic.cc @@ -21,8 +21,8 @@ * \file src/ir/transform.cc * \brief Infrastructure for transformation passes. */ -#include #include +#include #include From 32c0f0e4952ca3464ccb336ca7ee66596ca715ea Mon Sep 17 00:00:00 2001 From: Robert Kimball Date: Fri, 16 Oct 2020 09:08:46 -0700 Subject: [PATCH 5/7] Move stuff around a bit more --- .../tvm/{support => ir}/diagnostic_context.h | 6 +- include/tvm/ir/transform.h | 2 +- include/tvm/ir/type_relation.h | 4 +- include/tvm/relay/analysis.h | 2 +- include/tvm/runtime/object.h | 2 +- include/tvm/support/diagnostic.h | 74 ------------------- include/tvm/support/logging.h | 41 ++++++++++ .../diagnostic_context.cc} | 13 +--- 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 +- src/support/logging.cc | 34 +++++++++ 13 files changed, 88 insertions(+), 98 deletions(-) rename include/tvm/{support => ir}/diagnostic_context.h (97%) delete mode 100644 include/tvm/support/diagnostic.h rename src/{support/diagnostic.cc => ir/diagnostic_context.cc} (94%) create mode 100644 src/support/logging.cc diff --git a/include/tvm/support/diagnostic_context.h b/include/tvm/ir/diagnostic_context.h similarity index 97% rename from include/tvm/support/diagnostic_context.h rename to include/tvm/ir/diagnostic_context.h index 57f397500f16..2b7031a0252e 100644 --- a/include/tvm/support/diagnostic_context.h +++ b/include/tvm/ir/diagnostic_context.h @@ -18,13 +18,9 @@ */ /*! - * \file diagnostic.h + * \file diagnostic_context.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_CONTEXT_H_ diff --git a/include/tvm/ir/transform.h b/include/tvm/ir/transform.h index c7f666d1b579..575f21667ea8 100644 --- a/include/tvm/ir/transform.h +++ b/include/tvm/ir/transform.h @@ -56,11 +56,11 @@ #ifndef TVM_IR_TRANSFORM_H_ #define TVM_IR_TRANSFORM_H_ +#include #include #include #include #include -#include #include #include diff --git a/include/tvm/ir/type_relation.h b/include/tvm/ir/type_relation.h index 5dbc7f92f5e0..98cbdcf89b51 100644 --- a/include/tvm/ir/type_relation.h +++ b/include/tvm/ir/type_relation.h @@ -25,11 +25,11 @@ #define TVM_IR_TYPE_RELATION_H_ #include +#include #include #include #include -#include -#include +#include namespace tvm { diff --git a/include/tvm/relay/analysis.h b/include/tvm/relay/analysis.h index 1c19a032764c..5dd837038731 100644 --- a/include/tvm/relay/analysis.h +++ b/include/tvm/relay/analysis.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/tvm/runtime/object.h b/include/tvm/runtime/object.h index c3ee79467728..b5cf77d590f6 100644 --- a/include/tvm/runtime/object.h +++ b/include/tvm/runtime/object.h @@ -24,7 +24,7 @@ #define TVM_RUNTIME_OBJECT_H_ #include -#include +#include #include #include diff --git a/include/tvm/support/diagnostic.h b/include/tvm/support/diagnostic.h deleted file mode 100644 index ea3e02fcf500..000000000000 --- a/include/tvm/support/diagnostic.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * \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 - -namespace tvm { - -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, -}; - -} // namespace tvm -#endif // TVM_IR_DIAGNOSTIC_H_ diff --git a/include/tvm/support/logging.h b/include/tvm/support/logging.h index c318b89e5c51..f1c4fd0bd9b8 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 + // 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,43 @@ #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 { + +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, +}; + +} // namespace tvm #endif // TVM_SUPPORT_LOGGING_H_ diff --git a/src/support/diagnostic.cc b/src/ir/diagnostic_context.cc similarity index 94% rename from src/support/diagnostic.cc rename to src/ir/diagnostic_context.cc index 63ff0ca47fde..ad0ae4be9209 100644 --- a/src/support/diagnostic.cc +++ b/src/ir/diagnostic_context.cc @@ -18,11 +18,11 @@ */ /*! - * \file src/ir/transform.cc - * \brief Infrastructure for transformation passes. + * \file src/ir/diagnostic_context.cc + * \brief Implementation of DiagnosticContext and friends. */ +#include #include -#include #include @@ -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 2ec4994dc19c..9c9965ca588f 100644 --- a/src/parser/parser.cc +++ b/src/parser/parser.cc @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include diff --git a/src/parser/span_check.h b/src/parser/span_check.h index 3f44737a4c7e..9a887474fe67 100644 --- a/src/parser/span_check.h +++ b/src/parser/span_check.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/relay/analysis/well_formed.cc b/src/relay/analysis/well_formed.cc index 935b5fe9fce2..15f73826fb4a 100644 --- a/src/relay/analysis/well_formed.cc +++ b/src/relay/analysis/well_formed.cc @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include diff --git a/src/relay/op/nn/convolution.h b/src/relay/op/nn/convolution.h index f99d6d705562..935058c1a5b3 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 +#include #include #include diff --git a/src/support/logging.cc b/src/support/logging.cc new file mode 100644 index 000000000000..b96b710d61a9 --- /dev/null +++ b/src/support/logging.cc @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \file src/support/logging.cc + * \brief Definition of logging variables. + */ + +namespace tvm { + +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"; + +} // namespace tvm From 4c18a48193303dc049481947270b09cbf72641dc Mon Sep 17 00:00:00 2001 From: Robert Kimball Date: Fri, 16 Oct 2020 10:32:25 -0700 Subject: [PATCH 6/7] Fix global string --- include/tvm/support/logging.h | 7 ++++++- src/support/logging.cc | 34 ---------------------------------- 2 files changed, 6 insertions(+), 35 deletions(-) delete mode 100644 src/support/logging.cc diff --git a/include/tvm/support/logging.h b/include/tvm/support/logging.h index f1c4fd0bd9b8..4322435c06b0 100644 --- a/include/tvm/support/logging.h +++ b/include/tvm/support/logging.h @@ -113,7 +113,12 @@ namespace tvm { -extern const char* kTVM_INTERNAL_ERROR_MESSAGE; +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 " " diff --git a/src/support/logging.cc b/src/support/logging.cc deleted file mode 100644 index b96b710d61a9..000000000000 --- a/src/support/logging.cc +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * \file src/support/logging.cc - * \brief Definition of logging variables. - */ - -namespace tvm { - -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"; - -} // namespace tvm From 4a7bb0c2f3f601c40b1bd5f0731ccb598a654023 Mon Sep 17 00:00:00 2001 From: Robert Kimball Date: Fri, 16 Oct 2020 14:53:45 -0700 Subject: [PATCH 7/7] Revert diagnostic.* filenames --- include/tvm/ir/{diagnostic_context.h => diagnostic.h} | 8 ++++---- include/tvm/ir/transform.h | 2 +- include/tvm/ir/type_relation.h | 2 +- src/ir/{diagnostic_context.cc => diagnostic.cc} | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) rename include/tvm/ir/{diagnostic_context.h => diagnostic.h} (97%) rename src/ir/{diagnostic_context.cc => diagnostic.cc} (99%) diff --git a/include/tvm/ir/diagnostic_context.h b/include/tvm/ir/diagnostic.h similarity index 97% rename from include/tvm/ir/diagnostic_context.h rename to include/tvm/ir/diagnostic.h index 2b7031a0252e..2a2a6cd4e867 100644 --- a/include/tvm/ir/diagnostic_context.h +++ b/include/tvm/ir/diagnostic.h @@ -18,13 +18,13 @@ */ /*! - * \file diagnostic_context.h + * \file diagnostic.h * \brief A new diagnostic interface for TVM error reporting. * */ -#ifndef TVM_IR_DIAGNOSTIC_CONTEXT_H_ -#define TVM_IR_DIAGNOSTIC_CONTEXT_H_ +#ifndef TVM_IR_DIAGNOSTIC_H_ +#define TVM_IR_DIAGNOSTIC_H_ #include #include @@ -213,4 +213,4 @@ class DiagnosticContext : public ObjectRef { DiagnosticRenderer TerminalRenderer(std::ostream& ostream); } // namespace tvm -#endif // TVM_IR_DIAGNOSTIC_CONTEXT_H_ +#endif // TVM_IR_DIAGNOSTIC_H_ diff --git a/include/tvm/ir/transform.h b/include/tvm/ir/transform.h index 575f21667ea8..2bbf28311b30 100644 --- a/include/tvm/ir/transform.h +++ b/include/tvm/ir/transform.h @@ -56,7 +56,7 @@ #ifndef TVM_IR_TRANSFORM_H_ #define TVM_IR_TRANSFORM_H_ -#include +#include #include #include #include diff --git a/include/tvm/ir/type_relation.h b/include/tvm/ir/type_relation.h index 98cbdcf89b51..462588006c9b 100644 --- a/include/tvm/ir/type_relation.h +++ b/include/tvm/ir/type_relation.h @@ -25,7 +25,7 @@ #define TVM_IR_TYPE_RELATION_H_ #include -#include +#include #include #include #include diff --git a/src/ir/diagnostic_context.cc b/src/ir/diagnostic.cc similarity index 99% rename from src/ir/diagnostic_context.cc rename to src/ir/diagnostic.cc index ad0ae4be9209..148831dc3ab6 100644 --- a/src/ir/diagnostic_context.cc +++ b/src/ir/diagnostic.cc @@ -18,10 +18,10 @@ */ /*! - * \file src/ir/diagnostic_context.cc + * \file src/ir/diagnostic.cc * \brief Implementation of DiagnosticContext and friends. */ -#include +#include #include #include