From d054e1ab2c5a79c2dac42296cf599e14c1a6cc1f Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Sat, 4 Jan 2020 13:26:10 +0100 Subject: [PATCH] Add fib benchmark. --- CMakeLists.txt | 1 + app/benchmark_fib/CMakeLists.txt | 5 +++++ app/benchmark_fib/main.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ extern/benchmark_base/CMakeLists.txt | 3 ++- extern/benchmark_base/include/benchmark_base/fib.h | 18 ++++++++++++++++++ extern/benchmark_base/include/benchmark_base/matrix.h | 4 +--- 6 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 app/benchmark_fib/CMakeLists.txt create mode 100644 app/benchmark_fib/main.cpp create mode 100644 extern/benchmark_base/include/benchmark_base/fib.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ff7f6c4..bc1107e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ add_subdirectory(app/benchmark_unbalanced) add_subdirectory(app/benchmark_matrix) add_subdirectory(app/benchmark_prefix) add_subdirectory(app/benchmark_pipeline) +add_subdirectory(app/benchmark_fib) # Add optional tests option(PACKAGE_TESTS "Build the tests" ON) diff --git a/app/benchmark_fib/CMakeLists.txt b/app/benchmark_fib/CMakeLists.txt new file mode 100644 index 0000000..af2f63c --- /dev/null +++ b/app/benchmark_fib/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable(benchmark_fib_pls_v2 main.cpp) +target_link_libraries(benchmark_fib_pls_v2 pls benchmark_runner benchmark_base) +if (EASY_PROFILER) + target_link_libraries(benchmark_fib_pls_v2 easy_profiler) +endif () diff --git a/app/benchmark_fib/main.cpp b/app/benchmark_fib/main.cpp new file mode 100644 index 0000000..bf79171 --- /dev/null +++ b/app/benchmark_fib/main.cpp @@ -0,0 +1,84 @@ +#include "pls/internal/scheduling/scheduler.h" +#include "pls/internal/scheduling/parallel_result.h" +#include "pls/internal/scheduling/scheduler_memory.h" +#include "pls/internal/helpers/profiler.h" + +using namespace pls::internal::scheduling; + +#include +#include +#include + +#include "benchmark_runner.h" +#include "benchmark_base/fib.h" + +using namespace comparison_benchmarks::base; + +parallel_result pls_fib(int n) { + if (n <= 1) { + return parallel_result{1}; + } + + return scheduler::par([=]() { + return pls_fib(n - 1); + }, [=]() { + return pls_fib(n - 2); + }).then([=](int a, int b) { + return parallel_result{a + b}; + }); +} + +constexpr int MAX_NUM_THREADS = 8; +constexpr int MAX_NUM_TASKS = 64; +constexpr int MAX_NUM_CONTS = 64; +constexpr int MAX_CONT_SIZE = 256; + +int main(int argc, char **argv) { + int num_threads; + string directory; + benchmark_runner::read_args(argc, argv, num_threads, directory); + + string test_name = to_string(num_threads) + ".csv"; + string full_directory = directory + "/PLS_v2/"; + benchmark_runner runner{full_directory, test_name}; + + static_scheduler_memory static_scheduler_memory; + + scheduler scheduler{static_scheduler_memory, (unsigned int) num_threads}; + + volatile int res; + for (int i = 0; i < fib::NUM_WARMUP_ITERATIONS; i++) { + scheduler.perform_work([&]() { + return scheduler::par([&]() { + return pls_fib(fib::INPUT_N); + }, []() { + return parallel_result{0}; + }).then([&](int result, int) { + res = result; + return parallel_result{0}; + }); + }); + } + + for (int i = 0; i < fib::NUM_ITERATIONS; i++) { + scheduler.perform_work([&]() { + runner.start_iteration(); + + return scheduler::par([&]() { + return pls_fib(fib::INPUT_N); + }, []() { + return parallel_result{0}; + }).then([&](int result, int) { + res = result; + runner.end_iteration(); + return parallel_result{0}; + }); + }); + } + runner.commit_results(true); + + return 0; +} diff --git a/extern/benchmark_base/CMakeLists.txt b/extern/benchmark_base/CMakeLists.txt index 007519f..890a006 100644 --- a/extern/benchmark_base/CMakeLists.txt +++ b/extern/benchmark_base/CMakeLists.txt @@ -7,7 +7,8 @@ add_library(benchmark_base STATIC include/benchmark_base/heat.h include/benchmark_base/matrix.h include/benchmark_base/unbalanced.h src/unbalanced.cpp - include/benchmark_base/range.h) + include/benchmark_base/range.h + include/benchmark_base/fib.h) target_include_directories(benchmark_base PUBLIC diff --git a/extern/benchmark_base/include/benchmark_base/fib.h b/extern/benchmark_base/include/benchmark_base/fib.h new file mode 100644 index 0000000..b9a6a6e --- /dev/null +++ b/extern/benchmark_base/include/benchmark_base/fib.h @@ -0,0 +1,18 @@ + +#ifndef COMPARISON_BENCHMARKS_BASE_FIB_H_ +#define COMPARISON_BENCHMARKS_BASE_FIB_H_ + +namespace comparison_benchmarks { +namespace base { +namespace fib { + +const int INPUT_N = 18; + +const int NUM_ITERATIONS = 1000; +const int NUM_WARMUP_ITERATIONS = 100; + +} +} +} + +#endif //COMPARISON_BENCHMARKS_BASE_FIB_H_ diff --git a/extern/benchmark_base/include/benchmark_base/matrix.h b/extern/benchmark_base/include/benchmark_base/matrix.h index 4838d08..1944c44 100644 --- a/extern/benchmark_base/include/benchmark_base/matrix.h +++ b/extern/benchmark_base/include/benchmark_base/matrix.h @@ -40,9 +40,7 @@ class matrix { } for (int k = 0; k < SIZE; ++k) { for (int j = 0; j < SIZE; ++j) { - T a_data = a.data[i][k]; - T b_data = b.data[k][j]; - data[i][j] += a_data * b_data; + data[i][j] += a.data[i][k] * b.data[k][j]; } } } -- libgit2 0.26.0