Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The LS1 PR: Introduce system for checking compiler flags: avx2 & fma #34

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 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
32 changes: 30 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,36 @@ 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)
claudiushaag marked this conversation as resolved.
Show resolved Hide resolved
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# 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)
if (LSCU_OUTPUT MATCHES "avx2")
set(USE_AVX2 TRUE)
endif()

# Apply compiler options based on hardware detection
if (USE_AVX2)
claudiushaag marked this conversation as resolved.
Show resolved Hide resolved
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(
Expand Down