From 88ea0d39385c8c73fe626a2b9c89dc1dfa7a4423 Mon Sep 17 00:00:00 2001 From: Lukas Riebel Date: Tue, 9 Sep 2025 14:16:06 +0200 Subject: [PATCH 1/3] fix benchmark generation code for gcc --- src/util.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/util.h b/src/util.h index 47e627a..b6b832e 100644 --- a/src/util.h +++ b/src/util.h @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include #include #include #include @@ -103,7 +104,7 @@ namespace quxflux template constexpr std::string_view to_string() { - static std::unordered_map name_map{ + const std::unordered_map name_map{ std::pair{std::type_index(typeid(int16_t)), "int16_t"}, // std::pair{std::type_index(typeid(int32_t)), "int32_t"}, // std::pair{std::type_index(typeid(int64_t)), "int64_t"}, // @@ -125,7 +126,7 @@ namespace quxflux { using SN = quxflux::sorting_net::type; - static std::unordered_map name_map{ + const std::unordered_map name_map{ std::pair{SN::bubble_sort, "SN::bubble_sort"}, // std::pair{SN::insertion_sort, "SN::insertion_sort"}, // std::pair{SN::batcher_odd_even_merge_sort, "SN::batcher_odd_even_merge_sort"}, // @@ -237,16 +238,16 @@ namespace quxflux #define IMPL_BENCHMARK(T) \ template<> \ - void detail::benchmark_impl<##T>::operator()(std::set& benchmark_results) const \ + void detail::benchmark_impl::operator()(std::set& benchmark_results) const \ { \ - benchmark_all_with_size_and_type<1, ##T>(benchmark_results); \ - benchmark_all_with_size_and_type<2, ##T>(benchmark_results); \ - benchmark_all_with_size_and_type<4, ##T>(benchmark_results); \ - benchmark_all_with_size_and_type<8, ##T>(benchmark_results); \ - benchmark_all_with_size_and_type<16, ##T>(benchmark_results); \ - benchmark_all_with_size_and_type<32, ##T>(benchmark_results); \ - benchmark_all_with_size_and_type<64, ##T>(benchmark_results); \ - benchmark_all_with_size_and_type<128, ##T>(benchmark_results); \ + benchmark_all_with_size_and_type<1, T>(benchmark_results); \ + benchmark_all_with_size_and_type<2, T>(benchmark_results); \ + benchmark_all_with_size_and_type<4, T>(benchmark_results); \ + benchmark_all_with_size_and_type<8, T>(benchmark_results); \ + benchmark_all_with_size_and_type<16, T>(benchmark_results); \ + benchmark_all_with_size_and_type<32, T>(benchmark_results); \ + benchmark_all_with_size_and_type<64, T>(benchmark_results); \ + benchmark_all_with_size_and_type<128, T>(benchmark_results); \ \ std::clog << '\n'; \ } \ From e6afa04d590eb3d80cab4c499e0dc38fa45fdfdf Mon Sep 17 00:00:00 2001 From: Lukas Riebel Date: Sun, 14 Sep 2025 17:11:05 +0200 Subject: [PATCH 2/3] add github action --- .github/workflows/cmake-multi-platform.yml | 76 ++++++++++++++++++++++ CMakeLists.txt | 5 ++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/cmake-multi-platform.yml diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml new file mode 100644 index 0000000..55c4941 --- /dev/null +++ b/.github/workflows/cmake-multi-platform.yml @@ -0,0 +1,76 @@ +# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml +name: CMake on multiple platforms + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release] + c_compiler: [gcc, clang, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v4 + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + # Building with `SORTING_NETWORK_CPP_BUILD_BENCHMARK=ON` to ensure that the benchmarks can be built + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DSORTING_NETWORK_CPP_BUILD_TESTS=ON + -DSORTING_NETWORK_CPP_BUILD_BENCHMARK=ON + -S ${{ github.workspace }} + + - name: Build + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: ls -la . && ctest --build-config ${{ matrix.build_type }} + diff --git a/CMakeLists.txt b/CMakeLists.txt index e820e05..5858731 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,10 @@ if(SORTING_NETWORK_CPP_BUILD_TESTS) CPMAddPackage("gh:brunocodutra/metal#v2.1.4") CPMAddPackage("gh:google/googletest#release-1.12.0") + include(GoogleTest) + + enable_testing() + set(SN_TESTS_EXECUTABLE_NAME ${PROJECT_NAME}_tests) add_executable(${SN_TESTS_EXECUTABLE_NAME} @@ -60,4 +64,5 @@ if(SORTING_NETWORK_CPP_BUILD_TESTS) "test/test_size_optimized_sort.cpp" ) target_link_libraries(${SN_TESTS_EXECUTABLE_NAME} GTest::gtest GTest::gmock GTest::gtest_main Metal project_options sorting_network_cpp) + gtest_discover_tests(${SN_TESTS_EXECUTABLE_NAME}) endif() From 6c2a86506be83e2029d0ef15bf89e0273159ff44 Mon Sep 17 00:00:00 2001 From: Lukas Riebel Date: Sun, 14 Sep 2025 17:29:35 +0200 Subject: [PATCH 3/3] fix clang build --- .github/workflows/cmake-multi-platform.yml | 12 ++---------- src/util.h | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 55c4941..e0b569f 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -1,5 +1,3 @@ -# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. -# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml name: CMake on multiple platforms on: @@ -17,11 +15,6 @@ jobs: fail-fast: false # Set up a matrix to run the following 3 configurations: - # 1. - # 2. - # 3. - # - # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: os: [ubuntu-latest, windows-latest] build_type: [Release] @@ -68,9 +61,8 @@ jobs: -S ${{ github.workspace }} - name: Build - run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel - name: Test working-directory: ${{ steps.strings.outputs.build-output-dir }} - run: ls -la . && ctest --build-config ${{ matrix.build_type }} - + run: ctest --build-config ${{ matrix.build_type }} diff --git a/src/util.h b/src/util.h index b6b832e..c932d65 100644 --- a/src/util.h +++ b/src/util.h @@ -102,7 +102,7 @@ namespace quxflux } template - constexpr std::string_view to_string() + std::string_view to_string() { const std::unordered_map name_map{ std::pair{std::type_index(typeid(int16_t)), "int16_t"}, // @@ -122,7 +122,7 @@ namespace quxflux } template - constexpr std::string_view to_string() + std::string_view to_string() { using SN = quxflux::sorting_net::type;