From 8e93159b67631f8097e09be141856b16684b73ba Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Sun, 3 Aug 2025 19:47:11 +0200 Subject: [PATCH 1/2] Fix LoongArch fp16 table relocation --- ggml/src/ggml-impl.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ggml/src/ggml-impl.h b/ggml/src/ggml-impl.h index e4e3686088..10275eca99 100644 --- a/ggml/src/ggml-impl.h +++ b/ggml/src/ggml-impl.h @@ -611,6 +611,11 @@ static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) { #include #endif // __ARM_FEATURE_SVE +#if defined(__loongarch64) +#define GGML_FP16_TO_FP32(x) GGML_COMPUTE_FP16_TO_FP32(x) +#define GGML_FP32_TO_FP16(x) GGML_COMPUTE_FP32_TO_FP16(x) +#endif + // precomputed f32 table for f16 (256 KB) // defined in ggml.c, initialized in ggml_init() extern float ggml_table_f32_f16[1 << 16]; From 6ad24c8769c6459708247d06bb91f5fec07673b8 Mon Sep 17 00:00:00 2001 From: Volker Mauel Date: Sun, 3 Aug 2025 20:00:14 +0200 Subject: [PATCH 2/2] Fix x86_64 build by using medium code model for IQK --- ggml/src/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ggml/src/CMakeLists.txt b/ggml/src/CMakeLists.txt index 175f9c679c..dd46b9aec9 100644 --- a/ggml/src/CMakeLists.txt +++ b/ggml/src/CMakeLists.txt @@ -257,6 +257,16 @@ if (GGML_BLAS) endif() set (GGML_SOURCES_IQK iqk/iqk_quantize.cpp) + +# iqk_quantize.cpp defines large static tables which can exceed the +# 2GB limit imposed by the default small code model on x86_64. +# When this happens, the linker reports relocation truncation errors. +# Use the "medium" code model for this file so that references to the +# large data sections are encoded with 64-bit relocations. +if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|AMD64)" AND NOT MSVC) + set_source_files_properties(iqk/iqk_quantize.cpp + PROPERTIES COMPILE_OPTIONS "-mcmodel=medium") +endif() set (GGML_HEADERS_IQK iqk/iqk_config.h) if (GGML_IQK_MUL_MAT) message(STATUS "Using optimized iqk matrix multiplications")