What's the differences between relay.Call and _expr.Call()?

Hi, I am new to TVM. I have a question about these two calls:

It seems relay.Call needs a relay.Function as an input.

    vars = relay.analysis.free_vars(ethosn_expr)
    func = relay.Function([relay.Var("a")], ethosn_expr)
    func = func.with_attr("Composite", name)
    call = relay.Call(func, vars)

expr.Call is Function call node in Relay. It is to create a CallNode, right?

    def __init__(self, op, args, attrs=None, type_args=None, span=None):
        if not type_args:
            type_args = []
        self.__init_handle_by_constructor__(_ffi_api.Call, op, args, attrs, type_args, span)

Per comments, what does it mean relay.Expr with function type?

    Parameters
    ----------
    op: tvm.ir.Op or any tvm.relay.Expr with function type.
        The operation to be called.

example:

        if isinstance(tuple_value, _expr.Call):
            tuple_value = _expr.Call(tuple_value.op, tuple_value.args,
                                     tuple_value.attrs, tuple_value.type_args,
                                     span)

Thanks a lot.

Hi @wenxian,

relay.Call means a function call, the op field of it can be tvm.Op (meaning calling a relay operator), or relay.Function, relay.GlobalVar, relay.Var as long as they evaluate to a function: https://github.com/apache/tvm/blob/main/include/tvm/relay/expr.h#L293-L296.

“relay.Expr with function type” in the comment on the python side means the op field can be expressions such as relay.Function, relay.GlobalVar, relay.Var as long as they are of type FunctionType, which refer to functions.

@yuchenj I’m still confused, expr.Call is able to create a CallNode. But relay.Call is a function call? your link pasted: https://github.com/apache/tvm/blob/main/include/tvm/relay/expr.h#L293-L296 it is a CallNode, so you mean relay.Call will create a CallNode instead of expr.Call?

Moreover, there’s a class Op, what’s the differences between this Op and the op in CallNode?

class Op : public RelayExpr {
...
}

relay.expr.Call is the same as relay.Call: tvm/relay/init.py.

The Op class is a RelayExpr, it’s an expression (IR node) used to refer to a built-in Relay operator such as conv2d or relu. “op” in CallNode is a field name representing the callee of the CallNode, it’s of type RelayExpr (note that Op class is a subclass of RelayExpr). So this field can be an Op (representing calling a built-in operator in this context), or other expressions such as relay.Function, relay.GlobalVar, relay.Var.

Relay has a language spec that you might be interested in: Expressions in Relay — tvm 0.11.dev0 documentation.

1 Like