cornell-zhang / hcl-dialect

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

Schedule creation error with hcl.if_ and struct field access in the condition #141

Closed jcasas00 closed 1 year ago

jcasas00 commented 2 years ago
def test_if_struct_access():
    hcl.init()

    def kernel():
        tag = hcl.scalar(0, "tag", dtype='uint32')

        stype = hcl.Struct({"x": hcl.UInt(8), "y": hcl.UInt(8)})
        xy = hcl.scalar(0x1234, "xy", dtype=stype).v

        with hcl.if_(xy.x==1):  # use of struct field access causes a scheduler error
            tag.v = 1

        r = hcl.compute((2,), lambda i: tag.v, dtype=hcl.UInt(32))
        return r
    s = hcl.create_schedule([], kernel)

The above code generates the following runtime error:

error: 'affine.load' op operation destroyed but still has uses LLVM ERROR: operation destroyed but still has uses

zzzDavid commented 2 years ago

Fails at: https://github.com/cornell-zhang/hcl-dialect-prototype/blob/4704d17e46b2df07f8074857b706b82c8c671c06/include/hcl/Bindings/Python/hcl/build_ir.py#L2646-L2647

@chhzh123 why do we remove built condition operations here?

zzzDavid commented 1 year ago

Fixed by 7906b266f816e2b44b67d2576b66242b0f6e4af3

Added remove and profile mode for struct op visitors

zzzDavid commented 1 year ago

Test case added here: https://github.com/cornell-zhang/heterocl/blob/9f7212f02dcf49e72fe6a980ace86e9f8b591f4d/tests/test_scalar.py#L87-L125

Closing the thread as the issue has been fixed