From 5828d051e613e2b38c8da493d90ade7f44ec28de Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Wed, 14 Sep 2022 21:04:06 +0800 Subject: fix: Fix expt_0830 SIGSEGV Signed-off-by: KunoiSayami --- sortlib.cuh | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'sortlib.cuh') diff --git a/sortlib.cuh b/sortlib.cuh index c90e408..1fdac9c 100644 --- a/sortlib.cuh +++ b/sortlib.cuh @@ -39,6 +39,7 @@ public: } __device__ __host__ const key_type *binary_search(key_type *const start, + const key_type *end, const key_type val) { int step_limit = (int)fast_log(LENGTH); @@ -47,10 +48,21 @@ public: for (int i = 0; i < step_limit; i++) { const auto next_level_start = start + (1 << (i + 1)) - 1; + + // printf("start: %ld, last: %ld\n", next_level_start - start, + // last_known_point - start); + + if (last_known_point > end) { + printf("%ld\n", last_known_point - start); + } if (*last_known_point == val) { return last_known_point; } + if (next_level_start > end) { + printf("%ld\n", next_level_start - start); + } + // son = get_son_from_step(son, (*last_known_point > val)); auto tmp = ((*last_known_point - val) >> MOVE_OFFSET); // printf("tmp: %llu\n", tmp); @@ -62,32 +74,42 @@ public: /*printf("%d %d %d\n", (1 << (i + 1)), son, -(int)((*last_known_point - val) >> MOVE_OFFSET));*/ last_known_point = next_level_start + son; + if (last_known_point > end) { + printf("%p %ld\n", end, next_level_start - start); + } } return last_known_point; } - __device__ __host__ double sample_cdf_custom_version(key_type *start, - key_type x) { - auto it = this->binary_search(start, x); + __device__ __host__ double + sample_cdf_custom_version(key_type *start, const key_type *end, key_type x) { + // printf("custom version:\n"); + auto it = this->binary_search(start, end, x); + // printf("search result: %ld\n", it - start); assert(it <= start + this->LENGTH); - if (it < start) { + /*if (it < start) { printf("it: %p, start: %p\n", it, start); - } + }*/ assert(it >= start); - if (it == start + this->LENGTH) { + + auto prev_real_location = calculate_rank(it - start) - 1; + + if (prev_real_location == this->LENGTH) { return 1; } - if (it == start) { + if (prev_real_location == 0) { return 0; } - auto prev_real_location = calculate_rank(it - start) - 2; + // printf("cal rank: %lu\n", prev_real_location); - auto it_prev = start + calculate_index(prev_real_location) - 1; + auto it_prev = start + calculate_index(prev_real_location - 1) - 1; - return ((double)prev_real_location + - (double)(x - *it_prev) / (*it - *it_prev)) / - (double)(this->LENGTH - 1); + auto tmp = ((double)prev_real_location + + (double)(x - *it_prev) / (double)(*it - *it_prev)) / + (double)(this->LENGTH - 1); + // printf("tmp: %llu %lf %lu\n", *it - *it_prev, tmp, prev_real_location); + return tmp; } __device__ __host__ key_type * -- cgit v1.3.1