Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__invert__ is not implemented #165

Open
jcasas00 opened this issue Oct 28, 2022 · 3 comments
Open

__invert__ is not implemented #165

jcasas00 opened this issue Oct 28, 2022 · 3 comments
Labels
MLIR Limitation MLIR limitations

Comments

@jcasas00
Copy link
Collaborator

def test_bitnot():
    hcl.init()
    rshape = (1,)
    def kernel():
        r = hcl.compute(rshape, lambda _:0, dtype=hcl.UInt(32))
        a = hcl.scalar(10, "a", dtype='uint32')
        r[0] = ~a.v
        return r
    #
    s = hcl.create_schedule([], kernel)
    print(hcl.lower(s))
    hcl_res = hcl.asarray(np.zeros(rshape, dtype=np.uint32), dtype=hcl.UInt(32))
    f = hcl.build(s)
    f(hcl_res)

generates error:

    r[0] = ~a.v
  File "/home/jcasas/dprive/heterocl_mlir/hcl-dialect-prototype/build/tools/hcl/python_packages/hcl_core/hcl_mlir/build_ir.py", line 626, in __invert__
    raise HCLNotImplementedError("__invert__ is not implemented")
@chhzh123 chhzh123 added the MLIR Limitation MLIR limitations label Oct 31, 2022
@chhzh123
Copy link
Member

This is also a known limitation of MLIR. It does not provide bitwise NOT op in the arith dialect.
https://mlir.llvm.org/docs/Dialects/ArithOps/

@jcasas00
Copy link
Collaborator Author

I see. ~a can be implemented as arith.xori a ((1 << hcl.get_bitwidth(a.dtype))-1) as well.

@chhzh123
Copy link
Member

Right, this is a workaround. We probably need to provide our own bitwise NOT op. Using other bitwise ops to implement NOT is fine for the LLVM backend, but not a good solution for HLS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MLIR Limitation MLIR limitations
Projects
None yet
Development

No branches or pull requests

2 participants