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

Feature/softmax #1143

Draft
wants to merge 53 commits into
base: feature/prefix_node_names
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7583b42
[SETUPTOOLS] add all install requirements
Jan 27, 2024
8ae17bc
[SETUPTOOLS] Deps directory cleanup
Jan 28, 2024
3e0b04f
[QONNX] update to latest main fd61cfe
Mar 7, 2024
b066882
[RTL Thresh] Enable workaround for unsigned narrow quantization
auphelia Jul 19, 2024
9d95b1b
[RTL thresh] Fix datatype extension for unsigned narrow quantization
auphelia Jul 22, 2024
2747853
Merge pull request #1138 from Xilinx/feature/uint_thresh
auphelia Jul 22, 2024
ec120d5
Updated run-docker.sh to include values needed for verification
hannahxy13 Jul 22, 2024
6ab2573
Merge remote-tracking branch 'upstream/dev' into feature/validation_s…
auphelia Jul 23, 2024
6a4406d
[Docker] Add additional comment to clarify that additions to bash scr…
auphelia Jul 23, 2024
65a356a
Updated run-docker.sh to check VERIFICATION_IO path
hannahxy13 Jul 25, 2024
912cadf
Merge pull request #1140 from hannahxy13/feature/validation_steps
auphelia Jul 25, 2024
685ef48
Merge remote-tracking branch 'origin/dev' into feature/packaging
Jul 26, 2024
43dad3b
setup: upgrade onnxruntime
Jul 26, 2024
0256f04
softmax: add initial test harness
Jul 26, 2024
58da0f6
softmax: stub class an infersoftmax
Jul 26, 2024
bbbdc4a
softmax: stub abstract methods
Jul 29, 2024
cbda331
softmax: input image dimension attribute
Jul 29, 2024
48738f6
softmax: use input img dimension to build input shape
Jul 29, 2024
ec33c6a
softmax: softmax on inner dim
Jul 29, 2024
507b798
softmax: infer softmax helper implementation
Jul 29, 2024
7727a3f
softmax: hls class stub
Jul 29, 2024
26899d2
softmax: extend test to apply folding config
Jul 30, 2024
f917bfc
softmax: add Quant to node name
Jul 30, 2024
74c338c
softmax: generate hls code
Jul 30, 2024
41d0f06
softmax: use sname for input name
Jul 30, 2024
4fc3e2c
softmax: quantsoftmax replaces softmax+multithreshold
Jul 30, 2024
e26cc5f
softmax: run stitchedip
Jul 31, 2024
85b97a6
softmax: hls execute softmax bin
Jul 31, 2024
f53a838
softmax: include correct imports
Jul 31, 2024
9dbcc13
softmax: set preferred impl style
Jul 31, 2024
843b7b1
finn: add hls library paths
Jul 31, 2024
7052947
cpp compiler: raise exception if compilation fails
Aug 1, 2024
ffeb69c
softmax: compile node for cpp sim
Aug 1, 2024
ef80c8e
softmax: generate cppsim code
Aug 2, 2024
87fc354
softmax: does not suppor rtlsim
Aug 2, 2024
1c15022
softmax: transformation test
Aug 2, 2024
3a78f79
softmax: more generic testcase
Aug 6, 2024
cd8d270
hlsbackend: handle subprocess exceptions and log them
Aug 7, 2024
f6a7b8b
cpp template: try catch in cppsim templates
Aug 7, 2024
618a529
softmax: generate cppsim with npyvector stream
Aug 8, 2024
89dfd56
softmax: functional model
Aug 8, 2024
d98561a
softmax: clean up prints
Aug 8, 2024
2eaec1e
softmax: clear up functional test
Aug 8, 2024
42c810f
softmax: clean up unused modules in test
Aug 8, 2024
4b49c66
softmax: use folded output shape
Aug 8, 2024
1ff725f
softmax: use onnx graph to validate the finn integration
Aug 8, 2024
949d1e8
softmax: update latest hls implementation
Aug 8, 2024
98ac566
softmax: cpp sim stream size check
Aug 12, 2024
43b1577
softmax: fix expected stream size
Aug 12, 2024
8297bb4
softmax: add debug prints into testbench
Aug 12, 2024
abefce6
softmax: simplify testcase
Aug 12, 2024
2b026f8
softmax: move hls source to custom hls directory
Aug 14, 2024
d629093
softmax: quantization fix
Aug 14, 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