From 3453401cfef3bf65bc206ef74599c91a001d83ed Mon Sep 17 00:00:00 2001 From: Milot Mirdita Date: Sat, 11 Jan 2025 15:22:44 +0900 Subject: [PATCH] Fix GGML not compiling on macOS with GCC --- ggml/src/ggml-blas/CMakeLists.txt | 4 ++++ ggml/src/ggml-cpu/CMakeLists.txt | 4 ++++ ggml/src/ggml-cpu/ggml-cpu.c | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/ggml/src/ggml-blas/CMakeLists.txt b/ggml/src/ggml-blas/CMakeLists.txt index 0bf3c05d9..da79e779a 100644 --- a/ggml/src/ggml-blas/CMakeLists.txt +++ b/ggml/src/ggml-blas/CMakeLists.txt @@ -73,6 +73,10 @@ if (BLAS_FOUND) message(STATUS "BLAS found, Includes: ${BLAS_INCLUDE_DIRS}") target_compile_options(ggml-blas PRIVATE ${BLAS_LINKER_FLAGS}) + # GCC on apple complains about vector conversions + if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(ggml-blas PRIVATE -flax-vector-conversions) + endif () if (${BLAS_INCLUDE_DIRS} MATCHES "mkl" AND (${GGML_BLAS_VENDOR} MATCHES "Generic" OR ${GGML_BLAS_VENDOR} MATCHES "Intel")) add_compile_definitions(GGML_BLAS_USE_MKL) diff --git a/ggml/src/ggml-cpu/CMakeLists.txt b/ggml/src/ggml-cpu/CMakeLists.txt index 6b3641c42..defc60ee6 100644 --- a/ggml/src/ggml-cpu/CMakeLists.txt +++ b/ggml/src/ggml-cpu/CMakeLists.txt @@ -319,6 +319,10 @@ function(ggml_add_cpu_backend_variant_impl tag_name) message(STATUS "Adding CPU backend variant ${GGML_CPU_NAME}: ${ARCH_FLAGS} ${ARCH_DEFINITIONS}") target_sources(${GGML_CPU_NAME} PRIVATE ${GGML_CPU_SOURCES}) target_compile_options(${GGML_CPU_NAME} PRIVATE ${ARCH_FLAGS}) + # GCC on apple complains about vector conversions + if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${GGML_CPU_NAME} PRIVATE -flax-vector-conversions) + endif () target_compile_definitions(${GGML_CPU_NAME} PRIVATE ${ARCH_DEFINITIONS}) if (GGML_BACKEND_DL) diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.c index 2966ff768..7802d58b3 100644 --- a/ggml/src/ggml-cpu/ggml-cpu.c +++ b/ggml/src/ggml-cpu/ggml-cpu.c @@ -206,6 +206,14 @@ static int sched_yield (void) { } #else +// GCC fails to compile ggml on macos +#if defined(__APPLE__) && !defined(__clang__) +#undef __restrict +#define __restrict +#define _Nullable +#define _Nonnull +#endif + #include #include #include