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") 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];