cornell-zhang/hcl-dialect

TensorSlice dtype invalid

Closed this issue · 2 comments

Running the following code:

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
            t3 = hcl.get_bitwidth(z1.dtype)          # this doesn't fail
            t4 = hcl.get_bitwidth(t.dtype)            # this generates an error (below)
        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")

File "/home/jcasas/dprive/projects.research.advis-mlir/python/advis/designlib/test_slice.py", line 12, in do
t4 = hcl.get_bitwidth(t.dtype)
File "/home/jcasas/dprive/heterocl_mlir/python/heterocl/types.py", line 190, in get_bitwidth
dtype = dtype_to_hcl(dtype)
File "/home/jcasas/dprive/heterocl_mlir/python/heterocl/types.py", line 175, in dtype_to_hcl
raise DTypeError("Unrecognized data type format")
heterocl.debug.DTypeError: [Data Type] Unrecognized data type format

The dtype_to_hcl and dtype_to_str API did not support MLIR type input. This is added by this commit in the front-end:
cornell-zhang/heterocl@acbf6ef

This issue will be closed after test cases are added.

The test case is added at mlir/test_dsl_basic.py::test_tensor_slice_dtype by commit cornell-zhang/heterocl@1201426