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

Softmax integration #1155

Open
wants to merge 59 commits into
base: feature/prefix_node_names
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
b49a8cb
softmax: add initial test harness
Jul 26, 2024
3caff12
softmax: stub class an infersoftmax
Jul 26, 2024
735ed84
softmax: stub abstract methods
Jul 29, 2024
27f35ff
softmax: input image dimension attribute
Jul 29, 2024
e731727
softmax: use input img dimension to build input shape
Jul 29, 2024
1326657
softmax: softmax on inner dim
Jul 29, 2024
8befea8
softmax: infer softmax helper implementation
Jul 29, 2024
ef42207
softmax: hls class stub
Jul 29, 2024
3c41cf2
softmax: extend test to apply folding config
Jul 30, 2024
5264869
softmax: add Quant to node name
Jul 30, 2024
bbcc6ea
softmax: generate hls code
Jul 30, 2024
2653d36
softmax: use sname for input name
Jul 30, 2024
178a9d0
softmax: quantsoftmax replaces softmax+multithreshold
Jul 30, 2024
73e7244
softmax: run stitchedip
Jul 31, 2024
11b19cb
softmax: hls execute softmax bin
Jul 31, 2024
5faca11
softmax: include correct imports
Jul 31, 2024
8d9b9fd
softmax: set preferred impl style
Jul 31, 2024
ac22ecb
finn: add hls library paths
Jul 31, 2024
e6d3d3a
cpp compiler: raise exception if compilation fails
Aug 1, 2024
2a03747
softmax: compile node for cpp sim
Aug 1, 2024
a87fc03
softmax: generate cppsim code
Aug 2, 2024
ccf6842
softmax: does not suppor rtlsim
Aug 2, 2024
ed84da1
softmax: transformation test
Aug 2, 2024
f1e4b46
softmax: more generic testcase
Aug 6, 2024
fc0e5db
hlsbackend: handle subprocess exceptions and log them
Aug 7, 2024
11f9f0c
cpp template: try catch in cppsim templates
Aug 7, 2024
afa050f
softmax: generate cppsim with npyvector stream
Aug 8, 2024
ccd5c57
softmax: functional model
Aug 8, 2024
9c312e0
softmax: clean up prints
Aug 8, 2024
c076723
softmax: clear up functional test
Aug 8, 2024
ffba214
softmax: clean up unused modules in test
Aug 8, 2024
16235ac
softmax: use folded output shape
Aug 8, 2024
53225c1
softmax: use onnx graph to validate the finn integration
Aug 8, 2024
a15526a
softmax: update latest hls implementation
Aug 8, 2024
2877438
check for vitis xrt in docker
Aug 8, 2024
a1c6857
softmax: cpp sim stream size check
Aug 12, 2024
99e2f19
softmax: fix expected stream size
Aug 12, 2024
f806909
softmax: add debug prints into testbench
Aug 12, 2024
08a73aa
softmax: simplify testcase
Aug 12, 2024
27f36f9
entrypoint: only add necessary libs to path
Aug 12, 2024
c4d2690
entrypoint: fail if xrt not found
Aug 12, 2024
7274a8b
softmax: move hls source to custom hls directory
Aug 14, 2024
12cc01b
softmax: quantization fix
Aug 14, 2024
96c4c65
softmax: add softmax transform to dataflow step
Aug 14, 2024
f8715b6
softmax: make softmax shape agnostic
Aug 14, 2024
ef1b7f5
softmax: make softmax shape agnostic 2
Aug 15, 2024
4ff7fc8
Adding input/output datatype parameters to the softmax node rather th…
STFleming Aug 21, 2024
9eb9f1b
first cut and adding separate In/Out type template params for quantso…
STFleming Aug 21, 2024
01411cc
Output datatype is now passing tests
STFleming Aug 21, 2024
052ef46
Added an additional test for a different output type (which is passing)
STFleming Aug 21, 2024
a295bdc
Added INT9 Input test case
STFleming Aug 21, 2024
f5d1bfc
Fixing test, thanks @auphelia
STFleming Aug 21, 2024
640f81f
Merge pull request #1166 from STFleming/feature/sm_integration
auphelia Aug 21, 2024
1414e7e
[QuantSoftMax] Clean up setting of output data type
auphelia Aug 21, 2024
5d5bee9
Added rounding mode to avoid the default truncation rounding.
STFleming Sep 10, 2024
1ebe02f
Merge pull request #1180 from STFleming/feature/sm_integration
auphelia Sep 10, 2024
16ec172
Fixed is_signed detection for ap_int types
STFleming Sep 24, 2024
ef4000b
Merge branch 'feature/sm_integration' of github.com:STFleming/finn in…
STFleming Sep 24, 2024
f54d050
Merge pull request #1196 from STFleming/feature/sm_integration
auphelia Sep 24, 2024
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
164 changes: 164 additions & 0 deletions custom_hls/sm_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.
//
// This file is subject to the Xilinx Design License Agreement located
// in the LICENSE.md file in the root directory of this repository.
//
// This file contains confidential and proprietary information of Xilinx, Inc.
// and is protected under U.S. and international copyright and other
// intellectual property laws.
//
// DISCLAIMER
// This disclaimer is not a license and does not grant any rights to the materials
// distributed herewith. Except as otherwise provided in a valid license issued to
// you by Xilinx, and to the maximum extent permitted by applicable law: (1) THESE
// MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL FAULTS, AND XILINX HEREBY
// DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY,
// INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT, OR
// FITNESS FOR ANY PARTICULAR PURPOSE; and (2) Xilinx shall not be liable (whether
// in contract or tort, including negligence, or under any other theory of
// liability) for any loss or damage of any kind or nature related to, arising
// under or in connection with these materials, including for any direct, or any
// indirect, special, incidental, or consequential loss or damage (including loss
// of data, profits, goodwill, or any type of loss or damage suffered as a result
// of any action brought by a third party) even if such damage or loss was
// reasonably foreseeable or Xilinx had been advised of the possibility of the
// same.
//
// CRITICAL APPLICATIONS
// Xilinx products are not designed or intended to be fail-safe, or for use in
// any application requiring failsafe performance, such as life-support or safety
// devices or systems, Class III medical devices, nuclear facilities, applications
// related to the deployment of airbags, or any other applications that could lead
// to death, personal injury, or severe property or environmental damage
// (individually and collectively, "Critical Applications"). Customer assumes the
// sole risk and liability of any use of Xilinx products in Critical Applications,
// subject only to applicable laws and regulations governing limitations on product
// liability.
//
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE AT ALL TIMES.
#ifndef SM_UTIL_HPP
#define SM_UTIL_HPP
#include "hls_vector.h"

//- Compile-Time Functions --------------------------------------------------

// ceil(log2(x))
template<typename T>
constexpr unsigned clog2(T x) {
return x<2? 0 : 1+clog2((x+1)/2);
}

//- Streaming Flit with `last` Marking --------------------------------------
template<typename T>
struct flit_t {
bool last;
T data;

public:
flit_t(bool last_, T const &data_) : last(last_), data(data_) {}
~flit_t() {}
};

//- Streaming Copy ----------------------------------------------------------
template<typename T>
void move(hls::stream<T> &src, hls::stream<T> &dst) {
#pragma HLS pipeline II=1 style=flp
if(!src.empty()) dst.write(src.read());
}

//- Tree Reduce -------------------------------------------------------------
template< unsigned long N, typename TA, typename TR = TA, typename F >
TR tree_reduce(hls::stream<TA> &v, F f) {
#pragma HLS inline
#pragma HLS function_instantiate variable=f
TR tree[2*N-1];
#pragma HLS array_partition complete dim=1 variable=tree
for(unsigned i = N; i-- > 0;) {
#pragma HLS unroll
tree[N-1 + i] = v.read();
}
for(unsigned i = N-1; i-- > 0;) {
#pragma HLS unroll
tree[i] = f(tree[2*i+1], tree[2*i+2]);
}
return tree[0];
}

// Recursive comparison and count (of max)
// Builds a tree to compute the max of a vector
template<unsigned N, typename T>
struct MaxReduction {

static T max(const hls::vector<T, N>& input) {
#pragma HLS INLINE
constexpr unsigned M = (N + 1) / 2;
hls::vector<T, M> res;

for(unsigned i = 0; i < M; ++i) {
#pragma HLS unroll
if (2*i + 1 < N)
res[i] = input[2*i] > input[2*i + 1] ? input[2*i] : input[2*i + 1];
else
res[i] = input[2*i]; // Handle the case where the input size is odd
}

return MaxReduction<M, T>::max(res);
}

};

template<typename T>
struct MaxReduction<2, T> {
static T max(const hls::vector<T, 2>& input) {
#pragma HLS INLINE
return (input[0] > input[1]) ? input[0] : input[1];
}
};

template<typename T>
struct MaxReduction<1, T> {
static T max(const hls::vector<T, 1>& input) {
#pragma HLS INLINE
return input[0];
}
};

// Recursive reduction tree for the total summation
// Code for the Nth stage
template<unsigned N>
struct TreeReduction {
static float reduce(const hls::vector<float, N>& input) {
#pragma HLS INLINE
constexpr unsigned M = (N + 1) / 2;
hls::vector<float, M> sum;

for(unsigned i = 0; i < M; ++i) {
#pragma HLS unroll
if (2*i + 1 < N)
sum[i] = input[2*i] + input[2*i + 1];
else
sum[i] = input[2*i]; // Handle the case where the input size is odd
}

return TreeReduction<M>::reduce(sum);
}
};

template<>
struct TreeReduction<2> {
static float reduce(const hls::vector<float, 2>& input) {
#pragma HLS INLINE
return input[0] + input[1];
}
};

template<>
struct TreeReduction<1> {
static float reduce(const hls::vector<float, 1>& input) {
#pragma HLS INLINE
return input[0];
}
};


#endif
Loading