Skip to content

ggml-cpu : rework weak alias on apple targets #14146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 16, 2025
Merged

Conversation

xctan
Copy link
Collaborator

@xctan xctan commented Jun 12, 2025

Fixes #14138.

@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Jun 12, 2025
@xctan xctan force-pushed the fix-arch-ppc branch 3 times, most recently from c4ac5be to 90e1b6c Compare June 12, 2025 17:51
@barracuda156
Copy link
Contributor

barracuda156 commented Jun 13, 2025

A quick note re PowerPC detection in CMake: you can just use MATCHES with ppc|power with the same effect in a single line.

@barracuda156
Copy link
Contributor

@xctan Looks like something does not work correctly with symbols naming:

[ 14%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/llamafile/sgemm.cpp.o
cd /opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/build/ggml/src && /opt/local/bin/g++-mp-14 -DACCELERATE_LAPACK_ILP64 -DACCELERATE_NEW_LAPACK -DGGML_BACKEND_BUILD -DGGML_BACKEND_SHARED -DGGML_SCHED_MAX_COPIES=4 -DGGML_SHARED -DGGML_USE_ACCELERATE -DGGML_USE_CPU_REPACK -DGGML_USE_LLAMAFILE -DGGML_USE_OPENMP -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE=600 -Dggml_cpu_EXPORTS -I/opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/.. -I/opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/. -I/opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/ggml-cpu -I/opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/../include -F//System/Library/Frameworks -pipe -Os -fpermissive -DNDEBUG -isystem/opt/local/include/LegacySupport -I/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -std=gnu++17 -flto=auto -arch ppc -mmacosx-version-min=10.6 -fPIC -Wmissing-declarations -Wmissing-noreturn -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wno-array-bounds -Wextra-semi -fopenmp -MD -MT ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/llamafile/sgemm.cpp.o -MF CMakeFiles/ggml-cpu.dir/ggml-cpu/llamafile/sgemm.cpp.o.d -o CMakeFiles/ggml-cpu.dir/ggml-cpu/llamafile/sgemm.cpp.o -c /opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/ggml-cpu/llamafile/sgemm.cpp
[ 14%] Building C object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/arch/powerpc/quants.c.o
cd /opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/build/ggml/src && /opt/local/bin/gcc-mp-14 -DACCELERATE_LAPACK_ILP64 -DACCELERATE_NEW_LAPACK -DGGML_BACKEND_BUILD -DGGML_BACKEND_SHARED -DGGML_SCHED_MAX_COPIES=4 -DGGML_SHARED -DGGML_USE_ACCELERATE -DGGML_USE_CPU_REPACK -DGGML_USE_LLAMAFILE -DGGML_USE_OPENMP -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE=600 -Dggml_cpu_EXPORTS -I/opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/.. -I/opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/. -I/opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/ggml-cpu -I/opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/../include -F//System/Library/Frameworks -pipe -Os -DNDEBUG -isystem/opt/local/include/LegacySupport -I/opt/local/include -std=gnu11 -flto=auto -arch ppc -mmacosx-version-min=10.6 -fPIC -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int -Werror=implicit-function-declaration -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wdouble-promotion -fopenmp -MD -MT ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/arch/powerpc/quants.c.o -MF CMakeFiles/ggml-cpu.dir/ggml-cpu/arch/powerpc/quants.c.o.d -o CMakeFiles/ggml-cpu.dir/ggml-cpu/arch/powerpc/quants.c.o -c /opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/llama.cpp-5662/ggml/src/ggml-cpu/arch/powerpc/quants.c
[ 14%] Linking CXX shared library ../../../bin/libggml-blas.dylib
cd /opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/build/ggml/src/ggml-blas && /opt/local/bin/cmake -E cmake_link_script CMakeFiles/ggml-blas.dir/link.txt --verbose=ON
/opt/local/bin/g++-mp-14 -pipe -Os -fpermissive -DNDEBUG -isystem/opt/local/include/LegacySupport -I/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -flto=auto -arch ppc -mmacosx-version-min=10.6 -dynamiclib -Wl,-headerpad_max_install_names -Wl,-headerpad_max_install_names -L/opt/local/lib -lMacportsLegacySupport -o ../../../bin/libggml-blas.dylib -install_name @rpath/libggml-blas.dylib "CMakeFiles/ggml-blas.dir/ggml-blas.cpp.o"  -Wl,-rpath,/opt/local/lib ../../../bin/libggml-base.dylib -framework Accelerate
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/build'
[ 14%] Built target ggml-blas
[ 14%] Linking CXX shared library ../../bin/libggml-cpu.dylib
cd /opt/local/var/macports/build/_opt_local_ppcports_llm_llama.cpp/llama.cpp/work/build/ggml/src && /opt/local/bin/cmake -E cmake_link_script CMakeFiles/ggml-cpu.dir/link.txt --verbose=ON
Undefined symbols for architecture ppc:
  "_ggml_gemm_iq4_nl_4x4_q8_0", referenced from:
      void ggml::cpu::repack::gemm<block_iq4_nl, 4ll, 4ll, (ggml_type)8>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_iq4_nl, 4ll, 4ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemm_iq4_nl_4x4_q8_0_generic)
  "_ggml_gemm_q4_0_4x4_q8_0", referenced from:
      void ggml::cpu::repack::gemm<block_q4_0, 4ll, 4ll, (ggml_type)8>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_0, 4ll, 4ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemm_q4_0_4x4_q8_0_generic)
  "_ggml_gemm_q4_0_4x8_q8_0", referenced from:
      void ggml::cpu::repack::gemm<block_q4_0, 8ll, 4ll, (ggml_type)8>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_0, 8ll, 4ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemm_q4_0_4x8_q8_0_generic)
  "_ggml_gemm_q4_0_8x8_q8_0", referenced from:
      void ggml::cpu::repack::gemm<block_q4_0, 8ll, 8ll, (ggml_type)8>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_0, 8ll, 8ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemm_q4_0_8x8_q8_0_generic)
  "_ggml_gemm_q4_K_8x8_q8_K", referenced from:
      void ggml::cpu::repack::gemm<block_q4_K, 8ll, 8ll, (ggml_type)15>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_K, 8ll, 8ll, (ggml_type)15>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemm_q4_K_8x8_q8_K_generic)
  "_ggml_gemv_iq4_nl_4x4_q8_0", referenced from:
      void ggml::cpu::repack::gemv<block_iq4_nl, 4ll, 4ll, (ggml_type)8>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_iq4_nl, 4ll, 4ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemv_iq4_nl_4x4_q8_0_generic)
  "_ggml_gemv_q4_0_4x4_q8_0", referenced from:
      void ggml::cpu::repack::gemv<block_q4_0, 4ll, 4ll, (ggml_type)8>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_0, 4ll, 4ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemv_q4_0_4x4_q8_0_generic)
  "_ggml_gemv_q4_0_4x8_q8_0", referenced from:
      void ggml::cpu::repack::gemv<block_q4_0, 8ll, 4ll, (ggml_type)8>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_0, 8ll, 4ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemv_q4_0_4x8_q8_0_generic)
  "_ggml_gemv_q4_0_8x8_q8_0", referenced from:
      void ggml::cpu::repack::gemv<block_q4_0, 8ll, 8ll, (ggml_type)8>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_0, 8ll, 8ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemv_q4_0_8x8_q8_0_generic)
  "_ggml_gemv_q4_K_8x8_q8_K", referenced from:
      void ggml::cpu::repack::gemv<block_q4_K, 8ll, 8ll, (ggml_type)15>(int, float*, unsigned long, void const*, void const*, int, int) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_K, 8ll, 8ll, (ggml_type)15>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_gemv_q4_K_8x8_q8_K_generic)
  "_ggml_quantize_mat_q8_0_4x4", referenced from:
      void ggml_quantize_mat_t<4ll, (ggml_type)8>(float const*, void*, long long, long long) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_0, 4ll, 4ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_iq4_nl, 4ll, 4ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_quantize_mat_q8_0_4x4_generic)
  "_ggml_quantize_mat_q8_0_4x8", referenced from:
      void ggml_quantize_mat_t<8ll, (ggml_type)8>(float const*, void*, long long, long long) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_0, 8ll, 4ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_0, 8ll, 8ll, (ggml_type)8>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_quantize_mat_q8_0_4x8_generic)
  "_ggml_quantize_mat_q8_K_4x8", referenced from:
      void ggml_quantize_mat_t<8ll, (ggml_type)15>(float const*, void*, long long, long long) in repack.cpp.o
      ggml::cpu::repack::tensor_traits<block_q4_K, 8ll, 8ll, (ggml_type)15>::compute_forward(ggml_compute_params*, ggml_tensor*) in repack.cpp.o
     (maybe you meant: _ggml_quantize_mat_q8_K_4x8_generic)
  "_ggml_vec_dot_iq1_m_q8_K", referenced from:
      _type_traits_cpu in ggml-cpu.c.o
     (maybe you meant: _ggml_vec_dot_iq1_m_q8_K_generic)
  "_ggml_vec_dot_tq1_0_q8_K", referenced from:
      _type_traits_cpu in ggml-cpu.c.o
     (maybe you meant: _ggml_vec_dot_tq1_0_q8_K_generic)
  "_ggml_vec_dot_tq2_0_q8_K", referenced from:
      _type_traits_cpu in ggml-cpu.c.o
     (maybe you meant: _ggml_vec_dot_tq2_0_q8_K_generic)
  "_quantize_row_q8_K", referenced from:
      _type_traits_cpu in ggml-cpu.c.o
     (maybe you meant: _quantize_row_q8_K_generic)
ld: symbol(s) not found for architecture ppc
collect2: error: ld returned 1 exit status
/opt/local/bin/g++-mp-14 -pipe -Os -fpermissive -DNDEBUG -isystem/opt/local/include/LegacySupport -I/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -flto=auto -arch ppc -mmacosx-version-min=10.6 -dynamiclib -Wl,-headerpad_max_install_names -Wl,-headerpad_max_install_names -L/opt/local/lib -lMacportsLegacySupport -o ../../bin/libggml-cpu.dylib -install_name @rpath/libggml-cpu.dylib "CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.c.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/repack.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/hbm.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/quants.c.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/traits.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/amx/amx.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/amx/mmq.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/binary-ops.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/unary-ops.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/vec.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/ops.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/llamafile/sgemm.cpp.o" "CMakeFiles/ggml-cpu.dir/ggml-cpu/arch/powerpc/quants.c.o"  -Wl,-rpath,/opt/local/lib ../../bin/libggml-base.dylib -framework Accelerate /opt/local/lib/gcc14/libgomp.dylib

@xctan
Copy link
Collaborator Author

xctan commented Jun 14, 2025

@barracuda156 I was using the lowercase __powerpc__ based on my experiments on the Compiler Explorer, instead of the uppercase __POWERPC__ found in your macro.txt. I've now updated the code to use the more generic __PPC__ macro, and hopefully this should fix the build failure. Please let me know if it works for you.

@barracuda156
Copy link
Contributor

@xctan __powerpc__ works for Linux (and maybe *BSD), Darwin needs __POWERPC__ (assuming both ppc and ppc64 are implied). I am not sure which OS uses __PPC__, but this will not be recognized on Darwin. If there is a need to differentiate between 32- vs 64-bit implementation, then __ppc__ and __ppc64__ are to be used instead of __POWERPC__.

P. S. AIX has its own dedicated macros for PowerPC, I believe, but I am not sure which and cannot verify.

@xctan
Copy link
Collaborator Author

xctan commented Jun 14, 2025

@barracuda156 Thanks for the suggestion. The special handling is only required for Darwin due to the Mach-O toolchain's lack of an equivalent for weak aliases. On other systems, the linker will complete the alias resolution task. I realized the PowerPC macros were confusingly named and have fixed the detection logic again. My apologies for that oversight and any confusion it may have caused.

@barracuda156
Copy link
Contributor

I will re-run the build soon, thank you.

Copy link
Contributor

@barracuda156 barracuda156 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the build works successfully, thank you!

@xctan xctan marked this pull request as ready for review June 15, 2025 04:32
@xctan xctan requested a review from ggerganov June 16, 2025 04:48
@xctan xctan merged commit 3555b30 into ggml-org:master Jun 16, 2025
47 checks passed
Nexesenex added a commit to Nexesenex/croco.cpp that referenced this pull request Jun 18, 2025
Nexesenex added a commit to Nexesenex/croco.cpp that referenced this pull request Jun 18, 2025
Nexesenex added a commit to Nexesenex/croco.cpp that referenced this pull request Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ggml changes relating to the ggml tensor library for machine learning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile bug: since 5615 build on PowerPC fails with ICE: ggml-cpu-impl.h: internal compiler error: in assemble_alias, at varasm.cc:6435
3 participants