main.cpp 1.83 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 * 4;
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 52 53
  string test_name = to_string(num_threads) + ".csv";
  string full_directory = directory + "/PLS_v2/";
  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
  scheduler.perform_work([&]() {
    for (int i = 0; i < fft::NUM_WARMUP_ITERATIONS; i++) {
      conquer(data.begin(), fft::SIZE);
    }
  });
64

65 66 67 68 69 70 71
  scheduler.perform_work([&]() {
    for (int i = 0; i < fft::NUM_ITERATIONS; i++) {
      runner.start_iteration();
      conquer(data.begin(), fft::SIZE);
      runner.end_iteration();
    }
  });
72
  runner.commit_results(true);
73

74
  return 0;
75
}