main.cpp 2.46 KB
Newer Older
1 2 3
#include "pls/internal/scheduling/scheduler.h"
#include "pls/internal/scheduling/parallel_result.h"
#include "pls/internal/scheduling/scheduler_memory.h"
4
#include "pls/internal/helpers/profiler.h"
5

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

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

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

15
using namespace comparison_benchmarks::base;
16

17
parallel_result<short> conquer(fft::complex_vector::iterator data, int n) {
18
  if (n < 2) {
19
    return parallel_result<short>{0};
20 21
  }

22 23 24 25 26
  fft::divide(data, n);
  if (n <= fft::RECURSIVE_CUTOFF) {
    fft::conquer(data, n / 2);
    fft::conquer(data + n / 2, n / 2);
    fft::combine(data, n);
27
    return parallel_result<short>{0};
28
  } else {
29
    return scheduler::par([=]() {
30
      return conquer(data, n / 2);
31
    }, [=]() {
32
      return conquer(data + n / 2, n / 2);
33
    }).then([=](int, int) {
34
      fft::combine(data, n);
35
      return parallel_result<short>{0};
36
    });
37
  }
38 39
}

40 41 42 43
constexpr int MAX_NUM_THREADS = 8;
constexpr int MAX_NUM_TASKS = 64;
constexpr int MAX_NUM_CONTS = 64;
constexpr int MAX_CONT_SIZE = 256;
44

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

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

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

56 57 58
  static_scheduler_memory<MAX_NUM_THREADS,
                          MAX_NUM_TASKS,
                          MAX_NUM_CONTS,
59 60
                          MAX_CONT_SIZE> static_scheduler_memory;

61
  scheduler scheduler{static_scheduler_memory, (unsigned int) num_threads};
62

63
  for (int i = 0; i < fft::NUM_WARMUP_ITERATIONS; i++) {
64 65
    scheduler.perform_work([&]() {
      return scheduler::par([&]() {
66
        return conquer(data.begin(), fft::SIZE);
67
      }, []() {
68 69
        return parallel_result<short>{0};
      }).then([&](short, short) {
70
        return parallel_result<int>{0};
71 72 73
      });
    });
  }
74 75 76 77 78 79 80 81 82 83 84 85 86 87

  for (int i = 0; i < fft::NUM_ITERATIONS; i++) {
    scheduler.perform_work([&]() {
      runner.start_iteration();

      return scheduler::par([&]() {
        return conquer(data.begin(), fft::SIZE);
      }, []() {
        return parallel_result<short>{0};
      }).then([&](short, short) {
        runner.end_iteration();
        return parallel_result<int>{0};
      });
    });
88
  }
89
  runner.commit_results(true);
90

91
  return 0;
92
}