Skip to content

Commit 61ce823

Browse files
committed
refactor(ffi): always build with bundled tvm-ffi and align include paths
Switch to always using the bundled tvm-ffi submodule for builds. Update internal include paths and Python imports to match the tvm-ffi submodule restructure: headers moved from `tvm/ffi/ir/text/` to `tvm/ffi/extra/` and Python modules from `tvm_ffi.ir.text` to `tvm_ffi.pyast`. No public API changes. All 99 test suites (19,800 tests) pass.
1 parent a7bfc85 commit 61ce823

37 files changed

Lines changed: 3728 additions & 73 deletions

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
.claude/
2+
ir_testsuite.jsonl
3+
ir_testsuite_filtered.jsonl
4+
main.py
5+
main2.py
6+
plan-changed.md
7+
plan.md
8+
testsuite/
9+
tmp.md
10+
traits-printer-parser-v4.md
11+
112
# Byte-compiled / optimized / DLL files
213
__pycache__/
314
*.py[cod]

3rdparty/tvm-ffi

Submodule tvm-ffi updated 83 files

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ tvm_file_glob(GLOB_RECURSE COMPILER_SRCS
277277
src/driver/*.cc
278278
src/support/*.cc
279279
src/script/*.cc
280+
src/script_v2/*.cc
280281
src/relax/ir/*.cc
281282
src/relax/op/*.cc
282283
src/relax/analysis/*.cc

include/tvm/ir/attrs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <tvm/ffi/extra/structural_equal.h>
3333
#include <tvm/ffi/extra/structural_hash.h>
3434
#include <tvm/ffi/function.h>
35+
#include <tvm/ffi/extra/ir_traits.h>
3536
#include <tvm/ffi/reflection/accessor.h>
3637
#include <tvm/ffi/reflection/registry.h>
3738
#include <tvm/ir/expr.h>
@@ -145,7 +146,10 @@ class DictAttrsNode : public BaseAttrsNode {
145146

146147
static void RegisterReflection() {
147148
namespace rfl = ffi::reflection;
148-
rfl::ObjectDef<DictAttrsNode>().def_ro("__dict__", &DictAttrsNode::dict);
149+
namespace tr = tvm::ffi::ir_traits;
150+
rfl::ObjectDef<DictAttrsNode>()
151+
.def_ro("__dict__", &DictAttrsNode::dict)
152+
.def_ir_traits<tr::LiteralTraitsObj>("$field:__dict__");
149153
}
150154

151155
void InitByPackedArgs(const ffi::PackedArgs& args, bool allow_unknown) final;

include/tvm/ir/expr.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#ifndef TVM_IR_EXPR_H_
2525
#define TVM_IR_EXPR_H_
2626

27+
#include <tvm/ffi/extra/ir_traits.h>
2728
#include <tvm/ffi/reflection/registry.h>
2829
#include <tvm/ffi/string.h>
2930
#include <tvm/ir/source_map.h>
@@ -459,7 +460,10 @@ class GlobalVarNode : public RelaxExprNode {
459460

460461
static void RegisterReflection() {
461462
namespace refl = tvm::ffi::reflection;
462-
refl::ObjectDef<GlobalVarNode>().def_ro("name_hint", &GlobalVarNode::name_hint);
463+
namespace tr = tvm::ffi::ir_traits;
464+
refl::ObjectDef<GlobalVarNode>()
465+
.def_ro("name_hint", &GlobalVarNode::name_hint)
466+
.def_ir_traits<tr::CallTraitsObj>("I.GlobalVar", "$field:name_hint");
463467
}
464468

465469
bool SEqual(const GlobalVarNode* other,
@@ -498,7 +502,10 @@ class IntImmNode : public PrimExprNode {
498502

499503
static void RegisterReflection() {
500504
namespace refl = tvm::ffi::reflection;
501-
refl::ObjectDef<IntImmNode>().def_ro("value", &IntImmNode::value);
505+
namespace tr = tvm::ffi::ir_traits;
506+
refl::ObjectDef<IntImmNode>()
507+
.def_ro("value", &IntImmNode::value)
508+
.def_ir_traits<tr::LiteralTraitsObj>("$field:value", "int");
502509
}
503510
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.IntImm", IntImmNode, PrimExprNode);
504511
};
@@ -533,7 +540,10 @@ class FloatImmNode : public PrimExprNode {
533540

534541
static void RegisterReflection() {
535542
namespace refl = tvm::ffi::reflection;
536-
refl::ObjectDef<FloatImmNode>().def_ro("value", &FloatImmNode::value);
543+
namespace tr = tvm::ffi::ir_traits;
544+
refl::ObjectDef<FloatImmNode>()
545+
.def_ro("value", &FloatImmNode::value)
546+
.def_ir_traits<tr::LiteralTraitsObj>("$field:value", "float");
537547
}
538548
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FloatImm", FloatImmNode, PrimExprNode);
539549
};
@@ -675,10 +685,12 @@ class RangeNode : public Object {
675685

676686
static void RegisterReflection() {
677687
namespace refl = tvm::ffi::reflection;
688+
namespace tr = tvm::ffi::ir_traits;
678689
refl::ObjectDef<RangeNode>()
679690
.def_ro("min", &RangeNode::min)
680691
.def_ro("extent", &RangeNode::extent)
681-
.def_ro("span", &RangeNode::span, refl::AttachFieldFlag::SEqHashIgnore());
692+
.def_ro("span", &RangeNode::span, refl::AttachFieldFlag::SEqHashIgnore())
693+
.def_ir_traits<tr::CallTraitsObj>("I.Range", "$global:ir._range_args");
682694
}
683695

684696
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;

include/tvm/ir/global_info.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifndef TVM_IR_GLOBAL_INFO_H_
2626
#define TVM_IR_GLOBAL_INFO_H_
2727

28+
#include <tvm/ffi/extra/ir_traits.h>
2829
#include <tvm/ffi/reflection/registry.h>
2930
#include <tvm/ir/expr.h>
3031
#include <tvm/target/target.h>
@@ -71,10 +72,12 @@ class VDeviceNode : public GlobalInfoNode {
7172

7273
static void RegisterReflection() {
7374
namespace refl = tvm::ffi::reflection;
75+
namespace tr = tvm::ffi::ir_traits;
7476
refl::ObjectDef<VDeviceNode>()
7577
.def_ro("target", &VDeviceNode::target)
7678
.def_ro("vdevice_id", &VDeviceNode::vdevice_id)
77-
.def_ro("memory_scope", &VDeviceNode::memory_scope);
79+
.def_ro("memory_scope", &VDeviceNode::memory_scope)
80+
.def_ir_traits<tr::CallTraitsObj>("I.vdevice", "$global:ir._vdevice_args");
7881
}
7982

8083
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.VDevice", VDeviceNode, GlobalInfoNode);
@@ -97,7 +100,9 @@ class DummyGlobalInfoNode : public GlobalInfoNode {
97100
public:
98101
static void RegisterReflection() {
99102
namespace refl = tvm::ffi::reflection;
100-
refl::ObjectDef<DummyGlobalInfoNode>();
103+
namespace tr = tvm::ffi::ir_traits;
104+
refl::ObjectDef<DummyGlobalInfoNode>()
105+
.def_ir_traits<tr::CallTraitsObj>("I.dummy_global_info", "$global:ir._dummy_args");
101106
}
102107

103108
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.DummyGlobalInfo", DummyGlobalInfoNode, GlobalInfoNode);

include/tvm/ir/op.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define TVM_IR_OP_H_
2727

2828
#include <tvm/ffi/function.h>
29+
#include <tvm/ffi/extra/ir_traits.h>
2930
#include <tvm/ffi/reflection/registry.h>
3031
#include <tvm/ir/attrs.h>
3132
#include <tvm/ir/env_func.h>
@@ -93,14 +94,16 @@ class OpNode : public RelaxExprNode {
9394

9495
static void RegisterReflection() {
9596
namespace refl = tvm::ffi::reflection;
97+
namespace tr = tvm::ffi::ir_traits;
9698
refl::ObjectDef<OpNode>()
9799
.def_ro("name", &OpNode::name)
98100
.def_ro("op_type", &OpNode::op_type, refl::AttachFieldFlag::SEqHashIgnore())
99101
.def_ro("description", &OpNode::description, refl::AttachFieldFlag::SEqHashIgnore())
100102
.def_ro("arguments", &OpNode::arguments, refl::AttachFieldFlag::SEqHashIgnore())
101103
.def_ro("attrs_type_key", &OpNode::attrs_type_key, refl::AttachFieldFlag::SEqHashIgnore())
102104
.def_ro("num_inputs", &OpNode::num_inputs, refl::AttachFieldFlag::SEqHashIgnore())
103-
.def_ro("support_level", &OpNode::support_level, refl::AttachFieldFlag::SEqHashIgnore());
105+
.def_ro("support_level", &OpNode::support_level, refl::AttachFieldFlag::SEqHashIgnore())
106+
.def_ir_traits<tr::CallTraitsObj>("I.Op", "$field:name");
104107
}
105108

106109
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindUniqueInstance;

include/tvm/ir/type.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#define TVM_IR_TYPE_H_
5151

5252
#include <tvm/ffi/container/array.h>
53+
#include <tvm/ffi/extra/ir_traits.h>
5354
#include <tvm/ffi/reflection/registry.h>
5455
#include <tvm/ir/source_map.h>
5556
#include <tvm/runtime/data_type.h>
@@ -118,7 +119,10 @@ class PrimTypeNode : public TypeNode {
118119

119120
static void RegisterReflection() {
120121
namespace refl = tvm::ffi::reflection;
121-
refl::ObjectDef<PrimTypeNode>().def_ro("dtype", &PrimTypeNode::dtype);
122+
namespace tr = tvm::ffi::ir_traits;
123+
refl::ObjectDef<PrimTypeNode>()
124+
.def_ro("dtype", &PrimTypeNode::dtype)
125+
.def_ir_traits<tr::PrimTyTraitsObj>("$field:dtype");
122126
}
123127
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.PrimType", PrimTypeNode, TypeNode);
124128
};
@@ -162,9 +166,11 @@ class PointerTypeNode : public TypeNode {
162166

163167
static void RegisterReflection() {
164168
namespace refl = tvm::ffi::reflection;
169+
namespace tr = tvm::ffi::ir_traits;
165170
refl::ObjectDef<PointerTypeNode>()
166171
.def_ro("element_type", &PointerTypeNode::element_type)
167-
.def_ro("storage_scope", &PointerTypeNode::storage_scope);
172+
.def_ro("storage_scope", &PointerTypeNode::storage_scope)
173+
.def_ir_traits<tr::CallTraitsObj>("T.handle", "$global:ir._handle_args");
168174
}
169175
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.PointerType", PointerTypeNode, TypeNode);
170176
};
@@ -198,9 +204,11 @@ class TupleTypeNode : public TypeNode {
198204

199205
static void RegisterReflection() {
200206
namespace refl = tvm::ffi::reflection;
207+
namespace tr = tvm::ffi::ir_traits;
201208
refl::ObjectDef<TupleTypeNode>()
202209
.def_ro("fields", &TupleTypeNode::fields)
203-
.def_ro("span", &TupleTypeNode::span);
210+
.def_ro("span", &TupleTypeNode::span)
211+
.def_ir_traits<tr::TupleTyTraitsObj>("$field:fields");
204212
}
205213
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TupleType", TupleTypeNode, TypeNode);
206214
};
@@ -258,10 +266,12 @@ class FuncTypeNode : public TypeNode {
258266

259267
static void RegisterReflection() {
260268
namespace refl = tvm::ffi::reflection;
269+
namespace tr = tvm::ffi::ir_traits;
261270
refl::ObjectDef<FuncTypeNode>()
262271
.def_ro("arg_types", &FuncTypeNode::arg_types)
263272
.def_ro("ret_type", &FuncTypeNode::ret_type)
264-
.def_ro("span", &FuncTypeNode::span);
273+
.def_ro("span", &FuncTypeNode::span)
274+
.def_ir_traits<tr::FuncTyTraitsObj>("$field:arg_types", "$field:ret_type");
265275
}
266276
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FuncType", FuncTypeNode, TypeNode);
267277
};

include/tvm/relax/distributed/struct_info.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifndef TVM_RELAX_DISTRIBUTED_STRUCT_INFO_H_
2626
#define TVM_RELAX_DISTRIBUTED_STRUCT_INFO_H_
2727

28+
#include <tvm/ffi/extra/ir_traits.h>
2829
#include <tvm/relax/distributed/global_info.h>
2930
#include <tvm/relax/struct_info.h>
3031
namespace tvm {
@@ -91,7 +92,10 @@ class PlacementNode : public Object {
9192

9293
static void RegisterReflection() {
9394
namespace refl = tvm::ffi::reflection;
94-
refl::ObjectDef<PlacementNode>().def_ro("dim_specs", &PlacementNode::dim_specs);
95+
namespace tr = tvm::ffi::ir_traits;
96+
refl::ObjectDef<PlacementNode>()
97+
.def_ro("dim_specs", &PlacementNode::dim_specs)
98+
.def_ir_traits<tr::LiteralTraitsObj>("$global:relax._placement_str");
9599
}
96100

97101
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindConstTreeNode;

0 commit comments

Comments
 (0)