Skip to content

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

Open
ezw2 wants to merge 1 commit intocornell-zhang:tvmfrom
ezw2:add_tensor_slice
Open

[API] Add support for getting and setting tensor slices#404
ezw2 wants to merge 1 commit intocornell-zhang:tvmfrom
ezw2:add_tensor_slice

Conversation

@ezw2
Copy link
Copy Markdown
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.

2 participants