8000 Compile bug: Prooted Debian in Droid Termux only · Issue #12452 · ggml-org/llama.cpp · GitHub
[go: up one dir, main page]

Skip to content

Compile bug: Prooted Debian in Droid Termux only #12452

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

Open
Manamama opened this issue Mar 18, 2025 · 1 comment
Open

Compile bug: Prooted Debian in Droid Termux only #12452

Manamama opened this issue Mar 18, 2025 · 1 comment

Comments

@Manamama
Copy link
Manamama commented Mar 18, 2025

Git commit

git rev-parse HEAD
d9a1452

Operating systems

Other? (Please let us know in description), Linux

GGML backends

CPU

Problem description & steps to reproduce

Deja vu - I may have mentioned it some months ago. It used to compile with similar tricks, but now the number of seds grow.

ChatGPT wrote most of it:

Bug Report: Compilation Issue on Droid Debian (proot) Environment

Summary:
The compilation works correctly on the native Termux environment but fails on a Debian-based system running in a proot environment. The issue stems from system-specific calls that are incompatible in the proot environment, particularly the usage of pthread_setaffinity, pthread_getaffinity, and sched_setaffinity_np.


Environment Details (Non-working System):

  • OS: Debian GNU/Linux 12 (bookworm) aarch64
  • Host: realme RMX3085
  • Kernel: 6.2.1-PRoot-Distro
  • Shell: bash 5.2.15
  • Terminal: proot (rootless environment)
  • Packages: 1181 (dpkg), 1 (pkg)
  • Architecture: aarch64

Environment Details (Working System):

  • OS: Android 11 aarch64 (via Termux)
  • Host: realme RMX3085
  • Kernel: 4.14.186+
  • Shell: bash 5.2.37
  • Packages: 142 (pacman), 795 (dpkg), 1 (pkg)
  • Architecture: aarch64

Error:
During compilation on the Debian proot environment, the build fails with errors related to the function sched_setaffinity_np and other affinity-related system calls. These functions are not recognized or compatible in the proot environment.

Error Message:

make[2]: *** [ggml/src/CMakeFiles/ggml-cpu.dir/build.make:76: ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1745: ggml/src/CMakeFiles/ggml-cpu.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
root@localhost:~/downloads_Termux/llama.cpp/build# make
[  0%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml.c.o
[  1%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml-alloc.c.o
[  1%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml-quants.c.o
[  1%] Linking CXX shared library ../../bin/libggml-base.so
[  3%] Built target ggml-base
[  4%] Building C object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.c.o
/root/downloads_Termux/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2495:5: error: implicit declaration of function 'sched_getaffinity_np' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    sched_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
    ^
/root/downloads_Termux/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:2495:5: note: did you mean 'sched_getaffinity'?
/data/data/com.termux/files/usr/include/sched.h:235:5: note: 'sched_getaffinity' declared here
int sched_getaffinity(pid_t __pid, size_t __set_size, cpu_set_t* _Nonnull __set);
    ^
/root/downloads_Termux/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:14707:18: error: implicit declaration of function 'sched_setaffinity_np' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            rv = sched_setaffinity_np(pthread_self(), setsize, &g_state.numa.cpuset);

Nature of the Error:

Error Message: pthread_setaffinity, pthread_getaffinity are used in the code, which are incompatible with the system environment.
The functions need to be replaced with more universally supported alternatives, such as sched_setaffinity.

Solution:

Substitutions Needed:
In the source code files (.c files), replace all instances of pthread_setaffinity and pthread_getaffinity with sched_setaffinity. Additionally, replace sched_setaffinity_np with sched_setaffinity.

This was accomplished with the following commands:

find . -type f -name "*.c" -exec sed -i 's/pthread_setaffinity/sched_setaffinity/g' {} +

find . -type f -name "*.c" -exec sed -i 's/pthread_getaffinity/sched_getaffinity/g' {} +

find . -type f -name "*.c" -exec sed -i 's/sched_setaffinity_np/sched_setaffinity/g' {} +

find . -type f -name "*.c" -exec sed -i 's/sched_getaffinity_np/sched_getaffinity/g' {} +

Explanation:
These fixes ensure compatibility by replacing Android-specific affinity functions with their more general counterparts, allowing the code to compile in the proot environment.

Conclusion:
The issue was resolved by substituting affinity functions to avoid using platform-specific implementations. The build is now successful after applying these changes. Further investigation may be needed to enhance compatibility with proot environments.

First Bad Commit

Not sure, maybe all have been like this (I have used variants of this sed maybe 5 times before).

Compile command

Just the regular one, as per instructions

Relevant log output

See above. After these seds all compiles as it should: 

[ 98%] Building CXX object examples/llava/CMakeFiles/llama-llava-clip-quantize-cli.dir/clip-quantize-cli.cpp.o
[ 98%] Linking CXX executable ../../bin/llama-llava-clip-quantize-cli
[ 98%] Built target llama-llava-clip-quantize-cli
[ 99%] Building CXX object pocs/vdot/CMakeFiles/llama-vdot.dir/vdot.cpp.o
[ 99%] Linking CXX executable ../../bin/llama-vdot
[ 99%] Built target llama-vdot
[ 99%] Building CXX object pocs/vdot/CMakeFiles/llama-q8dot.dir/q8dot.cpp.o
[100%] Linking CXX executable ../../bin/llama-q8dot
[100%] Built target llama-q8dot
root@localhost:~/downloads_Termux/llama.cpp/build# make 
[  3%] Built target ggml-base
[  8%] Built target ggml-cpu
[  9%] Built target ggml
[ 19%] Built target llama
[ 19%] Built target build_info
...
 bin/llama-cli
build: 4910 (d9a14523) with clang version 19.1.7 for aarch64-unknown-linux-android24
main: llama backend init

...

on: 
`Linux localhost 6.2.1-PRoot-Distro #1 SMP PREEMPT Thu Mar 17 16:28:22 CST 2022 aarch64 GNU/Linux`

Ver. 1.2

@Manamama

This comment has been minimized.

@github-actions github-actions bot removed the stale label Apr 22, 2025
@github-actions github-actions bot added the stale label May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant
0