Skip to content

Commit 8d555a0

Browse files
authored
[REFACTOR] Cleanup legacy relay runtime data structures (#17713)
This PR cleans up legacy relay runtime data structures ADT and closure as they can be superseded by Array and VMClosure in the relax VM.
1 parent 775e050 commit 8d555a0

File tree

14 files changed

+9
-481
lines changed

14 files changed

+9
-481
lines changed

include/tvm/runtime/container/adt.h

Lines changed: 0 additions & 143 deletions
This file was deleted.

include/tvm/runtime/container/closure.h

Lines changed: 0 additions & 52 deletions
This file was deleted.

include/tvm/runtime/object.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ struct TypeIndex {
7777
/*! \brief runtime::RPCObjectRef */
7878
kRuntimeRPCObjectRef = 9,
7979
// static assignments that may subject to change.
80-
kRuntimeClosure,
81-
kRuntimeADT,
8280
kStaticIndexEnd,
8381
/*! \brief Type index is allocated during runtime. */
8482
kDynamic = kStaticIndexEnd

include/tvm/runtime/relax_vm/executable.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#ifndef TVM_RUNTIME_RELAX_VM_EXECUTABLE_H_
2424
#define TVM_RUNTIME_RELAX_VM_EXECUTABLE_H_
2525

26-
#include <tvm/runtime/container/closure.h>
2726
#include <tvm/runtime/object.h>
2827
#include <tvm/runtime/packed_func.h>
2928
#include <tvm/runtime/registry.h>

include/tvm/runtime/relax_vm/vm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ enum class VMInstrumentReturnKind : int {
6060
/*!
6161
* \brief An object representing a vm closure.
6262
*/
63-
class VMClosureObj : public ClosureObj {
63+
class VMClosureObj : public Object {
6464
public:
6565
/*!
6666
* \brief The function name. The function could be any
@@ -78,14 +78,14 @@ class VMClosureObj : public ClosureObj {
7878

7979
static constexpr const uint32_t _type_index = TypeIndex::kDynamic;
8080
static constexpr const char* _type_key = "relax.vm.Closure";
81-
TVM_DECLARE_FINAL_OBJECT_INFO(VMClosureObj, ClosureObj);
81+
TVM_DECLARE_FINAL_OBJECT_INFO(VMClosureObj, Object);
8282
};
8383

8484
/*! \brief reference to closure. */
85-
class VMClosure : public Closure {
85+
class VMClosure : public ObjectRef {
8686
public:
8787
VMClosure(String func_name, PackedFunc impl);
88-
TVM_DEFINE_OBJECT_REF_METHODS(VMClosure, Closure, VMClosureObj);
88+
TVM_DEFINE_OBJECT_REF_METHODS(VMClosure, ObjectRef, VMClosureObj);
8989

9090
/*!
9191
* \brief Create another PackedFunc with last arguments already bound to last_args.

python/tvm/relax/op/base.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -416,16 +416,6 @@ def render_object(val: tvm.Object) -> str:
416416
"""
417417
if isinstance(val, tvm.nd.NDArray):
418418
return str(val)
419-
# no pretty-printer by default, so if we don't handle this,
420-
# then we can't look inside tuples
421-
if isinstance(val, tvm.runtime.container.ADT):
422-
# the fields array of an ADT cannot be directly accessed in Python
423-
# so we have to get the length and index into the fields separately
424-
fields = ", ".join([render_object(val[i]) for i in range(len(val))])
425-
# special case: tag = 0 is a tuple
426-
if val.tag == 0:
427-
return f"({fields})"
428-
return f"ADT(tag={val.tag}, fields=[{fields}])"
429419
if isinstance(val, tvm.ir.Array):
430420
fields = ", ".join([render_object(val[i]) for i in range(len(val))])
431421
return f"({fields})"

python/tvm/runtime/container.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"""Runtime container structures."""
1818
import tvm._ffi
1919
from .object import Object, PyNativeObject
20-
from .object_generic import ObjectTypes
2120
from . import _ffi_api
2221

2322

@@ -60,58 +59,6 @@ def getitem_helper(obj, elem_getter, length, idx):
6059
return elem_getter(obj, idx)
6160

6261

63-
@tvm._ffi.register_object("runtime.ADT")
64-
class ADT(Object):
65-
"""Algebatic data type(ADT) object.
66-
67-
Parameters
68-
----------
69-
tag : int
70-
The tag of ADT.
71-
72-
fields : list[Object] or tuple[Object]
73-
The source tuple.
74-
"""
75-
76-
def __init__(self, tag, fields):
77-
for f in fields:
78-
assert isinstance(
79-
f, ObjectTypes
80-
), f"Expect object or tvm NDArray type, but received : {type(f)}"
81-
self.__init_handle_by_constructor__(_ffi_api.ADT, tag, *fields)
82-
83-
@property
84-
def tag(self):
85-
return _ffi_api.GetADTTag(self)
86-
87-
def __getitem__(self, idx):
88-
return getitem_helper(self, _ffi_api.GetADTFields, len(self), idx)
89-
90-
def __len__(self):
91-
return _ffi_api.GetADTSize(self)
92-
93-
94-
def tuple_object(fields=None):
95-
"""Create a ADT object from source tuple.
96-
97-
Parameters
98-
----------
99-
fields : list[Object] or tuple[Object]
100-
The source tuple.
101-
102-
Returns
103-
-------
104-
ret : ADT
105-
The created object.
106-
"""
107-
fields = fields if fields else []
108-
for f in fields:
109-
assert isinstance(
110-
f, ObjectTypes
111-
), f"Expect object or tvm NDArray type, but received : {type(f)}"
112-
return _ffi_api.Tuple(*fields)
113-
114-
11562
@tvm._ffi.register_object("runtime.String")
11663
class String(str, PyNativeObject):
11764
"""TVM runtime.String object, represented as a python str.

python/tvm/runtime/name_transforms.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)