diff --git a/src/finn/transformation/fpgadataflow/convert_to_hls_layers.py b/src/finn/transformation/fpgadataflow/convert_to_hls_layers.py index 39b17e3e6eb006ea49a9f00a82c14ef76de0df96..a221b510ab8d22f4daca1c32e717a9b482246712 100644 --- a/src/finn/transformation/fpgadataflow/convert_to_hls_layers.py +++ b/src/finn/transformation/fpgadataflow/convert_to_hls_layers.py @@ -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",