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

Schedule creation error with hcl.if_ when used with hcl.or_ #138

Closed jcasas00 closed 1 year ago

jcasas00 commented 2 years ago
def test_if_LogicalOr():
    hcl.init()
    def kernel():
        a = hcl.scalar(0, "a", dtype=hcl.UInt(8))
        b = hcl.scalar(0, "a", dtype=hcl.UInt(8))

        # this generates the following error:
        #   File "hcl-dialect-prototype/build/tools/hcl/python_packages/hcl_core/hcl_mlir/build_ir.py", line 2630, in make_if
        #     raise HCLValueError("`if` operation condition should be CmpOp")
        # hcl_mlir.exceptions.HCLValueError: [Value Error] `if` operation condition should be CmpOp
        with hcl.if_(hcl.or_(a.v == 0, b.v == 0)):
            pass

        # this generates the following error:
        #  File "hcl-dialect-prototype/build/tools/hcl/python_packages/hcl_core/hcl_mlir/build_ir.py", line 1726, in build
        #      raise APIError("Do not build logical_or op")
        #  hcl_mlir.exceptions.APIError: [API] Do not build logical_or op
        with hcl.if_(hcl.or_(a.v == 0, b.v == 0) != 0):
            pass

    s = hcl.create_schedule([], kernel)

Very similar to #135 (which is about hcl.while and hcl.and)

zzzDavid commented 2 years ago

logical or hasn't been implemented yet.

Relevant discussion threads:

My plan is to first add hcl.and and hcl.or representing logical operations with short-circuit evaluation, and then use nested scf.if to implement them in LLVM backend. We will decouple condition evaluation and if/while operations, see details at #65.

zzzDavid commented 1 year ago

Status update on this issue:

The new frontend build SCF operations for and/or, so there is no problem with affine_set not being able to support or anymore, and the above test case works.

We have not yet added logic operation that supports short-circuit evaluation yet.

zzzDavid commented 1 year ago

Test case added by cornell-zhang/heterocl@9f7212f02dcf49e72fe6a980ace86e9f8b591f4d Closing this thread because the issue has been resolved. Short-circuit logic op will be discussed in thread #65