main.cpp 2.57 KB
Newer Older
1
#include "pls/pls.h"
2 3 4

#include "benchmark_runner.h"
#include "benchmark_base/fft.h"
5

6
using namespace comparison_benchmarks::base;
7

8
void pls_conquer(fft::complex_vector::iterator data, fft::complex_vector::iterator swap_array, int n) {
9
  if (n < 2) {
10
    return;
11 12
  }

13
  fft::divide(data, swap_array, n);
14
  if (n <= fft::RECURSIVE_CUTOFF) {
15 16
    fft::conquer(data, swap_array, n / 2);
    fft::conquer(data + n / 2, swap_array + n / 2, n / 2);
17
  } else {
18
    pls::spawn([data, n, swap_array]() {
19
      pls_conquer(data, swap_array, n / 2);
20
    });
21
    pls::spawn_and_sync([data, n, swap_array]() {
22
      pls_conquer(data + n / 2, swap_array + n / 2, n / 2);
23
    });
24
  }
25 26

  fft::combine(data, n);
27 28
}

29 30
constexpr int MAX_NUM_TASKS = 16;
constexpr int MAX_STACK_SIZE = 4096 * 1;
31

32
int main(int argc, char **argv) {
33
  auto settings = benchmark_runner::parse_parameters(argc, argv);
34

35 36 37 38 39 40
  fft::complex_vector data(settings.size_);
  fft::complex_vector swap_array(settings.size_);
  fft::fill_input(data);

  string test_name = to_string(settings.num_threads_) + ".csv";
  string full_directory = settings.output_directory_ + "/PLS_v3/";
41
  benchmark_runner runner{full_directory, test_name};
42

43
  pls::scheduler scheduler{(unsigned) settings.num_threads_, MAX_NUM_TASKS, MAX_STACK_SIZE};
44

45
  if (settings.type_ == benchmark_runner::benchmark_settings::ISOLATED) {
46 47 48 49 50
#if PLS_PROFILING_ENABLED
    scheduler.get_profiler().disable_memory_measure();
    runner.add_custom_stats_field("T_1");
    runner.add_custom_stats_field("T_inf");
#endif
51 52 53
    printf("Running isolated measurement...\n");
    runner.enable_memory_stats();
    runner.pre_allocate_stats();
54

55 56 57 58 59 60
    runner.run_iterations(settings.iterations_, [&]() {
      scheduler.perform_work([&]() {
        pls_conquer(data.begin(), swap_array.begin(), settings.size_);;
      });
    }, [&]() {
      fft::fill_input(data); // Reset data before each run
61 62 63 64 65
    }, [&]() {
#if PLS_PROFILING_ENABLED
      runner.store_custom_stat("T_1", scheduler.get_profiler().current_run().t_1_);
      runner.store_custom_stat("T_inf", scheduler.get_profiler().current_run().t_inf_);
#endif
66
    });
67 68 69 70 71
    runner.commit_results(true);
  } else {
    printf("Running periodic measurement...\n");
    runner.enable_wall_time_stats();
    runner.pre_allocate_stats();
72

73 74 75 76 77 78 79 80
    runner.run_periodic(settings.iterations_, settings.interval_period_, settings.interval_deadline_, [&]() {
      scheduler.perform_work([&]() {
        pls_conquer(data.begin(), swap_array.begin(), settings.size_);;
      });
      fft::fill_input(data); // Reset data before each run
    });
    runner.commit_results(true);
  }
81

82
  return 0;
83
}