heterocl.tvm.intrin module

Expression Intrinsics and math functions in TVM.

call_extern(dtype, func_name, *args)[source]

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

call_intrin(dtype, func_name, *args)[source]

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

call_packed(*args)[source]

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.

call_pure_extern(dtype, func_name, *args)[source]

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

call_pure_intrin(dtype, func_name, *args)[source]

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

cos(x)[source]

Take cosine of input x.

Parameters

x (Expr) – Input argument.

Returns

y – The result.

Return type

Expr

exp(x)[source]

Take exponetial of input x.

Parameters

x (Expr) – Input argument.

Returns

y – The result.

Return type

Expr

log(x)[source]

Take log of input x.

Parameters

x (Expr) – Input argument.

Returns

y – The result.

Return type

Expr

popcount(x)[source]

Count the number of set bits in input x.

Parameters

x (Expr) – Input argument.

Returns

y – The result.

Return type

Expr

power(x, y)[source]

x power y

Parameters
  • x (Expr) – Input argument.

  • y (Expr) – The exponent

Returns

z – The result.

Return type

Expr

register_intrin_rule(target, intrin, f=None, override=False)[source]

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)
sigmoid(x)[source]

Quick function to get sigmoid

Parameters

x (Expr) – Input argument.

Returns

y – The result.

Return type

Expr

sin(x)[source]

Take sine of input x.

Parameters

x (Expr) – Input argument.

Returns

y – The result.

Return type

Expr

sqrt(x)[source]

Take log of input x.

Parameters

x (Expr) – Input argument.

Returns

y – The result.

Return type

Expr

tanh(x)[source]

Take hyperbolic tanh of input x.

Parameters

x (Expr) – Input argument.

Returns

y – The result.

Return type

Expr