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 --- expt_0830.cu | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'expt_0830.cu') diff --git a/expt_0830.cu b/expt_0830.cu index bbca9cf..845c44e 100644 --- a/expt_0830.cu +++ b/expt_0830.cu @@ -8,8 +8,9 @@ std::vector population_vector, sample_vector; constexpr size_t SAMPLE_LENGTH = 1023; -// constexpr size_t TEST_LENGTH = 16'384; -constexpr size_t TEST_LENGTH = 2048; +constexpr size_t TEST_LENGTH = 16'384; +// constexpr size_t TEST_LENGTH = 4096; +constexpr size_t RESERVED_BLOCK = 10'000; unsigned long long max_value = 0, min_value = 0xfffffffff; typedef std::pair dim_pair_type; @@ -46,17 +47,23 @@ __global__ void initSample(key_type *sample, key_type *population) { __global__ void kernel(unsigned long step, const double slice_size, const unsigned long split_size) { auto custom_sort = CustomSort(SAMPLE_LENGTH, sizeof(key_type) * 8); - // printf("kernel1\n"); + // printf("kernel1 step: %ld\n", step); for (int i = 0; i < step; i++) { auto tid = step * (blockIdx.x * blockDim.x + threadIdx.x) + i; // printf("%d\n", tid); auto index = (int)(custom_sort.sample_cdf_custom_version( - cudaSampleItem, cudaPopulationItem[tid]) / - slice_size); + cudaSampleItem, cudaSampleItem + SAMPLE_LENGTH, + cudaPopulationItem[tid]) / + slice_size) - + 1; + // printf("%llu %d\n", cudaPopulationItem[tid], index); if (cdf_result[index]) { while (cdf_result[++index]) { - assert(index < split_size); + /*if (index >= split_size) { + printf("escape: %llu %lu\n", cudaPopulationItem[tid], split_size); + }*/ + assert(index < (split_size + RESERVED_BLOCK)); } } cdf_result[index] = true; @@ -127,8 +134,9 @@ __global__ void print_function() { __global__ void initStorage(unsigned scale, unsigned test_size) { cudaFree(cdf_result); - cudaMalloc(&cdf_result, scale * test_size * sizeof(bool)); - memset(cdf_result, 0, scale * test_size * sizeof(bool)); + // printf("test size: %u\n", test_size); + cudaMalloc(&cdf_result, (scale * test_size + RESERVED_BLOCK) * sizeof(bool)); + memset(cdf_result, 0, (scale * test_size + RESERVED_BLOCK) * sizeof(bool)); } __global__ void freeStorage() { @@ -138,24 +146,24 @@ __global__ void freeStorage() { } __global__ void initCustomSample() { + // printf("init\n"); key_type *tmp = nullptr; auto custom_sort = CustomSort(SAMPLE_LENGTH, 0); cudaMalloc(&tmp, sizeof(key_type) * SAMPLE_LENGTH); for (size_t i = 0; i < SAMPLE_LENGTH; i++) { tmp[i] = cudaSampleItem[custom_sort.calculate_index(i) - 1]; } + // printf("copy\n"); memcpy(cudaSampleItem, tmp, sizeof(key_type) * SAMPLE_LENGTH); cudaFree(tmp); tmp = nullptr; // memset(cdf_result, 0, sizeof(key_type) * TEST_LENGTH); cudaFree(cdf_result); cdf_result = nullptr; + // printf("finalize\n"); } -const dim_pair_type DIM_PAIR[] = { - dim_pair_type(16, 64), - // dim_pair_type(32, 32) -}; +const dim_pair_type DIM_PAIR[] = {dim_pair_type(16, 64), dim_pair_type(32, 32)}; void run_kernel(size_t test_size, bool custom = false) { for (auto &pair : DIM_PAIR) { @@ -185,6 +193,9 @@ void run_kernel(size_t test_size, bool custom = false) { cudaEventElapsedTime(&time, start, stop); cudaEventDestroy(start); cudaEventDestroy(stop); + if (time == 0) { + // printf("last error: %u\n", cudaGetLastError()); + } printf("time: %lf\n", time); print_function<<<1, 1>>>(); @@ -202,6 +213,7 @@ int main() { ; fclose(file); + printf("test size: %d\n", test_size); sample_vector = std::vector( population_vector.begin(), population_vector.begin() + SAMPLE_LENGTH - 2); sample_vector.push_back(min_value); -- cgit v1.3.1