From 025215d8aaf55d7c5ab21b64b3b8a9bf453bd029 Mon Sep 17 00:00:00 2001
From: mmrahorovic <mmrahorovic@hotmail.com>
Date: Fri, 8 Jul 2022 21:30:45 +0100
Subject: [PATCH] [custom_op]: added warning for cycle estimation & minor
 adjustment to estimation

---
 .../fpgadataflow/streamingmaxpool_batch.py    | 20 ++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/finn/custom_op/fpgadataflow/streamingmaxpool_batch.py b/src/finn/custom_op/fpgadataflow/streamingmaxpool_batch.py
index 0131ca40b..882b40a0a 100755
--- a/src/finn/custom_op/fpgadataflow/streamingmaxpool_batch.py
+++ b/src/finn/custom_op/fpgadataflow/streamingmaxpool_batch.py
@@ -138,20 +138,22 @@ class StreamingMaxPool_Batch(HLSCustomOp):
     def get_exp_cycles(self):
         # derived from StreamingMaxPool_Batch loop nest
         ifm_dim, k, ifm_ch = self.get_1d_attrs_normalized()
-        _, _, ofm_dim_w, nf, _ = self.get_folded_output_shape()
 
+        warnings.warn(
+            """Estimated latency for layer {} can be lower than
+             actual latency!""".format(
+                self.onnx_node.name
+            )
+        )
         if self.is_1d():
-            exp_cycles = ofm_dim_w * nf * (k[1] + 1)
+            _, _, _, nf, _ = self.get_folded_output_shape()
+            ceil_mode = self.get_nodeattr("CeilMode")
+            ofm_dim = compute_pool_output_dim(ifm_dim[1], k[1], k[1], 0, ceil_mode)
+            exp_cycles = ofm_dim * nf * (k[1] + 1)
             return int(exp_cycles)
         else:
             # TODO: adjust inaccurate formula
-            warnings.warn(
-                """Estimated latency for layer {} can be (2-3x) lower
-                 than actual latency!""".format(
-                    self.onnx_node.name
-                )
-            )
-            return int(ifm_dim[1] * (ifm_dim[1] + (ifm_dim[1] / k[1])))
+            return int(ifm_dim[1] * ifm_dim[1] * (1 + 1 / (k[1] * k[1])))
 
     def get_instream_width(self):
         dt_bits = self.get_input_datatype().bitwidth()
-- 
GitLab