diff options
author | ngc92 <7938269+ngc92@users.noreply.github.com> | 2024-01-15 20:40:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-15 19:40:48 +0100 |
commit | 3e5ca7931c68152e4ec18d126e9c832dd84914c8 (patch) | |
tree | 87df5aa8d147c944e1248072890ea6e77ba34a58 | |
parent | 4483396751c79dea540808b9cb9238245d06da2b (diff) |
pass cpu-architecture arguments only to host code (C;C++) (#4943)
-rw-r--r-- | CMakeLists.txt | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2741568e..7bd64096 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -594,6 +594,13 @@ if (NOT MSVC) endif() endif() +function(add_compile_option_cpp ARG) + # Adds a compile option to C/C++ only, but not for Cuda. + # Use, e.g., for CPU-architecture flags. + add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${ARG}>) + add_compile_options($<$<COMPILE_LANGUAGE:C>:${ARG}>) +endfunction() + if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") OR ("${CMAKE_GENERATOR_PLATFORM_LWR}" MATCHES "arm64")) message(STATUS "ARM detected") if (MSVC) @@ -628,8 +635,7 @@ elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$" OR "${CMAKE_GE include(cmake/FindSIMD.cmake) endif () if (LLAMA_AVX512) - add_compile_options($<$<COMPILE_LANGUAGE:C>:/arch:AVX512>) - add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/arch:AVX512>) + add_compile_option_cpp(/arch:AVX512) # MSVC has no compile-time flags enabling specific # AVX512 extensions, neither it defines the # macros corresponding to the extensions. @@ -643,37 +649,35 @@ elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$" OR "${CMAKE_GE add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:__AVX512VNNI__>) endif() elseif (LLAMA_AVX2) - add_compile_options($<$<COMPILE_LANGUAGE:C>:/arch:AVX2>) - add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/arch:AVX2>) + add_compile_option_cpp(/arch:AVX2) elseif (LLAMA_AVX) - add_compile_options($<$<COMPILE_LANGUAGE:C>:/arch:AVX>) - add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/arch:AVX>) + add_compile_option_cpp(/arch:AVX) endif() else() if (LLAMA_NATIVE) - add_compile_options(-march=native) + add_compile_option_cpp(-march=native) endif() if (LLAMA_F16C) - add_compile_options(-mf16c) + add_compile_option_cpp(-mf16c) endif() if (LLAMA_FMA) - add_compile_options(-mfma) + add_compile_option_cpp(-mfma) endif() if (LLAMA_AVX) - add_compile_options(-mavx) + add_compile_option_cpp(-mavx) endif() if (LLAMA_AVX2) - add_compile_options(-mavx2) + add_compile_option_cpp(-mavx2) endif() if (LLAMA_AVX512) - add_compile_options(-mavx512f) - add_compile_options(-mavx512bw) + add_compile_option_cpp(-mavx512f) + add_compile_option_cpp(-mavx512bw) endif() if (LLAMA_AVX512_VBMI) - add_compile_options(-mavx512vbmi) + add_compile_option_cpp(-mavx512vbmi) endif() if (LLAMA_AVX512_VNNI) - add_compile_options(-mavx512vnni) + add_compile_option_cpp(-mavx512vnni) endif() endif() elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64") |