heterocl.tvm.api module

Functions defined in TVM.

all(*args)[source]
Create a new experssion of the intersection of all conditions in the

arguments

Parameters

args (list) – List of symbolic boolean expressions

Returns

expr – Expression

Return type

Expr

any(*args)[source]

Create a new experssion of the union of all conditions in the arguments

Parameters

args (list) – List of symbolic boolean expressions

Returns

expr – Expression

Return type

Expr

const(value, dtype=None)[source]

construct a constant

convert(value)[source]

Convert value to TVM node or function.

Parameters

value (python value) –

Returns

tvm_val – Converted value in TVM

Return type

Node or Function

decl_buffer(shape, dtype=None, name='buffer', data=None, strides=None, elem_offset=None, scope='', data_alignment=-1, offset_factor=0)[source]

Decleare a new symbolic buffer.

Normally buffer is created automatically during lower and build. This is only needed if user want to specify their own buffer layout.

See the note below for detailed discussion on usage of buffer.

Parameters
  • shape (tuple of Expr) – The shape of the buffer.

  • dtype (str, optional) – The data type of the buffer.

  • name (str, optional) – The name of the buffer.

  • data (Var, optional) – The data pointer in the buffer.

  • strides (array of Expr) – The stride of the buffer.

  • elem_offset (Expr, optional) – The beginning offset of the array to data. In terms of number of elements of dtype.

  • scope (str, optional) – The storage scope of the buffer, if not global. If scope equals empty string, it means it is global memory.

  • data_alignment (int, optional) – The alignment of data pointer in bytes. If -1 is passed, the alignment will be set to TVM’s internal default.

  • offset_factor (int, optional) – The factor of elem_offset field, when set, elem_offset is required to be multiple of offset_factor. If 0 is pssed, the alignment will be set to 1. if non-zero is passed, we will created a Var for elem_offset if elem_offset is not None.

Returns

buffer – The created buffer

Return type

Buffer

Note

Buffer data structure reflects the DLTensor structure in dlpack. While DLTensor data structure is very general, it is usually helpful to create function that only handles specific case of data structure and make compiled function benefit from it.

If user pass strides and elem_offset is passed as None when constructing the function, then the function will be specialized for the DLTensor that is compact and aligned. If user pass a fully generic symbolic array to the strides, then the resulting function becomes fully generic.

load_json(json_str)[source]

Load tvm object from json_str.

Parameters

json_str (str) – The json string

Returns

node – The loaded tvm node.

Return type

Node

max_value(dtype)[source]

maximum value of dtype

min_value(dtype)[source]

minimum value of dtype

save_json(node)[source]

Load tvm object as json string.

Parameters

node (Node) – A TVM Node object to be saved.

Returns

json_str – Saved json string.

Return type

str

select(cond, t, f)[source]

Construct a select branch :param cond: The condition :type cond: Expr :param t: The result expression if cond is true. :type t: Expr :param f: The result expression if cond is false. :type f: Expr

Returns

node – The tvm.expr.Select node

Return type

Node