cornell-zhang / hcl-dialect

HeteroCL-MLIR dialect for accelerator design
https://cornell-zhang.github.io/heterocl/index.html
Other
40 stars 17 forks source link

TensorSlice dtype invalid #132

Closed jcasas00 closed 2 years ago

jcasas00 commented 2 years ago

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

zzzDavid commented 2 years ago

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@acbf6ef3225a2410b7ab7a52017f1b9e434cc062

This issue will be closed after test cases are added.

zzzDavid commented 2 years ago

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