main.cpp 1.86 KB
Newer Older
1
#include "pls/internal/scheduling/scheduler.h"
2
#include "pls/internal/scheduling/static_scheduler_memory.h"
3

4
using namespace pls::internal::scheduling;
5

6 7
#include "benchmark_runner.h"
#include "benchmark_base/fft.h"
8

9
using namespace comparison_benchmarks::base;
10

11
void pls_conquer(fft::complex_vector::iterator data, fft::complex_vector::iterator swap_array, int n) {
12
  if (n < 2) {
13
    return;
14 15
  }

16
  fft::divide(data, swap_array, n);
17
  if (n <= fft::RECURSIVE_CUTOFF) {
18 19
    fft::conquer(data, swap_array, n / 2);
    fft::conquer(data + n / 2, swap_array + n / 2, n / 2);
20
  } else {
21 22
    scheduler::spawn([data, n, swap_array]() {
      pls_conquer(data, swap_array, n / 2);
23
    });
24 25
    scheduler::spawn([data, n, swap_array]() {
      pls_conquer(data + n / 2, swap_array + n / 2, n / 2);
26 27
    });
    scheduler::sync();
28
  }
29 30

  fft::combine(data, n);
31 32
}

33
constexpr int MAX_NUM_THREADS = 8;
34
constexpr int MAX_NUM_TASKS = 32;
35
constexpr int MAX_STACK_SIZE = 1024 * 8;
36

37 38 39 40
int main(int argc, char **argv) {
  int num_threads;
  string directory;
  benchmark_runner::read_args(argc, argv, num_threads, directory);
41

42
  string test_name = to_string(num_threads) + ".csv";
43
  string full_directory = directory + "/PLS_v3/";
44
  benchmark_runner runner{full_directory, test_name};
45

46 47 48
  fft::complex_vector data(fft::SIZE);
  fft::complex_vector swap_array(fft::SIZE);
  fft::fill_input(data);
49

50 51 52
  static_scheduler_memory<MAX_NUM_THREADS,
                          MAX_NUM_TASKS,
                          MAX_STACK_SIZE> global_scheduler_memory;
53
  scheduler scheduler{global_scheduler_memory, (unsigned) num_threads};
54

55 56
  runner.run_iterations(fft::NUM_ITERATIONS, [&]() {
    scheduler.perform_work([&]() {
57
      pls_conquer(data.begin(), swap_array.begin(), fft::SIZE);;
58
    });
59 60 61
  }, fft::NUM_WARMUP_ITERATIONS, [&]() {
    fft::fill_input(data); // Reset data before each run
  });
62
  runner.commit_results(true);
63

64
  return 0;
65
}