From ac5ec9ddbac56e582d1361a15f3fa3217fd55d9a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 1 Nov 2024 21:19:46 +0100 Subject: [PATCH 1/3] Introduce system for checking compiler flags + i7-2600 was otherwise not able to built + super backward change + does not apply/test on macos --- CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c652e7b..395857c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,8 +102,42 @@ add_library(FANS::FANS ALIAS FANS_FANS) if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm|aarch64") target_compile_options(FANS_FANS PUBLIC -march=armv8-a+simd+fp+crypto) elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") - target_compile_options(FANS_FANS PUBLIC -mavx2 -mfma) -endif () + # Detecting if there is avx2 and fma support on linux + # Deteced together, because these flags were introduced by Intel Haskell 4th. Gen + # Distinguishing between mac/linux because lscpu is used, which is not supported on mac. + if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + # macOS: Assume AVX2 and FMA are supported as per requirement + message(STATUS "Assuming AVX2 and FMA support on macOS; using -mavx2 and -mfma.") + target_compile_options(FANS_FANS PUBLIC -mavx2 -mfma) + elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") + # Linux: Check for AVX2 support using lscpu or /proc/cpuinfo + execute_process( + COMMAND lscpu + OUTPUT_VARIABLE LSCU_OUTPUT + ERROR_QUIET + ) + + # Default to AVX; enable AVX2 if supported by hardware + set(USE_AVX2 FALSE) + if (LSCU_OUTPUT MATCHES "avx2") + set(USE_AVX2 TRUE) + endif() + + # Apply compiler options based on hardware detection + if (USE_AVX2) + message(STATUS "AVX2 and FMA supported by hardware; using -mavx2 and -mfma.") + target_compile_options(FANS_FANS PUBLIC -mavx2 -mfma) + else() + message(WARNING "AVX2 and FMA not supported by hardware; falling back to AVX.") + target_compile_options(FANS_FANS PUBLIC -mavx) + endif() + else() + message(WARNING "Unsupported system for AVX2 detection; defaulting to -mavx.") + target_compile_options(FANS_FANS PUBLIC -mavx) + endif() +endif() + + add_executable(FANS_main) add_custom_command( From 5eca54240c9865077fb52a2ab7649c1e52025357 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 1 Nov 2024 21:41:57 +0100 Subject: [PATCH 2/3] Make pretty --- CMakeLists.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 395857c..9c66d14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,12 +110,8 @@ elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") message(STATUS "Assuming AVX2 and FMA support on macOS; using -mavx2 and -mfma.") target_compile_options(FANS_FANS PUBLIC -mavx2 -mfma) elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") - # Linux: Check for AVX2 support using lscpu or /proc/cpuinfo - execute_process( - COMMAND lscpu - OUTPUT_VARIABLE LSCU_OUTPUT - ERROR_QUIET - ) + # Linux: Check for AVX2 support using lscpu + execute_process(COMMAND lscpu OUTPUT_VARIABLE LSCU_OUTPUT ERROR_QUIET) # Default to AVX; enable AVX2 if supported by hardware set(USE_AVX2 FALSE) @@ -137,8 +133,6 @@ elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") endif() endif() - - add_executable(FANS_main) add_custom_command( TARGET FANS_main From c7903f682c29fe59ecf88da5aae81b3948f8962f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 4 Nov 2024 17:35:00 +0100 Subject: [PATCH 3/3] Change variable name --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c66d14..a272ea3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,13 +114,13 @@ elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") execute_process(COMMAND lscpu OUTPUT_VARIABLE LSCU_OUTPUT ERROR_QUIET) # Default to AVX; enable AVX2 if supported by hardware - set(USE_AVX2 FALSE) + set(FANS_USE_AVX2 FALSE) if (LSCU_OUTPUT MATCHES "avx2") - set(USE_AVX2 TRUE) + set(FANS_USE_AVX2 TRUE) endif() # Apply compiler options based on hardware detection - if (USE_AVX2) + if (FANS_USE_AVX2) message(STATUS "AVX2 and FMA supported by hardware; using -mavx2 and -mfma.") target_compile_options(FANS_FANS PUBLIC -mavx2 -mfma) else()