From 8609dea781dffe4bb88a85bd3df8325170e427d8 Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Fri, 1 Aug 2025 22:12:07 +0200 Subject: [PATCH 1/2] Disable CodeView debug format for Windows ARM64 --- cmake/arm64-windows-llvm.cmake | 19 +++++++++++++++++-- examples/quantize-stats/quantize-stats.cpp | 11 ++++++++++- ggml/src/ggml-impl.h | 2 +- ggml/src/iqk/iqk_quantize.cpp | 11 ++++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/cmake/arm64-windows-llvm.cmake b/cmake/arm64-windows-llvm.cmake index a93bf4fb4a..83c8b8efa3 100644 --- a/cmake/arm64-windows-llvm.cmake +++ b/cmake/arm64-windows-llvm.cmake @@ -12,5 +12,20 @@ set( CMAKE_CXX_COMPILER_TARGET ${target} ) set( arch_c_flags "-march=armv8.7-a -Xclang -target-feature -Xclang +fullfp16 -fvectorize -ffp-model=fast -fno-finite-math-only" ) set( warn_c_flags "-Wno-format -Wno-unused-variable -Wno-unused-function -Wno-gnu-zero-variadic-macro-arguments" ) -set( CMAKE_C_FLAGS_INIT "${arch_c_flags} ${warn_c_flags}" ) -set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags} ${warn_c_flags}" ) +set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "") +set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT_DEFAULT "") + +set(base_flags "${arch_c_flags} ${warn_c_flags}") +set(debug_flags "-g -gdwarf-4") + +set(CMAKE_C_FLAGS_INIT "${base_flags}") +set(CMAKE_CXX_FLAGS_INIT "${base_flags}") + +set(CMAKE_C_FLAGS_DEBUG_INIT "${debug_flags}") +set(CMAKE_CXX_FLAGS_DEBUG_INIT "${debug_flags}") +set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -DNDEBUG ${debug_flags}") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -DNDEBUG ${debug_flags}") +set(CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG") +set(CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG") +set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG") diff --git a/examples/quantize-stats/quantize-stats.cpp b/examples/quantize-stats/quantize-stats.cpp index 02cfb25d33..25ec15868b 100644 --- a/examples/quantize-stats/quantize-stats.cpp +++ b/examples/quantize-stats/quantize-stats.cpp @@ -34,15 +34,24 @@ #if defined(_MSC_VER) #pragma warning(disable: 4244 4267) // possible loss of data #include +#if defined(_M_X64) || defined(_M_IX86) #include #include #include +#endif #include -inline int popcount(uint8_t x) { return __popcnt(x); } +#if defined(_M_X64) || defined(_M_IX86) +inline int popcount(uint8_t x) { return __popcnt(x); } inline int popcount(uint16_t x) { return __popcnt(x); } inline int popcount(uint32_t x) { return __popcnt(x); } inline int popcount(uint64_t x) { return _mm_popcnt_u64(x); } #else +inline int popcount(uint8_t x) { return __builtin_popcount(x); } +inline int popcount(uint16_t x) { return __builtin_popcount(x); } +inline int popcount(uint32_t x) { return __builtin_popcount(x); } +inline int popcount(uint64_t x) { return __builtin_popcountll(x); } +#endif +#else constexpr int popcount(uint8_t x) { return __builtin_popcount(x); } constexpr int popcount(uint16_t x) { return __builtin_popcount(x); } constexpr int popcount(uint32_t x) { return __builtin_popcount(x); } diff --git a/ggml/src/ggml-impl.h b/ggml/src/ggml-impl.h index e4e3686088..213ce0b0e8 100644 --- a/ggml/src/ggml-impl.h +++ b/ggml/src/ggml-impl.h @@ -445,7 +445,7 @@ static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) { #include #else #if defined(__AVX__) || defined(__AVX2__) || defined(__AVX512F__) || defined(__SSSE3__) || defined(__SSE3__) || defined(__SSE__) -#if !defined(__riscv) +#if !defined(__riscv) && !defined(__aarch64__) #include #endif #endif diff --git a/ggml/src/iqk/iqk_quantize.cpp b/ggml/src/iqk/iqk_quantize.cpp index ece0b7346e..1325fd0280 100644 --- a/ggml/src/iqk/iqk_quantize.cpp +++ b/ggml/src/iqk/iqk_quantize.cpp @@ -34,15 +34,24 @@ #if defined(_MSC_VER) #pragma warning(disable: 4244 4267) // possible loss of data #include +#if defined(_M_X64) || defined(_M_IX86) #include #include #include +#endif #include -inline int popcount(uint8_t x) { return __popcnt(x); } +#if defined(_M_X64) || defined(_M_IX86) +inline int popcount(uint8_t x) { return __popcnt(x); } inline int popcount(uint16_t x) { return __popcnt(x); } inline int popcount(uint32_t x) { return __popcnt(x); } inline int popcount(uint64_t x) { return _mm_popcnt_u64(x); } #else +inline int popcount(uint8_t x) { return __builtin_popcount(x); } +inline int popcount(uint16_t x) { return __builtin_popcount(x); } +inline int popcount(uint32_t x) { return __builtin_popcount(x); } +inline int popcount(uint64_t x) { return __builtin_popcountll(x); } +#endif +#else constexpr int popcount(uint8_t x) { return __builtin_popcount(x); } constexpr int popcount(uint16_t x) { return __builtin_popcount(x); } constexpr int popcount(uint32_t x) { return __builtin_popcount(x); } From 8e105a5ee78ddaafac079b800fb3ca876a54915c Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Sat, 2 Aug 2025 08:28:06 +0200 Subject: [PATCH 2/2] Fix ARM64 cross build flags --- CMakeLists.txt | 5 +++++ examples/quantize-stats/quantize-stats.cpp | 11 +++++++---- ggml/src/iqk/iqk_quantize.cpp | 9 +++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index edb9e6570d..483129a224 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,9 @@ cmake_minimum_required(VERSION 3.14) # for add_link_options and implicit target directories. + +# Ensure CMAKE_MSVC_DEBUG_INFORMATION_FORMAT is honored +if(POLICY CMP0141) + cmake_policy(SET CMP0141 NEW) +endif() project("llama.cpp" C CXX) include(CheckIncludeFileCXX) diff --git a/examples/quantize-stats/quantize-stats.cpp b/examples/quantize-stats/quantize-stats.cpp index 25ec15868b..85aa7c1f61 100644 --- a/examples/quantize-stats/quantize-stats.cpp +++ b/examples/quantize-stats/quantize-stats.cpp @@ -31,20 +31,23 @@ #include #include -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) #pragma warning(disable: 4244 4267) // possible loss of data #include -#if defined(_M_X64) || defined(_M_IX86) #include #include #include -#endif #include -#if defined(_M_X64) || defined(_M_IX86) inline int popcount(uint8_t x) { return __popcnt(x); } inline int popcount(uint16_t x) { return __popcnt(x); } inline int popcount(uint32_t x) { return __popcnt(x); } inline int popcount(uint64_t x) { return _mm_popcnt_u64(x); } +#elif defined(_MSC_VER) +#include +inline int popcount(uint8_t x) { return __builtin_popcount(x); } +inline int popcount(uint16_t x) { return __builtin_popcount(x); } +inline int popcount(uint32_t x) { return __builtin_popcount(x); } +inline int popcount(uint64_t x) { return __builtin_popcountll(x); } #else inline int popcount(uint8_t x) { return __builtin_popcount(x); } inline int popcount(uint16_t x) { return __builtin_popcount(x); } diff --git a/ggml/src/iqk/iqk_quantize.cpp b/ggml/src/iqk/iqk_quantize.cpp index 1325fd0280..3068d04da7 100644 --- a/ggml/src/iqk/iqk_quantize.cpp +++ b/ggml/src/iqk/iqk_quantize.cpp @@ -31,26 +31,23 @@ #include #include -#if defined(_MSC_VER) +#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86)) #pragma warning(disable: 4244 4267) // possible loss of data #include -#if defined(_M_X64) || defined(_M_IX86) #include #include #include -#endif #include -#if defined(_M_X64) || defined(_M_IX86) inline int popcount(uint8_t x) { return __popcnt(x); } inline int popcount(uint16_t x) { return __popcnt(x); } inline int popcount(uint32_t x) { return __popcnt(x); } inline int popcount(uint64_t x) { return _mm_popcnt_u64(x); } -#else +#elif defined(_MSC_VER) +#include inline int popcount(uint8_t x) { return __builtin_popcount(x); } inline int popcount(uint16_t x) { return __builtin_popcount(x); } inline int popcount(uint32_t x) { return __builtin_popcount(x); } inline int popcount(uint64_t x) { return __builtin_popcountll(x); } -#endif #else constexpr int popcount(uint8_t x) { return __builtin_popcount(x); } constexpr int popcount(uint16_t x) { return __builtin_popcount(x); }