heterocl.tensor

HeteroCL tensors and scalars.

class Scalar(var)[source]

Bases: heterocl.tvm._ffi.node_generic.NodeGeneric, heterocl.tvm.expr.ExprOp

A non-mutable scalar.

This should be used by heterocl.placeholder only. Valid usages of accessing a scalar include direct access and bit operations.

Parameters

var (Var) – A TVM variable

Variables
  • var (Var) – The wrapped TVM variable

  • dtype (Type) – The data type of the scalar

Examples

# use () to specify it is a non-mutable scalar
a = hcl.placeholder((), "a")
# direct access
b = a + 5
# bit operations
c = a[2] # the third bit of a
d = a[3:5] # get a slice of a
asnode()[source]

Convert value to node

class Tensor(shape, dtype='int32', name='tensor', buf=None)[source]

Bases: heterocl.tvm._ffi.node_generic.NodeGeneric, heterocl.tvm.expr.ExprOp

A HeteroCL tensor.

This is a wrapper for a TVM tensor. It should be generated from HeteroCL compute APIs.

Parameters
  • shape (tuple of int) – The shape of the tensor

  • dtype (Type, optional) – The data type of the tensor

  • name (str, optional) – The name of the tensor

  • buf (Buffer, optional) – The TVM buffer of the tensor

Variables
  • dtype (Type) – The data type of the tensor

  • name (str) – The name of the tensor

  • var_dict (dict(str, Var)) – A dictionary that maps between a name and a variable

  • first_update (Stage) – The first stage that updates the tensor

  • last_update (Stage) – The last stage that updates the tensor

  • tensor (Operation) – The TVM tensor

  • buf (Buffer) – The TVM buffer

  • type (Type) – The data type in HeteroCL format

  • op (Stmt) – The operation statement

  • axis (list of IterVar) – A list of axes of the tensor

  • v (Expr) – Syntactic sugar to access the element of an single-element tensor

asnode()[source]

Convert value to node

class TensorSlice(tensor, indices, dtype=None)[source]

Bases: heterocl.tvm._ffi.node_generic.NodeGeneric, heterocl.tvm.expr.ExprOp

A helper class for tensor operations.

Valid tensor accesses include: 1. getting an element from a tensor 2. bit operations on the element. We do not support operations on a slice of tensor.

Parameters
  • tensor (Tensor) – The target tensor

  • indices (int or tuple of int) – The indices to access the tensor

Variables
  • tensor (Tensor) – The target tensor

  • indices (int or tuple of int) – The indices to access the tensor

  • dtype (Type) – The data type of the tensor

Examples

A = hcl.placeholder((10,), "A")
# get a single element
a = A[5]
# bit operations on a single element
b = A[5][2]
c = A[5][3:7]

# not allowed: A[5:7]
asnode()[source]

Convert value to node