[Frontend] Tensor indexing issue
zzzDavid opened this issue · 5 comments
zzzDavid commented
The following code reports error:
z1 = hcl.compute((2,3,4), lambda x,y,z: 0, dtype=hcl.Int(32))
def do(i,j,k):
z1[0][0][0] = 55
hcl.mutate(z1.shape, do)
hcl-dialect-prototype/build/tools/hcl/python_packages/hcl_core/hcl_mlir/build_ir.py", line 997, in __setitem__
raise TensorError("Indices length > # of array dimensions")
TypeError: __init__() missing 1 required positional argument: 'line'
jcasas00 commented
Behavior still isn't quite the same as in the main branch. If the do loop looked like:
def do(i,j,k):
t = z1[0][0] # a slice
t[0] = 53
then I get the same error. The reason for doing this is that we could pass the variable t to other functions (a 1-D tensorslice).
zzzDavid commented
Reopening this issue
zzzDavid commented
hmmm I couldn't repeat this issue, I tried this:
def test_tensor_slice():
hcl.init()
def kernel():
z1 = hcl.compute((2,3,4), lambda x,y,z: 0, dtype=hcl.Int(32))
def do(i,j,k):
t = z1[0][0]
t[0] = 53
hcl.mutate(z1.shape, do)
return z1
s = hcl.create_schedule([], kernel)
hcl_res = hcl.asarray(np.zeros((2,3,4), dtype=np.int32))
f = hcl.build(s)
f(hcl_res)
np_res = hcl_res.asnumpy()
golden = np.zeros((2,3,4), dtype=np.int32)
golden[0][0][0] = 53
assert np.array_equal(golden, np_res)
print("test_tensor_slice passed")
test_tensor_slice()
And I got the test passed output:
Using mlir as IR
Done HCL-MLIR initialization
test_tensor_slice passed
@jcasas00 are you using the latest HeteroCL HCL-MLIR branch?
zzzDavid commented
Turns out it's issue with __getitem__
API on tensor slice. Fixed by 3d1f429, I will close this issue later after I add more tests
zzzDavid commented
The following tests are added by commit cornell-zhang/heterocl@c7d72ee:
mlir/test_dsl_basic.py::test_tensor_slice_mutate PASSED
mlir/test_dsl_basic.py::test_get_bit_expr_mutate PASSED
mlir/test_dsl_basic.py::test_set_bit_expr_mutate PASSED
mlir/test_dsl_basic.py::test_set_bit_tensor_mutate PASSED
mlir/test_dsl_basic.py::test_get_slice_expr_mutate PASSED
mlir/test_dsl_basic.py::test_get_slice_tensor_mutate PASSED
mlir/test_dsl_basic.py::test_get_slice_tensor_reverse_mutate PASSED
mlir/test_dsl_basic.py::test_set_slice_expr_mutate PASSED
mlir/test_dsl_basic.py::test_set_slice_tensor_mutate PASSED
mlir/test_dsl_basic.py::test_set_slice_tensor_reverse_mutate PASSED
mlir/test_dsl_basic.py::test_slice_op_mutate PASSED