From 890bba64ec1205816f106548c58bb53bb8fb23d9 Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Thu, 31 Jul 2025 16:47:42 +0200 Subject: [PATCH 1/7] Specify DWARF debug info for Windows ARM64 --- cmake/arm64-windows-llvm.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/arm64-windows-llvm.cmake b/cmake/arm64-windows-llvm.cmake index a93bf4fb4a..070857d9d0 100644 --- a/cmake/arm64-windows-llvm.cmake +++ b/cmake/arm64-windows-llvm.cmake @@ -12,5 +12,6 @@ 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( debug_flags "-gdwarf-4" ) +set( CMAKE_C_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) +set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) From bd0cb4c11601c594bc47fd1020daef49a847610c Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Thu, 31 Jul 2025 18:03:00 +0200 Subject: [PATCH 2/7] fix arm64 cross compile --- cmake/arm64-windows-llvm.cmake | 2 +- ggml/src/ggml-impl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/arm64-windows-llvm.cmake b/cmake/arm64-windows-llvm.cmake index 070857d9d0..ef06f9fe4b 100644 --- a/cmake/arm64-windows-llvm.cmake +++ b/cmake/arm64-windows-llvm.cmake @@ -12,6 +12,6 @@ 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( debug_flags "-gdwarf-4" ) +set( debug_flags "-gdwarf-4 -Xclang -gno-codeview" ) set( CMAKE_C_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) 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 From 3ec3970ea7ec5e1cbdc6e854973e3f199458a33a Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Thu, 31 Jul 2025 18:45:17 +0200 Subject: [PATCH 3/7] Fix Windows ARM64 toolchain flags --- cmake/arm64-windows-llvm.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/arm64-windows-llvm.cmake b/cmake/arm64-windows-llvm.cmake index ef06f9fe4b..e2e7259871 100644 --- a/cmake/arm64-windows-llvm.cmake +++ b/cmake/arm64-windows-llvm.cmake @@ -12,6 +12,7 @@ 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( debug_flags "-gdwarf-4 -Xclang -gno-codeview" ) +set( CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "" ) +set( debug_flags "-gdwarf-4" ) set( CMAKE_C_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) From ee5c9e32320a891692a95193b842fd808ee93122 Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Thu, 31 Jul 2025 20:12:24 +0200 Subject: [PATCH 4/7] Fix arm64 headers --- cmake/arm64-windows-llvm.cmake | 2 +- examples/quantize-stats/quantize-stats.cpp | 11 ++++++++++- ggml/src/iqk/iqk_quantize.cpp | 11 ++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmake/arm64-windows-llvm.cmake b/cmake/arm64-windows-llvm.cmake index e2e7259871..3001cbd16f 100644 --- a/cmake/arm64-windows-llvm.cmake +++ b/cmake/arm64-windows-llvm.cmake @@ -12,7 +12,7 @@ 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_MSVC_DEBUG_INFORMATION_FORMAT "" ) +set( CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "DWARF" ) set( debug_flags "-gdwarf-4" ) set( CMAKE_C_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) 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/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 1812a4af15f9b598e80bb87b7b1ec6ab5a603c51 Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Fri, 1 Aug 2025 12:54:17 +0200 Subject: [PATCH 5/7] Disable codeview for LLVM ARM64 --- cmake/arm64-windows-llvm.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/arm64-windows-llvm.cmake b/cmake/arm64-windows-llvm.cmake index 3001cbd16f..acf30108f3 100644 --- a/cmake/arm64-windows-llvm.cmake +++ b/cmake/arm64-windows-llvm.cmake @@ -13,6 +13,7 @@ set( arch_c_flags "-march=armv8.7-a -Xclang -target-feature -Xclang +fullfp16 -f set( warn_c_flags "-Wno-format -Wno-unused-variable -Wno-unused-function -Wno-gnu-zero-variadic-macro-arguments" ) set( CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "DWARF" ) -set( debug_flags "-gdwarf-4" ) +# disable implicit CodeView debug info generation +set( debug_flags "-gdwarf-4 -Xclang -gno-codeview" ) set( CMAKE_C_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) From 7ee4e1ca8c7351e9ae3c4fcd28f40d545496cb17 Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Fri, 1 Aug 2025 13:24:39 +0200 Subject: [PATCH 6/7] cmake: fix arm64 windows debug flags --- cmake/arm64-windows-llvm.cmake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmake/arm64-windows-llvm.cmake b/cmake/arm64-windows-llvm.cmake index acf30108f3..97e2152bd0 100644 --- a/cmake/arm64-windows-llvm.cmake +++ b/cmake/arm64-windows-llvm.cmake @@ -12,8 +12,7 @@ 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_MSVC_DEBUG_INFORMATION_FORMAT "DWARF" ) -# disable implicit CodeView debug info generation -set( debug_flags "-gdwarf-4 -Xclang -gno-codeview" ) +set( CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "" ) +set( debug_flags "-g -gdwarf-4" ) set( CMAKE_C_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) From 8a1a3e315ce7fa53700c01ff78ad07f846821abf Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Fri, 1 Aug 2025 18:15:13 +0200 Subject: [PATCH 7/7] disable debug info for arm64 toolchain --- cmake/arm64-windows-llvm.cmake | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmake/arm64-windows-llvm.cmake b/cmake/arm64-windows-llvm.cmake index 97e2152bd0..51a4657d31 100644 --- a/cmake/arm64-windows-llvm.cmake +++ b/cmake/arm64-windows-llvm.cmake @@ -13,6 +13,13 @@ set( arch_c_flags "-march=armv8.7-a -Xclang -target-feature -Xclang +fullfp16 -f set( warn_c_flags "-Wno-format -Wno-unused-variable -Wno-unused-function -Wno-gnu-zero-variadic-macro-arguments" ) set( CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "" ) -set( debug_flags "-g -gdwarf-4" ) -set( CMAKE_C_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) -set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags} ${warn_c_flags} ${debug_flags}" ) +set( base_flags "${arch_c_flags} ${warn_c_flags}" ) + +# Disable debug info on Windows/ARM64 as it triggers LLVM crashes +foreach(cfg RELWITHDEBINFO RELEASE DEBUG MINSIZEREL) + set("CMAKE_C_FLAGS_${cfg}" "${base_flags} -O2") + set("CMAKE_CXX_FLAGS_${cfg}" "${base_flags} -O2") +endforeach() + +set( CMAKE_C_FLAGS_INIT "${base_flags}" ) +set( CMAKE_CXX_FLAGS_INIT "${base_flags}" )