__invert__ is not implemented
jcasas00 opened this issue · 3 comments
jcasas00 commented
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 commented
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 commented
I see. ~a can be implemented as arith.xori a ((1 << hcl.get_bitwidth(a.dtype))-1) as well.
chhzh123 commented
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.