diff --git a/3rdparty/tvm-ffi b/3rdparty/tvm-ffi index 3c35034fd102..98d0029dd4e0 160000 --- a/3rdparty/tvm-ffi +++ b/3rdparty/tvm-ffi @@ -1 +1 @@ -Subproject commit 3c35034fd1026011736e19a4e0e1ed0f22058c42 +Subproject commit 98d0029dd4e002da1516d43f9b92e792f139e709 diff --git a/include/tvm/ir/expr.h b/include/tvm/ir/expr.h index 1ce7a112a325..fcd267163c2c 100644 --- a/include/tvm/ir/expr.h +++ b/include/tvm/ir/expr.h @@ -24,11 +24,11 @@ #ifndef TVM_IR_EXPR_H_ #define TVM_IR_EXPR_H_ +#include #include #include #include #include -#include #include #include #include diff --git a/include/tvm/ir/repr.h b/include/tvm/ir/repr.h deleted file mode 100644 index de2f62522143..000000000000 --- a/include/tvm/ir/repr.h +++ /dev/null @@ -1,72 +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 tvm/ir/repr.h - * \brief ostream operator<< for ffi::ObjectRef, Any, and Variant, delegating to - * ffi::ReprPrint. Also re-exports the Dump() debug helpers. - * - * Include this header wherever you need `os << some_objectref` and you are - * no longer pulling in the legacy repr_printer.h. - */ -#ifndef TVM_IR_REPR_H_ -#define TVM_IR_REPR_H_ - -#include -#include - -#include - -namespace tvm { - -/*! - * \brief Dump the node to stderr, used for debug purposes. - * \param node The input node - */ -TVM_DLL void Dump(const ffi::ObjectRef& node); - -/*! - * \brief Dump the node to stderr, used for debug purposes. - * \param node The input node - */ -TVM_DLL void Dump(const ffi::Object* node); - -} // namespace tvm - -namespace tvm { -namespace ffi { - -// ostream << ObjectRef — delegates to ffi::ReprPrint -inline std::ostream& operator<<(std::ostream& os, const ObjectRef& n) { // NOLINT(*) - return os << ffi::ReprPrint(Any(n)); -} - -// ostream << Any — delegates to ffi::ReprPrint -inline std::ostream& operator<<(std::ostream& os, const Any& n) { // NOLINT(*) - return os << ffi::ReprPrint(n); -} - -// ostream << Variant<...> — delegates to ffi::ReprPrint -template -inline std::ostream& operator<<(std::ostream& os, const ffi::Variant& n) { // NOLINT(*) - return os << ffi::ReprPrint(Any(n)); -} - -} // namespace ffi -} // namespace tvm -#endif // TVM_IR_REPR_H_ diff --git a/include/tvm/relax/exec_builder.h b/include/tvm/relax/exec_builder.h index 29e680eff2d8..74f4b8bce153 100644 --- a/include/tvm/relax/exec_builder.h +++ b/include/tvm/relax/exec_builder.h @@ -23,12 +23,12 @@ #ifndef TVM_RELAX_EXEC_BUILDER_H_ #define TVM_RELAX_EXEC_BUILDER_H_ +#include #include #include #include #include #include -#include #include #include diff --git a/include/tvm/relax/expr.h b/include/tvm/relax/expr.h index e94a9ea150c8..6da9cb1692a3 100644 --- a/include/tvm/relax/expr.h +++ b/include/tvm/relax/expr.h @@ -574,7 +574,8 @@ class BindingNode : public ffi::Object { namespace refl = tvm::ffi::reflection; refl::ObjectDef() .def_ro("span", &BindingNode::span, refl::AttachFieldFlag::SEqHashIgnore()) - .def_ro("var", &BindingNode::var, refl::AttachFieldFlag::SEqHashDef()); + // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release + .def_ro("var", &BindingNode::var, refl::AttachFieldFlag::SEqHashDefRecursive()); } static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode; @@ -616,7 +617,9 @@ class MatchCastNode : public BindingNode { namespace refl = tvm::ffi::reflection; refl::ObjectDef() .def_ro("value", &MatchCastNode::value) - .def_ro("struct_info", &MatchCastNode::struct_info, refl::AttachFieldFlag::SEqHashDef()); + // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release + .def_ro("struct_info", &MatchCastNode::struct_info, + refl::AttachFieldFlag::SEqHashDefRecursive()); } TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.MatchCast", MatchCastNode, BindingNode); }; @@ -822,7 +825,7 @@ class FunctionNode : public BaseFuncNode { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("params", &FunctionNode::params, refl::AttachFieldFlag::SEqHashDef()) + .def_ro("params", &FunctionNode::params, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("body", &FunctionNode::body) .def_ro("ret_struct_info", &FunctionNode::ret_struct_info) .def_ro("is_pure", &FunctionNode::is_pure); diff --git a/include/tvm/relax/struct_info.h b/include/tvm/relax/struct_info.h index de7650e1662c..049469027ba2 100644 --- a/include/tvm/relax/struct_info.h +++ b/include/tvm/relax/struct_info.h @@ -294,7 +294,7 @@ class FuncStructInfoNode : public StructInfoNode { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("params", &FuncStructInfoNode::params, refl::AttachFieldFlag::SEqHashDef()) + .def_ro("params", &FuncStructInfoNode::params, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("ret", &FuncStructInfoNode::ret) .def_ro("derive_func", &FuncStructInfoNode::derive_func) .def_ro("purity", &FuncStructInfoNode::purity); diff --git a/include/tvm/tirx/buffer.h b/include/tvm/tirx/buffer.h index f3bccc5372f5..b32b06b7559d 100644 --- a/include/tvm/tirx/buffer.h +++ b/include/tvm/tirx/buffer.h @@ -126,13 +126,18 @@ class BufferNode : public ffi::Object { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("data", &BufferNode::data, refl::AttachFieldFlag::SEqHashDef()) + // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release + .def_ro("data", &BufferNode::data, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("dtype", &BufferNode::dtype) - .def_ro("shape", &BufferNode::shape, refl::AttachFieldFlag::SEqHashDef()) - .def_ro("strides", &BufferNode::strides, refl::AttachFieldFlag::SEqHashDef()) + // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release + .def_ro("shape", &BufferNode::shape, refl::AttachFieldFlag::SEqHashDefRecursive()) + // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release + .def_ro("strides", &BufferNode::strides, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("axis_separators", &BufferNode::axis_separators, - refl::AttachFieldFlag::SEqHashDef()) - .def_ro("elem_offset", &BufferNode::elem_offset, refl::AttachFieldFlag::SEqHashDef()) + refl::AttachFieldFlag::SEqHashDefRecursive()) + // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release + .def_ro("elem_offset", &BufferNode::elem_offset, + refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("name", &BufferNode::name, refl::AttachFieldFlag::SEqHashIgnore()) .def_ro("data_alignment", &BufferNode::data_alignment) .def_ro("offset_factor", &BufferNode::offset_factor) diff --git a/include/tvm/tirx/exec_scope.h b/include/tvm/tirx/exec_scope.h index 9378c2f5458c..bce8889394df 100644 --- a/include/tvm/tirx/exec_scope.h +++ b/include/tvm/tirx/exec_scope.h @@ -126,7 +126,7 @@ class ScopeIdDefNode : public ffi::Object { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("def_ids", &ScopeIdDefNode::def_ids, refl::AttachFieldFlag::SEqHashDef()) + .def_ro("def_ids", &ScopeIdDefNode::def_ids, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("extents", &ScopeIdDefNode::extents) .def_ro("scope", &ScopeIdDefNode::scope) .def_ro("preferred_extents", &ScopeIdDefNode::preferred_extents); diff --git a/include/tvm/tirx/expr.h b/include/tvm/tirx/expr.h index e2c1c3f33d63..cd51108b0d23 100644 --- a/include/tvm/tirx/expr.h +++ b/include/tvm/tirx/expr.h @@ -698,7 +698,8 @@ class LetNode : public PrimExprNode { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("var", &LetNode::var, refl::AttachFieldFlag::SEqHashDef()) + // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release + .def_ro("var", &LetNode::var, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("value", &LetNode::value) .def_ro("body", &LetNode::body); } @@ -823,8 +824,8 @@ class CommReducerNode : public ffi::Object { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("lhs", &CommReducerNode::lhs, refl::AttachFieldFlag::SEqHashDef()) - .def_ro("rhs", &CommReducerNode::rhs, refl::AttachFieldFlag::SEqHashDef()) + .def_ro("lhs", &CommReducerNode::lhs, refl::AttachFieldFlag::SEqHashDefRecursive()) + .def_ro("rhs", &CommReducerNode::rhs, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("result", &CommReducerNode::result) .def_ro("identity_element", &CommReducerNode::identity_element) .def_ro("span", &CommReducerNode::span, refl::AttachFieldFlag::SEqHashIgnore()); diff --git a/include/tvm/tirx/function.h b/include/tvm/tirx/function.h index aec5f3045418..45a8600a6ee4 100644 --- a/include/tvm/tirx/function.h +++ b/include/tvm/tirx/function.h @@ -105,7 +105,7 @@ class PrimFuncNode : public BaseFuncNode { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("params", &PrimFuncNode::params, refl::AttachFieldFlag::SEqHashDef()) + .def_ro("params", &PrimFuncNode::params, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("ret_type", &PrimFuncNode::ret_type) .def_ro("buffer_map", &PrimFuncNode::buffer_map) .def_ro("body", &PrimFuncNode::body); diff --git a/include/tvm/tirx/index_map.h b/include/tvm/tirx/index_map.h index 05dea246c35a..7d4c6684b118 100644 --- a/include/tvm/tirx/index_map.h +++ b/include/tvm/tirx/index_map.h @@ -156,7 +156,7 @@ class IndexMapNode : public ffi::Object { namespace refl = tvm::ffi::reflection; refl::ObjectDef() .def_ro("initial_indices", &IndexMapNode::initial_indices, - refl::AttachFieldFlag::SEqHashDef()) + refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("final_indices", &IndexMapNode::final_indices) .def_ro("inverse_index_map", &IndexMapNode::inverse_index_map, refl::AttachFieldFlag::SEqHashIgnore()); diff --git a/include/tvm/tirx/predicate.h b/include/tvm/tirx/predicate.h index 44426d877cac..f9e7667cfe2f 100644 --- a/include/tvm/tirx/predicate.h +++ b/include/tvm/tirx/predicate.h @@ -45,7 +45,7 @@ class PredicateNode : public ffi::Object { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("vars", &PredicateNode::vars, refl::AttachFieldFlag::SEqHashDef()) + .def_ro("vars", &PredicateNode::vars, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("pred", &PredicateNode::pred); } diff --git a/include/tvm/tirx/stmt.h b/include/tvm/tirx/stmt.h index a7443d940514..39cfbac0cdca 100644 --- a/include/tvm/tirx/stmt.h +++ b/include/tvm/tirx/stmt.h @@ -86,7 +86,8 @@ class BindNode : public StmtNode { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("var", &BindNode::var, refl::AttachFieldFlag::SEqHashDef()) + // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release + .def_ro("var", &BindNode::var, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("value", &BindNode::value); } TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.Bind", BindNode, StmtNode); @@ -273,7 +274,8 @@ class AllocBufferNode : public StmtNode { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("buffer", &AllocBufferNode::buffer, refl::AttachFieldFlag::SEqHashDef()) + // TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release + .def_ro("buffer", &AllocBufferNode::buffer, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("annotations", &AllocBufferNode::annotations); } TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.AllocBuffer", AllocBufferNode, StmtNode); @@ -619,7 +621,7 @@ class ForNode : public StmtNode { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("loop_var", &ForNode::loop_var, refl::AttachFieldFlag::SEqHashDef()) + .def_ro("loop_var", &ForNode::loop_var, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("min", &ForNode::min) .def_ro("extent", &ForNode::extent) .def_ro("kind", &ForNode::kind) @@ -879,7 +881,7 @@ class SBlockNode : public StmtNode { static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() - .def_ro("iter_vars", &SBlockNode::iter_vars, refl::AttachFieldFlag::SEqHashDef()) + .def_ro("iter_vars", &SBlockNode::iter_vars, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("reads", &SBlockNode::reads) .def_ro("writes", &SBlockNode::writes) .def_ro("name_hint", &SBlockNode::name_hint, refl::AttachFieldFlag::SEqHashIgnore()) diff --git a/include/tvm/tirx/var.h b/include/tvm/tirx/var.h index c38908d56d7d..8c536ef0d668 100644 --- a/include/tvm/tirx/var.h +++ b/include/tvm/tirx/var.h @@ -279,7 +279,7 @@ class IterVarNode : public PrimExprConvertibleNode { namespace refl = tvm::ffi::reflection; refl::ObjectDef() .def_ro("dom", &IterVarNode::dom) - .def_ro("var", &IterVarNode::var, refl::AttachFieldFlag::SEqHashDef()) + .def_ro("var", &IterVarNode::var, refl::AttachFieldFlag::SEqHashDefRecursive()) .def_ro("iter_type", &IterVarNode::iter_type) .def_ro("thread_tag", &IterVarNode::thread_tag); } diff --git a/python/tvm/ir/attrs.py b/python/tvm/ir/attrs.py index 5451b65ef6c0..473f646e6a83 100644 --- a/python/tvm/ir/attrs.py +++ b/python/tvm/ir/attrs.py @@ -79,6 +79,16 @@ def __getitem__(self, item): class DictAttrs(Attrs): """Dictionary attributes.""" + @property + def __dict__(self): + """Return the underlying key-value map as a Python dict. + + Defined explicitly so that tvm_ffi's _add_class_attrs skips registering + the C++ reflection field named '__dict__' (Python forbids adding a class + attribute named '__dict__' via setattr on extension-type subclasses). + """ + return dict(self._dict()) + def _dict(self): """Get internal dict""" return _ffi_api.DictAttrsGetDict(self) diff --git a/src/ir/repr.cc b/src/ir/access_path_repr.cc similarity index 87% rename from src/ir/repr.cc rename to src/ir/access_path_repr.cc index addbd33209f3..0e56b91eceaa 100644 --- a/src/ir/repr.cc +++ b/src/ir/access_path_repr.cc @@ -18,30 +18,27 @@ */ /*! - * \file ir/repr.cc - * \brief Implements Dump helpers and FFI registration for ffi-repr-based printing. + * \file ir/access_path_repr.cc + * \brief FFI registration for ffi-repr-based printing. * - * The legacy ReprPrinter has been replaced by ffi::ReprPrint. This file: - * - Implements the Dump() debug helpers (they call ffi::ReprPrint). + * This file: * - Registers node.AsRepr (for backward Python compatibility) via ffi::ReprPrint. - * - Registers __ffi_repr__ hooks for ffi::reflection::AccessPath and AccessStep. + * - Registers __ffi_repr__ hooks for ffi::reflection::AccessPath and AccessStep + * so that ffi.ReprPrint formats them as concise ".field[idx]" strings. + * + * Note: tvm::Dump() has been removed (zero in-tree callers). Use + * tvm::ffi::ReprPrint(any) directly from gdb instead. */ #include #include #include #include #include -#include -#include #include namespace tvm { -void Dump(const ffi::ObjectRef& n) { std::cerr << ffi::ReprPrint(ffi::Any(n)) << "\n"; } - -void Dump(const ffi::Object* n) { Dump(ffi::GetRef(n)); } - TVM_FFI_STATIC_INIT_BLOCK() { namespace refl = tvm::ffi::reflection; // node.AsRepr: backward-compatible Python entry point. diff --git a/src/ir/instrument.cc b/src/ir/instrument.cc index e88713a50632..42d4ad0fe05d 100644 --- a/src/ir/instrument.cc +++ b/src/ir/instrument.cc @@ -21,10 +21,10 @@ * \file src/ir/instrument.cc * \brief Infrastructure for instrumentation. */ +#include #include #include #include -#include #include #include diff --git a/src/ir/transform.cc b/src/ir/transform.cc index 075d5a7e66d2..2c4618eff69a 100644 --- a/src/ir/transform.cc +++ b/src/ir/transform.cc @@ -21,11 +21,11 @@ * \file src/ir/transform.cc * \brief Infrastructure for transformation passes. */ +#include #include #include #include #include -#include #include #include #include diff --git a/src/relax/ir/dataflow_pattern.cc b/src/relax/ir/dataflow_pattern.cc index 0e9f9df4df68..56389c63f5f9 100644 --- a/src/relax/ir/dataflow_pattern.cc +++ b/src/relax/ir/dataflow_pattern.cc @@ -24,7 +24,6 @@ #include #include -#include #include #include diff --git a/src/relax/ir/transform.cc b/src/relax/ir/transform.cc index 4b4c7077c64d..0a80de9a4ebb 100644 --- a/src/relax/ir/transform.cc +++ b/src/relax/ir/transform.cc @@ -22,10 +22,10 @@ * \brief Relax specific transformation passes. */ #include +#include #include #include #include -#include #include #include #include diff --git a/src/script/printer/script_printer.cc b/src/script/printer/script_printer.cc index a7cb7cff6596..f3fc27cf42db 100644 --- a/src/script/printer/script_printer.cc +++ b/src/script/printer/script_printer.cc @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/src/tirx/ir/transform.cc b/src/tirx/ir/transform.cc index 74d225d0e9b6..7156f421142c 100644 --- a/src/tirx/ir/transform.cc +++ b/src/tirx/ir/transform.cc @@ -21,10 +21,10 @@ * \file tirx/ir/transform.cc * \brief TIR specific transformation passes. */ +#include #include #include #include -#include #include namespace tvm {