cornell-zhang/hcl-dialect

hcl.cast doesn't accept string type descriptors

Closed this issue · 4 comments

v = hcl.cast('uint16', xy.x)

generates:

File "python/advis/designlib/test_list.py", line 78, in kernel
v = hcl.cast('uint16', xy.x)
File "heterocl_mlir/python/heterocl/operation.py", line 100, in cast
return hcl_mlir.CastOp(expr, hcl_dtype_to_mlir(dtype))
File "heterocl_mlir/python/heterocl/utils.py", line 41, in hcl_dtype_to_mlir
raise RuntimeError("Not supported type")

This support is added by cornell-zhang/heterocl@d57bfe8

I just tried this test case and it works on my side:

def test_struct_scalar_twice():
    hcl.init()

    dt8='int8'
    dt32=hcl.Int(32)
    def kernel():
        stype = hcl.Struct({"x": dt8, "y": dt8})
        xy = hcl.scalar(0x12, "foo", dtype=stype).v

        stype2 = hcl.Struct({"a": dt8, "b": dt8})
        v = hcl.cast('int16', xy.x)
        ab = hcl.scalar(v, "ab", dtype=stype2).v                               

        r = hcl.compute((2,), lambda i: 0, dtype=dt32)
        r[0] = xy.y
        r[1] = ab.a
        return r
    s = hcl.create_schedule([], kernel)
    hcl_res = hcl.asarray(np.zeros((2,), dtype=np.int32), dtype=dt32)
    f = hcl.build(s)
    f(hcl_res)
    assert hcl_res.asnumpy()[1] == 0x12

Confirming that it works on my end as well. Thanks.

Closing this thread as text dtype has been supported by hcl.cast