Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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:
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 }} --parallel

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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()
27 changes: 14 additions & 13 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <algorithm>
#include <array>
#include <chrono>
#include <cstddef>
Expand Down Expand Up @@ -101,9 +102,9 @@ namespace quxflux
}

template<typename T>
constexpr std::string_view to_string()
std::string_view to_string()
{
static std::unordered_map<std::type_index, std::string_view> name_map{
const std::unordered_map<std::type_index, std::string_view> 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"}, //
Expand All @@ -121,11 +122,11 @@ namespace quxflux
}

template<quxflux::sorting_net::type NWT>
constexpr std::string_view to_string()
std::string_view to_string()
{
using SN = quxflux::sorting_net::type;

static std::unordered_map<quxflux::sorting_net::type, std::string_view> name_map{
const std::unordered_map<quxflux::sorting_net::type, std::string_view> 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"}, //
Expand Down Expand Up @@ -237,16 +238,16 @@ namespace quxflux

#define IMPL_BENCHMARK(T) \
template<> \
void detail::benchmark_impl<##T>::operator()(std::set<benchmark_result>& benchmark_results) const \
void detail::benchmark_impl<T>::operator()(std::set<benchmark_result>& 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'; \
} \
Expand Down
Loading