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

[TVMScript][TIR] Parse subroutine calls with no arguments #14919

Merged
merged 3 commits into from
May 28, 2023
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
14 changes: 13 additions & 1 deletion python/tvm/script/parser/tir/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,25 @@ def visit_expr_stmt(self: Parser, node: doc.Expr) -> None:
The doc AST Expr node.
"""
res = self.eval_expr(node.value)
if isinstance(res, Frame):
if res is None:
pass
elif isinstance(res, Frame):
res.add_callback(partial(res.__exit__, None, None, None))
res.__enter__()
elif isinstance(res, PrimExpr):
T.evaluate(res)
elif isinstance(res, (int, bool)):
T.evaluate(tvm.tir.const(res))
elif isinstance(res, tvm.relay.Call) and not res.args:
# Using GlobalVar.__call__ with no arguments is ambiguous, as
# each IR has a different function Call representation. If
# this occurs, convert to the TIR representation.
T.evaluate(tvm.tir.call_tir(res.op))
elif isinstance(res, str):
# Ignore docstrings
pass
else:
self.report_error(node, f"Parsing resulted in unexpected type {type(res)}")


@dispatch.register(token="tir", type_name="If")
Expand Down
19 changes: 19 additions & 0 deletions tests/python/unittest/test_tvmscript_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3855,6 +3855,24 @@ def func():
return func


def subroutine_call_without_arguments():
@I.ir_module
class mod:
@T.prim_func
def main():
# Should be equivalent to the bare "mod.subroutine()", but
# that relies on `GlobalVar.__call__` returning the
# correct IR type. Previously, this instead returned a
# `relay.Call` object.
tir.call_tir(mod.subroutine)

@T.prim_func
def subroutine():
T.evaluate(0)

return mod


ir_generator = tvm.testing.parameter(
launch_env_thread,
opt_gemm_normalize,
Expand Down Expand Up @@ -3929,6 +3947,7 @@ def func():
undefined_shape_in_decl_buffer,
undefined_stride_in_decl_buffer,
undefined_elem_offset_in_decl_buffer,
subroutine_call_without_arguments,
)


Expand Down