main.cpp 1.75 KB
Newer Older
1
#include "pls/internal/scheduling/scheduler.h"
2
#include "pls/internal/scheduling/static_scheduler_memory.h"
3
#include "pls/algorithms/for_each.h"
4

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

7 8
#include "benchmark_runner.h"
#include "benchmark_base/matrix.h"
9

10
using namespace comparison_benchmarks::base;
11 12

template<typename T, int SIZE>
13
class pls_matrix : public matrix::matrix<T, SIZE> {
14
 public:
15
  pls_matrix() : matrix::matrix<T, SIZE>() {}
16

17 18
  void pls_multiply(const matrix::matrix<T, SIZE> &a, const matrix::matrix<T, SIZE> &b) {
    pls::algorithm::for_each_range(0, SIZE, [this, &a, &b](int i) {
19 20 21 22 23
      this->multiply_column(i, a, b);
    });
  }
};

24 25 26 27 28 29 30
constexpr int MAX_NUM_THREADS = 8;
constexpr int MAX_NUM_TASKS = 32;
constexpr int MAX_STACK_SIZE = 1024 * 1;

static_scheduler_memory<MAX_NUM_THREADS,
                        MAX_NUM_TASKS,
                        MAX_STACK_SIZE> global_scheduler_memory;
31

32 33 34 35
int main(int argc, char **argv) {
  int num_threads;
  string directory;
  benchmark_runner::read_args(argc, argv, num_threads, directory);
36

37 38 39
  string test_name = to_string(num_threads) + ".csv";
  string full_directory = directory + "/PLS_v2/";
  benchmark_runner runner{full_directory, test_name};
40

41 42 43
  pls_matrix<double, matrix::MATRIX_SIZE> a;
  pls_matrix<double, matrix::MATRIX_SIZE> b;
  pls_matrix<double, matrix::MATRIX_SIZE> result;
44

45
  scheduler scheduler{global_scheduler_memory, (unsigned) num_threads};
46

47 48 49 50 51
  scheduler.perform_work([&]() {
    for (int i = 0; i < matrix::WARMUP_ITERATIONS; i++) {
      result.pls_multiply(a, b);
    }
  });
52

53 54
  scheduler.perform_work([&]() {
    for (int i = 0; i < matrix::NUM_ITERATIONS; i++) {
55
      runner.start_iteration();
56 57 58 59
      result.pls_multiply(a, b);
      runner.end_iteration();
    }
  });
60 61
  runner.commit_results(true);
}