From: Jacob Lifshay Date: Thu, 21 Jul 2022 10:18:09 +0000 (-0700) Subject: benchmarking c++11 atomics works X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ecb29549cf226ed129caa7d43ce79e8b2e4d9575;p=benchmarks.git benchmarking c++11 atomics works --- diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1a14a9d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug", + "program": "${workspaceFolder}/build-x86_64/benchmarks", + "args": [ + "-j1" + ], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 630965c..c096ee7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,4 +4,5 @@ "-DCMAKE_TOOLCHAIN_FILE=toolchain-x86_64-linux-gnu.cmake" ], "cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json", + "cmake.generator": "Unix Makefiles", } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index f239c80..025462d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,17 @@ -cmake_minimum_required(VERSION 3.11.0) +cmake_minimum_required(VERSION 3.12.0) project(benchmarks VERSION 0.1.0) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +find_package(Threads REQUIRED) + add_compile_options(-Wall -Wextra -Wimplicit-fallthrough) -add_executable(benchmarks main.cpp harness.cpp) +file(GLOB_RECURSE sources + RELATIVE ${CMAKE_SOURCE_DIR} + CONFIGURE_DEPENDS src/*.cpp src/*.c) +add_executable(benchmarks "${sources}") +target_link_libraries(benchmarks Threads::Threads) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) diff --git a/Makefile b/Makefile index a701537..64bacb5 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ all: $(foreach arch,$(enabled_arches),build-$(arch)/benchmarks) common_cmake_flags = -S . common_cmake_flags += -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE +common_cmake_flags += -DCMAKE_BUILD_TYPE=RelWithDebInfo reset_make_env = "MAKEFLAGS=" "MFLAGS=" "MAKELEVEL=" "MAKE_TERMERR=" "MAKE_TERMOUT=" diff --git a/harness.cpp b/harness.cpp deleted file mode 100644 index 2de66f0..0000000 --- a/harness.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "harness.h" - -void BenchHarnessBase::base_run( - Config config, void (*fn)(BenchHarnessBase *bench_harness_base, - std::uint64_t iteration_count)) -{ - // FIXME: finish -} \ No newline at end of file diff --git a/harness.h b/harness.h deleted file mode 100644 index 3c4cd28..0000000 --- a/harness.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -struct Config final -{ - std::optional thread_count; - std::optional iteration_count; -}; - -template > -class BenchHarness; - -class BenchHarnessBase -{ - template - friend class BenchHarness; - - private: - void base_run(Config config, - void (*fn)(BenchHarnessBase *bench_harness_base, - std::uint64_t iteration_count)); -}; - -template -class BenchHarness> final - : private BenchHarnessBase -{ - private: - Fn fn; - - public: - void run(Config config) - { - base_run(config, [](BenchHarnessBase *bench_harness_base, - std::uint64_t iteration_count) { - auto &fn = static_cast(bench_harness_base)->fn; - for (std::uint64_t i = 0; i < iteration_count; i++) - { - Input input; - - // optimization barrier - asm("" : : "r"(std::addressof(input)) : "memory"); - - auto output = fn(input); - - // optimization barrier - asm("" : : "r"(std::addressof(output)) : "memory"); - } - }); - } -}; \ No newline at end of file diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 2008393..0000000 --- a/main.cpp +++ /dev/null @@ -1,418 +0,0 @@ -#include "harness.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std::literals; - -enum class OptionValueKind -{ - None, - Required, -}; - -class OptionsParser; - -struct Option final -{ - char short_name = '\0'; - std::string_view long_name = "", description = ""; - bool required = false; - bool all_other_args_not_required = false; - OptionValueKind value_kind = OptionValueKind::None; - std::function value)> - parse_value; - bool has_short_name() const - { - return short_name != '\0'; - } - bool has_long_name() const - { - return !long_name.empty(); - } - friend std::ostream &operator<<(std::ostream &os, const Option &option) - { - if (option.has_long_name()) - { - os << "--" << option.long_name; - } - else if (option.has_short_name()) - { - os << "-" << option.short_name; - } - else - { - os << "--"; - } - return os; - } -}; - -class Options final -{ - friend class OptionsParser; - - private: - std::vector