Skip to content

Commit

Permalink
added simpler version sDTW
Browse files Browse the repository at this point in the history
  • Loading branch information
ioeddk committed Jun 18, 2024
1 parent 7885791 commit 986de8d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions kernels/sdtw/kernel_sdtw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions kernels/sdtw/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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/[email protected]/DP-HLS-Debug/global_affine/"
Expand Down
19 changes: 3 additions & 16 deletions testbench/test_csim_sdtw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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<tbr_t, N_BLOCKS, MAX_QUERY_LENGTH, MAX_REFERENCE_LENGTH>(
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;
}


}

0 comments on commit 986de8d

Please sign in to comment.