Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] MultiThreshold by Binary Search #687

Closed
wants to merge 121 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
3002e62
HDL for new thresholding by binary search.
preusser Sep 20, 2022
3c92c2f
IP core support files for thresholding module.
preusser Sep 20, 2022
09c6da9
[thresholding] FINN-44: Add skeleton class for Threshold (the RTL ver…
fionnodonohoe-xlnx Sep 21, 2022
1dde247
[thresholding] FINN-44: Update custom_op's __init__ to pick up new Th…
fionnodonohoe-xlnx Sep 21, 2022
95082d3
[thresholding] FINN-44: Add inital node attributes for Thresholding b…
fionnodonohoe-xlnx Sep 21, 2022
72832be
[thresholding] FINN-44: Add calc_tmem() method
fionnodonohoe-xlnx Sep 21, 2022
0d4e3be
[thresholding] FINN-44: Add methods for retrieving inut/output/weight…
fionnodonohoe-xlnx Sep 21, 2022
28568c6
[thresholding] FINN-44: Add methods for retrieving node input/output …
fionnodonohoe-xlnx Sep 21, 2022
280870d
Thresholding over signed inputs.
preusser Oct 24, 2022
2bf1a21
Introduce an optional threshold output bias.
preusser Oct 24, 2022
4c7b5ac
Exposing the thresholding bias through the AXI adapter.
preusser Oct 25, 2022
7663d3f
Have thresholding wrapper pass on bias parameter and compute derived …
preusser Oct 25, 2022
55e2eac
Fix typo.
preusser Oct 25, 2022
fa5d71a
Abandon IPI support files.
preusser Oct 25, 2022
174c0ff
[thresholding] allow for positive and negative bias values
fionnodonohoe-xlnx Nov 15, 2022
2ec20e5
[thresholding] pass bias from top module to thresholding.sv core
fionnodonohoe-xlnx Nov 15, 2022
8616148
[thresholding] pass O_BITS from top module to thresholding.sv core
fionnodonohoe-xlnx Nov 15, 2022
275abad
[thresholding] pass C_BITS from top module to thresholding.sv core
fionnodonohoe-xlnx Nov 15, 2022
8849c02
[thresholding] create & fill in RTL template values using FINN
fionnodonohoe-xlnx Nov 16, 2022
84704ed
[thresholding] add method get_weightstream_width()
fionnodonohoe-xlnx Nov 16, 2022
9aa7ff3
[thresholding] add method get_in/output_width()
fionnodonohoe-xlnx Nov 16, 2022
608b5da
[thresholding] add method body for code_generation_ipi()
fionnodonohoe-xlnx Nov 16, 2022
ca6e7e7
[thresholding] add method get_verilog_top_module_intf_names()
fionnodonohoe-xlnx Nov 16, 2022
7266ee9
[thresholding] retrieve axilite write sequence for runtime weight pro…
fionnodonohoe-xlnx Nov 16, 2022
f88bdbf
[thresholding] add methods for creating weight files for each simulat…
fionnodonohoe-xlnx Nov 16, 2022
560771a
[thresholding] add method generate_params()
fionnodonohoe-xlnx Nov 16, 2022
e763bf8
[thresholding] add method for preparing a Pyverilator object for RTL …
fionnodonohoe-xlnx Nov 16, 2022
84e08f1
[thresholding] add method to run rtlsim on a thresholding binary sear…
fionnodonohoe-xlnx Nov 16, 2022
b0be07a
[thresholding] add stubbed method for ipgen_singlenode_code()
fionnodonohoe-xlnx Nov 16, 2022
30d22f8
[thresholding] update class name to a more consistent naming convention
fionnodonohoe-xlnx Nov 16, 2022
3594edd
[thresholding] add fpgadataflow pytests for thresholding binary searc…
fionnodonohoe-xlnx Nov 17, 2022
0bee70d
[thresholding] add linter fixes
fionnodonohoe-xlnx Nov 17, 2022
0689c6a
[thresholding] add flake8 fixes
fionnodonohoe-xlnx Nov 17, 2022
e9a4a7b
[thresholding] change the pytest markers to omit tests from quicktest
fionnodonohoe-xlnx Nov 17, 2022
41c0b4b
[thresholding] update copyright banners of files I have added/changed
fionnodonohoe-xlnx Nov 25, 2022
71ef39b
Translate byte to parameter word addressing in AXI adapter.
preusser Dec 1, 2022
47a0cf9
Merge branch 'dev' into feature/thresholding_addressing
preusser Dec 1, 2022
bdd100f
Merge branch 'dev' into feature/thresholding
fionnodonohoe-xlnx Dec 13, 2022
d44a66c
[thresholding] remove unused attribute
fionnodonohoe-xlnx Dec 19, 2022
f79b9ec
[thresholding] remove unnecessary HLS bug prevention check
fionnodonohoe-xlnx Dec 19, 2022
7b82de2
[thresholding] align methods with hlscustom class by adding in additi…
fionnodonohoe-xlnx Dec 19, 2022
e2816d3
[thresholding] replace hardcoded tcl commands with node attributes
fionnodonohoe-xlnx Dec 19, 2022
61acc64
Merge branch 'feature/thresholding' into feature/thresholding_addressing
preusser Dec 20, 2022
bda05ae
Fix BIAS parameter specification.
preusser Dec 20, 2022
7388e76
[thresholding] remove unused ram_style attribute
fionnodonohoe-xlnx Dec 20, 2022
e965396
[thresholding] skip test for unsupported cppsim configuration and mer…
fionnodonohoe-xlnx Jan 5, 2023
2b8a674
[thresholding] moving find_next_power_of_2() to the util suite
fionnodonohoe-xlnx Jan 5, 2023
45bb19f
[thresholding] remove find_next_power_of_2() from thresholding binary…
fionnodonohoe-xlnx Jan 5, 2023
ca00422
[thresholding] replace math functions with existing functions
fionnodonohoe-xlnx Jan 5, 2023
7f3455f
[thresholding] remove convept of mem_mode for RTL thresholding binary…
fionnodonohoe-xlnx Jan 5, 2023
4bc69f1
[thresholding] add methods needed for convertingToHls transformation
fionnodonohoe-xlnx Jan 5, 2023
3b6a198
[thresholding] add convertingToHls transformation for thresholding bi…
fionnodonohoe-xlnx Jan 5, 2023
b3800cd
[thresholding] add test for convertingToHls transformation for thresh…
fionnodonohoe-xlnx Jan 5, 2023
11464d8
[thresholding] skip tests with unsupported folding factor input
fionnodonohoe-xlnx Jan 5, 2023
e71b1c0
[thresholding] add comments for attributes
fionnodonohoe-xlnx Jan 5, 2023
3be1140
[thresholding] replace min() with signed() function
fionnodonohoe-xlnx Jan 5, 2023
e05effc
[thresholding] fix formatting from pre-commit
fionnodonohoe-xlnx Jan 5, 2023
48c3304
[thresholding] fix more flake8 formatting
fionnodonohoe-xlnx Jan 5, 2023
1e8a36c
[thresholding] remove backslashes for flake8
fionnodonohoe-xlnx Jan 5, 2023
08f1b5f
[thresholding] more flake8 fixes
fionnodonohoe-xlnx Jan 5, 2023
481d773
[thresholding] undo flake8 fixes
fionnodonohoe-xlnx Jan 5, 2023
a51bef4
[thresholding] another flake8 fix
fionnodonohoe-xlnx Jan 5, 2023
2c313ad
[thresholding] remove cppsim test file generation
fionnodonohoe-xlnx Jan 6, 2023
49bdd28
[thresholding] remove unnecessary data generation functions for simul…
fionnodonohoe-xlnx Jan 6, 2023
e663030
[thresholding] remove potentially problematic helper function
fionnodonohoe-xlnx Jan 6, 2023
42dbf23
[thresholding] implement flake8 formatting
fionnodonohoe-xlnx Jan 6, 2023
933d747
[thresholding] remove unused imports
fionnodonohoe-xlnx Jan 6, 2023
5c6dcd9
[thresholding] remove last ununsed import
fionnodonohoe-xlnx Jan 6, 2023
51acd11
[thresholding] reformat existing import
fionnodonohoe-xlnx Jan 6, 2023
9dd4e67
Merge pull request #715 from Xilinx/feature/thresholding_addressing
auphelia Jan 10, 2023
412de82
Merge branch 'dev' into feature/thresholding
auphelia Jan 18, 2023
b886a5a
[Docs] Add bin search thresholding to docs generation
auphelia Jan 18, 2023
2c3de2a
Corrected address width in Verilog wrapper for thresholding.
preusser Jan 23, 2023
7c9f5d8
[thresholding] remove bug affecting input width in top level wrapper
fionnodonohoe-xlnx Jan 23, 2023
3a0d59d
[thresholding] adjust thresholding binary search tests to use word ad…
fionnodonohoe-xlnx Jan 23, 2023
757e3a1
[thresholding] adjust typo in exception
fionnodonohoe-xlnx Jan 23, 2023
479575b
[thresholding] undo copyright header change - only needed for new files
fionnodonohoe-xlnx Jan 23, 2023
0d99b6c
[thresholding] add docstring for migrated find_next_power_of_2() func…
fionnodonohoe-xlnx Jan 23, 2023
5a77a32
[thresholding] add docstrings for methods not in base class
fionnodonohoe-xlnx Jan 23, 2023
eeed070
[thresholding] remove unused method
fionnodonohoe-xlnx Jan 23, 2023
c270868
[thresholding] remove 'return' at end of function - not needed
fionnodonohoe-xlnx Jan 27, 2023
af22177
[thresholding] remove cppsim exec_mode from test - not exercised
fionnodonohoe-xlnx Jan 27, 2023
fab120b
[thresholding] remove unused attributes
fionnodonohoe-xlnx Jan 27, 2023
5d6c964
[thresholding] adjust i/o port names on thresholding RTL wrapper
fionnodonohoe-xlnx Jan 27, 2023
bdfa6cb
[thresholding] remove duplicated test helper function
fionnodonohoe-xlnx Jan 31, 2023
6809351
[thresholding] assert on finding unsupported memory mode for threshol…
fionnodonohoe-xlnx Jan 31, 2023
4515cf7
[thresholding] precommit fix
fionnodonohoe-xlnx Jan 31, 2023
b51498e
[thresholding] precommit fix 2
fionnodonohoe-xlnx Jan 31, 2023
ff3b201
[thresholding] precommit fix 3
fionnodonohoe-xlnx Jan 31, 2023
e0e263b
Merge branch 'dev' into feature/thresholding
auphelia Jan 31, 2023
fc7e00d
[thresholding] adjust templates so that .sv files are modular and can…
fionnodonohoe-xlnx Mar 23, 2023
f530aba
[thresholding]: remove SIGN template in thresholding RTL and create p…
fionnodonohoe-xlnx Mar 23, 2023
3cd600c
[thresholding]: decouple thresholding core from axi wrapper by removi…
fionnodonohoe-xlnx Mar 23, 2023
54afa63
[thresholding]: patch in PE value to the thresholding AXI module and …
fionnodonohoe-xlnx Mar 28, 2023
29f9e1c
[thresholding]: remove reset that erases the 0th stage threshold value
fionnodonohoe-xlnx Mar 30, 2023
2c4c8e2
[thresholding]: enable PE testing of RTL threhoslding binary search node
fionnodonohoe-xlnx Mar 31, 2023
5d07a43
[thresholding]: add comment about why bipolar activations skipped for…
fionnodonohoe-xlnx Mar 31, 2023
33fadc7
Merge branch 'dev' into feature/thresholding
fionnodonohoe-xlnx Mar 31, 2023
fcf579c
fix precommit issues
fionnodonohoe-xlnx Mar 31, 2023
6c9d1f5
[thresholding] only adjust MSB thresholding addressing bits when chan…
fionnodonohoe-xlnx Apr 5, 2023
b247ffb
[thresholding] update binary search to match qonnx 0.2.0
fionnodonohoe-xlnx Apr 5, 2023
7be5ce4
Defaulting BIAS and SIGNED parameters. Renaming M to K avoiding namin…
preusser Apr 17, 2023
a0120f2
Thresholding rework to support parameter readback.
preusser May 4, 2023
81cad6e
Merge branch 'dev' into feature/thresholding_readback
preusser May 4, 2023
c7c18d9
Merge branch 'dev' into feature/thresholding
preusser Jun 26, 2023
28e5ad7
Packaged IP for RTL thresholding implementation.
preusser Jun 27, 2023
bd7ec27
Merge branch 'dev' into feature/thresholding
preusser Nov 14, 2023
bc5b738
Allow for custom start-up intialization of thresholds.
preusser Nov 15, 2023
730bcf8
Make AXI-Lite threshold read/write interface optional.
preusser Nov 15, 2023
95d6a3e
Double wrapping for both structured SystemVerilog parameters and a IP…
preusser Nov 16, 2023
8003c91
Templating the wrapper layers for specialization by FINN compiler.
preusser Nov 16, 2023
d9db257
Replicate correct O_BITS computation for negative BIASes in inner wra…
preusser Nov 20, 2023
073844a
Correcting wrong unsigned interpretation of BIAS in inner wrapper.
preusser Nov 20, 2023
98184ac
Working around an LRM ambiguity when also having assignments in initi…
preusser Nov 20, 2023
528184d
Attempt to mitigate long elaboration times by more explicit configura…
preusser Nov 21, 2023
8fb250c
Switching to threshold initialization from hex data files.
preusser Nov 23, 2023
9de06be
Adding parameters to request local memories of a given depth to be ma…
preusser Nov 28, 2023
038a58a
Prevent BRAM use below specified trigger.
preusser Nov 29, 2023
f39187c
Fixing N vs. 2^N confusion in the module description.
preusser Dec 1, 2023
7284d2c
Add deep pipelining option to thresholding implementation.
preusser Dec 6, 2023
aa57255
Removing the inner wrapper. Exposing the DEEP_PIPELINING option and a…
preusser Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/finn/source_code/finn.custom_op.fpgadataflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ finn.custom\_op.fpgadataflow.thresholding\_batch
:undoc-members:
:show-inheritance:

finn.custom\_op.fpgadataflow.thresholding\_binary\_search
-----------------------------------------------------------

.. automodule:: finn.custom_op.fpgadataflow.thresholding_binary_search
:members:
:undoc-members:
:show-inheritance:


finn.custom\_op.fpgadataflow.tlastmarker
-----------------------------------------------
Expand Down
1,002 changes: 1,002 additions & 0 deletions finn-rtllib/thresholding/component.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions finn-rtllib/thresholding/gui/thresholding_axi_v1_0.gtcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is automatically written. Do not modify.
proc gen_USERPARAMETER_CF_VALUE {C PE } {expr $C/$PE}
proc gen_USERPARAMETER_ADDR_BITS_VALUE {C PE N } {expr int(ceil(log($C/$PE)/log(2))+ceil(log($PE)/log(2))+$N+2)}
proc gen_USERPARAMETER_O_BITS_VALUE {BIAS N } {expr int(ceil($BIAS >= 0? log(pow(2,$N)+$BIAS)/log(2) : 1+log(-$BIAS >= pow(2,$N-1)? -$BIAS : pow(2,$N)+$BIAS)/log(2)))}
210 changes: 210 additions & 0 deletions finn-rtllib/thresholding/hdl/axilite_if.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/*
Copyright (c) 2020, Xilinx
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of FINN nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

module axi4lite_if
#(
parameter ADDR_WIDTH = 32,
parameter DATA_WIDTH = 32,//AXI4 spec requires this to be strictly 32 or 64
parameter IP_DATA_WIDTH = 64//can be any power-of-2 multiple of DATA_WIDTH
)
(
//system signals
input aclk,
input aresetn,//active low, asynchronous assertion and synchronous deassertion

//Write channels
//write address
output reg awready,
input awvalid,
input [ADDR_WIDTH-1:0] awaddr,
input [2:0] awprot,
//write data
output reg wready,
input wvalid,
input [DATA_WIDTH-1:0] wdata,
input [(DATA_WIDTH/8)-1:0] wstrb,
//burst response
input bready,
output reg bvalid,
output reg [1:0] bresp,//NOTE: 00 = OKAY, 10 = SLVERR (write error)

//Read channels
//read address
output reg arready,
input arvalid,
input [ADDR_WIDTH-1:0] araddr,
input [2:0] arprot,
//read data
input rready,
output reg rvalid,
output reg [1:0] rresp,//NOTE: 00 = OKAY, 10 = SLVERR (read error)
output reg [DATA_WIDTH-1:0] rdata,

//IP-side interface
output reg ip_en,
output reg ip_wen,
output reg [ADDR_WIDTH-1:0] ip_addr,
output [IP_DATA_WIDTH-1:0] ip_wdata,
input ip_rack,
input [IP_DATA_WIDTH-1:0] ip_rdata
);

localparam RESP_OKAY = 2'b00;
localparam RESP_SLVERR = 2'b10;
//get ceil(log2(ceil(IP_DATA_WIDTH/DATA_WIDTH)))
localparam NFOLDS_LOG = $clog2((IP_DATA_WIDTH + DATA_WIDTH - 1) / DATA_WIDTH);

reg internal_ren;
reg internal_wen;
reg internal_wack;
reg [ADDR_WIDTH-1:0] internal_raddr;
reg [ADDR_WIDTH-1:0] internal_waddr;
reg [DATA_WIDTH-1:0] internal_wdata;
wire [DATA_WIDTH-1:0] internal_rdata;
reg internal_error = 0;

//check DATA_WIDTH
initial begin
if(DATA_WIDTH != 32 & DATA_WIDTH != 64) begin
$display("AXI4Lite DATA_WIDTH must be 32 or 64");
$finish;
end
end

//transaction state machine
localparam STATE_IDLE = 0,
STATE_READ = 1,
STATE_WRITE = 2;

reg [1:0] state;

always @(posedge aclk or negedge aresetn)
if(~aresetn)
state <= STATE_IDLE;
else case(state)
STATE_IDLE:
if(awvalid & wvalid)
state <= STATE_WRITE;
else if(arvalid)
state <= STATE_READ;
STATE_READ:
if(rvalid & rready)
state <= STATE_IDLE;
STATE_WRITE:
if(bvalid & bready)
state <= STATE_IDLE;
default: state <= STATE_IDLE;
endcase

//write-related internal signals
always @(*) begin
internal_waddr = awaddr >> $clog2(DATA_WIDTH/8);
internal_wdata = wdata;
internal_wen = (state == STATE_IDLE) & awvalid & wvalid;
end

always @(posedge aclk) begin
awready <= internal_wen;
wready <= internal_wen;
end

//read-related internal signals
always @(*) begin
internal_raddr = araddr >> $clog2(DATA_WIDTH/8);
internal_ren = (state == STATE_IDLE) & ~internal_wen & arvalid;
end

always @(posedge aclk)
arready <= internal_ren;

wire write_to_last_fold;

always @(posedge aclk) begin
ip_wen <= write_to_last_fold;
ip_en <= internal_ren | write_to_last_fold;
if(internal_ren | write_to_last_fold)
ip_addr <= internal_ren ? (internal_raddr >> NFOLDS_LOG) : (internal_waddr >> NFOLDS_LOG);
internal_wack <= internal_wen;
end

genvar i;
reg [(1<<NFOLDS_LOG)*DATA_WIDTH-1:0] ip_wdata_wide;
generate
if(NFOLDS_LOG == 0) begin: no_fold
assign write_to_last_fold = internal_wen;
assign internal_rdata = ip_rdata;
always @(posedge aclk)
ip_wdata_wide <= internal_wdata;
end else begin: fold
reg [NFOLDS_LOG-1:0] internal_rfold;
assign write_to_last_fold = internal_wen & (internal_waddr[NFOLDS_LOG-1:0] == {(NFOLDS_LOG){1'b1}});
assign internal_rdata = ip_rdata >> (internal_rfold*DATA_WIDTH);
always @(posedge aclk)
if(internal_ren)
internal_rfold <= internal_raddr[NFOLDS_LOG-1:0];
for(i=0; i<(1<<NFOLDS_LOG); i = i+1) begin: gen_wdata
always @(posedge aclk)
if(internal_waddr[NFOLDS_LOG-1:0] == i)
ip_wdata_wide[(i+1)*DATA_WIDTH-1:i*DATA_WIDTH] <= internal_wdata;
end
end
endgenerate
assign ip_wdata = ip_wdata_wide[IP_DATA_WIDTH-1:0];

//write response on AXI4L bus
always @(posedge aclk or negedge aresetn)
if(~aresetn) begin
bvalid <= 0;//AXI4 spec requires BVALID pulled LOW during reset
bresp <= RESP_OKAY;
end else if(internal_wack) begin
bvalid <= 1;
bresp <= internal_error ? RESP_SLVERR : RESP_OKAY;
end else if(bready) begin
bvalid <= 0;
bresp <= RESP_OKAY;
end

//read response on AXI4L bus
always @(posedge aclk or negedge aresetn)
if(~aresetn) begin
rvalid <= 0;//AXI4 spec requires RVALID pulled LOW during reset
rdata <= 0;
rresp <= RESP_OKAY;
end else if(ip_rack) begin
rvalid <= 1;
rdata <= internal_rdata;
rresp <= internal_error ? RESP_SLVERR : RESP_OKAY;
end else if(rready) begin
rvalid <= 0;
rdata <= 0;
rresp <= RESP_OKAY;
end

endmodule
Loading
Loading