Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Add support for getting and setting tensor slices #404

Open
wants to merge 1 commit into
base: tvm
Choose a base branch
from

Conversation

ezw2
Copy link
Contributor

@ezw2 ezw2 commented Aug 5, 2021

Add feature: Added support for getting and setting tensor slices

How to use the new feature:

  1. Copy a slice of a tensor
A = hcl.placeholder((10,))
B = hcl.copy(A[2:5])
# equivalent API
B = hcl.compute((3,), lambda x: A[x+2])
  1. Set a slice of a tensor
A = hcl.placeholder((10,))
B = hcl.placeholder((15,))
A[2:5] =B[4:7]
A[2:5] = 4  # broadcast

  1. Get a slice of a tensor without making a copy
A = hcl.placeholder((10, 10))
B = A[2:5]
B[0] = 1
hcl.print(A[2]) # returns 1

Description: Most of the changes were in tensor.py where additional logic had to be added to handle slices in the list of indices. In the TensorSlice class, indices immediately following one or more slice had to be shifted so that the correct element would be accessed (as demonstrated in the third example). get_index in util.py also had to be modified to return the correct index when a slice of a tensor was being set.

Link to the tests: The tests are in heterocl/tests/test_dsl_tensorslice.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant