Commit 95d1268
authored
[REFACTOR] Introduce and modernize FFI system (#17920)
This PR modernizes the FFI foundation of the project and introduce
a new minimal and lightweight module [tvm ffi](https://github.com/apache/tvm/tree/refactor-s3/ffi)
based on our lessons in the past few years. It implements a modern
version of the [Unified Packed and Object RFC](https://github.com/apache/tvm-rfcs/blob/main/rfcs/0097-unify-packed-and-object.md)
that unifies the packed function call and object systems.
Summary of the change:
- A dedicated clean Any/AnyView that can store strong and weak
references of items
- Function(previously PackedFunc) system built on top of the Any/AnyView
- A minimal C API that backs the overall calls. We are stabilizing the
API with a goal to bring clean, stable FFI conventions for both compiled
and registered code
- A rewrite of core python binding and generated code based on the module
- Update existing code and test cases to the new module
- Latest dlpack support
The new module brings many benefits thanks to the cleaner design,
to name a few:
- Any can support both POD types(int) and object types.
- Containers (e.g. Array) can now also contain Any value, e.g. now
`Array<int>` is supported, no need for boxed types
- Error handling now upgrades to object-based, allowing cleaner
traceback across languages
- Map now preserves insertion orders
- Path toward isolated stabilize minimum core ABI/API foundation module
- Type traits based design that cleanly defines how values interact
with Any system
- Automatic conversion of different types based on traits if needed
Because FFI upgrade is at heart of the project, the change touches every
component of the system. Importantly, this is an upgrade of the ABI so the
change is not backward compatible. The code compiled under the old
FFI won't work under the new one. We did provide example ABI translation
(e.g. LegacyTVMArgValueToFFIAny) functions for compatibility.
The PR tries to leave files in their old places while creating redirections.
The goal is to have the first milestone landed and infrastructure in place,
so we can do further refactors to complete features and cleanup legacy code
as trackable PRs. As of now, python binding and compiled code are under the
new convention while RPC and some other bindings still relies on legacy ABI
translation. We will work on upgrades in the coming PRs, including areas such
as reflection, phasing out legacy redirections etc.1 parent fa26a05 commit 95d1268
File tree
925 files changed
+28150
-22679
lines changed- .github/workflows
- 3rdparty
- apps
- android_rpc/app/src/main/jni
- cpp_rpc
- hexagon_api
- hexagon_launcher
- cmake
- android
- hexagon
- ios_rpc/tvmrpc
- cmake
- modules
- contrib
- utils
- docs
- arch
- deep_dive/tensor_ir/tutorials
- ffi
- 3rdparty
- cmake/Utils
- include/tvm/ffi
- container
- reflection
- scripts
- src/ffi
- tests/cpp
- include/tvm
- ir
- meta_schedule
- node
- relax
- attrs
- distributed
- runtime
- container
- disco
- memory
- relax_vm
- script
- ir_builder
- ir
- relax
- tir
- printer
- target
- te
- tir
- schedule
- topi
- detail
- nn
- jvm
- core/src/main/java/org/apache/tvm
- native
- linux-x86_64
- osx-x86_64
- python
- tvm
- _ffi
- _cython
- contrib
- cutlass
- msc
- core
- frontend
- tools/prune
- utils
- framework
- tensorrt/tools
- quantize
- track
- torch/codegen
- dlight
- base
- benchmark
- ffi
- cython
- ir
- meta_schedule
- cost_model
- post_optimization
- testing
- relax
- backend
- adreno
- cuda
- gpu_generic
- frontend
- nn
- llm
- torch
- transform
- legalize_ops
- tuning_api
- rpc
- runtime
- disco
- script
- ir_builder
- relax
- distributed
- tir
- parser/tir
- target
- testing
- te
- tir
- schedule
- transform
- topi
- image
- testing
- rust/tvm-rt/src
- src
- arith
- contrib/msc
- core
- codegen
- ir
- printer
- transform
- framework
- tensorflow
- tensorrt
- torch
- tvm
- ir
- meta_schedule
- builder
- cost_model
- database
- feature_extractor
- measure_callback
- mutator
- postproc
- runner
- schedule_rule
- schedule/cuda
- search_strategy
- space_generator
- task_scheduler
- node
- relax
- analysis
- backend
- contrib
- clml
- codegen_json
- cublas
- cudnn
- cutlass
- dnnl
- hipblas
- nnapi
- tensorrt
- vm
- distributed/transform
- ir
- op
- image
- nn
- tensor
- training
- transform
- tuning_api
- runtime
- contrib
- amx
- cblas
- clml
- coreml
- cublas
- cudnn
- curand
- cutlass
- dnnl
- edgetpu
- hipblas
- json
- miopen
- mps
- mrvl
- msc
- nnapi
- papi
- random
- rocblas
- sort
- tflite
- thrust
- cuda
- disco
- cuda_ipc
- distributed
- nccl
- hexagon
- ops
- rpc
- android
- hexagon
- simulator
- memory
- metal
- minrpc
- opencl
- relax_vm
- cuda
- rocm
- rpc
- vulkan
- script
- ir_builder
- ir
- relax
- tir
- printer
- doc_printer
- ir
- relax
- tir
- support
- target
- datatype
- llvm
- opt
- parsers
- source
- spirv
- te
- operation
- tir
- analysis
- ir
- op
- schedule
- analysis
- primitive
- transforms
- topi
- tests
- cpp-runtime
- hexagon
- opencl
- cpp
- lint
- python
- all-platform-minimal-test
- codegen
- contrib
- test_hexagon
- test_msc
- dlight
- driver
- ffi
- ir
- meta_schedule
- nightly/test_nnapi
- relax
- backend/clml
- distributed
- nvshmem
- runtime
- target
- te
- tir-analysis
- tir-base
- tir-schedule
- tir-transform
- tvmscript
- scripts
- web
- emcc
- src
- tests/node
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
925 files changed
+28150
-22679
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
163 | 162 | | |
164 | 163 | | |
165 | 164 | | |
| |||
496 | 495 | | |
497 | 496 | | |
498 | 497 | | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
499 | 501 | | |
500 | 502 | | |
501 | 503 | | |
| |||
567 | 569 | | |
568 | 570 | | |
569 | 571 | | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
570 | 575 | | |
571 | 576 | | |
572 | 577 | | |
| |||
602 | 607 | | |
603 | 608 | | |
604 | 609 | | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
605 | 614 | | |
606 | 615 | | |
607 | 616 | | |
| |||
639 | 648 | | |
640 | 649 | | |
641 | 650 | | |
| 651 | + | |
642 | 652 | | |
643 | 653 | | |
644 | 654 | | |
| |||
696 | 706 | | |
697 | 707 | | |
698 | 708 | | |
699 | | - | |
700 | | - | |
| 709 | + | |
| 710 | + | |
701 | 711 | | |
702 | | - | |
| 712 | + | |
703 | 713 | | |
704 | 714 | | |
705 | 715 | | |
| |||
734 | 744 | | |
735 | 745 | | |
736 | 746 | | |
737 | | - | |
738 | | - | |
739 | | - | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
740 | 750 | | |
741 | 751 | | |
742 | 752 | | |
| |||
750 | 760 | | |
751 | 761 | | |
752 | 762 | | |
753 | | - | |
754 | | - | |
755 | | - | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
756 | 766 | | |
757 | 767 | | |
758 | 768 | | |
| |||
774 | 784 | | |
775 | 785 | | |
776 | 786 | | |
777 | | - | |
778 | | - | |
779 | | - | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
| 787 | + | |
| 788 | + | |
788 | 789 | | |
789 | 790 | | |
790 | 791 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
130 | | - | |
131 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
132 | 132 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
148 | 142 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
154 | 150 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
162 | 156 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
169 | 167 | | |
170 | 168 | | |
171 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
402 | | - | |
403 | | - | |
| 401 | + | |
404 | 402 | | |
405 | 403 | | |
0 commit comments