Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unity][BlockBuilder] Restore bb.get() #16378

Merged
merged 2 commits into from
Jan 12, 2024
Merged
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
6 changes: 5 additions & 1 deletion include/tvm/relax/block_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ class BlockBuilderNode : public Object {
* GlobalVars in the IRModule to ensure name uniqueness and the invariant:
* every public function has the same name as its "global_symbol" attribute.
*
* \return The IRModule in this BlockBuilder.
* \note this method should be called only once at the end of the building process, since it may
* invalidate global vars previously returned by this builder. See also
* transform::NormalizeGlobalVar.
*
* \return The result IRModule.
*/
virtual IRModule Finalize() = 0;

Expand Down
13 changes: 6 additions & 7 deletions python/tvm/relax/block_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import tvm
from tvm import relax as rx
from tvm import tir
from tvm.ir.base import deprecated
from tvm.ir.module import IRModule
from tvm.runtime import Object

Expand Down Expand Up @@ -654,26 +653,26 @@ def normalize(self, expr: Expr) -> Expr:
"""
return _ffi_api.BlockBuilderNormalize(self, expr) # type: ignore

@deprecated("tvm.relax.BlockBuilder.get", "tvm.relax.BlockBuilder.finalize")
def get(self) -> tvm.IRModule:
"""Return the IRModule being built.
"""Return intermediate IRModule. For the situation where the IRModule is needed in the
middle of a building process.

Returns
-------
ret : tvm.IRModule
An IRModule with Relax and TIR functions being built.
"""
return self.finalize()
return _ffi_api.BlockBuilderGetContextIRModule(self) # type: ignore

def finalize(self) -> tvm.IRModule:
"""Finalize the building process and return the result IRModule.

Possibly rename GlobalVars in the IRModule to ensure name uniqueness and the invariant:
every public function has the same name as its "global_symbol" attribute.

Note this call may invalidate global vars previously returned by this builder
(see tvm.relax.transform.NormalizeGlobalVar), so it can only be called once at the end of
the building process.
Note this method should be called only once at the end of the building process, since it may
invalidate global vars previously returned by this builder.
See also tvm.relax.transform.NormalizeGlobalVar.

Returns
-------
Expand Down
12 changes: 8 additions & 4 deletions tests/python/relax/test_blockbuilder_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,10 @@ def te_one():
gv1 = bb.emit_te(te_one, primfunc_name_hint="func")
bb.emit_func_output((gv0, gv1))

mod = bb.finalize()
assert rx.analysis.well_formed(mod)
mod = bb.get()
assert not rx.analysis.well_formed(mod)
mod_final = bb.finalize()
assert rx.analysis.well_formed(mod_final)

# relax function call
bb = rx.BlockBuilder()
Expand All @@ -724,8 +726,10 @@ def te_one():
gv0 = bb.emit(rx.Call(gvar1, []))
bb.emit_func_output(gv0)

mod = bb.finalize()
assert rx.analysis.well_formed(mod)
mod = bb.get()
assert not rx.analysis.well_formed(mod)
mod_final = bb.finalize()
assert rx.analysis.well_formed(mod_final)


def test_emit_nested_seqexpr_in_binding_block():
Expand Down
Loading