Skip to content

Commit

Permalink
check specific avx512dq
Browse files Browse the repository at this point in the history
  • Loading branch information
azimafroozeh committed Dec 4, 2024
1 parent 8ca34eb commit f8164c5
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
# Detect hardware AVX-512 support
include(CheckCXXCompilerFlag)
# Step 1: Check compiler support for AVX-512DQ
check_cxx_compiler_flag("-mavx512dq" COMPILER_SUPPORTS_AVX512DQ)

# Step 1: Check compiler support for AVX-512
check_cxx_compiler_flag("-mavx512dq" COMPILER_SUPPORTS_AVX512)
if (COMPILER_SUPPORTS_AVX512DQ)
message(STATUS "Compiler supports AVX-512DQ.")

if (COMPILER_SUPPORTS_AVX512)
message(STATUS "Compiler supports AVX512.")

# Write the test program
file(WRITE "${CMAKE_BINARY_DIR}/check_avx512.cpp"
# Write the test program to check for AVX-512DQ support
file(WRITE "${CMAKE_BINARY_DIR}/check_avx512dq.cpp"
"#include <immintrin.h>
int main() {
__m512i x = _mm512_set1_epi32(1);
return 0;
}"
int main() {
__m512d x = _mm512_set1_pd(1.0); // AVX-512DQ specific intrinsic for double-precision
return 0;
}"
)

try_compile(HAS_AVX512_SUPPORT
try_compile(HAS_AVX512DQ_SUPPORT
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/check_avx512.cpp"
"${CMAKE_BINARY_DIR}/check_avx512dq.cpp"
COMPILE_DEFINITIONS -mavx512dq
)

if (HAS_AVX512_SUPPORT)
message(STATUS "Hardware supports AVX-512. Adding AVX-512 flags.")
set(AVX512_FLAG "-mavx512dq")
if (HAS_AVX512DQ_SUPPORT)
message(STATUS "Hardware supports AVX-512DQ. Adding AVX-512DQ flags.")
set(AVX512DQ_FLAG "-mavx512dq")
else ()
message(STATUS "Hardware does not support AVX-512.")
message(STATUS "Hardware does not support AVX-512DQ.")
endif ()
else ()
message(STATUS "Compiler does not support AVX-512.")
message(STATUS "Compiler does not support AVX-512DQ.")
endif ()

# Define the library
Expand All @@ -42,7 +39,7 @@ add_library(ALP
fastlanes_unffor.cpp
)

# Add AVX-512 flag if supported
if (AVX512_FLAG)
target_compile_options(ALP PUBLIC ${AVX512_FLAG})
# Add AVX-512DQ flag if supported
if (AVX512DQ_FLAG)
target_compile_options(ALP PUBLIC ${AVX512DQ_FLAG})
endif ()

0 comments on commit f8164c5

Please sign in to comment.