Skip to content
Snippets Groups Projects
Commit 9cd32803 authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[ConvertToHLS] fix conversion for bipolar outputs

parent 048878d2
No related branches found
No related tags found
No related merge requests found
......@@ -566,7 +566,7 @@ class InferQuantizedStreamingFCLayer(Transformation):
wmem = mw * mh // (pe * simd)
assert (
mw * mh == wmem * pe * simd
), """Requirement (MW * MH) divisiable by
), """Requirement (MW * MH) divisible by
(WMEM * PE * SIMD) is violated."""
# see if we have any following thresholds
consumer = model.find_consumer(mm_output)
......@@ -583,20 +583,27 @@ class InferQuantizedStreamingFCLayer(Transformation):
thresholds neither 1 nor MH."""
odt = model.get_tensor_datatype(mt_output)
scale = getCustomOp(consumer).get_nodeattr("out_scale")
bipolar_ok = odt == DataType.BIPOLAR and scale == 2.0
assert (
scale == 1.0 or bipolar_ok
), "out_scale must be equal to 1.0 for HLS conversion."
actval = getCustomOp(consumer).get_nodeattr("out_bias")
assert (
int(actval) == actval
), "out_bias must be integer for HLS conversion."
actval = int(actval)
odt_is_bipolar = odt == DataType.BIPOLAR
bipolar_ok = (
odt_is_bipolar and (scale == 2.0) and (actval == -1)
)
assert (
scale == 1.0 or bipolar_ok
), "out_scale = 1.0 or bipolar output needed for conversion."
assert (not odt.signed()) or (
actval < 0
), "Signed output requres actval < 0"
model.set_tensor_shape(mm_input, mm_in_shape)
model.set_tensor_shape(mt_output, mt_out_shape)
if bipolar_ok:
# remove bias for bipolar, since
# binary->bipolar is achieved by reinterpretation
actval = 0
# create and insert new StreamingFCLayer node
new_node = helper.make_node(
"StreamingFCLayer_Batch",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment