Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions python/heterocl/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,34 @@ def print_val(val):
stage = Stage.get_current()
if isinstance(val, (Scalar, _expr.Expr, numbers.Number)):
stage.emit(_make.Print([val], get_format(val) + "\n"))
elif isinstance(val, TensorSlice) \
and sum(isinstance(x, slice) for x in val.indices) > 0:
nshape = len(val.tensor.shape)
startdim = len(val.indices) - sum(isinstance(x, slice) for x in val.indices)
ndim = nshape - startdim
args = ["print_"+str(n) for n in range(0, ndim)]
ivs = [_IterVar((0, val._shape[n]), args[n-startdim], 0) for n in range(startdim, nshape)]
if ndim >= 1:
import builtins
stage.emit(print_tensor(val, ivs, ndim-1, ndim))
stage.emit(_make.Print([], "\n"))
else:
stage.emit(_make.Print([val], get_format(val) + "\n"))
elif isinstance(val, TensorSlice) \
and len(val.indices) == len(val.tensor.shape):
stage.emit(_make.Print([val], get_format(val) + "\n"))
else: # we are dealing with tensors
else:
nshape = len(val.tensor.shape)
ndim = nshape
if isinstance(val, TensorSlice):
ndim = nshape - len(val.indices)
args = ["print_"+str(n) for n in range(0, ndim)]
ivs = [_IterVar((0, val.tensor.shape[nshape-n-1]), args[n], 0) \
startdim = len(val.indices)
args = ["print_"+str(n) for n in range(startdim, nshape)]
ivs = [_IterVar((0, val.tensor.shape[n]), args[n-startdim], 0) \
for n in range(startdim, nshape)]
else:
args = ["print_"+str(n) for n in range(0, ndim)]
ivs = [_IterVar((0, val.tensor.shape[n]), args[n], 0) \
for n in range(0, ndim)]
import builtins
stage.emit(print_tensor(val, ivs, ndim-1, ndim))
Expand Down
2 changes: 1 addition & 1 deletion python/heterocl/compute_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def copy(tensor, name=None, dtype=None):
B3 = hcl.copy(nA, "B3")
"""
name = get_name("copy", name)
if isinstance(tensor, Tensor):
if isinstance(tensor, (Tensor, TensorSlice)):
return compute(
tensor.shape,
lambda *args: tensor[args],
Expand Down
Loading