Skip to content

Commit

Permalink
Merge pull request #23 from TurakhiaLab/transition_protein_sw
Browse files Browse the repository at this point in the history
Implemented the protein local affine kernel with the switch that if enabled, it allows each PE to keep their own copy of the transition matrices.
  • Loading branch information
ioeddk authored Jun 20, 2024
2 parents 986de8d + 73d49f8 commit 0b21825
Show file tree
Hide file tree
Showing 21 changed files with 441 additions and 67 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ add_executable(test_csim_local_two_piece_affine
"kernels/local_two_piece_affine/kernel_local_two_piece_affine.cpp"
${COMMON_SRCS})


add_executable(test_global_affine_real_data
"testbench/test_csim_global_affine_real_data.cpp"
"kernels/global_affine/kernel_global_affine.cpp"
Expand Down
9 changes: 9 additions & 0 deletions include/PE.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace PE
const input_char_block_t qry,
const input_char_block_t ref,
const Penalties penalties,
#ifdef LOCAL_TRANSITION_MATRIX
const type_t (&transitions)[PE_NUM][TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
tbp_vec_t &tbp);

/**
Expand All @@ -47,6 +50,9 @@ namespace PE
const input_char_block_t &qry,
const input_char_block_t &ref,
const Penalties penalties,
#ifdef LOCAL_TRANSITION_MATRIX
const type_t (&transitions)[PE_NUM][TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
wavefront_scores_inf_t &score,
tbp_vec_t &tbp);

Expand All @@ -66,6 +72,9 @@ namespace PE
const input_char_block_t qry,
const input_char_block_t ref,
const Penalties penalties,
#ifdef LOCAL_TRANSITION_MATRIX
const type_t (&transitions)[PE_NUM][TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
wavefront_scores_inf_t &score,
tbp_vec_t &tbp);

Expand Down
12 changes: 12 additions & 0 deletions include/align.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ namespace Align
const idx_t query_length,
const idx_t reference_length,
const Penalties &penalties,
#ifdef LOCAL_TRANSITION_MATRIX
const type_t (&transitions)[TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
idx_t &tb_i, idx_t &tb_j
#ifndef NO_TRACEBACK
, tbr_t (&tb_out)[MAX_REFERENCE_LENGTH + MAX_QUERY_LENGTH]
Expand Down Expand Up @@ -286,6 +289,9 @@ namespace Align
idx_t global_query_length, idx_t query_length, idx_t reference_length,
const bool (&col_pred)[PE_NUM],
const Penalties &penalties,
#ifdef LOCAL_TRANSITION_MATRIX
const type_t (&transitions)[PE_NUM][TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
ScorePack (&max)[PE_NUM]
#ifndef NO_TRACEBACK
, tbp_t (&chunk_tbp_out)[PE_NUM][TBMEM_SIZE]
Expand Down Expand Up @@ -329,6 +335,9 @@ namespace Align
const idx_t query_length,
const idx_t reference_length,
const Penalties &penalties,
#ifdef LOCAL_TRANSITION_MATRIX
const type_t (&transitions)[TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
idx_t &tb_i, idx_t &tb_j
#ifndef NO_TRACEBACK
, tbr_t (&tb_out)[MAX_REFERENCE_LENGTH + MAX_QUERY_LENGTH]
Expand Down Expand Up @@ -362,6 +371,9 @@ namespace Align
const bool (&col_pred)[PE_NUM],
const idx_t global_query_length, const idx_t local_query_length, const idx_t reference_length,
const Penalties &penalties,
#ifdef LOCAL_TRANSITION_MATRIX
const type_t (&transitions)[PE_NUM][TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
ScorePack (&max)[PE_NUM] // write out so must pass by reference
#ifndef NO_TRACEBACK
, tbp_t (&chunk_tbp_out)[PE_NUM][TBMEM_SIZE]
Expand Down
3 changes: 3 additions & 0 deletions include/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace ALIGN_TYPE
score_vec_t diag_prev,
score_vec_t left_prev,
const Penalties penalties,
#ifdef LOCAL_TRANSITION_MATRIX
const type_t transitions[TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
score_vec_t &write_score,
tbp_t &write_traceback);

Expand Down
5 changes: 4 additions & 1 deletion include/seq_align_multiple.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ extern "C" {
char_t (&references)[MAX_REFERENCE_LENGTH][N_BLOCKS],
idx_t (&query_lengths)[N_BLOCKS],
idx_t (&reference_lengths)[N_BLOCKS],
Penalties (&penalties)[N_BLOCKS],
const Penalties (&penalties)[N_BLOCKS],
#ifdef LOCAL_TRANSITION_MATRIX
const type_t (&transitions)[TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
idx_t (&tb_is)[N_BLOCKS], idx_t (&tb_js)[N_BLOCKS]
#ifndef NO_TRACEBACK
, tbr_t (&tb_streams)[MAX_REFERENCE_LENGTH + MAX_QUERY_LENGTH][N_BLOCKS]
Expand Down
4 changes: 3 additions & 1 deletion kernels/dtw/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#define PE_NUM 32
#define LAYER_MAXIMIUM 0 // We need to indicate from which layer (main matrix) is the maximum score stored.

#define BANDING RECTANGULAR

typedef ap_fixed<32, 26> num_t;

#define BANDING RECTANGULAR

// Primitive Types
struct char_t_st {
Expand All @@ -30,6 +31,7 @@ struct char_t_st {
};

typedef char_t_st char_t; // Sequence Alphabet

typedef ap_fixed<32,26> 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<2> tbp_t; // Traceback Pointer Type
Expand Down
19 changes: 0 additions & 19 deletions kernels/global_linear/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@ typedef ap_uint<2> tbp_t; // Traceback Pointer Type
#define DEBUG_OUTPUT_PATH "/home/[email protected]/DP-HLS-Debug/global_affine/"
#define DEBUG_FILENAME "debug_kernel"

struct ScorePack{
type_t score;
idx_t row;
idx_t col;
idx_t p_col;
idx_t ck;
idx_t pe;

// Default Constructor
ScorePack() {
score = 0;
row = 0;
col = 0;
p_col = 0;
ck = 0;
pe = 0;
}
};

struct Penalties {
type_t open;
type_t extend;
Expand Down
4 changes: 2 additions & 2 deletions kernels/local_affine/kernel_local_affine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ void LocalAffine::PE::Compute(char_t local_query_val,
// 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 insert_extend = left_prev[0] + penalties.extend; // 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
const type_t delete_extend = up_prev[2] + penalties.extend; // delete extend

bool insert_open_b = insert_open > insert_extend;
bool delete_open_b = delete_open > delete_extend;
Expand Down
25 changes: 13 additions & 12 deletions kernels/protein_local_affine/kernel_protein_local_affine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ void ProteinLocalAffine::PE::Compute(char_t local_query_val,
score_vec_t diag_prev,
score_vec_t left_prev,
const Penalties penalties,
#ifdef LOCAL_TRANSITION_MATRIX
const type_t transitions[TRANSITION_MATRIX_SIZE][TRANSITION_MATRIX_SIZE],
#endif
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
const type_t insert_open = left_prev[1] + penalties.open; // Insert open
const type_t insert_extend = left_prev[0] + penalties.extend; // insert extend
const type_t delete_open = up_prev[1] + penalties.open; // delete open
const type_t delete_extend = up_prev[2] + penalties.extend; // delete extend

bool insert_open_b = insert_open > insert_extend;
bool delete_open_b = delete_open > delete_extend;
Expand All @@ -24,8 +27,10 @@ void ProteinLocalAffine::PE::Compute(char_t local_query_val,
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;
// transition SW
// std::cout << "accessing" << local_query_val.to_int() << "and" << local_reference_val.to_int() << std::endl;
const type_t match = transitions[local_query_val][local_reference_val] + diag_prev[1];
// std::cout << "accessed" << std::endl;

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;
Expand Down Expand Up @@ -68,16 +73,12 @@ void ProteinLocalAffine::InitializeScores(
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;
init_col_scr[i] = {NINF, 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;
init_row_scr[i] = {0, 0, NINF};
}
}

Expand Down
8 changes: 5 additions & 3 deletions kernels/protein_local_affine/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

#define BANDING RECTANGULAR

#define LOCAL_TRANSITION_MATRIX
#define TRANSITION_MATRIX_SIZE 20

#define SCORED

#define ALIGN_TYPE ProteinLocalAffine
#define N_BLOCKS 1
#define N_LAYERS 3
Expand Down Expand Up @@ -46,9 +51,6 @@ typedef ap_uint<4> tbp_t; // Traceback Pointer Type
struct Penalties {
type_t open;
type_t extend;
type_t mismatch;
type_t match;
type_t linear_gap;
};

enum TB_STATE {
Expand Down
1 change: 1 addition & 0 deletions kernels/sdtw/kernel_sdtw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void SDTW::PE::Compute(char_t local_query_val,
// The RTL code uses left and diagonal is because possible the query and reference is transposed.
// find max from diagonal and left
write_score[0] = (diag_prev[0] < up_prev[0] ? diag_prev[0] : up_prev[0]) + abs(local_query_val - local_reference_val);

}

void SDTW::UpdatePEMaximum(
Expand Down
2 changes: 1 addition & 1 deletion kernels/sdtw/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

#define MAX_QUERY_LENGTH 500 // This is read length in SF
#define MAX_REFERENCE_LENGTH 1000 // This is Reference length in SF.
#define MAX_REFERENCE_LENGTH 60000 // This is Reference length in SF.

// The default PE_NUM is 100.

Expand Down
5 changes: 4 additions & 1 deletion some notes
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
/usr/lib64/libOpenCL.so
/usr/lib64/libOpenCL.so.1
/usr/lib64/libOpenCL.so.1.0.0
(base) [centos@ip-172-31-21-210 DP-HLS]$
(base) [centos@ip-172-31-21-210 DP-HLS]$

Kernel Aligned Query : MAFSAEDVLKEYDRRRRMEALLLSLYYPNDRKLLDYKEWSPPRVQVECPKAPVEWNNPPSEKGLIVGHFSGIKYKGEKAQASEVDVNKMCCWVSKFKDAMRRYQGIQTCKIPGKVLSDLDAKIKAYNLTVEGVEGFVRYSRVTKQHVAAFLKELRHSKQYENVNLIHYILTDKRVDIQHLEKDLVKDFKALV
Kernel Aligned Reference: ___________________________________________________________________________________MSIIGATRLQNDKSDTYSAGPCYAGGCSAFTPRGTCGKDWDLGEQTCASGFCTSQPLCARIKKTQVCGLRYSSKGKDPLVSAEWDSRGAPYV_RCTYDADL_IDTQAQV
Loading

0 comments on commit 0b21825

Please sign in to comment.