From 875271995b12c00b24f38124b2b19e3fc94d2057 Mon Sep 17 00:00:00 2001 From: Yun-Ze Li Date: Thu, 23 Dec 2021 09:05:17 +0100 Subject: bs_bug_fix: Modify boundary case handlings in BS Current boundary case handling may discard some numbers obliged to be compared with `searching_for`, which in my opinion can result in false positives (BS fails to identify the number which is indeed in the input array). This commit changed the boundary check condition to `if(current_mram_block_addr_A < start_mram_block_addr_A + BLOCK_SIZE)`, where the expression returns true if and only if the length of the range [start_mram_block_addr_A, end_mram_block_addr_A) has become smaller than 2*BLOCK_SIZE. When this happens, we can then finalize the BS result by checking if `searching_for` exists within [start_mram_block_addr_A, end_mram_block_addr_A) without overlooking any number that should be checked. Signed-off-by: Yun-Ze Li --- BS/dpu/task.c | 79 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 41 deletions(-) (limited to 'BS') diff --git a/BS/dpu/task.c b/BS/dpu/task.c index 45c48f5..ac4ca38 100644 --- a/BS/dpu/task.c +++ b/BS/dpu/task.c @@ -17,12 +17,12 @@ __host dpu_arguments_t DPU_INPUT_ARGUMENTS; __host dpu_results_t DPU_RESULTS[NR_TASKLETS]; // Search -static DTYPE search(DTYPE *bufferA, DTYPE searching_for) { +static DTYPE search(DTYPE *bufferA, DTYPE searching_for, size_t search_size) { DTYPE found = -2; if(bufferA[0] <= searching_for) { found = -1; - for (uint32_t i = 0; i < BLOCK_SIZE / sizeof(DTYPE); i++){ + for (uint32_t i = 0; i < search_size / sizeof(DTYPE); i++){ if(bufferA[i] == searching_for) { found = i; @@ -94,13 +94,47 @@ int main_kernel1() { current_mram_block_addr_A = (start_mram_block_addr_A + end_mram_block_addr_A) / 2; current_mram_block_addr_A &= WORD_MASK; - while(!end) + + while(1) { + // Boundary check + if(current_mram_block_addr_A < (start_mram_block_addr_A + BLOCK_SIZE)) + { + //end = true; + // find (start_mram_block_addr_A, start_mram_block_addr_A + BLOCK_SIZE) + mram_read((__mram_ptr void const *) start_mram_block_addr_A, cache_A, BLOCK_SIZE); + found = search(cache_A, searching_for, BLOCK_SIZE); + + if(found > -1) + { + result->found = found + (start_mram_block_addr_A - start_mram_block_addr_aux) / sizeof(DTYPE); + printf("Tasklet %d has found %lld\n", me(), result->found + 1); + } + // find (start_mram_block_addr_A + BLOCK_SIZE, end_mram_block_addr_A) + else + { + size_t remain_bytes_to_search = end_mram_block_addr_A - (start_mram_block_addr_A + BLOCK_SIZE); + mram_read((__mram_ptr void const *) start_mram_block_addr_A + BLOCK_SIZE, cache_A, remain_bytes_to_search); + found = search(cache_A, searching_for, remain_bytes_to_search); + + if(found > -1) + { + result->found = found + (start_mram_block_addr_A + BLOCK_SIZE - start_mram_block_addr_aux) / sizeof(DTYPE); + printf("Tasklet %d has found %lld\n", me(), result->found + 1); + } + else + { + printf("%lld NOT found\n", searching_for); + } + } + break; + } + // Load cache with current MRAM block mram_read((__mram_ptr void const *) current_mram_block_addr_A, cache_A, BLOCK_SIZE); // Search inside block - found = search(cache_A, searching_for); + found = search(cache_A, searching_for, BLOCK_SIZE); // If found > -1, we found the searching_for query if(found > -1) @@ -125,43 +159,6 @@ int main_kernel1() { current_mram_block_addr_A = (current_mram_block_addr_A + end_mram_block_addr_A) / 2; current_mram_block_addr_A &= WORD_MASK; } - - // Start boundary check - if(current_mram_block_addr_A < (start_mram_block_addr_aux + BLOCK_SIZE)) - { - end = true; - mram_read((__mram_ptr void const *) current_mram_block_addr_A, cache_A, BLOCK_SIZE); - found = search(cache_A, searching_for); - - if(found > -1) - { - end = true; - result->found = found + (current_mram_block_addr_A - start_mram_block_addr_aux) / sizeof(DTYPE); - printf("Tasklet %d has found %lld\n", me(), result->found + 1); - } - else - { - printf("%lld NOT found\n", searching_for); - } - } - - // End boundary check - if(current_mram_block_addr_A > (end_mram_block_addr_A - BLOCK_SIZE)) - { - end = true; - mram_read((__mram_ptr void const *) end_mram_block_addr_A - BLOCK_SIZE, cache_A, BLOCK_SIZE); - found = search(cache_A, searching_for); - - if(found > -1) - { - result->found = found + (current_mram_block_addr_A - start_mram_block_addr_aux) / sizeof(DTYPE); - printf("Tasklet %d has found %lld\n", me(), result->found + 1); - } - else - { - printf("%lld NOT found\n", searching_for); - } - } } } return 0; -- cgit v1.2.3