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
See also
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
-
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
- 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
See also
-
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
- Variables
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]