From 1b6351741bfae3ecb31b476a67d594dd109268f6 Mon Sep 17 00:00:00 2001 From: auphelia Date: Wed, 17 Apr 2024 11:43:55 +0100 Subject: [PATCH 1/3] [FIFO] Add additional count width parameter to set range of maxcount and count in FIFO template --- finn-rtllib/fifo/hdl/Q_srl.v | 9 +++++---- finn-rtllib/fifo/hdl/fifo_template.v | 3 ++- src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/finn-rtllib/fifo/hdl/Q_srl.v b/finn-rtllib/fifo/hdl/Q_srl.v index 11cef604e0..bcada9da31 100644 --- a/finn-rtllib/fifo/hdl/Q_srl.v +++ b/finn-rtllib/fifo/hdl/Q_srl.v @@ -73,8 +73,9 @@ module Q_srl (clock, reset, i_d, i_v, i_r, o_d, o_v, o_r, count, maxcount); parameter depth = 16; // - greatest #items in queue (2 <= depth <= 256) parameter width = 16; // - width of data (i_d, o_d) + parameter countwidth = $clog2(depth + 1); - parameter addrwidth = $clog2(depth); + localparam addrwidth = $clog2(depth); input clock; input reset; @@ -89,10 +90,10 @@ module Q_srl (clock, reset, i_d, i_v, i_r, o_d, o_v, o_r, count, maxcount); input o_r; // - output stream ready wire o_b; // - output stream back-pressure - output [addrwidth:0] count; // - output number of elems in queue - output [addrwidth:0] maxcount; // - maximum observed count since reset + output [countwidth-1:0] count; // - output number of elems in queue + output [countwidth-1:0] maxcount; // - maximum observed count since reset - reg [addrwidth:0] maxcount_reg; // - maximum count seen until now + reg [countwidth-1:0] maxcount_reg; // - maximum count seen until now reg [addrwidth-1:0] addr, addr_, a_; // - SRL16 address // for data output reg shift_en_; // - SRL16 shift enable diff --git a/finn-rtllib/fifo/hdl/fifo_template.v b/finn-rtllib/fifo/hdl/fifo_template.v index 3f14ae991f..2561355fc1 100644 --- a/finn-rtllib/fifo/hdl/fifo_template.v +++ b/finn-rtllib/fifo/hdl/fifo_template.v @@ -53,7 +53,8 @@ output $OUT_RANGE$ out_V_TDATA Q_srl #( .depth($DEPTH$), -.width($WIDTH$) +.width($WIDTH$), +.countwidth($COUNT_WIDTH$) ) impl ( diff --git a/src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py b/src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py index dfae607622..7af4ae60d7 100644 --- a/src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py +++ b/src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py @@ -95,12 +95,13 @@ def generate_hdl(self, model, fpgapart, clk): code_gen_dict["$TOP_MODULE_NAME$"] = topname # make instream width a multiple of 8 for axi interface in_width = self.get_instream_width_padded() - count_width = int(self.get_nodeattr("depth") - 1).bit_length() + count_width = int(self.get_nodeattr("depth") + 1).bit_length() code_gen_dict["$COUNT_RANGE$"] = "[{}:0]".format(count_width - 1) code_gen_dict["$IN_RANGE$"] = "[{}:0]".format(in_width - 1) code_gen_dict["$OUT_RANGE$"] = "[{}:0]".format(in_width - 1) code_gen_dict["$WIDTH$"] = str(in_width) code_gen_dict["$DEPTH$"] = str(self.get_nodeattr("depth")) + code_gen_dict["$COUNT_WIDTH$"] = count_width # apply code generation to templates code_gen_dir = self.get_nodeattr("code_gen_dir_ipgen") with open(template_path, "r") as f: From 3bf03b66bbc751ab32dd8205c8b342f337a94560 Mon Sep 17 00:00:00 2001 From: auphelia Date: Wed, 17 Apr 2024 15:33:32 +0100 Subject: [PATCH 2/3] [FIFO] Adjust count width and make param local in verilog files --- finn-rtllib/fifo/hdl/Q_srl.v | 2 +- finn-rtllib/fifo/hdl/fifo_template.v | 1 - src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/finn-rtllib/fifo/hdl/Q_srl.v b/finn-rtllib/fifo/hdl/Q_srl.v index bcada9da31..d1ce33c41f 100644 --- a/finn-rtllib/fifo/hdl/Q_srl.v +++ b/finn-rtllib/fifo/hdl/Q_srl.v @@ -73,8 +73,8 @@ module Q_srl (clock, reset, i_d, i_v, i_r, o_d, o_v, o_r, count, maxcount); parameter depth = 16; // - greatest #items in queue (2 <= depth <= 256) parameter width = 16; // - width of data (i_d, o_d) - parameter countwidth = $clog2(depth + 1); + localparam countwidth = $clog2(depth + 1); localparam addrwidth = $clog2(depth); input clock; diff --git a/finn-rtllib/fifo/hdl/fifo_template.v b/finn-rtllib/fifo/hdl/fifo_template.v index 2561355fc1..5b2636996f 100644 --- a/finn-rtllib/fifo/hdl/fifo_template.v +++ b/finn-rtllib/fifo/hdl/fifo_template.v @@ -54,7 +54,6 @@ output $OUT_RANGE$ out_V_TDATA Q_srl #( .depth($DEPTH$), .width($WIDTH$), -.countwidth($COUNT_WIDTH$) ) impl ( diff --git a/src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py b/src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py index 7af4ae60d7..f8f27cb647 100644 --- a/src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py +++ b/src/finn/custom_op/fpgadataflow/rtl/streamingfifo_rtl.py @@ -95,13 +95,12 @@ def generate_hdl(self, model, fpgapart, clk): code_gen_dict["$TOP_MODULE_NAME$"] = topname # make instream width a multiple of 8 for axi interface in_width = self.get_instream_width_padded() - count_width = int(self.get_nodeattr("depth") + 1).bit_length() + count_width = int(self.get_nodeattr("depth")).bit_length() code_gen_dict["$COUNT_RANGE$"] = "[{}:0]".format(count_width - 1) code_gen_dict["$IN_RANGE$"] = "[{}:0]".format(in_width - 1) code_gen_dict["$OUT_RANGE$"] = "[{}:0]".format(in_width - 1) code_gen_dict["$WIDTH$"] = str(in_width) code_gen_dict["$DEPTH$"] = str(self.get_nodeattr("depth")) - code_gen_dict["$COUNT_WIDTH$"] = count_width # apply code generation to templates code_gen_dir = self.get_nodeattr("code_gen_dir_ipgen") with open(template_path, "r") as f: From 50c4e6f76260754b608feb54d4b66ccbd819b32b Mon Sep 17 00:00:00 2001 From: auphelia Date: Wed, 17 Apr 2024 15:38:29 +0100 Subject: [PATCH 3/3] [FIFO] Delete obsolete comma in template code --- finn-rtllib/fifo/hdl/fifo_template.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/finn-rtllib/fifo/hdl/fifo_template.v b/finn-rtllib/fifo/hdl/fifo_template.v index 5b2636996f..3f14ae991f 100644 --- a/finn-rtllib/fifo/hdl/fifo_template.v +++ b/finn-rtllib/fifo/hdl/fifo_template.v @@ -53,7 +53,7 @@ output $OUT_RANGE$ out_V_TDATA Q_srl #( .depth($DEPTH$), -.width($WIDTH$), +.width($WIDTH$) ) impl (