main.cpp 1.66 KB
Newer Older
1
#include "pls/internal/scheduling/scheduler.h"
2
#include "pls/internal/scheduling/static_scheduler_memory.h"
3
#include "pls/internal/helpers/profiler.h"
4

5
using namespace pls::internal::scheduling;
6 7 8 9 10

#include <iostream>
#include <complex>
#include <vector>

11 12
#include "benchmark_runner.h"
#include "benchmark_base/fft.h"
13

14
using namespace comparison_benchmarks::base;
15

16
void conquer(fft::complex_vector::iterator data, int n) {
17
  if (n < 2) {
18
    return;
19 20
  }

21 22 23 24
  fft::divide(data, n);
  if (n <= fft::RECURSIVE_CUTOFF) {
    fft::conquer(data, n / 2);
    fft::conquer(data + n / 2, n / 2);
25
  } else {
26 27
    scheduler::spawn([data, n]() {
      conquer(data, n / 2);
28
    });
29 30 31 32
    scheduler::spawn([data, n]() {
      conquer(data + n / 2, n / 2);
    });
    scheduler::sync();
33
  }
34 35

  fft::combine(data, n);
36 37
}

38
constexpr int MAX_NUM_THREADS = 8;
39
constexpr int MAX_NUM_TASKS = 32;
40
constexpr int MAX_STACK_SIZE = 1024 * 32;
41 42 43 44

static_scheduler_memory<MAX_NUM_THREADS,
                        MAX_NUM_TASKS,
                        MAX_STACK_SIZE> global_scheduler_memory;
45

46 47 48 49
int main(int argc, char **argv) {
  int num_threads;
  string directory;
  benchmark_runner::read_args(argc, argv, num_threads, directory);
50

51
  string test_name = to_string(num_threads) + ".csv";
52
  string full_directory = directory + "/PLS_v3/";
53
  benchmark_runner runner{full_directory, test_name};
54

55
  fft::complex_vector data = fft::generate_input();
56

57
  scheduler scheduler{global_scheduler_memory, (unsigned) num_threads};
58

59 60 61 62 63
  runner.run_iterations(fft::NUM_ITERATIONS, [&]() {
    scheduler.perform_work([&]() {
      conquer(data.begin(), fft::SIZE);;
    });
  }, fft::NUM_WARMUP_ITERATIONS);
64
  runner.commit_results(true);
65

66
  return 0;
67
}