Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.claude/
ir_testsuite.jsonl
ir_testsuite_filtered.jsonl
main.py
main2.py
testsuite/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/tvm-ffi
Submodule tvm-ffi updated 97 files
+114 −0 .github/actions/build-orcjit-wheel/action.yml
+42 −0 .github/workflows/ci_test.yml
+83 −0 .github/workflows/publish_orcjit_wheel.yml
+1 −1 .github/workflows/publish_wheel.yml
+1 −1 .github/workflows/torch_c_dlpack.yml
+2 −0 .gitignore
+0 −4 .pre-commit-config.yaml
+4 −0 CMakeLists.txt
+87 −0 addons/ast-testsuit/README.md
+179 −0 addons/ast-testsuit/ast_roundtrip_check.py
+54 −0 addons/ast-testsuit/run_multi_python.sh
+178 −0 addons/tvm_ffi_orcjit/CMakeLists.txt
+535 −0 addons/tvm_ffi_orcjit/ORCJIT_PRIMER.md
+261 −0 addons/tvm_ffi_orcjit/README.md
+67 −0 addons/tvm_ffi_orcjit/examples/quick-start/CMakeLists.txt
+83 −0 addons/tvm_ffi_orcjit/examples/quick-start/README.md
+46 −0 addons/tvm_ffi_orcjit/examples/quick-start/add.cc
+59 −0 addons/tvm_ffi_orcjit/examples/quick-start/add_c.c
+137 −0 addons/tvm_ffi_orcjit/examples/quick-start/run.py
+83 −0 addons/tvm_ffi_orcjit/pyproject.toml
+94 −0 addons/tvm_ffi_orcjit/python/tvm_ffi_orcjit/__init__.py
+21 −0 addons/tvm_ffi_orcjit/python/tvm_ffi_orcjit/_ffi_api.py
+85 −0 addons/tvm_ffi_orcjit/python/tvm_ffi_orcjit/dylib.py
+90 −0 addons/tvm_ffi_orcjit/python/tvm_ffi_orcjit/session.py
+212 −0 addons/tvm_ffi_orcjit/src/ffi/orcjit_dylib.cc
+129 −0 addons/tvm_ffi_orcjit/src/ffi/orcjit_dylib.h
+696 −0 addons/tvm_ffi_orcjit/src/ffi/orcjit_session.cc
+129 −0 addons/tvm_ffi_orcjit/src/ffi/orcjit_session.h
+90 −0 addons/tvm_ffi_orcjit/src/ffi/orcjit_utils.h
+107 −0 addons/tvm_ffi_orcjit/tests/CMakeLists.txt
+109 −0 addons/tvm_ffi_orcjit/tests/README.md
+106 −0 addons/tvm_ffi_orcjit/tests/sources/c/test_call_global.c
+152 −0 addons/tvm_ffi_orcjit/tests/sources/c/test_ctor_dtor.c
+31 −0 addons/tvm_ffi_orcjit/tests/sources/c/test_error.c
+43 −0 addons/tvm_ffi_orcjit/tests/sources/c/test_funcs.c
+42 −0 addons/tvm_ffi_orcjit/tests/sources/c/test_funcs2.c
+43 −0 addons/tvm_ffi_orcjit/tests/sources/c/test_funcs_conflict.c
+33 −0 addons/tvm_ffi_orcjit/tests/sources/c/test_link_order_base.c
+35 −0 addons/tvm_ffi_orcjit/tests/sources/c/test_link_order_caller.c
+60 −0 addons/tvm_ffi_orcjit/tests/sources/c/test_types.c
+37 −0 addons/tvm_ffi_orcjit/tests/sources/cc/test_call_global.cc
+82 −0 addons/tvm_ffi_orcjit/tests/sources/cc/test_ctor_dtor.cc
+26 −0 addons/tvm_ffi_orcjit/tests/sources/cc/test_error.cc
+26 −0 addons/tvm_ffi_orcjit/tests/sources/cc/test_funcs.cc
+26 −0 addons/tvm_ffi_orcjit/tests/sources/cc/test_funcs2.cc
+26 −0 addons/tvm_ffi_orcjit/tests/sources/cc/test_funcs_conflict.cc
+24 −0 addons/tvm_ffi_orcjit/tests/sources/cc/test_link_order_base.cc
+43 −0 addons/tvm_ffi_orcjit/tests/sources/cc/test_link_order_caller.cc
+33 −0 addons/tvm_ffi_orcjit/tests/sources/cc/test_types.cc
+61 −0 addons/tvm_ffi_orcjit/tests/sources/cuda/test_funcs.cu
+475 −0 addons/tvm_ffi_orcjit/tests/test_basic.py
+232 −0 addons/tvm_ffi_orcjit/tests/utils.py
+3 −0 docs/conf.py
+759 −0 include/tvm/ffi/extra/ir_traits.h
+3,259 −0 include/tvm/ffi/extra/pyast.h
+1 −1 include/tvm/ffi/object.h
+1 −0 include/tvm/ffi/reflection/creator.h
+12 −5 include/tvm/ffi/reflection/init.h
+18 −0 include/tvm/ffi/reflection/registry.h
+116 −0 include/tvm/ffi/string.h
+6 −1 include/tvm/ffi/type_traits.h
+5 −3 pyproject.toml
+1 −1 python/tvm_ffi/__init__.py
+11 −0 python/tvm_ffi/_ffi_api.py
+160 −0 python/tvm_ffi/_pyast_colored_print.py
+770 −0 python/tvm_ffi/_pyast_translator.py
+4 −4 python/tvm_ffi/container.py
+1 −0 python/tvm_ffi/core.pyi
+210 −90 python/tvm_ffi/cpp/extension.py
+46 −1 python/tvm_ffi/cython/function.pxi
+28 −0 python/tvm_ffi/cython/object.pxi
+53 −0 python/tvm_ffi/cython/type_info.pxi
+24 −0 python/tvm_ffi/dataclasses/py_class.py
+306 −0 python/tvm_ffi/ir_traits.py
+2,340 −0 python/tvm_ffi/pyast.py
+717 −5 python/tvm_ffi/testing/testing.py
+108 −80 python/tvm_ffi/utils/kwargs_wrapper.py
+53 −6 src/ffi/container.cc
+1,950 −0 src/ffi/extra/pyast_printer.cc
+1,631 −0 src/ffi/extra/pyast_trait_print.cc
+47 −1 src/ffi/testing/testing.cc
+1 −0 tests/lint/check_file_type.py
+1 −1 tests/python/test_build.py
+71 −0 tests/python/test_build_inline.py
+4 −4 tests/python/test_container.py
+210 −0 tests/python/test_container_dlpack_conversion.py
+1 −1 tests/python/test_current_work_stream_gpu.py
+0 −3 tests/python/test_dataclass_copy.py
+3 −3 tests/python/test_dataclass_init.py
+1 −3 tests/python/test_dataclass_py_class.py
+876 −0 tests/python/test_ir_traits.py
+1,463 −0 tests/python/test_pyast.py
+1,064 −0 tests/python/test_pyast_from_py.py
+235 −0 tests/python/test_pyast_printer.py
+1 −1 tests/python/test_stl.py
+3 −5 tests/python/test_type_converter.py
+82 −0 tests/python/utils/test_kwargs_wrapper.py
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ tvm_file_glob(GLOB_RECURSE COMPILER_SRCS
src/driver/*.cc
src/support/*.cc
src/script/*.cc
src/script_v2/*.cc
src/relax/ir/*.cc
src/relax/op/*.cc
src/relax/analysis/*.cc
Expand Down
6 changes: 5 additions & 1 deletion include/tvm/ir/attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <tvm/ffi/extra/structural_equal.h>
#include <tvm/ffi/extra/structural_hash.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/extra/ir_traits.h>
#include <tvm/ffi/reflection/accessor.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ir/expr.h>
Expand Down Expand Up @@ -145,7 +146,10 @@ class DictAttrsNode : public BaseAttrsNode {

static void RegisterReflection() {
namespace rfl = ffi::reflection;
rfl::ObjectDef<DictAttrsNode>().def_ro("__dict__", &DictAttrsNode::dict);
namespace tr = tvm::ffi::ir_traits;
rfl::ObjectDef<DictAttrsNode>()
.def_ro("__dict__", &DictAttrsNode::dict)
.def_ir_traits<tr::LiteralTraitsObj>("$field:__dict__");
}

void InitByPackedArgs(const ffi::PackedArgs& args, bool allow_unknown) final;
Expand Down
20 changes: 16 additions & 4 deletions include/tvm/ir/expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifndef TVM_IR_EXPR_H_
#define TVM_IR_EXPR_H_

#include <tvm/ffi/extra/ir_traits.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ffi/string.h>
#include <tvm/ir/source_map.h>
Expand Down Expand Up @@ -459,7 +460,10 @@ class GlobalVarNode : public RelaxExprNode {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<GlobalVarNode>().def_ro("name_hint", &GlobalVarNode::name_hint);
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<GlobalVarNode>()
.def_ro("name_hint", &GlobalVarNode::name_hint)
.def_ir_traits<tr::CallTraitsObj>("I.GlobalVar", "$field:name_hint");
}

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

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<IntImmNode>().def_ro("value", &IntImmNode::value);
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<IntImmNode>()
.def_ro("value", &IntImmNode::value)
.def_ir_traits<tr::LiteralTraitsObj>("$field:value", "int");
}
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.IntImm", IntImmNode, PrimExprNode);
};
Expand Down Expand Up @@ -533,7 +540,10 @@ class FloatImmNode : public PrimExprNode {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<FloatImmNode>().def_ro("value", &FloatImmNode::value);
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<FloatImmNode>()
.def_ro("value", &FloatImmNode::value)
.def_ir_traits<tr::LiteralTraitsObj>("$field:value", "float");
}
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FloatImm", FloatImmNode, PrimExprNode);
};
Expand Down Expand Up @@ -675,10 +685,12 @@ class RangeNode : public Object {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<RangeNode>()
.def_ro("min", &RangeNode::min)
.def_ro("extent", &RangeNode::extent)
.def_ro("span", &RangeNode::span, refl::AttachFieldFlag::SEqHashIgnore());
.def_ro("span", &RangeNode::span, refl::AttachFieldFlag::SEqHashIgnore())
.def_ir_traits<tr::CallTraitsObj>("I.Range", "$global:ir._range_args");
}

static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
Expand Down
9 changes: 7 additions & 2 deletions include/tvm/ir/global_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef TVM_IR_GLOBAL_INFO_H_
#define TVM_IR_GLOBAL_INFO_H_

#include <tvm/ffi/extra/ir_traits.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ir/expr.h>
#include <tvm/target/target.h>
Expand Down Expand Up @@ -71,10 +72,12 @@ class VDeviceNode : public GlobalInfoNode {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<VDeviceNode>()
.def_ro("target", &VDeviceNode::target)
.def_ro("vdevice_id", &VDeviceNode::vdevice_id)
.def_ro("memory_scope", &VDeviceNode::memory_scope);
.def_ro("memory_scope", &VDeviceNode::memory_scope)
.def_ir_traits<tr::CallTraitsObj>("I.vdevice", "$global:ir._vdevice_args");
}

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

TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.DummyGlobalInfo", DummyGlobalInfoNode, GlobalInfoNode);
Expand Down
5 changes: 4 additions & 1 deletion include/tvm/ir/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define TVM_IR_OP_H_

#include <tvm/ffi/function.h>
#include <tvm/ffi/extra/ir_traits.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ir/attrs.h>
#include <tvm/ir/env_func.h>
Expand Down Expand Up @@ -93,14 +94,16 @@ class OpNode : public RelaxExprNode {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<OpNode>()
.def_ro("name", &OpNode::name)
.def_ro("op_type", &OpNode::op_type, refl::AttachFieldFlag::SEqHashIgnore())
.def_ro("description", &OpNode::description, refl::AttachFieldFlag::SEqHashIgnore())
.def_ro("arguments", &OpNode::arguments, refl::AttachFieldFlag::SEqHashIgnore())
.def_ro("attrs_type_key", &OpNode::attrs_type_key, refl::AttachFieldFlag::SEqHashIgnore())
.def_ro("num_inputs", &OpNode::num_inputs, refl::AttachFieldFlag::SEqHashIgnore())
.def_ro("support_level", &OpNode::support_level, refl::AttachFieldFlag::SEqHashIgnore());
.def_ro("support_level", &OpNode::support_level, refl::AttachFieldFlag::SEqHashIgnore())
.def_ir_traits<tr::CallTraitsObj>("I.Op", "$field:name");
}

static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindUniqueInstance;
Expand Down
18 changes: 14 additions & 4 deletions include/tvm/ir/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#define TVM_IR_TYPE_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/extra/ir_traits.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ir/source_map.h>
#include <tvm/runtime/data_type.h>
Expand Down Expand Up @@ -118,7 +119,10 @@ class PrimTypeNode : public TypeNode {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<PrimTypeNode>().def_ro("dtype", &PrimTypeNode::dtype);
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<PrimTypeNode>()
.def_ro("dtype", &PrimTypeNode::dtype)
.def_ir_traits<tr::PrimTyTraitsObj>("$field:dtype");
}
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.PrimType", PrimTypeNode, TypeNode);
};
Expand Down Expand Up @@ -162,9 +166,11 @@ class PointerTypeNode : public TypeNode {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<PointerTypeNode>()
.def_ro("element_type", &PointerTypeNode::element_type)
.def_ro("storage_scope", &PointerTypeNode::storage_scope);
.def_ro("storage_scope", &PointerTypeNode::storage_scope)
.def_ir_traits<tr::CallTraitsObj>("T.handle", "$global:ir._handle_args");
}
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.PointerType", PointerTypeNode, TypeNode);
};
Expand Down Expand Up @@ -198,9 +204,11 @@ class TupleTypeNode : public TypeNode {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<TupleTypeNode>()
.def_ro("fields", &TupleTypeNode::fields)
.def_ro("span", &TupleTypeNode::span);
.def_ro("span", &TupleTypeNode::span)
.def_ir_traits<tr::TupleTyTraitsObj>("$field:fields");
}
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TupleType", TupleTypeNode, TypeNode);
};
Expand Down Expand Up @@ -258,10 +266,12 @@ class FuncTypeNode : public TypeNode {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<FuncTypeNode>()
.def_ro("arg_types", &FuncTypeNode::arg_types)
.def_ro("ret_type", &FuncTypeNode::ret_type)
.def_ro("span", &FuncTypeNode::span);
.def_ro("span", &FuncTypeNode::span)
.def_ir_traits<tr::FuncTyTraitsObj>("$field:arg_types", "$field:ret_type");
}
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FuncType", FuncTypeNode, TypeNode);
};
Expand Down
6 changes: 5 additions & 1 deletion include/tvm/relax/distributed/struct_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef TVM_RELAX_DISTRIBUTED_STRUCT_INFO_H_
#define TVM_RELAX_DISTRIBUTED_STRUCT_INFO_H_

#include <tvm/ffi/extra/ir_traits.h>
#include <tvm/relax/distributed/global_info.h>
#include <tvm/relax/struct_info.h>
namespace tvm {
Expand Down Expand Up @@ -91,7 +92,10 @@ class PlacementNode : public Object {

static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<PlacementNode>().def_ro("dim_specs", &PlacementNode::dim_specs);
namespace tr = tvm::ffi::ir_traits;
refl::ObjectDef<PlacementNode>()
.def_ro("dim_specs", &PlacementNode::dim_specs)
.def_ir_traits<tr::LiteralTraitsObj>("$global:relax._placement_str");
}

static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindConstTreeNode;
Expand Down
Loading