From 986de8ddb3567f3acdf83166516aac2768bfcf7e Mon Sep 17 00:00:00 2001 From: Yingqi Cao Date: Tue, 18 Jun 2024 22:55:26 +0000 Subject: [PATCH] added simpler version sDTW --- CMakeLists.txt | 2 +- kernels/sdtw/kernel_sdtw.cpp | 12 ++++++++---- kernels/sdtw/params.h | 6 +++--- testbench/test_csim_sdtw.cpp | 19 +++---------------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9926be4..578fb09c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fsanitize=address -fno-inline -D # "-fsanitize=address" flag was used to check the stack smashing with Google Address Sanitizer. Use this flag with CLang and # run the program to check. -set(DP_HLS_HOME "/home/centos/workspace/banding/DP-HLS") +set(DP_HLS_HOME "/home/centos/workspace/DP-HLS") set(EXECUTABLE_TARGETS baseline_local_linear diff --git a/kernels/sdtw/kernel_sdtw.cpp b/kernels/sdtw/kernel_sdtw.cpp index 0c1f45f4..89b3502d 100644 --- a/kernels/sdtw/kernel_sdtw.cpp +++ b/kernels/sdtw/kernel_sdtw.cpp @@ -14,9 +14,9 @@ void SDTW::InitializeScores( // Because the cell scores are non-negative (because the distance is L1 distance and accumulates), thus initialize // them to all 0 means exactly the same to initialize the first column in actual score matrix to be the distance // between q_i and r_0. min(diag, left, always have 0). - for (int i = 0; i < MAX_QUERY_LENGTH; i++) + for (int i = 0; i < MAX_REFERENCE_LENGTH; i++) { - init_col_scr[i][0] = 0; + init_row_scr[i][0] = 0; } // doesn't need to initialize the initial reference since no upper cell dependencey. @@ -31,8 +31,10 @@ void SDTW::PE::Compute(char_t local_query_val, score_vec_t &write_score, tbp_t &write_traceback) { + // The paper mentions there is no reference deletion, which means that the there is no left dependency but only diag and up. + // 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] < left_prev[0] ? diag_prev[0] : left_prev[0]) + abs(local_query_val - local_reference_val); + 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( @@ -46,10 +48,12 @@ void SDTW::UpdatePEMaximum( // Like SF, only do when QueryLength is multiple of PE_NUM, thus only let last PE findmax. if (predicate[PE_NUM-1]) { - if (scores[PE_NUM][LAYER_MAXIMIUM] > max[PE_NUM-1].score) + if (scores[PE_NUM][LAYER_MAXIMIUM] > max[PE_NUM-1].score && chunk_row_offset + PE_NUM == query_len) { // NOTE: If we just care about the score but doesn't care where does the score come from, then we doesn't need to update p_cols and ck index as well. max[PE_NUM-1].score = scores[PE_NUM][LAYER_MAXIMIUM]; + max[PE_NUM-1].p_col = p_cols; + max[PE_NUM-1].ck = ck_idx; } } } diff --git a/kernels/sdtw/params.h b/kernels/sdtw/params.h index 3fedf8a2..c964305e 100644 --- a/kernels/sdtw/params.h +++ b/kernels/sdtw/params.h @@ -37,7 +37,7 @@ // const int sf_score_width = 10 + std::ceil(std::log2(MAX_REFERENCE_LENGTH)); typedef ap_uint<8> char_t; // Sequence Alphabet -typedef ap_uint<32> type_t; // FIXME +typedef ap_uint<64> type_t; // FIXME typedef short idx_t; // Indexing Type, could be much less than 32. ap_uint<8> typedef ap_uint<2> tbp_t; // Traceback Pointer Type @@ -49,11 +49,11 @@ typedef ap_uint<2> tbp_t; // Traceback Pointer Type // Define Zero Value #define zero_fp ((type_t)0) -#define ZERO_CHAR (char_t({0,0})) +#define ZERO_CHAR (char_t(0)) // Defien upper and lower bound for score type, aka type_t #define INF 16777216 -#define NINF -16777216 +#define NINF 0 // Because all the scores are non-negative, it make sense only if the NINF is 0. Assign negative score here result in underflow for type_t and incorrect alignment score. // Legacy Debugger Configuration #define DEBUG_OUTPUT_PATH "/home/yic033@AD.UCSD.EDU/DP-HLS-Debug/global_affine/" diff --git a/testbench/test_csim_sdtw.cpp b/testbench/test_csim_sdtw.cpp index f3a40133..5513689b 100644 --- a/testbench/test_csim_sdtw.cpp +++ b/testbench/test_csim_sdtw.cpp @@ -112,10 +112,6 @@ int main(){ } } - - // Allocate traceback streams - tbr_t tb_streams[MAX_REFERENCE_LENGTH + MAX_QUERY_LENGTH][N_BLOCKS]; - // initialize traceback starting coordinates idx_t tb_is[N_BLOCKS]; idx_t tb_js[N_BLOCKS]; @@ -167,19 +163,10 @@ int main(){ tb_query_lengths[i] = (int) tb_is[i]; tb_reference_lengths[i] = (int) tb_js[i]; } - tbr_t tb_streams_host[N_BLOCKS][MAX_REFERENCE_LENGTH + MAX_QUERY_LENGTH]; - HostUtils::IO::SwitchDimension(tb_streams, tb_streams_host); - kernel_alignments = HostUtils::Sequence::ReconstructTracebackBlocks( - query_string_blocks, reference_string_blocks, - tb_query_lengths, tb_reference_lengths, - tb_streams_host); - - // Print kernel 0 traceback + + // Print kernel alignment scores for (int i = 0; i < N_BLOCKS; i++) { cout << "Kernel " << i << " Traceback" << endl; - cout << "Kernel Aligned Query : " << kernel_alignments[0]["query"] << endl; - cout << "Kernel Aligned Reference: " << kernel_alignments[0]["reference"] << endl; + cout << "Alignment Scores: " << scores[i] << endl; } - - } \ No newline at end of file