From 1c8d6b84e8f8dba5b70b35869794dfb06d07b73f Mon Sep 17 00:00:00 2001 From: Yaman Umuroglu <maltanar@gmail.com> Date: Thu, 28 Nov 2019 17:40:11 +0000 Subject: [PATCH] [StreamingFC] transpose W matrix while generating hls version --- src/finn/custom_op/fpgadataflow/streamingfclayer_batch.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/finn/custom_op/fpgadataflow/streamingfclayer_batch.py b/src/finn/custom_op/fpgadataflow/streamingfclayer_batch.py index 0250cc9b0..80109d0fa 100644 --- a/src/finn/custom_op/fpgadataflow/streamingfclayer_batch.py +++ b/src/finn/custom_op/fpgadataflow/streamingfclayer_batch.py @@ -104,7 +104,11 @@ class StreamingFCLayer_Batch(HLSCustomOp): assert orig_weight_matrix.shape == (mw, mh) assert mw % simd == 0 assert mh % pe == 0 - ret = orig_weight_matrix + # start by transposing the original weight matrix, since ONNX and + # finn-hlslib use different assumptions + # ONNX uses (in_features, out_features) and matmul(x, W) + # finn-hlslib uses (out_features, in_features) and matmul(W, x) + ret = orig_weight_matrix.T if self.get_weight_datatype() == DataType.BIPOLAR: # convert bipolar to binary ret = (ret + 1) / 2 -- GitLab