@ -25,12 +25,94 @@ endif()
message ( STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}" )
message ( STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}" )
if ( NOT UNAME_S )
execute_process ( COMMAND uname -s OUTPUT_VARIABLE UNAME_S )
endif ( )
if ( NOT UNAME_P )
execute_process ( COMMAND uname -p OUTPUT_VARIABLE UNAME_P )
endif ( )
if ( NOT UNAME_M )
execute_process ( COMMAND uname -m OUTPUT_VARIABLE UNAME_M )
endif ( )
message ( STATUS "UNAME_S: ${UNAME_S} UNAME_P: ${UNAME_P} UNAME_M: ${UNAME_M}" )
# M a c O S + A r m c a n r e p o r t x 8 6 _ 6 4
# r e f : h t t p s : / / g i t h u b . c o m / g g e r g a n o v / w h i s p e r . c p p / i s s u e s / 6 6 # i s s u e c o m m e n t - 1 2 8 2 5 4 6 7 8 9
if ( UNAME_S MATCHES "Darwin" )
if ( NOT UNAME_P MATCHES "arm" )
execute_process ( COMMAND sysctl -n hw.optional.arm64 OUTPUT_VARIABLE SYSCTL_M )
if ( SYSCTL_M MATCHES "1" )
# set ( UNAME_P "arm" )
# set ( UNAME_M "arm64" )
message ( WARNING "Your arch is announced as x86_64, but it seems to actually be ARM64. Not fixing that can lead to bad performance. For more info see: https://github.com/ggerganov/whisper.cpp/issues/66\#issuecomment-#1282546789" )
endif ( )
endif ( )
endif ( )
if ( ${ CMAKE_SYSTEM_PROCESSOR } MATCHES "arm" OR ${ CMAKE_SYSTEM_PROCESSOR } MATCHES "aarch64" )
if ( ${ CMAKE_SYSTEM_PROCESSOR } MATCHES "arm" OR ${ CMAKE_SYSTEM_PROCESSOR } MATCHES "aarch64" )
message ( STATUS "ARM detected" )
message ( STATUS "ARM detected" )
# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=apple-m1" )
# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=apple-m1" )
else ( )
else ( )
message ( STATUS "x86 detected" )
message ( STATUS "x86 detected" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx -mavx2 -mfma -mf16c" )
# set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx -mavx2 -mfma -mf16c" )
if ( UNAME_S MATCHES "Darwin" )
execute_process ( COMMAND sysctl machdep.cpu.features OUTPUT_VARIABLE AVX1_M )
if ( AVX1_M MATCHES "AVX1.0" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx" )
endif ( )
execute_process ( COMMAND sysctl machdep.cpu.leaf7_features OUTPUT_VARIABLE AVX2_M )
if ( AVX2_M MATCHES "AVX2" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2" )
endif ( )
if ( AVX1_M MATCHES "FMA" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma" )
endif ( )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mf16c" )
elseif ( UNAME_S MATCHES "Linux" )
message ( STATUS "Linux detected" )
execute_process ( COMMAND grep "avx " /proc/cpuinfo OUTPUT_VARIABLE AVX1_M )
if ( AVX1_M MATCHES "avx" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx" )
endif ( )
execute_process ( COMMAND grep "avx2 " /proc/cpuinfo OUTPUT_VARIABLE AVX2_M )
if ( AVX2_M MATCHES "avx2" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2" )
endif ( )
execute_process ( COMMAND grep "fma " /proc/cpuinfo OUTPUT_VARIABLE FMA_M )
if ( FMA_M MATCHES "fma" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma" )
endif ( )
execute_process ( COMMAND grep "f16c " /proc/cpuinfo OUTPUT_VARIABLE F16C_M )
if ( F16C_M MATCHES "f16c" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mf16c" )
endif ( )
execute_process ( COMMAND grep "sse3 " /proc/cpuinfo OUTPUT_VARIABLE SSE3_M )
if ( SSE3_M MATCHES "sse3" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3" )
endif ( )
message ( STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}" )
elseif ( UNAME_S MATCHES "Haiku" )
message ( STATUS "Haiku detected" )
execute_process ( COMMAND sysinfo -cpu | grep "AVX " OUTPUT_VARIABLE AVX1_M )
if ( AVX1_M MATCHES "avx" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx" )
endif ( )
execute_process ( COMMAND sysinfo -cpu | grep "AVX2 " OUTPUT_VARIABLE AVX2_M )
if ( AVX2_M MATCHES "avx2" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2" )
endif ( )
execute_process ( COMMAND sysinfo -cpu | grep "FMA " OUTPUT_VARIABLE FMA_M )
if ( FMA_M MATCHES "fma" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma" )
endif ( )
execute_process ( COMMAND sysinfo -cpu | grep "F16C " OUTPUT_VARIABLE F16C_M )
if ( F16C_M MATCHES "f16c" )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mf16c" )
endif ( )
message ( STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}" )
else ( )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfma -mf16c -mavx -mavx2" )
endif ( )
endif ( )
endif ( )