diff options
| author | KunoiSayami <[email protected]> | 2023-07-07 02:33:31 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2023-07-07 02:33:31 +0800 |
| commit | cbe4695b8bd0a4f0e429af19694030edeaf047a5 (patch) | |
| tree | 2bef84e54fa08fb18031d0f9cac0a3d95a2edc90 /expt_0503.cu | |
| parent | 9eea0a726ffd7dd8f83bbd3a4c5730322c763084 (diff) | |
feat: Use new read helper class
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'expt_0503.cu')
| -rw-r--r-- | expt_0503.cu | 32 |
1 files changed, 9 insertions, 23 deletions
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 <algorithm> #include <cassert> #include <cstdio> @@ -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<<<grid_dim, block_dim>>>(step, slice_size, split_size); + kernel<<<grid_dim, block_dim>>>(step, slice_size); } else { kernel2<<<grid_dim, block_dim>>>(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<key_type>( - 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); |
