Skip to content

Commit

Permalink
syn error compare.
Browse files Browse the repository at this point in the history
  • Loading branch information
microideax committed Sep 19, 2018
1 parent c0eb0b3 commit bcdf54c
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 65 deletions.
34 changes: 29 additions & 5 deletions codeGenerator/local_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,43 @@ def conv_layer_perf(n, m, r, s, k, Tn, Tm, P_const, Tr, Tc):
R_iter = math.ceil(r / float(Tr))
M_iter = math.ceil(m / float(Tm))
N_iter = math.ceil(n / float(Tn))
lat_read = math.ceil((min(Tn, n)/float(8))) * ((Tr-1)*s + k)
lat_read = math.ceil((min(Tn, n)/float(8))) * ((Tr-1)*s + k) * ((Tr-1)*s + k)
# lat_read = 0
lat_com = Tr * Tc * k * k
# lat_out = math.ceil(Tm/float(8)) * Tr*Tc
lat_out = 0
if n == 3:
lat_com = Tr * Tc * math.ceil(k*2)
else:
lat_com = Tr * Tc * k * k

lat_out = math.ceil(Tm/float(8)) * math.ceil(Tr/2) * math.ceil(Tc/2)
# lat_out = 0
# tmp = R_iter * R_iter * M_iter * (lat_read + N_iter*lat_com + lat_out)
# tmp = R_iter * R_iter * M_iter * N_iter * lat_com
tmp = R_iter * R_iter * M_iter * ((N_iter + 1) * max(lat_read, lat_com) + lat_out)

#TODO: use a condition to decide is the layer is the first one in the model
return tmp

def conv_layer_perf_x(n, m, r, s, k, Tn, Tm, P_const, Tr, Tc, ln):
tmp = 0

# revised layer performance
R_iter = math.ceil(r / float(Tr))
M_iter = math.ceil(m / float(Tm))
N_iter = math.ceil(n / float(Tn))
lat_read = math.ceil((min(Tn, n)/float(8))) * ((Tr-1)*s + k) * ((Tr-1)*s + k)
# lat_read = 0
if ln ==1:
lat_com = Tr * Tc * math.ceil(k * k /2)
else:
lat_com = Tr * Tc * k * k
lat_out = math.ceil(Tm/float(8)) * math.ceil(Tr) * math.ceil(Tc)
# lat_out = 0
# tmp = R_iter * R_iter * M_iter * (lat_read + N_iter*lat_com + lat_out)
# tmp = R_iter * R_iter * M_iter * N_iter * lat_com
tmp = R_iter * R_iter * M_iter * ((N_iter + 1) * max(lat_read, lat_com) + lat_out)

return tmp


def pool_layer_perf(m, r, k, Tm, P_const):
tmp = (math.ceil(m / float(Tm))) * r * r * k * k + P_const
return tmp
Expand Down
83 changes: 42 additions & 41 deletions example/test_demo.lenet.multinet/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/test_demo.lenet.multinet/hls_impl/hls_script.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ set_part {xcvu9p-flgb2104-2-i}
create_clock -period 5 -name default
config_interface -m_axi_addr64 -m_axi_offset off -register_io off

#csim_design -clean -argv {net_weights.txt, 3.bmp, val.txt, net_mean.txt}
csim_design -clean -argv {net_weights.txt, 3.bmp, val.txt, net_mean.txt}

csynth_design

Expand Down
4 changes: 2 additions & 2 deletions example/test_demo.lenet.multinet/inference_net/acc_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

using namespace std;

conv_acc<data_type, data_type_w, data_type_o, 8, 8, 28, 28, 5, 5, 32, 32, 32> convAcc1;
conv_acc<data_type, data_type_w, data_type_o, 8, 8, 4, 4, 5, 5, 32, 32, 32> convAcc1;

void conv_layer_acc_1(
const int N,
Expand Down Expand Up @@ -228,4 +228,4 @@ void fc_layer_new(
fc_o_data);
}

#endif
#endif
54 changes: 38 additions & 16 deletions example/test_demo.lenet.multinet/inference_net/conv_acc_innerpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <iostream>
#include <fstream>
#include "hls_stream.h"
#include "activation_functions.h"

#if _C_DEBUG_MODE_
Expand Down Expand Up @@ -318,13 +319,36 @@ class conv_acc
}
}

void conv_iq(hls::stream<T> &data_i,
hls::stream<W> &data_w,
hls::stream<G> &data_o,
void conv_iq(T in_buf[][(Tr - 1) * S_max + K_max][(Tc - 1) * S_max + K_max], W w_buf[][Tm][K_max][K_max],
W b_buf[], G out_buf[][Tr][Tc],
int S, int n, int N, int r, int c, int K, int R_OUT, int C_OUT,
int w_offset, int i_offset){


if (n >= 0 && n - Tn < N) {
for (int tr = 0; tr < Tr; tr++) {
for (int tc = 0; tc < Tc; tc++) {
//#pragma HLS PIPELINE
for (int tn = 0; tn < Tn; tn++) {
#pragma HLS UNROLL
for (int tm = 0; tm < Tm; tm++) {
#pragma HLS UNROLL
for (int i = 0; i < K_max; i++) {
for (int j = 0; j < K_max; j++) {
#pragma HLS PIPELINE
if (i == 0 && j == 0 && tn == 0 && n == 0)
out_buf[tm][tr][tc] = b_buf[tm] + w_buf[tn][tm][i][j] *
in_buf[tn][S_max * (tr) + i][S_max * (tc) + j];
else
out_buf[tm][tr][tc] =
out_buf[tm][tr][tc] + w_buf[tn][tm][i][j] *
in_buf[tn][S_max * (tr) + i][S_max * (tc) + j];
}
}
}
}
}
}
}
}

// Ouput out_buf data to output interface
Expand Down Expand Up @@ -698,29 +722,27 @@ class conv_acc
bool out_1 = 0;

#if _HLS_MODE_
//#pragma HLS INTERFACE s_axilite port=return bundle=CRTL_BUS

#pragma HLS resource variable=in_buf_0 core=XPM_MEMORY uram
#pragma HLS resource variable=w_buf_0 core=XPM_MEMORY uram
//#pragma HLS resource variable=w_buf_0 core=XPM_MEMORY uram
#pragma HLS resource variable=out_buf_0 core=XPM_MEMORY uram
#pragma HLS resource variable=in_buf_1 core=XPM_MEMORY uram
#pragma HLS resource variable=w_buf_1 core=XPM_MEMORY uram
//#pragma HLS resource variable=w_buf_1 core=XPM_MEMORY uram
#pragma HLS resource variable=out_buf_1 core=XPM_MEMORY uram

#pragma HLS ARRAY_PARTITION variable = in_buf_0 complete dim = 1
//#pragma HLS ARRAY_PARTITION variable = in_buf_0 complete dim = 3
#pragma HLS ARRAY_PARTITION variable = w_buf_0 complete dim = 1
#pragma HLS ARRAY_PARTITION variable = w_buf_0 complete dim = 2
#pragma HLS ARRAY_PARTITION variable = w_buf_0 complete
//#pragma HLS ARRAY_PARTITION variable = w_buf_0 complete dim = 2
//#pragma HLS ARRAY_PARTITION variable = w_buf_0 complete dim = 4
#pragma HLS ARRAY_PARTITION variable = b_buf_0 complete dim = 1
#pragma HLS ARRAY_PARTITION variable = b_buf_0 complete
#pragma HLS ARRAY_PARTITION variable = out_buf_0 complete dim = 1
//#pragma HLS ARRAY_PARTITION variable = out_buf_0 factor=2 dim = 2 //II=4 depth=61 // II=2 Depth=65
//II=4 depth=61 // II=2 Depth=65

#pragma HLS ARRAY_PARTITION variable = in_buf_1 complete dim = 1
//#pragma HLS ARRAY_PARTITION variable = in_buf_1 complete dim = 3
#pragma HLS ARRAY_PARTITION variable = w_buf_1 complete dim = 1
#pragma HLS ARRAY_PARTITION variable = w_buf_1 complete dim = 2
#pragma HLS ARRAY_PARTITION variable = w_buf_1 complete
//#pragma HLS ARRAY_PARTITION variable = w_buf_1 complete dim = 2
//#pragma HLS ARRAY_PARTITION variable = w_buf_1 complete dim = 4
#pragma HLS ARRAY_PARTITION variable = b_buf_1 complete dim = 1
#pragma HLS ARRAY_PARTITION variable = b_buf_1 complete
#pragma HLS ARRAY_PARTITION variable = out_buf_1 complete dim = 1

#endif
Expand Down

0 comments on commit bcdf54c

Please sign in to comment.