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.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.
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_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.
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.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.
Returns:

call – The call expression.

Return type:

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.
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
tvm.floor(x)

Take floor of float input x.

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

Take ceil of float input x.

Parameters:x (Expr) – Input argument.
Returns:y – The result.
Return type: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.
Returns:y – The result.
Return type:Expr
tvm.round(x)

Round elements of the array to the nearest integer.

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

Get absolute value of the input element-wise.

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