14 #include <unordered_map>
15 #include <hls_vector.h>
32 array<array<array<float, MAX_REFERENCE_LENGTH>, MAX_QUERY_LENGTH>, N_LAYERS>
scores_cpp;
35 array<array<unsigned int, MAX_REFERENCE_LENGTH>, MAX_QUERY_LENGTH>
tbp_mat_cpp;
37 array<array<tbr_t, MAX_REFERENCE_LENGTH>, MAX_QUERY_LENGTH>
tb_mat_kernel;
38 array<array<char, MAX_REFERENCE_LENGTH>, MAX_QUERY_LENGTH>
tb_mat_cpp;
40 std::map<std::pair<uint, uint>, std::array<std::array<std::array<float, N_LAYERS>, PE_NUM+1>, 2>>
wf_dp_mem;
41 std::map<std::pair<uint, uint>, std::array<bool, PE_NUM>>
wf_predicates;
47 float write[N_LAYERS];
62 : scores_kernel(MAX_QUERY_LENGTH, std::vector<
score_vec_t>(MAX_REFERENCE_LENGTH))
70 void set_score(
int chunk_row_offset,
int chunk_col_offset,
int pe_num,
int wavefront,
score_vec_t vals,
bool pred);
71 void set_scores_wf(
int chunk_row_offset,
int chunk_col_offset,
int wavefront,
score_vec_t vals[PE_NUM],
bool predicates[PE_NUM]);
73 template <
typename IDX_T>
75 array<std::array<std::array<float, N_LAYERS>, PE_NUM+1>, 2> store_dp_mem;
76 for (
int i = 0; i < PE_NUM+1; i++){
77 for (
int j = 0; j < 2; j++){
78 for (
int k = 0; k < N_LAYERS; k++){
79 store_dp_mem[j][i][k] = dp_mem[i][j][k];
83 wf_dp_mem[std::make_pair(ck_idx, wf_idx)] = store_dp_mem;
86 template <
typename IDX_T>
88 for (
int i = 0; i < PE_NUM; i++){
90 scores_infos[std::make_pair(chunk_offset + i, wf_idx - i)] = curr_info;
91 for (
int k = 0; k < N_LAYERS; k++){
92 scores_infos[std::make_pair(chunk_offset + i, wf_idx - i)].
up[k] = dp_mem[i][0][k];
93 scores_infos[std::make_pair(chunk_offset + i, wf_idx - i)].left[k] = dp_mem[i+1][0][k];
94 scores_infos[std::make_pair(chunk_offset + i, wf_idx - i)].diag[k] = dp_mem[i][1][k];
100 template <
typename IDX_T>
102 for (
int i = 0; i < PE_NUM; i++){
103 scores_infos[std::make_pair(chunk_offset + i, wf_idx - i)].entering = entering;
104 scores_infos[std::make_pair(chunk_offset + i, wf_idx - i)].exiting = exiting;
105 scores_infos[std::make_pair(chunk_offset + i, wf_idx - i)].entering_pe = entering_pe;
106 scores_infos[std::make_pair(chunk_offset + i, wf_idx - i)].exiting_pe = exiting_pe;
111 template <
int N_LAYERS_>
114 file <<
"Scores: " << endl;
115 for (
const auto& kv : this->scores_infos) {
116 const std::pair<int, int>& key = kv.first;
118 for (
int i = 0; i < N_LAYERS_; i++){
119 file <<
"Coordinate: (" << key.first <<
", " << key.second <<
"), Layer: " << i <<
120 ", Up: " << value.
up[i] <<
", Left: " << value.
left[i] <<
", Diag: " << value.
diag[i] <<
", Pred: " << value.
pred <<
", ";
122 file <<
"Entering PE: " << value.
entering_pe <<
", ";
125 file <<
"Exiting PE: " << value.
exiting_pe <<
", ";
133 template <
typename IDX_T>
135 for (
int i = 0; i < PE_NUM; i++){
136 this->scores_infos[std::make_pair(ck_offset + i, wf_idx-i)].pred = preds[i];
145 void compare_scores(array<array<array<float, MAX_REFERENCE_LENGTH>, MAX_QUERY_LENGTH>, N_LAYERS> scores_sol,
146 int query_len,
int ref_len);
148 void compare_scores(array<array<array<float, MAX_REFERENCE_LENGTH>, MAX_QUERY_LENGTH>, N_LAYERS> scores_sol,
149 int query_len,
int ref_len,
float threashold);
159 void compare_scores_double(array<array<array<double, MAX_REFERENCE_LENGTH>, MAX_QUERY_LENGTH>, N_LAYERS> scores_sol,
160 int query_len,
int ref_len,
float threashold);
163 std::string debugpath;
164 std::string filepath;
185 template <
typename T1,
typename T2,
int LEN>
188 for (
int i = 0; i < LEN; i++)
190 std_arr[i] = (T2)(hls_arr[i]);
194 template <
typename T1,
typename T2,
int M,
int N>
195 void translate(T1 (&hls_mat)[M][N], T2 (&std_mat)[M][N])
197 for (
int i = 0; i < M; i++)
199 for (
int j = 0; j < N; j++)
201 std_mat[i][j] = (T2)(hls_mat[i][j]);
206 template <
typename T1,
typename T2,
int M,
int N,
int K>
209 for (
int i = 0; i < M; i++)
211 for (
int j = 0; j < N; j++)
213 for (
int k = 0; k < K; k++)
215 std_mat[k][i][j] = (float)(hls_mat[i][j][k]);
221 std::vector<float>
translate_vec(hls::vector<type_t, N_LAYERS>(&arr));
222 std::vector<std::vector<float>>
translate_scores(hls::vector<type_t, N_LAYERS> (&arr)[PE_NUM]);
237 template <
typename T,
int NL,
int M,
int N>
239 hls::vector<T, NL> scores[M][N])
241 std::vector<std::vector<std::vector<float>>> result;
243 for (
int i = 0; i < M; i++)
245 std::vector<std::vector<float>> pe_row;
246 for (
int j = 0; j < N; j++)
248 std::vector<float> pe_vec;
249 for (
int k = 0; k < NL; k++)
251 pe_vec.push_back(scores[i][j][k].to_float());
253 pe_row.push_back(pe_vec);
255 result.push_back(pe_row);
270 template <
typename T,
int NL,
int N>
272 hls::vector<T, NL> scores[N])
274 std::vector<std::vector<float>> result;
276 for (
int i = 0; i < N; i++)
278 std::vector<float> pe_vec;
279 for (
int k = 0; k < NL; k++)
281 pe_vec.push_back(scores[i][k].to_float());
283 result.push_back(pe_vec);
288 template <
typename T,
int M,
int N>
292 std::vector<std::vector<float>> result;
294 for (
int i = 0; i < M; i++)
296 std::vector<float> pe_vec;
297 for (
int k = 0; k < N; k++)
299 pe_vec.push_back(scores[i][k].to_float());
301 result.push_back(pe_vec);
315 template <
typename T,
int NL>
317 hls::vector<T, NL> scores)
319 std::vector<float> result;
321 for (
int k = 0; k < NL; k++)
323 result.push_back(scores[k].to_float());
328 template <
typename T,
int N>
332 std::vector<float> result;
334 for (
int k = 0; k < N; k++)
336 result.push_back(
float(scores[k]));
341 void print_3d(
const char * name, std::vector<std::vector<std::vector<float>>> scores);
342 void print_2d(
const char * name, std::vector<std::vector<float>> scores);
343 void print_1d(
const char * name, std::vector<float> scores);
349 #endif //DP_HLS_DEBUG_H
float diag[N_LAYERS]
Definition: debug.h:46
float left[N_LAYERS]
Definition: debug.h:45
hls::vector< type_t, N_LAYERS > score_vec_t
Vector of scores, used to store the scores of each layer in the same coordiante in the DP matrix...
Definition: dp_hls_common.h:31
void print_2d(const char *name, std::vector< std::vector< float >> scores)
void dump_scores_infos(ofstream &file)
Definition: debug.h:112
void translate_multilayer(T1(&hls_mat)[M][N], T2(&std_mat)[K][M][N])
Definition: debug.h:207
void set_score_info_dependency(IDX_T chunk_offset, IDX_T wf_idx, dp_mem_block_t dp_mem)
Definition: debug.h:87
bool entering
Definition: debug.h:50
Declaration of types used by DP-HLS internally, referred from the user defined params.h file.
std::map< std::pair< int, int >, score_info > scores_infos
Record the information of scores, with their coordinate as the index.
Definition: debug.h:59
std::vector< float > translate_1d(hls::vector< T, NL > scores)
Translate a data structure of the shape hls::vector<T, NL> scores[N] to 1d nested float stl vector...
Definition: debug.h:316
array< array< unsigned int, MAX_REFERENCE_LENGTH >, MAX_QUERY_LENGTH > tbp_mat_cpp
Definition: debug.h:35
std::vector< float > translate_vec(hls::vector< type_t, N_LAYERS >(&arr))
Container()
Definition: debug.h:61
int entering_pe
Definition: debug.h:51
void print_3d(const char *name, std::vector< std::vector< std::vector< float >>> scores)
std::map< std::pair< uint, uint >, std::array< std::array< std::array< float, N_LAYERS >, PE_NUM+1 >, 2 > > wf_dp_mem
Definition: debug.h:40
std::map< std::pair< uint, uint >, std::array< bool, PE_NUM > > wf_predicates
Definition: debug.h:41
void print_1d(const char *name, std::vector< float > scores)
void set_wf_dp_mem(IDX_T ck_idx, IDX_T wf_idx, dp_mem_block_t dp_mem)
Definition: debug.h:74
int exiting_pe
Definition: debug.h:52
std::vector< std::vector< float > > translate_scores(hls::vector< type_t, N_LAYERS >(&arr)[PE_NUM])
void set_score_info_predicates(IDX_T ck_offset, IDX_T wf_idx, bool preds[PE_NUM])
Definition: debug.h:134
float up[N_LAYERS]
Definition: debug.h:44
std::vector< std::vector< std::vector< float > > > translate_3d(hls::vector< T, NL > scores[M][N])
Translate a data structure of the shape hls::vector<T, NL> scores[M][N] to 3d nested float stl vector...
Definition: debug.h:238
array< array< tbr_t, MAX_REFERENCE_LENGTH >, MAX_QUERY_LENGTH > tb_mat_kernel
Definition: debug.h:37
array< array< char, MAX_REFERENCE_LENGTH >, MAX_QUERY_LENGTH > tb_mat_cpp
Definition: debug.h:38
bool exiting
Definition: debug.h:49
score_vec_t dp_mem_block_t[PE_NUM+1][2]
Definition: dp_hls_common.h:87
void set_score_info_entering_exiting(IDX_T chunk_offset, IDX_T wf_idx, bool entering, bool exiting, int entering_pe, int exiting_pe)
Definition: debug.h:101
void translate(T1(&hls_arr)[LEN], T2(&std_arr)[LEN])
Definition: debug.h:186
std::vector< std::vector< float > > translate_2d(hls::vector< T, NL > scores[N])
Translate a data structure of the shape hls::vector<T, NL> scores[N] to 2d nested float stl vector...
Definition: debug.h:271
array< array< tbp_t, MAX_REFERENCE_LENGTH >, MAX_QUERY_LENGTH > tbp_mat_kernel
Definition: debug.h:34
bool pred
Definition: debug.h:48
std::vector< std::vector< score_vec_t > > scores_kernel
Definition: debug.h:31
array< array< array< float, MAX_REFERENCE_LENGTH >, MAX_QUERY_LENGTH >, N_LAYERS > scores_cpp
Definition: debug.h:32