Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Maas committed Nov 25, 2024
1 parent 486f8ee commit b824f74
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ endif()


#################################################################
## Platform-specific includes, which interact with options ##
## Platform compatibility checks, which interact with options ##
#################################################################

if(UNIX)
Expand All @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions cmake/modules/CheckThreadPinning.cmake
Original file line number Diff line number Diff line change
@@ -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 <sched.h>
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()

0 comments on commit b824f74

Please sign in to comment.