From b824f7476f36ae6e1dfd3eca49db5f985a62b4b3 Mon Sep 17 00:00:00 2001 From: Nikolai Maas Date: Mon, 25 Nov 2024 15:44:17 +0100 Subject: [PATCH] fix --- CMakeLists.txt | 10 ++++----- cmake/modules/CheckThreadPinning.cmake | 29 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 cmake/modules/CheckThreadPinning.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index de9f648b5..8cc3f1dd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,7 +155,7 @@ endif() ################################################################# -## Platform-specific includes, which interact with options ## +## Platform compatibility checks, which interact with options ## ################################################################# if(UNIX) @@ -166,10 +166,10 @@ if(UNIX) if(NOT KAHYPAR_HEADERS_AVAILABLE) message(FATAL_ERROR "The following system headers are required, but some are not available: ${KAHYPAR_REQUIRED_HEADERS}") endif() - set(KAHYPAR_THREAD_PINNING_HEADERS "sched.h") - check_include_files("${KAHYPAR_THREAD_PINNING_HEADERS}" KAHYPAR_THREAD_PINNING_IS_POSSIBLE LANGUAGE CXX) - if(KAHYPAR_ENABLE_THREAD_PINNING AND NOT KAHYPAR_THREAD_PINNING_IS_POSSIBLE) - message(WARNING "Thread pinning disabled since header is not available: ${KAHYPAR_THREAD_PINNING_HEADERS}") + + include(CheckThreadPinning) + if(KAHYPAR_ENABLE_THREAD_PINNING AND NOT THREAD_PINNING_WORKS) + message(WARNING "Thread pinning disabled since required system APIs are not available.") set(KAHYPAR_ENABLE_THREAD_PINNING FALSE) endif() elseif(NOT WIN32) diff --git a/cmake/modules/CheckThreadPinning.cmake b/cmake/modules/CheckThreadPinning.cmake new file mode 100644 index 000000000..24431bdce --- /dev/null +++ b/cmake/modules/CheckThreadPinning.cmake @@ -0,0 +1,29 @@ +# Check if the required APIs for thread pinning are available + +set(THREAD_PINNING_WORKS FALSE) +if(UNIX) + # Check if sched_getcpu/sched_setaffinity are available + check_include_files("schedx.h" HEADER_AVAILABLE LANGUAGE CXX) + if(${HEADER_AVAILABLE}) + # we need to actually check the available symbols + include(CheckSourceCompiles) + check_source_compiles(CXX + "#include + int main() { + int cpu_id = sched_getcpu(); + int num_cpus = 4; + const size_t size = CPU_ALLOC_SIZE(num_cpus); + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(cpu_id, &mask); + int err = sched_setaffinity(0, size, &mask); + return 0; + }" + EXAMPLE_COMPILES) + if(${EXAMPLE_COMPILES}) + set(THREAD_PINNING_WORKS TRUE) + endif() + endif() +elseif(WIN32) + set(THREAD_PINNING_WORKS TRUE) +endif()