# 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_intrin(dtype, func_name, *args) Build expression by calling an intrinsic function. tvm.call_pure_extern(dtype, func_name, *args) Build expression by calling a pure extern function. tvm.call_extern(dtype, func_name, *args) Build expression by calling a extern function. tvm.call_llvm_intrin(dtype, name, *args) Build expression by calling an llvm intrinsic function tvm.register_intrin_rule(target, intrin[, …]) Register an intrinsic function generation rule. tvm.if_then_else(cond, t, f) Conditional selection expression. tvm.exp(x) Take exponetial of input x. tvm.log(x) Take log of input x. tvm.floor(x) Take floor of float input x. tvm.ceil(x) Take ceil of float input x. tvm.trunc(x) Get truncated value of the input. tvm.round(x) Round elements of the array to the nearest integer. tvm.abs(x) Get absolute value of the input element-wise.
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. call – The call expression. Expr

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. call – The call expression. Expr
tvm.call_intrin(dtype, func_name, *args)

Build expression by calling an 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. call – The call expression. 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. call – The call expression. Expr
tvm.call_extern(dtype, func_name, *args)

Build expression by calling a extern function.

Parameters: dtype (str) – The data type of the result. func_name (str) – The extern function name. args (list) – Positional arguments. call – The call expression. Expr
tvm.call_llvm_intrin(dtype, name, *args)

Build expression by calling an llvm intrinsic function

Parameters: dtype (str) – The data type of the result. name (str) – The name of the llvm intrinsic function. args (list) – Poistional arguments. call – The call expression. 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. fregister – Register function if f is not specified. function

Examples

The following code registers exp expansion rule for opencl.

register_intrin_rule("opencl", "exp", my_exp_rule, override=True)

tvm.if_then_else(cond, t, f)

Conditional selection expression.

Parameters: cond (Expr) – The condition t (Expr) – The result expression if cond is true. f (Expr) – The result expression if cond is false. result – The result of conditional expression. Node

Note

Unlike Select, if_then_else will not execute the branch that does not satisfy the condition. You can use it to guard against out of bound access. Unlike Select, if_then_else cannot be vectorized if some lanes in the vector have different conditions.

tvm.exp(x)

Take exponetial of input x.

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

Take log of input x.

Parameters: x (Expr) – Input argument. y – The result. Expr
tvm.floor(x)

Take floor of float input x.

Parameters: x (Expr) – Input argument. y – The result. Expr
tvm.ceil(x)

Take ceil of float input x.

Parameters: x (Expr) – Input argument. y – The result. Expr
tvm.trunc(x)

Get truncated value of the input.

The truncated value of the scalar x is the nearest integer i which is closer to zero than x is.

Parameters: x (Expr) – Input argument. y – The result. Expr
tvm.round(x)

Round elements of the array to the nearest integer.

Parameters: x (Expr) – Input argument. y – The result. Expr
tvm.abs(x)

Get absolute value of the input element-wise.

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