From cbe4695b8bd0a4f0e429af19694030edeaf047a5 Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Fri, 7 Jul 2023 02:33:31 +0800 Subject: feat: Use new read helper class Signed-off-by: KunoiSayami --- expt_0503.cu | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'expt_0503.cu') diff --git a/expt_0503.cu b/expt_0503.cu index c738e43..2785392 100644 --- a/expt_0503.cu +++ b/expt_0503.cu @@ -2,6 +2,7 @@ #define ENABLE_SORT_TEST #include "sortlib.cuh" +#include "read_helper.h" #include #include #include @@ -51,8 +52,7 @@ __global__ void initSample(key_type *sample, key_type *normal_sample, #endif } -__global__ void kernel(unsigned long step, const double slice_size, - const unsigned long split_size) { +__global__ void kernel(unsigned long step, const double slice_size) { auto custom_sort = CustomSort(cuda_sample_length, sizeof(key_type) * 8); // printf("kernel1 step: %ld\n", step); for (int i = 0; i < step; i++) { @@ -151,7 +151,7 @@ void run_kernel(size_t test_size, bool normal = true) { cudaEventCreate(&stop); cudaEventRecord(start, nullptr); if (normal) { - kernel<<>>(step, slice_size, split_size); + kernel<<>>(step, slice_size); } else { kernel2<<>>(step, slice_size); } @@ -173,19 +173,6 @@ void run_kernel(size_t test_size, bool normal = true) { cudaDeviceSynchronize(); } -void read_file(char const *filename, long sample_length, - unsigned long max_number = TEST_LENGTH) { - max_number += sample_length + 256; - auto read_number = 0; - FILE *file = fopen(filename, "r"); - assert(file); - for (long long i; - read_number < max_number && fscanf(file, "%lld ", &i) != EOF; - store_into_vector(i)) - read_number++; - fclose(file); -} - long pow_for_sample(long n) { auto x = 2; for (int i = 0; i < n; i++) { @@ -210,17 +197,16 @@ int main(int argc, char const *argv[]) { sample_length = pow_for_sample(strtol(argv[2], nullptr, 10)); } - read_file("normal_distribution.txt", test_size); + ReadHelper readHelper("normal_distribution.txt", sample_length, test_size, 0); + + printf("test size: %zu, sample length: %zu\n", test_size, sample_length); - printf("population: %zu, test size: %zu, sample length: %zu\n", - population_vector.size(), test_size, sample_length); + readHelper.readFile(); + readHelper.split_into(sample_vector, population_vector); - sample_vector = std::vector( - population_vector.begin(), population_vector.begin() + sample_length - 2); - sample_vector.push_back(min_value); - sample_vector.push_back(max_value); std::sort(sample_vector.begin(), sample_vector.end()); le_sample_vector = sample_vector; + rebuild(sample_vector); key_type *cudaSample = nullptr, *cudaPopulation; cudaMalloc(&cudaSample, sizeof(key_type) * sample_length); -- cgit v1.3.1