MCPcopy Create free account
hub / github.com/apache/tvm / DataflowBlockRewrite

Class DataflowBlockRewrite

python/tvm/relax/binding_rewrite.py:29–158  ·  view source on GitHub ↗

A binding/statement-level dataflow block rewriter. Notes ----- Due to the immutable and copy-on-write nature of TVM AST nodes, the rewriting is not done in place. Instead, a new DataflowBlock is created and returned with mutated_dfb. Similarly, its new root Function is crea

Source from the content-addressed store, hash-verified

27
28@tvm_ffi.register_object("relax.DataflowBlockRewrite")
29class DataflowBlockRewrite(Object):
30 """
31 A binding/statement-level dataflow block rewriter.
32
33 Notes
34 -----
35 Due to the immutable and copy-on-write nature of TVM AST nodes, the rewriting is not done in
36 place. Instead, a new DataflowBlock is created and returned with mutated_dfb. Similarly, its new
37 root Function is created and returned by mutated_root_fn. To apply this change for an IRModule,
38 use mutate_irmodule which rewrites the old function that registered in the constructor.
39 """
40
41 __slots__ = ("__dict__",)
42
43 def __init__(self, dfb: DataflowBlock, root_fn: Function):
44 """
45 Construct a rewriter with the DataflowBlock to rewrite and its root function.
46
47 Parameters
48 ----------
49 dfb : DataflowBlock
50 The DataflowBlock to rewrite.
51 root_fn : Function
52 The root function of the DataflowBlock.
53 """
54 self.func_name = root_fn.__name__ if hasattr(root_fn, "__name__") else None
55 self.__init_handle_by_constructor__(
56 _ffi_api.DataflowBlockRewrite,
57 dfb,
58 root_fn, # type: ignore
59 )
60
61 def replace_all_uses(self, old_var: Var, new_var: Var) -> None:
62 """
63 Replace all uses of old_var with new_var.
64
65 Parameters
66 ----------
67 old_var : Var
68 The old variable to replace.
69 new_var : Var
70 The new variable to replace with.
71 """
72 _ffi_api.dfb_rewrite_replace_all_uses(self, old_var, new_var) # type: ignore
73
74 def add_binding(self, binding: Binding) -> None:
75 return _ffi_api.dfb_rewrite_add_binding(self, binding) # type: ignore
76
77 def add(self, expr: Expr, name: str | None = None, is_dfvar: bool = False) -> None:
78 """
79 Add a new statement to the DataflowBlock with an automatically generated variable name.
80
81 Parameters
82 ----------
83 expr : Expr
84 The expression to add.
85 name : Optional[str], optional
86 Variable name, by default None

Callers 12

test_null_constructFunction · 0.90
test_simple_addFunction · 0.90
test_simple_auto_add_varFunction · 0.90
test_remove_unused_undefFunction · 0.90

Calls

no outgoing calls

Tested by 12

test_null_constructFunction · 0.72
test_simple_addFunction · 0.72
test_simple_auto_add_varFunction · 0.72
test_remove_unused_undefFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…