Skip to content

feat(ios): load ggml-metal.metal instead of prebuilt metallib#252

Merged
jhen0409 merged 1 commit into
mainfrom
use-metal-source-only
Nov 24, 2025
Merged

feat(ios): load ggml-metal.metal instead of prebuilt metallib#252
jhen0409 merged 1 commit into
mainfrom
use-metal-source-only

Conversation

@jhen0409
Copy link
Copy Markdown
Member

@jhen0409 jhen0409 commented Nov 24, 2025

Going back to using the ggml-metal source to compile it at runtime, in this way we will not need #244.

  • Tested on macOS 15 (Metal 3.2)
  • Tested on iOS 26 and macOS 26 (Metal 4.0)

@jhen0409 jhen0409 force-pushed the use-metal-source-only branch from 418742f to 5ae8d4e Compare November 24, 2025 07:14
@jhen0409 jhen0409 marked this pull request as ready for review November 24, 2025 08:17
@jhen0409 jhen0409 merged commit 3985af1 into main Nov 24, 2025
6 checks passed
@jhen0409 jhen0409 deleted the use-metal-source-only branch November 24, 2025 08:17
jhen0409 added a commit to mybigday/whisper.rn that referenced this pull request Dec 4, 2025
jhen0409 added a commit that referenced this pull request May 25, 2026
* feat(ios): embed ggml-metal source into framework binary

Fixes #348.

Following the precompile-rollback rationale in #252, switch to upstream
llama.cpp's GGML_METAL_EMBED_LIBRARY pattern: emit ggml-metal-embed.s
during bootstrap, link it into the rnllama framework, and let
ggml-metal-device.m's embedded code path supply the Metal source to
newLibraryWithSource: directly. Removes the .metal resource shipping
and the LM_GGML_METAL_PATH_RESOURCES fallback chain.

ggml-metal-device.m itself is unchanged — its #if GGML_METAL_EMBED_LIBRARY
branch already supports this path; we only define the macro, generate the
asm wrapper, and link it.

Cross-platform notes from porting:

- scripts/bootstrap.sh: emit ggml-metal-embed.s right after the LM_
  prefix sed pass. The od invocation intentionally omits -w16 because
  macOS BSD od rejects it ("illegal option -- w"); GNU od and BSD od
  both default to 16 bytes per line.
- The Mach-O section name is __ggml_metallib (15 chars), not the
  LM_-prefixed variant, because Mach-O caps section specifiers at
  16 characters. Only the exported symbols carry the LM_ prefix.
- ios/CMakeLists.txt: project() needs LANGUAGES ASM so the Xcode
  generator emits a build rule for .s sources; without it, .s files
  are silently dropped from the build phase and the link step fails
  with undefined _lm_ggml_metallib_{start,end}.

Tested on iPhone 13 mini (A15) with iOS 26.5 — initLlama succeeds and
the native log reports "lm_ggml_metal_library_init: using embedded
metal library" / "loaded in 9.690 sec" instead of the
"default.metallib not found ... XPC_ERROR_CONNECTION_INTERRUPTED"
chain from the #348 repro. nm confirms _lm_ggml_metallib_start /
_lm_ggml_metallib_end are present as data section symbols (S) in all
four xcframework slices (ios-arm64, ios-simulator arm64+x86_64,
tvos-arm64, tvos-simulator arm64+x86_64).

* chore: ignore ggml-metal-embed.s

---------

Co-authored-by: Jhen-Jie Hong <developer@jhen.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant