DP-HLS
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
align.h
Go to the documentation of this file.
1 
12 #ifndef SEQ_ALIGN_H
13 #define SEQ_ALIGN_H
14 
15 #include <ap_int.h>
16 #include <hls_vector.h>
17 #include <hls_stream.h>
18 
19 #include "dp_hls_common.h"
20 #include "PE.h"
21 #include "utils.h"
22 #include "frontend.h"
23 
24 #ifdef CMAKEDEBUG
25 #include "./debug.h"
26 #endif // DBEUG
27 
28 using namespace hls;
29 
34 namespace Align
35 {
36 
44  void PrepareLocalQuery(
45  char_t (&query)[MAX_QUERY_LENGTH],
46  char_t (&local_query)[PE_NUM],
47  const idx_t offset);
48 
50  score_vec_t (&init_col_scr)[PE_NUM],
51  stream_of_blocks<dp_mem_block_t> &dp_mem_out);
52 
53  void PrepareScoresArr(
54  dp_mem_block_t &dp_mem_in,
55  score_vec_t (&init_col_scr)[PE_NUM], int id,
56  score_vec_t (&last_chunk_scr)[2],
57  wavefront_scores_t &up_out,
58  wavefront_scores_t &diag_out,
59  wavefront_scores_t &left_out);
60 
72  template <int PE_NUM_T>
74  const char_t (&query)[MAX_QUERY_LENGTH],
75  char_t (&local_query)[PE_NUM_T],
76  score_vec_t (&init_col_scr)[MAX_QUERY_LENGTH],
77  chunk_col_scores_inf_t &init_col_scr_local,
78  bool (&col_pred)[PE_NUM], const idx_t local_query_len,
79  const idx_t idx)
80  {
81  init_col_scr_local[0] = init_col_scr_local[PE_NUM_T]; // backup the last element from previous chunk
82  for (int i = 0; i < PE_NUM_T; i++)
83  {
84  init_col_scr_local[i + 1] = init_col_scr[idx + i];
85  local_query[i] = query[idx + i];
86  col_pred[i] = i < local_query_len;
87  }
88  }
89 
100  void InitializeChunkCoordinates(idx_t chunk_row_offset, idx_t chunk_col_offset, hls::vector<idx_t, PE_NUM> &ic, hls::vector<idx_t, PE_NUM> &jc);
101 
110  void ArrangeTBP(
111  const tbp_vec_t &tbp_in,
112  const idx_t &p_col_offset,
113  const bool (&predicate)[PE_NUM],
114  tbp_t (&chunk_tbp_out)[PE_NUM][TBMEM_SIZE]);
115 
123  void ShiftPredicate(bool (&predicate)[PE_NUM], int idx, int query_len, int reference_len);
124 
132  void ShiftReference(
133  char_t (&local_reference)[PE_NUM], const char_t (&reference)[MAX_REFERENCE_LENGTH],
134  int idx, int ref_len);
135 
143  void PreserveRowScore(
144  score_vec_t (&preserved_row_scr)[MAX_REFERENCE_LENGTH],
145  const score_vec_t score_vec,
146  const bool predicate_pe_last,
147  const idx_t idx);
148 
159  void UpdateDPMem(dp_mem_block_t &dp_mem, idx_t i, chunk_col_scores_inf_t &init_col_scr, score_vec_t (&init_row_scr)[MAX_REFERENCE_LENGTH]);
160 
161  void UpdateDPMemShift(dp_mem_block_t &dp_mem);
162  void UpdateDPMemSet(dp_mem_block_t &dp_mem, idx_t i, chunk_col_scores_inf_t &init_col_scr, score_vec_t (&init_row_scr)[MAX_REFERENCE_LENGTH]);
163 
168  namespace FindMax
169  {
175  void ReductionMaxScores(ScorePack (&max)[PE_NUM], ScorePack &chunk_max, idx_t &max_pe);
176  };
177 
182  namespace Rectangular
183  {
193  void AlignStatic(
194  const char_t (&querys)[MAX_QUERY_LENGTH],
195  const char_t (&references)[MAX_REFERENCE_LENGTH],
196  const idx_t query_length,
197  const idx_t reference_length,
198  const Penalties &penalties,
199 #ifdef LOCAL_TRANSITION_MATRIX
200  const type_t (&transitions)[TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
201 #endif
202  idx_t &tb_i, idx_t &tb_j
203 #ifndef NO_TRACEBACK
204  , tbr_t (&tb_out)[MAX_REFERENCE_LENGTH + MAX_QUERY_LENGTH]
205 #endif
206 #ifdef SCORED
207  , type_t &score
208 #endif
209 #ifdef CMAKEDEBUG
210  , Container &debugger
211 #endif
212  );
213 
224  void ChunkCompute(
225  idx_t chunk_row_offset,
226  input_char_block_t &query,
227  const char_t (&reference)[MAX_REFERENCE_LENGTH],
228  chunk_col_scores_inf_t &init_col_scr,
229  score_vec_t (&init_row_scr)[MAX_REFERENCE_LENGTH],
230  idx_t &p_col_offset, idx_t ck_idx,
231  idx_t global_query_length, idx_t query_length, idx_t reference_length,
232  const bool (&col_pred)[PE_NUM],
233  const Penalties &penalties,
234 #ifdef LOCAL_TRANSITION_MATRIX
235  const type_t (&transitions)[PE_NUM][TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
236 #endif
237  ScorePack (&max)[PE_NUM]
238 #ifndef NO_TRACEBACK
239  , tbp_t (&chunk_tbp_out)[PE_NUM][TBMEM_SIZE]
240 #endif
241 #ifdef CMAKEDEBUG
242  , Container &debugger
243 #endif
244  );
245 
255  void MapPredicate(
256  const idx_t wavefront,
257  const idx_t ref_len, const idx_t qry_len, // This query length is local query length in chunk, always less than PE_NUM
258  bool (&row_pred)[PE_NUM],
259  const bool (&col_pred)[PE_NUM],
260  bool (&pred)[PE_NUM]);
261  }
262 
267  namespace Fixed
268  {
278  void AlignStatic(
279  const char_t (&querys)[MAX_QUERY_LENGTH],
280  const char_t (&references)[MAX_REFERENCE_LENGTH],
281  const idx_t query_length,
282  const idx_t reference_length,
283  const Penalties &penalties,
284 #ifdef LOCAL_TRANSITION_MATRIX
285  const type_t (&transitions)[TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
286 #endif
287  idx_t &tb_i, idx_t &tb_j
288 #ifndef NO_TRACEBACK
289  , tbr_t (&tb_out)[MAX_REFERENCE_LENGTH + MAX_QUERY_LENGTH]
290 #endif
291 #ifdef SCORED
292  , type_t &score
293 #endif
294 #ifdef CMAKEDEBUG
295  , Container &debugger
296 #endif
297  );
298 
309  void ChunkCompute(
310  const idx_t chunk_row_offset,
311  const input_char_block_t &query,
312  const char_t (&reference)[MAX_REFERENCE_LENGTH],
313  const chunk_col_scores_inf_t &init_col_scr,
314  score_vec_t (&init_row_scr)[MAX_REFERENCE_LENGTH],
315  idx_t p_cols, const idx_t ck_idx,
316  idx_t &l_lim_reg, idx_t &u_lim_reg,
317  const bool (&col_pred)[PE_NUM],
318  const idx_t global_query_length, const idx_t local_query_length, const idx_t reference_length,
319  const Penalties &penalties,
320 #ifdef LOCAL_TRANSITION_MATRIX
321  const type_t (&transitions)[PE_NUM][TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
322 #endif
323  ScorePack (&max)[PE_NUM] // write out so must pass by reference
324 #ifndef NO_TRACEBACK
325  , tbp_t (&chunk_tbp_out)[PE_NUM][TBMEM_SIZE]
326 #endif
327 #ifdef CMAKEDEBUG
328  ,
329  Container &debugger
330 #endif
331  );
332 
342  void MapPredicate(
343  const idx_t (&local_l_lim)[PE_NUM], const idx_t (&local_u_lim)[PE_NUM],
344  const idx_t (&virtual_cols)[PE_NUM], const bool (&col_pred)[PE_NUM],
345  bool (&predicate)[PE_NUM]);
346 
347  template <int PE_NUM_, int MAX_QUERY_LENGTH_>
349  const char_t (&query)[MAX_QUERY_LENGTH_],
350  const score_vec_t (&init_col_scr)[MAX_QUERY_LENGTH_],
351  char_t (&local_query)[PE_NUM_],
352  chunk_col_scores_inf_t &init_col_scr_local,
353  bool (&col_pred)[PE_NUM_], const idx_t local_query_len,
354  const idx_t idx)
355  {
356  FixedBandingPrepareChunkLocals:
357  init_col_scr_local[0] = init_col_scr_local[PE_NUM_]; // backup the last element from previous chunk
358  for (int i = 0; i < PE_NUM_; i++)
359  {
360  init_col_scr_local[i + 1] = init_col_scr[idx + i];
361  local_query[i] = query[idx + i];
362  col_pred[i] = i < local_query_len;
363  }
364  }
365  }
366 
374  void InitializeScores(
375  score_vec_t (&init_col_scr)[MAX_QUERY_LENGTH],
376  score_vec_t (&init_row_scr)[MAX_REFERENCE_LENGTH],
377  const Penalties &penalties);
378 
379  void ChunkMax(ScorePack &max, ScorePack new_scr);
380 
381  void UpdatePEOffset(idx_t (&pe_offset)[PE_NUM], bool (&predicate)[PE_NUM]);
382 
383  void CopyColScore(chunk_col_scores_inf_t &init_col_scr_local, score_vec_t (&init_col_scr)[MAX_QUERY_LENGTH], idx_t i);
384 
385  void UpdateDPMemSep(
386  score_vec_t (&dp_mem)[PE_NUM + 1][2],
387  score_vec_t (&score_in)[PE_NUM + 1]);
388 
389  void PrepareScoreBuffer(
390  score_vec_t (&score_buff)[PE_NUM + 1],
391  const idx_t i,
392  const chunk_col_scores_inf_t(&init_col_scr),
393  const score_vec_t (&init_row_scr)[MAX_REFERENCE_LENGTH]);
394 }
395 
396 #endif // !SEQ_ALIGN_H
void ArrangeTBP(const tbp_vec_t &tbp_in, const idx_t &p_col_offset, const bool(&predicate)[PE_NUM], tbp_t(&chunk_tbp_out)[PE_NUM][TBMEM_SIZE])
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
A structure to hold score and index information.
Definition: dp_hls_common.h:46
Definition: debug.h:28
Declaration of types used by DP-HLS internally, referred from the user defined params.h file.
score_vec_t chunk_col_scores_inf_t[PE_NUM+1]
Definition: dp_hls_common.h:88
void ShiftPredicate(bool(&predicate)[PE_NUM], int idx, int query_len, int reference_len)
Determine the predicate values by constantantly shifting the predicate array with truth values...
score_vec_t wavefront_scores_t[PE_NUM]
Definition: dp_hls_common.h:85
void UpdatePEOffset(idx_t(&pe_offset)[PE_NUM], bool(&predicate)[PE_NUM])
void AlignStatic(const char_t(&querys)[MAX_QUERY_LENGTH], const char_t(&references)[MAX_REFERENCE_LENGTH], const idx_t query_length, const idx_t reference_length, const Penalties &penalties, idx_t &tb_i, idx_t &tb_j, tbr_t(&tb_out)[MAX_REFERENCE_LENGTH+MAX_QUERY_LENGTH])
Perform Pairwise alignment for two sequences in rectangular grid, with virtual coordinates.
void PrepareScoreBuffer(score_vec_t(&score_buff)[PE_NUM+1], const idx_t i, const chunk_col_scores_inf_t(&init_col_scr), const score_vec_t(&init_row_scr)[MAX_REFERENCE_LENGTH])
void ReductionMaxScores(ScorePack(&max)[PE_NUM], ScorePack &chunk_max, idx_t &max_pe)
Compare the local maximum of each PE after the score computation and keep the global maximum score...
void PrepareLocalQuery(char_t(&query)[MAX_QUERY_LENGTH], char_t(&local_query)[PE_NUM], const idx_t offset)
At beginning of the computation of each strip, it copy a PE_NUM number of the global query characters...
char_t input_char_block_t[PE_NUM]
Definition: dp_hls_common.h:91
void CopyColScore(chunk_col_scores_inf_t &init_col_scr_local, score_vec_t(&init_col_scr)[MAX_QUERY_LENGTH], idx_t i)
void ShiftReference(char_t(&local_reference)[PE_NUM], const char_t(&reference)[MAX_REFERENCE_LENGTH], int idx, int ref_len)
Shift into the local reference buffer a new reference element, given current wavefront index and refe...
void InitializeScores(score_vec_t(&init_col_scr)[MAX_QUERY_LENGTH], score_vec_t(&init_row_scr)[MAX_REFERENCE_LENGTH], const Penalties &penalties)
Initialize initial scores for the first column and row on the device.
void UpdateDPMemShift(dp_mem_block_t &dp_mem)
void MapPredicate(const idx_t wavefront, const idx_t ref_len, const idx_t qry_len, bool(&row_pred)[PE_NUM], const bool(&col_pred)[PE_NUM], bool(&pred)[PE_NUM])
Logics to map the global coordinates of a wavefront of PE to their prediate values. MapPredicateSquare is a function F: (pe_row: int, pe_col: int) -&gt; (predicate_balue: boolean) It&#39;s unrolled for PE_NUM applying to each PE.
score_vec_t dp_mem_block_t[PE_NUM+1][2]
Definition: dp_hls_common.h:87
void UpdateDPMemSep(score_vec_t(&dp_mem)[PE_NUM+1][2], score_vec_t(&score_in)[PE_NUM+1])
void InitializeChunkCoordinates(idx_t chunk_row_offset, idx_t chunk_col_offset, hls::vector< idx_t, PE_NUM > &ic, hls::vector< idx_t, PE_NUM > &jc)
Initialize two lists of coordinates, x coordinate and y coordinate, for each chunk. Theis function is called within the chunk compute function. This is especially useful if the chunk doesn&#39;t start at the beginning, i.e. after chunk column offset is developed.
void PrepareLocals(const char_t(&query)[MAX_QUERY_LENGTH], char_t(&local_query)[PE_NUM_T], score_vec_t(&init_col_scr)[MAX_QUERY_LENGTH], chunk_col_scores_inf_t &init_col_scr_local, bool(&col_pred)[PE_NUM], const idx_t local_query_len, const idx_t idx)
This function merge PrepareLocalQuery function and CopyColScore function into one, where CopyColScore is a function to copy a column of initial scores from the global buffer to each PE&#39;s local buffer before the computation of each chunk.
Definition: align.h:73
void PreserveRowScore(score_vec_t(&preserved_row_scr)[MAX_REFERENCE_LENGTH], const score_vec_t score_vec, const bool predicate_pe_last, const idx_t idx)
Write the last PE&#39;s output score to the preserved_row_score buffer to be used in the next chunk...
void PrepareScoresArr(dp_mem_block_t &dp_mem_in, score_vec_t(&init_col_scr)[PE_NUM], int id, score_vec_t(&last_chunk_scr)[2], wavefront_scores_t &up_out, wavefront_scores_t &diag_out, wavefront_scores_t &left_out)
void UpdateDPMem(dp_mem_block_t &dp_mem, idx_t i, chunk_col_scores_inf_t &init_col_scr, score_vec_t(&init_row_scr)[MAX_REFERENCE_LENGTH])
Updated the content of the DP Memory with the new scores. It saparates the step of shifting and setti...
void ChunkMax(ScorePack &max, ScorePack new_scr)
void ChunkCompute(idx_t chunk_row_offset, input_char_block_t &query, const char_t(&reference)[MAX_REFERENCE_LENGTH], chunk_col_scores_inf_t &init_col_scr, score_vec_t(&init_row_scr)[MAX_REFERENCE_LENGTH], idx_t &p_col_offset, idx_t ck_idx, idx_t global_query_length, idx_t query_length, idx_t reference_length, const bool(&col_pred)[PE_NUM], const Penalties &penalties, ScorePack(&max)[PE_NUM], tbp_t(&chunk_tbp_out)[PE_NUM][TBMEM_SIZE])
Compute the traceback pointers for a chunk of the size PE_NUM * REFERENCE_LENGTH, with rectangular gr...
tbp_t tbp_vec_t[PE_NUM]
Definition: dp_hls_common.h:90
void InitializeChunkColScore(score_vec_t(&init_col_scr)[PE_NUM], stream_of_blocks< dp_mem_block_t > &dp_mem_out)
ap_uint< 3 > tbr_t
Definition: dp_hls_common.h:94
void UpdateDPMemSet(dp_mem_block_t &dp_mem, idx_t i, chunk_col_scores_inf_t &init_col_scr, score_vec_t(&init_row_scr)[MAX_REFERENCE_LENGTH])