Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor diagnostic to avoid circular dependencies #6692

Merged
merged 7 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/tvm/ir/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
#ifndef TVM_IR_TRANSFORM_H_
#define TVM_IR_TRANSFORM_H_

#include <tvm/ir/diagnostic.h>
#include <tvm/ir/error.h>
#include <tvm/ir/module.h>
#include <tvm/node/container.h>
#include <tvm/runtime/container.h>
#include <tvm/support/diagnostic_context.h>
#include <tvm/support/with.h>

#include <string>
Expand Down
3 changes: 2 additions & 1 deletion include/tvm/ir/type_relation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
#define TVM_IR_TYPE_RELATION_H_

#include <tvm/ir/attrs.h>
#include <tvm/ir/diagnostic.h>
#include <tvm/ir/env_func.h>
#include <tvm/ir/module.h>
#include <tvm/ir/type.h>
#include <tvm/support/diagnostic.h>
#include <tvm/support/diagnostic_context.h>

namespace tvm {

Expand Down
2 changes: 1 addition & 1 deletion include/tvm/relay/analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/diagnostic.h>

#include <string>
#include <unordered_map>
Expand Down
16 changes: 8 additions & 8 deletions include/tvm/runtime/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/diagnostic.h>

#include <string>
#include <type_traits>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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_); \
Expand Down Expand Up @@ -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))));
}
Expand All @@ -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_));
}
Expand Down
74 changes: 74 additions & 0 deletions include/tvm/support/diagnostic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 <dmlc/logging.h>

namespace tvm {

extern const char* kTVM_INTERNAL_ERROR_MESSAGE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge this file content with tvm/support/logging.h as previous content are already there


#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_
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,20 @@
* replace the existing errors.h.
*/

#ifndef TVM_IR_DIAGNOSTIC_H_
#define TVM_IR_DIAGNOSTIC_H_
#ifndef TVM_IR_DIAGNOSTIC_CONTEXT_H_
#define TVM_IR_DIAGNOSTIC_CONTEXT_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,
};

Copy link
Member

@tqchen tqchen Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diagnostic context should not be part of support, because right now it brings large amount of dep related to IR. keep it as in include/tvm/ir/diagnostic.h

class DiagnosticBuilder;

/*! \brief A compiler diagnostic. */
Expand Down Expand Up @@ -259,4 +217,4 @@ class DiagnosticContext : public ObjectRef {
DiagnosticRenderer TerminalRenderer(std::ostream& ostream);

} // namespace tvm
#endif // TVM_IR_DIAGNOSTIC_H_
#endif // TVM_IR_DIAGNOSTIC_CONTEXT_H_
2 changes: 1 addition & 1 deletion src/parser/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -31,6 +30,7 @@
#include <tvm/relay/transform.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/registry.h>
#include <tvm/support/diagnostic.h>

#include <fstream>

Expand Down
2 changes: 1 addition & 1 deletion src/parser/span_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/diagnostic.h>

#include <fstream>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/relay/analysis/well_formed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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/diagnostic.h>

#include <unordered_set>

Expand Down
2 changes: 1 addition & 1 deletion src/relay/op/nn/convolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/diagnostic.h>
#include <tvm/tir/analysis.h>

#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/ir/diagnostic.cc → src/support/diagnostic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* \file src/ir/transform.cc
* \brief Infrastructure for transformation passes.
*/
#include <tvm/ir/diagnostic.h>
#include <tvm/parser/source_map.h>
#include <tvm/support/diagnostic_context.h>

#include <rang.hpp>

Expand Down