Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Apple Silicon), CUDA, or Vulkan. Drop-in replacement for
- **End-to-end CLI** — WAV in, MIDI/TXT/CSV out (mirrors Python `extract`).
- **Small footprint** — ~50 MB GGUF for the 1.0-medium checkpoint, ~50 M params.
- **Fast startup** — Metal binary-archive patch keeps first-run latency under a
second on Apple Silicon.
second on Apple Silicon. (The patch is kept in-repo at
`cmake/patches/ggml-metal-binary-archive.{patch,md}`; see the `.md` for
design and re-apply notes.)
- **Third-party integration** — clean PIMPL C++ API; `add_subdirectory` and link
`game_ggml::game_ggml`.
- **Parity-tested** — full pipeline output matches the PyTorch reference bit-for-bit
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- **端到端 CLI** — WAV 输入,MIDI/TXT/CSV 输出(镜像 Python `extract`)
- **体积小** — 1.0-medium checkpoint 约 50 MB GGUF,约 50M 参数
- **启动快** — Metal binary-archive 补丁使 Apple Silicon 首次运行延迟低于 1 秒
(补丁随生态解散收编于本仓库 `cmake/patches/ggml-metal-binary-archive.{patch,md}`)
- **第三方集成** — 干净的 PIMPL C++ API;`add_subdirectory` 后链接 `game_ggml::game_ggml`
- **逐位对齐** — 注入相同 RNG 时全流水线输出与 PyTorch 参考逐位一致

Expand Down
53 changes: 53 additions & 0 deletions cmake/patches/ggml-metal-binary-archive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ggml-metal-binary-archive(本仓库所有权)

> 本 patch 原属 KakaruHayate/ggml-patch 的「生态」扩张内容,现随生态解散
> 收编回 game.cpp(即本仓库),由本仓库全权维护、随 ggml 升级重打。

## Purpose

Cache compiled Metal pipeline state objects (PSOs) to disk via
`MTLBinaryArchive` so subsequent launches skip the expensive
`newComputePipelineState` compilation. On a fresh launch metal rebuilds
thousands of kernels, adding seconds-per-model to load time; this reduces it
to a single archive load.

## Change

`src/ggml-metal/ggml-metal-device.m` — add `MTLBinaryArchive` PSO cache:

- `ggml_metal_archive_url()` reads `GGML_METAL_ARCHIVE_PATH` (falls back to
~/.cache/ggml-metal archive path).
- At pipeline creation, try `newBinaryArchiveWithDescriptor` / completion
handler; on first run nothing is cached so it compiles normally.
- After compiling, capture the pipeline state into the archive via
`storeRenderPipelineState` and `commit` it to the archive file.

Controlled by the same `GGML_METAL_ARCHIVE_PATH` env var; disable with
`GGML_METAL_DISABLE_ARCHIVE`.

## Baseline

Applied against **ggml v0.19.0** (`ggml-metal-device.m`). Verify with the
same command used in `cmake/Dependencies.cmake`:

```
git -C <ggml> apply --check cmake/patches/ggml-metal-binary-archive.patch
```

Test:

```
GGML_METAL_ARCHIVE_PATH=/tmp/game-mtl-archive game_ggml_cli extract ...
# second run should show near-zero PSO compile; compare GAME_GGML_PROFILE
```

## Origin

Internal Shenzhen branch derived from Metal submission overhead experiments.
Kept out-of-line from ggml main; re-apply per ggml upgrade (see
`cmake/Dependencies.cmake` `game_ggml_apply_patch`).

## Ownership (2026-08)

`ggml-patch` 已弃用;本 patch 收编于 game.cpp `cmake/patches/`(本目录)。
改动本 patch 只改本目录,不改 ggml-patch 历史形态。
Loading