-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the option to output scores and remove the traceback pointer st…
…eramming in the top level function. Added the kernel configuration for local affine with scores without traceback, targeting the BSW kernel in Darwin-WGA.
- Loading branch information
Cloud User
committed
Jun 3, 2024
1 parent
18c714e
commit 9cbcb07
Showing
8 changed files
with
526 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
kernels/banding_local_affine_scored/banding_local_affine_scored.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
#include "frontend.h" | ||
|
||
void BSWAffine::PE::Compute(char_t local_query_val, | ||
char_t local_reference_val, | ||
score_vec_t up_prev, | ||
score_vec_t diag_prev, | ||
score_vec_t left_prev, | ||
const Penalties penalties, | ||
score_vec_t &write_score, | ||
tbp_t &write_traceback) | ||
{ | ||
|
||
// Define Traceback Pointer Navigation Direction | ||
|
||
const type_t insert_open = left_prev[1] + penalties.open + penalties.extend; // Insert open | ||
const type_t insert_extend = left_prev[0] + penalties.open; // insert extend | ||
const type_t delete_open = up_prev[1] + penalties.open + penalties.extend; // delete open | ||
const type_t delete_extend = up_prev[2] + penalties.open; // delete extend | ||
|
||
bool insert_open_b = insert_open > insert_extend; | ||
bool delete_open_b = delete_open > delete_extend; | ||
write_score[0] = insert_open_b ? insert_open : insert_extend; | ||
write_score[2] = delete_open_b ? delete_open : delete_extend; | ||
tbp_t insert_tb = insert_open_b ? (tbp_t) 0 : TB_IMAT; | ||
tbp_t delete_tb = delete_open_b ? (tbp_t) 0 : TB_DMAT; | ||
|
||
|
||
const type_t match = (local_query_val == local_reference_val) ? diag_prev[1] + penalties.match : diag_prev[1] + penalties.mismatch; | ||
|
||
type_t max_value = write_score[0] > write_score[2] ? write_score[0] : write_score[2]; // compare between insertion and deletion | ||
max_value = max_value > match ? max_value : match; | ||
max_value = max_value >= 0 ? max_value : (type_t) 0; // compare with match/mismatch | ||
write_score[1] = max_value; | ||
|
||
tbp_t dir_tb; | ||
|
||
// Set traceback pointer based on the direction of the maximum score. | ||
if (max_value == write_score[0]) | ||
{ // Insert Case | ||
dir_tb = TB_LEFT; | ||
} | ||
else if (max_value == write_score[2]) | ||
{ | ||
dir_tb = TB_UP; | ||
} | ||
else if (max_value == write_score[1]) | ||
{ | ||
dir_tb = TB_DIAG; | ||
} else if (max_value == 0){ | ||
dir_tb = TB_PH; | ||
} | ||
else | ||
{ | ||
// Undefined behavior happens if the max score is non of the I, D, or M. | ||
} | ||
|
||
write_traceback = dir_tb + insert_tb + delete_tb; | ||
} | ||
|
||
void BSWAffine::InitializeScores( | ||
score_vec_t (&init_col_scr)[MAX_QUERY_LENGTH], | ||
score_vec_t (&init_row_scr)[MAX_REFERENCE_LENGTH], | ||
Penalties penalties) | ||
{ | ||
// Utils::Init::ArrSet(init_col_scr, {NINF, 0.0, 0.0}); // qry | ||
// Utils::Init::ArrSet(init_row_scr, {0.0, 0.0, NINF}); // reference layer 0 | ||
|
||
InitializeColumnScores: | ||
for (int i = 0; i < MAX_QUERY_LENGTH; i++) | ||
{ | ||
init_col_scr[i][0] = NINF; | ||
init_col_scr[i][1] = 0.0; | ||
init_col_scr[i][2] = 0.0; | ||
} | ||
InitializeRowScores: | ||
for (int i = 0; i < MAX_REFERENCE_LENGTH; i++) | ||
{ | ||
init_row_scr[i][0] = 0.0; | ||
init_row_scr[i][1] = 0.0; | ||
init_row_scr[i][2] = NINF; | ||
} | ||
} | ||
|
||
void BSWAffine::UpdatePEMaximum( | ||
const wavefront_scores_inf_t scores, | ||
ScorePack (&max)[PE_NUM], | ||
const idx_t chunk_row_offset, const idx_t wavefront, | ||
const idx_t p_cols, const idx_t ck_idx, | ||
const bool (&predicate)[PE_NUM], | ||
const idx_t query_len, const idx_t ref_len){ | ||
|
||
for (idx_t i = 0; i < PE_NUM; i++) | ||
{ | ||
#pragma HLS unroll | ||
if (predicate[i] && (scores[i + 1][LAYER_MAXIMIUM] > max[i].score)) | ||
{ | ||
max[i].score = scores[i + 1][LAYER_MAXIMIUM]; | ||
max[i].p_col = p_cols; | ||
max[i].ck = ck_idx; | ||
} | ||
} | ||
} | ||
|
||
void BSWAffine::InitializeMaxScores(ScorePack (&max)[PE_NUM], idx_t qry_len, idx_t ref_len) | ||
{ | ||
for (int i = 0; i < PE_NUM; i++) | ||
{ | ||
#pragma HLS unroll | ||
max[i].score = NINF; | ||
max[i].p_col = 0; | ||
max[i].ck = 0; | ||
} | ||
} | ||
|
||
void BSWAffine::Traceback::StateMapping(tbp_t tbp, TB_STATE &state, tbr_t &navigation) | ||
{ | ||
|
||
if (state == TB_STATE::MM) | ||
{ | ||
if (tbp(1, 0) == TB_DIAG) | ||
{ | ||
navigation = AL_MMI; | ||
} | ||
else if (tbp(1, 0) == TB_UP) | ||
{ | ||
state = TB_STATE::DEL; | ||
navigation = AL_NULL; | ||
} | ||
else if (tbp(1, 0) == TB_LEFT) | ||
{ | ||
state = TB_STATE::INS; | ||
navigation = AL_NULL; | ||
} else if (tbp(1, 0) == TB_PH){ | ||
navigation = AL_END; | ||
} | ||
} | ||
else if (state == TB_STATE::DEL) | ||
{ | ||
if ((bool)tbp[3]) | ||
{ // deletion extending | ||
// states remains the same. | ||
// printf("delete extend"); | ||
} | ||
else | ||
{ // deletion closing | ||
state = TB_STATE::MM; // set the state back to MM | ||
} | ||
navigation = AL_DEL; | ||
} | ||
else if (state == TB_STATE::INS) | ||
{ | ||
if ((bool)tbp[2]) | ||
{ // insertion extending | ||
// states remains the same. | ||
// ("delete extend"); | ||
} | ||
else | ||
{ // insertion closing | ||
state = TB_STATE::MM; // set the state back to MM | ||
} | ||
navigation = AL_INS; | ||
} | ||
else | ||
{ | ||
// Placeholder for kernel side debug | ||
} | ||
} | ||
|
||
void BSWAffine::Traceback::StateInit(tbp_t tbp, TB_STATE &state) | ||
{ | ||
if (tbp(1, 0) == TB_DIAG) | ||
{ | ||
state = TB_STATE::MM; | ||
} | ||
else if (tbp(1, 0) == TB_UP) | ||
{ | ||
state = TB_STATE::DEL; | ||
} | ||
else if (tbp(1, 0) == TB_LEFT) | ||
{ | ||
state = TB_STATE::INS; | ||
} | ||
else | ||
{ | ||
// Placeholder for kernel side debug | ||
} | ||
} | ||
|
||
// <<< Local Affine Implementation <<< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#ifndef PARAMS_H | ||
#define PARAMS_H | ||
|
||
#include <ap_int.h> | ||
#include <ap_fixed.h> | ||
#include <hls_vector.h> | ||
|
||
#define MAX_QUERY_LENGTH 256 | ||
#define MAX_REFERENCE_LENGTH 256 | ||
|
||
#define BANDING FIXED | ||
#define BANDWIDTH 64 | ||
|
||
#define SCORED | ||
#define NO_TRACEBACK | ||
|
||
#define PE_NUM 32 | ||
|
||
#define ALIGN_TYPE BSWAffine | ||
#define N_BLOCKS 8 | ||
#define N_LAYERS 3 | ||
#define LAYER_MAXIMIUM 1 // We need to indicate from which layer (main matrix) is the maximum score stored. | ||
|
||
// Primitive Types | ||
typedef ap_uint<2> char_t; // Sequence Alphabet | ||
typedef ap_fixed<16, 12> type_t; // Scores Type <width, integer_width> | ||
typedef short idx_t; // Indexing Type, could be much less than 32. ap_uint<8> | ||
typedef ap_uint<4> tbp_t; // Traceback Pointer Type | ||
|
||
// Define Zero Value | ||
#define zero_fp ((type_t)0) | ||
#define ZERO_CHAR (char_t(0)) | ||
|
||
// Defien upper and lower bound for score type, aka type_t | ||
#define INF 1024 | ||
#define NINF -1024 | ||
|
||
// Legacy Debugger Configuration | ||
#define DEBUG_OUTPUT_PATH "/home/[email protected]/DP-HLS-Debug/local_affine/" | ||
#define DEBUG_FILENAME "debug_kernel" | ||
|
||
#define TB_PH (tbp_t) 0b00 | ||
#define TB_LEFT (tbp_t) 0b01 | ||
#define TB_DIAG (tbp_t) 0b10 | ||
#define TB_UP (tbp_t) 0b11 | ||
|
||
#define TB_IMAT (tbp_t) 0b0100 // Insertion Matrix | ||
#define TB_DMAT (tbp_t) 0b1000 // Deletion Matrix | ||
|
||
|
||
struct Penalties { | ||
type_t open; | ||
type_t extend; | ||
type_t mismatch; | ||
type_t match; | ||
type_t linear_gap; | ||
}; | ||
|
||
enum TB_STATE { | ||
MM = 0, // Match/Mismatch | ||
INS = 1, // Insertion | ||
DEL = 2, // Deletion | ||
END = 3 // End | ||
}; | ||
|
||
|
||
#endif |
Oops, something went wrong.