diff options
| author | KunoiSayami <[email protected]> | 2022-09-14 21:04:06 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2022-09-14 21:04:06 +0800 |
| commit | 5828d051e613e2b38c8da493d90ade7f44ec28de (patch) | |
| tree | a461b058f955a15025b76aa52765a43fdaf16e8e /sortlib.cuh | |
| parent | dfff6e20d97539ef85d105eab0b41487e3602878 (diff) | |
fix: Fix expt_0830 SIGSEGV
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'sortlib.cuh')
| -rw-r--r-- | sortlib.cuh | 46 |
1 files changed, 34 insertions, 12 deletions
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 * |
