15 Commits

Author SHA1 Message Date
Tianqi Chen 556571fc9d [REFACTOR][RUNTIME] Phase out include/tvm/runtime/object.h (#19476)
## Summary

include/tvm/runtime/object.h was a vestige of the pre-tvm-ffi world — a
thin compat layer re-exporting
Object/ObjectRef/ObjectPtr/GetRef/GetObjectPtr
aliases into tvm::runtime:: and tvm::, plus a few TVM-specific macros
and
an enum TypeIndex with mostly-dead constants.

This PR phases the header out entirely, with no shim:

- `TVM_DEFINE_OBJECT_REF_COW_METHOD` relocated to a new
`include/tvm/ir/cow.h`
  (its consumer set is entirely IR/TIRX/relax/arith/te).
-
`TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE_WITHOUT_DEFAULT_CONSTRUCTOR`
  inlined at its 2 callers (rare; not worth a new home).
- `TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN` inlined at its 1 caller.
- `TVM_STR_CONCAT` removed; callers switch to `TVM_FFI_STR_CONCAT`
  (already in tvm-ffi; the local copy was a duplicate).
- `kRuntimeRPCObjectRef` / `kRuntimeDiscoDRef` inlined into
`rpc_session.h`
  / `disco/session.h` respectively (the only live type-index constants).
- All using-aliases (`tvm::runtime::Object` etc.) rewritten to fully-
qualified `tvm::ffi::Object` at use sites — no using-injections
anywhere.
- `include/tvm/runtime/object.h` deleted.

## Test plan

- ninja build clean (USE_LLVM=ON, default targets) — exit 0.
- ./cpptest — 118/118.
- pytest tests/python/all-platform-minimal-test/ — green.
- pytest tests/python/runtime/ — green.
- pre-commit clean.
2026-04-29 20:05:42 -04:00
Tianqi Chen f533d0b3c1 [REFACTOR] Migrate CHECK macros to tvm-ffi ones (#18803) 2026-02-21 09:00:44 -05:00
Tianqi Chen abc8ae802f [FFI][REFACTOR] Streamline Object Declare Macros (#18289) 2025-09-09 19:33:41 +08:00
Tianqi Chen 349df2bc26 [FFI][REFACTOR] Cleanup namespace (#18280)
* [FFI][REFACTOR] Cleanup namespace

This PR cleansup the namespace to ensure all ffi classes
are accessed through ffi:: namespace.
It will helps to cleanup the ffi package before isolation.

* fix hexagon
2025-09-08 08:58:30 -04:00
Tianqi Chen ba994d32f9 [FFI][REFACTOR] Migrate the Save/Load JSON to the new reflection (#18188)
This PR migrates the Save/Load JSON to the new reflection based mechanism.

This is a breaking change that updates the the JSON format
to ffi/extra/serialization to handle the serialization,
see the json graph schema comment in ffi/extra/serialization.h
for the format, which roughly aligns with the old style.

After this change, we no longer need node/reflection and reflection vtable.
We can also phase out TVM_REGISTER_NODE and TVM_REGISTER_OBJECT to have a single
place that defines the reflection.
2025-08-05 15:44:33 -04:00
Tianqi Chen 1f8103e203 [REFACTOR][FFI] Cleanup container redirections (#17929)
This PR cleans up the container redirections and headers
so the files directly points to new ones in ffi folder

- runtime/shape_tuple.h => ffi/container/shape.h
  - for IntTuple alias, introduce runtime/int_tuple.h for now
- runtime/container/array.h => ffi/container/array.h
- runtime/container/map.h => ffi/container/map.h
- runtime/container/optional.h => ffi/optional.h
- runtime/container/string.h => ffi/string.h
- runtime/container/variant.h => ffi/container/variant.h
- runtime/container/tuple.h => ffi/container/tuple.h

We also introduce limited number of tvm::ffi classes into tvm namespace,
when they are commonly used and their is no ambiguity.
2025-05-08 13:55:33 -04:00
Tianqi Chen 95d1268982 [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.
2025-05-06 19:18:33 -04:00
Tianqi Chen a531d170b9 [REFACTOR] Phase out relay c++ components (#17660)
* cleanup relay c++

* [REFACTOR] Phase out relay c++ components

This PR phases out the relay C++ components and
simplifies the overall codegen runtime logic.

---------

Co-authored-by: Siyuan Feng <hzfengsy@sjtu.edu.cn>
2025-02-17 22:21:37 +08:00
Christopher Sidebottom b77a7d4fc6 Apply CPPLint to C++ Unit Tests (#8827)
This change enables `cpplint` for the tests in `tests/cpp` and corrects any current linting errors. I had to use `NOLINT` in some of the PackedFunc tests due to a bug (see: https://github.com/cpplint/cpplint/issues/131) in CPPLint where `int(int)` is picked up as a cast rather than a nameless argument.
2021-08-24 13:45:52 -07:00
Christopher Sidebottom 356879d4c3 Use CTest for C++ tests (#8809)
By using the `gtest_discover_tests` CMake macro the CPP and CRT tests can be configured to build binaries with a single test runner each. Once CTest has information about tests it can be used in IDE extensions such as [CMake Test Explorer](https://marketplace.visualstudio.com/items?itemName=fredericbonnet.cmake-test-adapter).

`ctest` can also run tests in parallel using the `-j` flag, which could be interesting in future.
2021-08-23 17:08:18 -07:00
Robert Kimball 8695a57619 More CHECK to ICHECK (#6758)
* Address apps, docs, and nnvm directories

* Catch some that were missed

* crt has it's own logging.h

* Fix missing include
2020-10-26 15:55:43 -07:00
Tianqi Chen 7bad56b74e [LINT] clang-format the h,cc,m files. (#5557)
This PR prepares for our migration to use the clang-format
as part of the linter system.
2020-05-10 21:43:33 -07:00
Tianqi Chen 3cc4971990 [RUNTIME][OBJECT] Introduce static slots for common objects. (#5423)
The _type_child_slots can be used to enable quick type checking optimization
by checking the whether the type index is within the bound.

This PR enables these static slots:

- Introduce a static assert to avoid the scenario when a developer forget to
  _type_child_slots when the field is set for the type's parent.
- Revamp and assign static type index to common runtime objects
- Add a DumpTypeTable call to allow developer monitor the current situation
  of type table and offers suggestions for the slots(ideally the slots equals
  the number of children so there is no overflow.
2020-04-24 12:49:05 -07:00
Tianqi Chen 7895adb243 [REFACTOR][NODE][RUNTIME] Move Node to the new Object protocol. (#4161)
* [REFACTOR][NODE][RUNTIME] Move Node to the new Object protocol.

This PR removes the original node system, and make node as a subclass of Object.
This is a major refactor towards a better unified runtime object system.

List of changes in the refactor:

- We now hide data_ field, use Downcast explicitly to get a sub-class object.
- Removed the node system FFI in python.
- Removed the node C API, instead use PackedFunc for list and get attrs.
- Change relay::Op::set_attr_type_key(attr_key_name) to relay::Op::set_attr_type<AttrType>().
  - This change was necessary because of the new Object registration mechanism.
  - Subsequent changes to the op registrations
  - The change revealed a few previous problems that is now fixed.
- Patched up a few missing node type registration.
  - Now we will raise an error if we register object that is not registered.
- The original node.h and container.h are kept in the same location.
- Calling convention: kObjectHandle now equals the old kNodeHandle, kNodeHandle is removed.
- IRFunctor now dispatches on ObjectRef.
- Update to the new type checking API: is_type, derived_from are replaced by IsInstance.
- Removed .hash member function, instead use C++ convention hasher functors.

* Address review comments
2019-10-20 18:30:41 -07:00
Tianqi Chen a0bd3786ed [RFC][RUNTIME] Introduce new object protocol. (#4115)
* [RUNTIME] Introduce new object protocol.

This PR introduces a new object protocol to unify the node and object.
We also updated the existing runtime::vm code to make use of the new system.

Update to the node will be done in a follow up PR.

Other changes:

- Remove object related code in json serializer as that code logic was not complete
  and we have a separate serializer for VM, can revisit later.

* address review  comment

* Fix the child slot logic
2019-10-14 22:46:35 -07:00