From 21514001acaf560c5cc3cb483995435992ec3705 Mon Sep 17 00:00:00 2001
From: mmrahorovic <mmrahorovic@hotmail.com>
Date: Fri, 21 Jan 2022 15:13:06 +0000
Subject: [PATCH] [custom_op]: support for 1D SWU

---
 .../custom_op/fpgadataflow/convolutioninputgenerator1d.py   | 6 ++++--
 .../transformation/fpgadataflow/convert_to_hls_layers.py    | 5 +++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/finn/custom_op/fpgadataflow/convolutioninputgenerator1d.py b/src/finn/custom_op/fpgadataflow/convolutioninputgenerator1d.py
index 8d401c40d..8b4d3e425 100644
--- a/src/finn/custom_op/fpgadataflow/convolutioninputgenerator1d.py
+++ b/src/finn/custom_op/fpgadataflow/convolutioninputgenerator1d.py
@@ -272,10 +272,12 @@ class ConvolutionInputGenerator1D(HLSCustomOp):
             cycles_read_block = ifm_dim_w * ifm_ch / simd
             cycles_write_block = ofm_dim_w * k_w * ifm_ch / simd
             exp_cycles = cycles_read_block + cycles_write_block
-        else:
+        elif self.get_nodeattr("depthwise") == 1:
             cycles_read_block = ifm_ch / simd * (k_w - 1) - (k_w - 1)
             cycles_write_block = ofm_dim_w * k_w * ifm_ch / simd
             exp_cycles = cycles_read_block + cycles_write_block
+        else:
+            exp_cycles = 1 + ofm_dim_w * k_w * ifm_ch / simd
 
         return int(exp_cycles)
 
@@ -599,7 +601,7 @@ class ConvolutionInputGenerator1D(HLSCustomOp):
                 self.code_gen_dict["$DOCOMPUTE$"] = [
                     """{}<ConvKernelDim1_x, IFMChannels1,
                     Input_precision1, IFMDim1_x, OFMDim1_x,
-                    SIMD1> (in0, out, numReps, {});""".format(
+                    Stride1_x, SIMD1> (in0, out, numReps, {});""".format(
                         hls_call, hls_ram_style
                     )
                 ]
diff --git a/src/finn/transformation/fpgadataflow/convert_to_hls_layers.py b/src/finn/transformation/fpgadataflow/convert_to_hls_layers.py
index f7cb0a16b..2cf039427 100644
--- a/src/finn/transformation/fpgadataflow/convert_to_hls_layers.py
+++ b/src/finn/transformation/fpgadataflow/convert_to_hls_layers.py
@@ -213,6 +213,11 @@ class InferConvInpGen(Transformation):
                                 1D depthwise separable convolutions"""
                                 % n.name
                             )
+                        if stride_h > 1 or stride_w > 1:
+                            assert (
+                                stride_h < k_h and stride_w < k_w and depthwise == 0
+                            ), """%s: Stride value must be smaller than kernel dimension, not supported
+                                for depthwise convolutions """
                         ConvInpGen_node = helper.make_node(
                             "ConvolutionInputGenerator1D",
                             [ConvInpGen_input],
-- 
GitLab