Skip to content

[BUG] float16 and bfloat16 missing critical operators #478

@kian-mahmoodi

Description

@kian-mahmoodi

Describe the bug

float16 and bfloat16 is missing exp
bfloat16 is missing multiple comparator operators (eg >, >=, etc)

To Reproduce EXP

def testExpT -> T:
return allo.exp(a)

def top_vitis_csyn():
sch_top = allo.customize(testExp, instantiate=[float16])
mod = sch_top.build(
target="vitis_hls",
mode="csyn",
project="top.prj",
)
mod()
print("Vitis HLS synthesis complete!")

top_vitis_csyn()

Buggy output

Traceback (most recent call last):
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 3262, in build_stmts
results.append(build_stmt(ctx, stmt))
^^^^^^^^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 101, in call
res = method(ctx, node, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 3125, in build_Return
ret = build_stmt(ctx, node.value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 101, in call
res = method(ctx, node, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 2702, in build_Call
raise RuntimeError(f"Unsupported function {fn_name} with type {arg_types}")
RuntimeError: Unsupported function exp with type [F16Type(f16)]

Error: Unsupported function exp with type [F16Type(f16)]

To Reproduce Comparator

Note this compiles without issue for float32 but not b/float16

def testGTT -> T:
c : T = 0
if a < 0:
c = 1.0
else:
c = 2.0
return 2.0

def top_vitis_csyn():
sch_top = allo.customize(testGT, instantiate=[float16])
mod = sch_top.build(
target="vitis_hls",
mode="csyn",
project="top.prj",
)
mod()
print("Vitis HLS synthesis complete!")

top_vitis_csyn()

Buggy output (NOTE DIFFERENT FOR float16 and bfloat16!

Output for float16

File "/scratch/km777/hls_final/baseline/HLS_final_project/src/allo/test.py", line 36, in
top_vitis_csyn()
File "/scratch/km777/hls_final/baseline/HLS_final_project/src/allo/test.py", line 28, in top_vitis_csyn
mod = sch_top.build(
^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/customize.py", line 1236, in build
return HLSModule(
^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/backend/hls.py", line 271, in init
header, self.args = separate_header(self.hls_code, self.top_func_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/backend/hls.py", line 158, in separate_header
raise ValueError(f"Fail to resolve ctype {ele_type}")
ValueError: Fail to resolve ctype half

Output for bfloat16

Traceback (most recent call last):
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 3262, in build_stmts
results.append(build_stmt(ctx, stmt))
^^^^^^^^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 101, in call
res = method(ctx, node, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 2019, in build_If
cond = build_stmt(ctx, node.test)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 101, in call
res = method(ctx, node, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/km777/hls_final/allo/allo/ir/builder.py", line 1967, in build_Compare
raise RuntimeError(f"Unsupported types for binary op: {dtype}")
RuntimeError: Unsupported types for binary op: bf16

Error: Unsupported types for binary op: bf16

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions