tvm.intrin

Expression Intrinsics and math functions in TVM.

tvm.call_packed(*args) Build expression by call an external packed function.
tvm.call_pure_intrin(dtype, func_name, *args) Build expression by calling a pure intrinsic function.
tvm.call_pure_extern(dtype, func_name, *args) Build expression by calling a pure extern function.
tvm.register_intrin_rule(target, intrin[, …]) Register an intrinsic function generation rule.
tvm.exp(x) Take exponetial of input x.
tvm.log(x) Take log of input x.
tvm.call_packed(*args)

Build expression by call an external packed function.

The argument to packed function can be Expr or Buffer. The argument is the corresponding POD type when Expr is presented.

When the argument is Buffer, the corresponding PackedFunc will recieve an TVMArrayHandle whose content is valid during the callback period. If the PackedFunc is a python callback, then the corresponding argument is NDArray.

Parameters:args (list of Expr or Buffer.) – Positional arguments.
Returns:call – The call expression.
Return type:Expr

See also

tvm.extern()
Create tensor with extern function call.
tvm.call_pure_intrin(dtype, func_name, *args)

Build expression by calling a pure intrinsic function.

Intrinsics can be overloaded with multiple data types via the intrinsic translation rule.

Parameters:
  • dtype (str) – The data type of the result.
  • func_name (str) – The intrinsic function name.
  • args (list) – Positional arguments.
Returns:

call – The call expression.

Return type:

Expr

tvm.call_pure_extern(dtype, func_name, *args)

Build expression by calling a pure extern function.

Parameters:
  • dtype (str) – The data type of the result.
  • func_name (str) – The extern function name.
  • args (list) – Positional arguments.
Returns:

call – The call expression.

Return type:

Expr

tvm.register_intrin_rule(target, intrin, f=None, override=False)

Register an intrinsic function generation rule.

Intrinsic generation rules are callback functions for code generator to get device specific calls. This function simply translates to.

register_func("tvm.intrin.rule.%s.%s" % (target, intrin), f, override)

TVM may already pre-register intrinsic rules in the backend. However, user can use this function to change the intrinsic translation behavior or add new intrinsic rules during runtime.

Parameters:
  • target (str) – The name of codegen target.
  • intrin (str) – The name of the instrinsic.
  • f (function, optional) – The function to be registered.
  • override (boolean optional) – Whether override existing entry.
Returns:

fregister – Register function if f is not specified.

Return type:

function

Examples

The following code registers exp expansion rule for opencl.

register_intrin_rule("opencl", "exp", my_exp_rule, override=True)
tvm.exp(x)

Take exponetial of input x.

Parameters:x (Expr) – Input argument.
Returns:y – The result.
Return type:Expr
tvm.log(x)

Take log of input x.

Parameters:x (Expr) – Input argument.
Returns:y – The result.
Return type:Expr