From df133a54f2ae892dc498bdee9c065789290612df Mon Sep 17 00:00:00 2001
From: Yaman Umuroglu <maltanar@gmail.com>
Date: Wed, 9 Sep 2020 21:43:22 +0200
Subject: [PATCH] [Test] add rtlsim throughput test to end2end

---
 tests/end2end/test_end2end_bnn_pynq.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tests/end2end/test_end2end_bnn_pynq.py b/tests/end2end/test_end2end_bnn_pynq.py
index ac73831ab..7f8287471 100644
--- a/tests/end2end/test_end2end_bnn_pynq.py
+++ b/tests/end2end/test_end2end_bnn_pynq.py
@@ -87,7 +87,7 @@ from finn.transformation.fpgadataflow.annotate_cycles import AnnotateCycles
 from finn.analysis.fpgadataflow.dataflow_performance import dataflow_performance
 from finn.core.modelwrapper import ModelWrapper
 from scipy.stats import linregress
-from finn.core.throughput_test import throughput_test_remote
+from finn.core.throughput_test import throughput_test_remote, throughput_test_rtlsim
 
 build_dir = "/tmp/" + os.environ["FINN_INST_NAME"]
 target_clk_ns = 10
@@ -342,6 +342,21 @@ class TestEnd2End:
         warnings.warn("Estimated & rtlsim performance: " + str(perf))
         assert np.isclose(y, output_tensor_npy).all()
 
+    @pytest.mark.slow
+    @pytest.mark.vivado
+    def test_throughput_rtlsim(self, topology, wbits, abits):
+        prev_chkpt_name = get_checkpoint_name(topology, wbits, abits, "ipstitch_rtlsim")
+        model = load_test_checkpoint_or_skip(prev_chkpt_name)
+        n_nodes = len(model.graph.node)
+        perf_est = model.analysis(dataflow_performance)
+        latency = int(model.get_metadata_prop("cycles_rtlsim"))
+        cycles_per_sample_est = perf_est["max_cycles"]
+        batchsize = 2 * n_nodes
+        ret = throughput_test_rtlsim(model, batchsize=batchsize)
+        res_cycles = ret["cycles"]
+        est_cycles = latency + cycles_per_sample_est * batchsize
+        assert (abs(res_cycles - est_cycles) / res_cycles) < 0.15
+
     @pytest.mark.slow
     @pytest.mark.vivado
     @pytest.mark.vitis
-- 
GitLab