Skip to content

Commit

Permalink
Merge pull request #637 from Xilinx/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
auphelia authored Jul 13, 2022
2 parents c98c221 + ed0e969 commit fe4a150
Show file tree
Hide file tree
Showing 254 changed files with 9,606 additions and 5,583 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/quicktest-dev-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
- name: DockerRunQuicktest
run: |
docker run --init --hostname finn_gha -v $(pwd):/workspace/finn -e FINN_BUILD_DIR=/tmp/finn_gha -e FINN_INST_NAME=finn_gha finn_gha quicktest.sh
docker run --init --hostname finn_gha -w $(pwd) -v $(pwd):$(pwd) -e FINN_BUILD_DIR=/tmp/finn_gha -e FINN_INST_NAME=finn_gha finn_gha quicktest.sh
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ MANIFEST
# Per-project virtualenvs
.venv*/

# Jenkins cfg dir
/docker/jenkins_home

# SSH key dir mounted into Docker
/ssh_keys/

Expand All @@ -96,3 +93,6 @@ MANIFEST

# generated files as part of end2end notebooks
/notebooks/end2end_example/**/*.onnx

# downloaded dep repos
/deps/
8 changes: 6 additions & 2 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Contributors
============

* Yaman Umuroglu (@maltanar) (maintainer)
* Jakoba Petri-Koenig (@auphelia)
* Jakoba Petri-Koenig (@auphelia) (maintainer)
* Thomas Preusser (@preusser)
* Yaman Umuroglu (@maltanar)
* Andrea Rigoni (@AndreaRigoni)
* Hendrik Borras (@HenniOVP)
* Lucian Petrica (@quetric)
Expand All @@ -22,3 +23,6 @@ Contributors
* Javier Duarte (@jmduarte)
* Uma Maheshwari (@umav1511)
* José Rosa (@pinxau1000)
* Aziz Bahri (@azizb-xlnx)
* Fionn O'Donohoe (@fionnodonohoe-xlnx)
* Matthias Gehre (@mgehre-amd)
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ We welcome contributions to FINN.

Please follow the steps below and be sure that your contribution complies with our guidelines.

1. Share your proposal via <a href="https://github.com/Xilinx/finn/issues" target="_blank">Github issues</a>. If you are looking for some issues to get started with, we have a list of <a href="https://github.com/Xilinx/finn/labels/good%20first%20issue">good first issues</a> in the issue tracker. Feel free to ask questions on the <a href="https://gitter.im/xilinx-finn/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge">FINN gitter channel as well</a>.
1. Share your proposal via <a href="https://github.com/Xilinx/finn/issues" target="_blank">Github issues</a>. If you are looking for some issues to get started with, we have a list of <a href="https://github.com/Xilinx/finn/labels/good%20first%20issue">good first issues</a> in the issue tracker. Feel free to ask questions in the <a href="https://github.com/Xilinx/finn/discussions">FINN GitHub discussions</a> as well.

We welcome submissions to:

Expand All @@ -17,7 +17,7 @@ Please follow the steps below and be sure that your contribution complies with o

2. Clone the fork to your local computer using *git clone*. Checkout the branch you want to work on.

3. Please install <a href="https://pre-commit.com/" target="_blank">pre-commit</a> to ensure your code is formatted to our style guidelines. The hooks we use for pre-commit can be found in <a href="https://github.com/Xilinx/finn/blob/master/.pre-commit-config.yaml" target="_blank">this file</a>
3. Please install <a href="https://pre-commit.com/" target="_blank">pre-commit</a> to ensure your code is formatted to our style guidelines. The hooks we use for pre-commit can be found in <a href="https://github.com/Xilinx/finn/blob/main/.pre-commit-config.yaml" target="_blank">this file</a>

4. Modify the Python source code, Jupyter notebooks and Sphinx documentation etc. as needed.

Expand All @@ -26,9 +26,9 @@ Please follow the steps below and be sure that your contribution complies with o
6. If you are introducing new functionality, add at least one unit test under the `test/` folder and make sure it passes before you submit the pull request.

7. Submit a pull request by clicking the *pull request* button on your GitHub repo:
1. The <a href="https://github.com/Xilinx/finn" target="_blank">master branch</a> should always be treated as stable and clean. Only hot fixes are allowed to be pull-requested. The hot fix is supposed to be very important such that without this fix, a lot of things will break.
1. The <a href="https://github.com/Xilinx/finn" target="_blank">main branch</a> should always be treated as stable and clean. Only hot fixes are allowed to be pull-requested. The hot fix is supposed to be very important such that without this fix, a lot of things will break.
2. For new features, smaller bug fixes, doc updates, and many other fixes, users should pull request against the <a href="https://github.com/Xilinx/finn/tree/dev" target="_blank">development branch</a>.

3. We will review your contribution and, if any additional fixes or modifications are
necessary, may provide feedback to guide you. When accepted, your pull request will
be merged to the repository. If you have more questions please contact us via the <a href="https://gitter.im/xilinx-finn/community" target="_blank">FINN gitter channel</a>.
be merged to the repository. If you have more questions please contact us.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ Please see the [Getting Started](https://finn.readthedocs.io/en/latest/getting_s

## What's New in FINN?

* **2021-11-05:** v0.7 is released, introducing QONNX support, three new example networks and many other improvements. Read more on the [v0.7 release blog post](https://xilinx.github.io/finn//2021/11/05/finn-v07-is-released.html).
* **2021-06-15:** v0.6 is released, with ResNet-50 on U250 and ZCU104 MobileNet-v1 in finn-examples showcasing new features plus a lot more. Read more on the [v0.6 release blog post](https://xilinx.github.io/finn//2021/06/15/finn-v06-is-released.html).
* **2020-12-17:** v0.5b (beta) is released, with a new [examples repo](https://github.com/Xilinx/finn-examples) including MobileNet-v1. Read more on the <a href="https://xilinx.github.io/finn/2020/12/17/finn-v05b-beta-is-released.html">release blog post</a>.
* Please find all news under [GitHub discussions Announcements](https://github.com/Xilinx/finn/discussions/categories/announcements).

## Documentation

Expand Down
36 changes: 36 additions & 0 deletions custom_hls/checksum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/******************************************************************************
* Copyright (c) 2022, Xilinx, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. Neither the name of the copyright holder 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.
*
* @brief Validation top-level module for checksum component.
* @author Thomas B. Preußer <[email protected]>
*
*******************************************************************************/
#include "checksum.hpp"
CHECKSUM_TOP(WORDS_PER_FRAME, WORD_SIZE, ITEMS_PER_WORD)
134 changes: 134 additions & 0 deletions custom_hls/checksum.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/******************************************************************************
* Copyright (c) 2022, Xilinx, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. Neither the name of the copyright holder 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.
*
* @brief Checksum over stream-carried data frames.
* @author Thomas B. Preußer <[email protected]>
*
*******************************************************************************/
#include <hls_stream.h>
#include <ap_int.h>


/**
* Computes a checksum over a forwarded stream assumed to carry frames of
* N words further subdivided into K subwords.
* - Subword slicing can be customized typically by using a lambda.
* The provided DefaultSubwordSlicer assumes an `ap_(u)int`-like word
* type with a member `width` and a range-based slicing operator. It
* further assumes a little-endian arrangement of subwords within words
* for the canonical subword stream order.
* - Subwords wider than 23 bits are folded using bitwise XOR across
* slices of 23 bits starting from the LSB.
* - The folded subword values are weighted according to their position
* in the stream relative to the start of frame by a periodic weight
* sequence 1, 2, 3, ...
* - The weighted folded subword values are reduced to a checksum by an
* accumulation module 2^24.
* - A checksum is emitted for each completed frame. It is the concatenation
* of an 8-bit (modulo 256) frame counter and the 24-bit frame checksum.
*/
template<typename T, unsigned K> class DefaultSubwordSlicer {
static_assert(T::width%K == 0, "Word size must be subword multiple.");
static constexpr unsigned W = T::width/K;
public:
ap_uint<W> operator()(T const &x, unsigned const j) const {
#pragma HLS inline
return x((j+1)*W-1, j*W);
}
};

template<
unsigned N, // number of data words in a frame
unsigned K, // subword count per data word
typename T, // type of stream-carried data words
typename F = DefaultSubwordSlicer<T, K> // f(T(), j) to extract subwords
>
void checksum(
hls::stream<T> &src,
hls::stream<T> &dst,
ap_uint<32> &chk,
ap_uint<1> drain, // drain data after checksuming without forward to `dst`
F&& f = F()
) {
ap_uint<2> coeff[3] = { 1, 2, 3 };
ap_uint<24> s = 0;

for(unsigned i = 0; i < N; i++) {
#pragma HLS pipeline II=1 style=flp
T const x = src.read();

// Pass-thru copy
if(!drain) dst.write(x);

// Actual checksum update
for(unsigned j = 0; j < K; j++) {
#pragma HLS unroll
auto const v0 = f(x, j);
constexpr unsigned W = 1 + (decltype(v0)::width-1)/23;
ap_uint<K*23> v = v0;
ap_uint< 23> w = 0;
for(unsigned k = 0; k < W; k++) {
w ^= v(23*k+22, 23*k);
}
s += (coeff[j%3][1]? (w, ap_uint<1>(0)) : ap_uint<24>(0)) + (coeff[j%3][0]? w : ap_uint<23>(0));
}

// Re-align coefficients
for(unsigned j = 0; j < 3; j++) {
#pragma HLS unroll
ap_uint<3> const cc = coeff[j] + ap_uint<3>(K%3);
coeff[j] = cc(1, 0) + cc[2];
}
}

// Frame counter & output
static ap_uint<8> cnt = 0;
#pragma HLS reset variable=cnt
chk = (cnt++, s);
}

#define CHECKSUM_TOP_(WORDS_PER_FRAME, WORD_SIZE, ITEMS_PER_WORD) \
using T = ap_uint<WORD_SIZE>; \
void checksum_ ## WORDS_PER_FRAME ## _ ## WORD_SIZE ## _ ## ITEMS_PER_WORD ( \
hls::stream<T> &src, \
hls::stream<T> &dst, \
ap_uint<32> &chk, \
ap_uint< 1> drain \
) { \
_Pragma("HLS interface port=src axis") \
_Pragma("HLS interface port=dst axis") \
_Pragma("HLS interface port=chk s_axilite") \
_Pragma("HLS interface port=drain s_axilite") \
_Pragma("HLS interface port=return ap_ctrl_none") \
_Pragma("HLS dataflow disable_start_propagation") \
checksum<WORDS_PER_FRAME, ITEMS_PER_WORD>(src, dst, chk, drain); \
}
#define CHECKSUM_TOP(WORDS_PER_FRAME, WORD_SIZE, ITEMS_PER_WORD) \
CHECKSUM_TOP_(WORDS_PER_FRAME, WORD_SIZE, ITEMS_PER_WORD)
136 changes: 136 additions & 0 deletions custom_hls/checksum_tb.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/******************************************************************************
* Copyright (c) 2022, Xilinx, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. Neither the name of the copyright holder 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.
*
* @brief Testbench for checksum component.
* @author Thomas B. Preußer <[email protected]>
*
*******************************************************************************/
module checksum_tb;

//-----------------------------------------------------------------------
// Global Control
logic clk = 0;
always #5ns clk = !clk;
logic rst;

//-----------------------------------------------------------------------
// DUT
localparam int unsigned N = 60; // words per frame
localparam int unsigned K = 4; // subwords per word
localparam int unsigned W = 8; // subword size

logic [K-1:0][W-1:0] src_TDATA;
logic src_TVALID;
uwire src_TREADY;

uwire [K-1:0][W-1:0] dst_TDATA;
uwire dst_TVALID;
logic dst_TREADY;

uwire [31:0] chk;
uwire chk_vld;

checksum_top dut (
.ap_clk(clk), .ap_rst_n(!rst),
.src_TDATA, .src_TVALID, .src_TREADY,
.dst_TDATA, .dst_TVALID, .dst_TREADY,
.chk, .chk_ap_vld(chk_vld),
.ap_local_block(), .ap_local_deadlock()
);

//-----------------------------------------------------------------------
// Stimulus
logic [K-1:0][W-1:0] Bypass [$] = {};
logic [31:0] Checksum[$] = {};
initial begin
src_TDATA = 'x;
src_TVALID = 0;

rst = 1;
repeat(9) @(posedge clk);
rst <= 0;

for(int unsigned r = 0; r < 311; r++) begin
automatic logic [23:0] sum = 0;
src_TVALID <= 1;
for(int unsigned i = 0; i < N; i++) begin
for(int unsigned k = 0; k < K; k++) begin
automatic logic [W-1:0] v = $urandom()>>17;
src_TDATA[k] <= v;
sum += ((K*i+k)%3 + 1) * v;
end
@(posedge clk iff src_TREADY);
Bypass.push_back(src_TDATA);
end
src_TVALID <= 0;
$display("Expect: %02x:%06x", r[7:0], sum);
Checksum.push_back({r, sum});
end

repeat(8) @(posedge clk);
$finish;
end

//-----------------------------------------------------------------------
// Output Validation

// Drain and check pass-thru stream
assign dst_TREADY = 1;
always_ff @(posedge clk iff dst_TVALID) begin
assert(Bypass.size()) begin
automatic logic [K-1:0][W-1:0] exp = Bypass.pop_front();
assert(dst_TDATA === exp) else begin
$error("Unexpected output %0x instead of %0x.", dst_TDATA, exp);
$stop;
end
end
else begin
$error("Spurious data output.");
$stop;
end
end

// Validate checksum reports
always_ff @(posedge clk iff chk_vld) begin
$display("Check: %02x:%06x", chk[31:24], chk[23:0]);
assert(Checksum.size()) begin
automatic logic [31:0] exp = Checksum.pop_front();
assert(chk === exp) else begin
$error("Unexpected checksum %0x instead of %0x.", chk, exp);
$stop;
end
end
else begin
$error("Spurious checksum output.");
$stop;
end
end

endmodule : checksum_tb
Loading

0 comments on commit fe4a150

Please sign in to comment.