Skip to content
Open
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
2 changes: 1 addition & 1 deletion 3rdparty/tvm-ffi
Submodule tvm-ffi updated 120 files
1 change: 1 addition & 0 deletions include/tvm/runtime/device_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define TVM_RUNTIME_DEVICE_API_H_

#include <tvm/ffi/any.h>
#include <tvm/ffi/device.h>
#include <tvm/ffi/error.h>
#include <tvm/ffi/optional.h>
#include <tvm/ffi/string.h>
Expand Down
1 change: 1 addition & 0 deletions include/tvm/script/printer/ir_docsifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef TVM_SCRIPT_PRINTER_IR_DOCSIFIER_H_
#define TVM_SCRIPT_PRINTER_IR_DOCSIFIER_H_

#include <tvm/ffi/device.h>
#include <tvm/ffi/reflection/access_path.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ir/module.h>
Expand Down
6 changes: 6 additions & 0 deletions python/tvm/ir/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class IRModule(Node, Scriptable):
Map of global var to BaseFunc
"""

# Opt into a per-instance ``__dict__``: ``IRModule`` stores the Python-only
# ``pyfuncs`` mapping. The base ``Object`` metaclass otherwise injects
# ``__slots__ = ()`` (required by the tvm-ffi lifetime model), which would
# forbid setting attributes.
__slots__ = ("__dict__",)

def __init__(self, functions=None, attrs=None, global_infos=None):
if functions is None:
functions = {}
Expand Down
6 changes: 6 additions & 0 deletions python/tvm/relax/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ def __init__(self, blocks: list[BindingBlock], body: Expr, span: Span | None = N
class Function(BaseFunc, Scriptable):
"""A Relax function."""

# Opt into a per-instance ``__dict__``: callers attach ``__name__`` to the
# function (e.g. DataflowBlockRewrite.mutated_root_fn). The base ``Object``
# metaclass otherwise injects ``__slots__ = ()`` (required by the tvm-ffi
# lifetime model), which would forbid setting attributes.
__slots__ = ("__dict__",)

params: list[Var]
body: Expr
ret_ty: Type
Expand Down
6 changes: 6 additions & 0 deletions python/tvm/runtime/_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class Tensor(tvm_ffi.core.Tensor):
how can we use TVM in existing project which might have their own array containers.
"""

# Keep the same instance layout as ``tvm_ffi.core.Tensor``: the FFI runtime
# registers ``ffi.Tensor`` to its base wrapper and rejects re-registration
# with a larger wrapper (a subclass without ``__slots__`` would add
# ``__dict__``/``__weakref__`` and grow ``__basicsize__``).
__slots__ = ()

def __setitem__(self, in_slice, value):
"""Set ndarray value"""
if (
Expand Down
6 changes: 6 additions & 0 deletions python/tvm/runtime/script_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ def _relax_script(obj: Object, config: PrinterConfig) -> str:
class Scriptable:
"""A base class that enables the script() and show() method."""

# Empty slots so this mixin does not add ``__dict__``/``__weakref__`` to the
# FFI object subclasses that combine it with a slotted ``Object``/``Node``.
# The tvm-ffi lifetime model rejects registering a wrapper whose instance
# layout is larger than the base wrapper already registered for the type.
__slots__ = ()

def script(
self,
*,
Expand Down
6 changes: 6 additions & 0 deletions python/tvm/te/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ def astype(self, dtype, span=None):
class TensorOpBase:
"""Operator overloads for whole TE Tensor values."""

# Empty slots so this mixin does not add ``__dict__``/``__weakref__`` to the
# FFI object subclasses that combine it with a slotted ``Object``/``Node``.
# The tvm-ffi lifetime model rejects registering a wrapper whose instance
# layout is larger than the base wrapper already registered for the type.
__slots__ = ()

def __add__(self, other):
return _te_tensor_overload.__add__(self, other)

Expand Down
6 changes: 6 additions & 0 deletions python/tvm/tirx/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def _is_scalar_operand(value):
class ExprOp:
"""Operator overloading for Expr like expressions."""

# Empty slots so this mixin does not add ``__dict__``/``__weakref__`` to the
# FFI object subclasses that combine it with a slotted ``Object``/``Expr``.
# The tvm-ffi lifetime model rejects registering a wrapper whose instance
# layout is larger than the base wrapper already registered for the type.
__slots__ = ()

# TODO(tkonolige): use inspect to add source information to these objects

def expr_ty(self) -> ir.PrimType:
Expand Down
6 changes: 6 additions & 0 deletions python/tvm/tirx/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class PrimFunc(BaseFunc, Scriptable):
The location of this itervar in the source code.
"""

# Opt into a per-instance ``__dict__``: the TVMScript parser attaches
# ``__name__`` to the parsed function. The base ``Object`` metaclass
# otherwise injects ``__slots__ = ()`` (required by the tvm-ffi lifetime
# model), which would forbid setting attributes.
__slots__ = ("__dict__",)

def __init__(self, params, body, ret_type=None, buffer_map=None, attrs=None, span=None):
# Legacy compatibility: expand body-carrying leaf stmt wrappers
# (e.g. DeclBuffer/AllocBuffer forms) into SeqStmt form.
Expand Down
12 changes: 12 additions & 0 deletions python/tvm/tirx/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ class AllocBuffer(Stmt):
The location of this AllocBuffer in the source code.
"""

# Opt into a per-instance ``__dict__``: the legacy ``body`` is carried on the
# Python side only. The base ``Object`` metaclass otherwise injects
# ``__slots__ = ()`` (required by the tvm-ffi lifetime model), which would
# forbid setting attributes.
__slots__ = ("__dict__",)

buffer: Buffer
span: Span | None

Expand Down Expand Up @@ -434,6 +440,12 @@ class DeclBuffer(Stmt):
The location of this DeclBuffer in the source code.
"""

# Opt into a per-instance ``__dict__``: the legacy ``body`` is carried on the
# Python side only. The base ``Object`` metaclass otherwise injects
# ``__slots__ = ()`` (required by the tvm-ffi lifetime model), which would
# forbid setting attributes.
__slots__ = ("__dict__",)

buffer: Buffer
span: Span | None

Expand Down
Loading