Repository navigation
Conversation
- Define _GNU_SOURCE for CMAKE_SYSTEM_NAME=OHOS so musl exposes cpu_set_t / CPU_SET / M_PI and other GNU extensions used by ggml - Use sched_setaffinity instead of pthread_setaffinity_np on musl (OpenHarmony musl does not provide the _np variants) - Vendor subprocess.h: set SUBPROCESS_HAVE_CWD=0 on OHOS, which has no posix_spawn_file_actions_addchdir Signed-off-by: momo0410 <[email protected]>
|
Hi @momo0410, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
llama.cpp currently fails to build for OpenHarmony (the open-source HarmonyOS), whose standard-system userland is musl + LLVM with
CMAKE_SYSTEM_NAME=OHOS(targetsx86_64-linux-ohos/aarch64-linux-ohos). Three small libc/toolchain assumptions break the build:_GNU_SOURCEis only defined when the system name matchesLinux/Android(ggml/src/CMakeLists.txt), so musl hidescpu_set_t/CPU_SETused by the thread-affinity code.CMAKE_SYSTEM_NAME=OHOSfalls into theelse()branch which only sets_XOPEN_SOURCE=600.pthread_setaffinity_np/pthread_getaffinity_np(glibc extensions). OpenHarmony's musl does not provide the_npvariants; POSIXsched_setaffinity(0, ...)(already used for__ANDROID__) works on musl.vendor/sheredom/subprocess.hcallsposix_spawn_file_actions_addchdir_np; OpenHarmony's musl has neither spelling ofaddchdir. The header documentsSUBPROCESS_HAVE_CWD=0as the supported override for exactly this case.Changes
CMakeLists.txt: define_GNU_SOURCEandSUBPROCESS_HAVE_CWD=0whenCMAKE_SYSTEM_NAME STREQUAL "OHOS"ggml/src/ggml-cpu/ggml-cpu.c: usesched_setaffinitywhen__MUSL__is defined (set by the OHOS toolchain; also correct for other musl targets)common/common.cpp: shimpthread_{get,set}affinity_nptosched_{get,set}affinityon muslNo behavior change for Linux/glibc, Android, Apple or Windows builds.
Testing
Verified on OpenHarmony 7.0.0.39 standard system (x86_64, VMware, kernel 6.6.101):
llama-cli -m stories260K.gguf: completion works, ~2426 t/s generationllama-cli -m Qwen2.5-0.5B-Instruct-Q4_0.gguf --single-turn -p '用一句话介绍开源鸿蒙操作系统': correct Chinese chat output, ~29 t/s generation (4 threads, CPU backend)llama-server --host 0.0.0.0 --port 8080:/healthreturns OK, OpenAI-compatible/v1/chat/completionsverified from a remote clientAlso cross-built clean for
aarch64-linux-ohos(not yet run on ARM hardware). Build/deploy scripts and full verification log: https://github.com/momo0410/llama.cpp-openharmony-portDCO: signed off.