Skip to content

metal: per-op source split + parallel compile (replay) - #26561

Merged
ggerganov merged 8 commits into
masterfrom
stack/metal-split
Aug 24, 2026
Merged

metal: per-op source split + parallel compile (replay)#26561
ggerganov merged 8 commits into
masterfrom
stack/metal-split

Conversation

@forforever73

Copy link
Copy Markdown
Contributor

Overview

First layer of the dev-metal -> stacked PR migration proposed in #26520. cc @ggerganov

Layer Branch Content
L1 (this PR) stack/metal-split Per-op source split (#24021), plus all kernels merged into master since then
L2 stack/metal-fa-vec Per-device FlashAttention vector tuning (Q, NE) (#25750)
L3 stack/metal-tuner Standalone FA-vector tuning tool (#26498)

The first seven commits are a replay of #24021 together with the six follow-up commits needed to adapt it to the kernels that have since been merged into master.

The final commit ports four additional kernels that landed on master after the original split:

Kernel PR Target
Lightning indexer #25893 kernels/fa.metal
DSv4 hyper-connections #26459 kernels/misc.metal
silu_back #25982 kernels/unary.metal
f16 binary ops #26465 kernels/binbcast.metal

Requirements

@forforever73
forforever73 requested a review from a team as a code owner August 4, 2026 09:35
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning Apple Metal https://en.wikipedia.org/wiki/Metal_(API) labels Aug 4, 2026
@forforever73
forforever73 force-pushed the stack/metal-split branch 2 times, most recently from 2934b5b to 5522498 Compare August 5, 2026 08:22
forforever73 and others added 8 commits August 22, 2026 13:39
* preliminary extract common header

* op source split

* split metallib into 8 libs && load in parallel

* derive kernel->library routing from functionNames

* x-macro lib list + underscore filenames, dedup QK_NL, MRC fixes

* op source split 8 to 20

* improve robustness of source fallback

* clean up

* change bool -> atomic_bool

* only prepend headers that source actually includes

* no semaphore, use GCD global queue

* dedup library compile path, fix NSError lifetime, rename gla

* relocate upstream concat/rope_back/repeat kernel changes into split files

* move ggml-common.h from common.h into dequantize.h to shrink binary size

---------

Co-authored-by: lvyichen <lvyichen@stepfun.com>
Move the kernels added on master after the split (lightning indexer,
DSv4 hyper-connections, silu_back, f16 bin ops, TQ2_0, the flash-attn KV
dequantization pass, rope offset/inplace, ssm_scan rollback, packed q8_0
dequantization and the tensor-API mat-mat K clamp) into the corresponding
kernels/*.metal sources. Copied verbatim, no functional change.

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@forforever73 The stack is good to merge. Anything left on your end?

@forforever73

Copy link
Copy Markdown
Contributor Author

@ggerganov no, ready to go :)

@ggerganov
ggerganov merged commit b615f5b into master Aug 24, 2026
36 of 38 checks passed
@ggerganov
ggerganov deleted the stack/metal-split branch August 24, 2026 16:21
therealkenc pushed a commit to therealkenc/llama.cpp that referenced this pull request Aug 24, 2026
* metal : per-op source split + parallel compile (ggml-org#24021)

* preliminary extract common header

* op source split

* split metallib into 8 libs && load in parallel

* derive kernel->library routing from functionNames

* x-macro lib list + underscore filenames, dedup QK_NL, MRC fixes

* op source split 8 to 20

* improve robustness of source fallback

* clean up

* change bool -> atomic_bool

* only prepend headers that source actually includes

* no semaphore, use GCD global queue

* dedup library compile path, fix NSError lifetime, rename gla

* relocate upstream concat/rope_back/repeat kernel changes into split files

* move ggml-common.h from common.h into dequantize.h to shrink binary size

---------

Co-authored-by: lvyichen <lvyichen@stepfun.com>

* metal: add col2im_1d op (f32/f16/bf16) (ggml-org#25176)

* metal : add set_rows with src0 f16 (ggml-org#25434)

* metal : add CONV_2D_DW (depthwise convolution) support (ggml-org#21565)

* metal : add Q2_0 support (ggml-org#25419)

* metal: fuse snake activation (mul, sin, sqr, mul, add) (ggml-org#25459)

* ggml-metal: FWHT kernel for metal backend (ggml-org#25924)

* metal : port new kernels into the split sources

Move the kernels added on master after the split (lightning indexer,
DSv4 hyper-connections, silu_back, f16 bin ops, TQ2_0, the flash-attn KV
dequantization pass, rope offset/inplace, ssm_scan rollback, packed q8_0
dequantization and the tensor-API mat-mat K clamp) into the corresponding
kernels/*.metal sources. Copied verbatim, no functional change.

---------

Co-authored-by: lvyichen <lvyichen@stepfun.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
srossitto79 added a commit to srossitto79/llama.cpp that referenced this pull request Aug 25, 2026
Conflicts resolved:

- common/CMakeLists.txt: keep both the fork's jsonl.cpp/.h and upstream's
  new json.cpp/.h (common_json wrapper, ggml-org#27511).

- ggml/src/ggml-cuda/out-prod.cu: take upstream's removal of the redundant
  cublasSetStream (ggml-org#26574 binds the cuBLAS handle to its stream at creation).
  The fork's conditional lda for dequantized (quantized) src0 is unchanged;
  upstream's unconditional lda decl is dropped as it would redeclare it.

- ggml/src/ggml-metal/ggml-metal.metal: upstream split the monolithic
  source into kernels/*.metal (ggml-org#26561). The fork's kernels were ported into
  the new layout:
    * quantize_q3_K / quantize_q4_K / quantize_mxfp4 -> kernels/quantize.h
    * kernel_cpy_* q3_K/q4_K/mxfp4 instantiations    -> kernels/quantize.metal
    * adamw gclip, out_prod, out_prod_id, get_rows_back, repeat_back,
      cross_entropy_loss{,_back}                     -> kernels/misc.metal
    * rms_norm_back                                  -> kernels/norm.metal
    * soft_max_back                                  -> kernels/softmax.metal
  No CMake or enum changes are needed: kernel->library routing is built from
  each compiled library's functionNames.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ravel7524 pushed a commit to ravel7524/llama.cpp that referenced this pull request Aug 30, 2026
* metal : per-op source split + parallel compile (ggml-org#24021)

* preliminary extract common header

* op source split

* split metallib into 8 libs && load in parallel

* derive kernel->library routing from functionNames

* x-macro lib list + underscore filenames, dedup QK_NL, MRC fixes

* op source split 8 to 20

* improve robustness of source fallback

* clean up

* change bool -> atomic_bool

* only prepend headers that source actually includes

* no semaphore, use GCD global queue

* dedup library compile path, fix NSError lifetime, rename gla

* relocate upstream concat/rope_back/repeat kernel changes into split files

* move ggml-common.h from common.h into dequantize.h to shrink binary size

---------

Co-authored-by: lvyichen <lvyichen@stepfun.com>

* metal: add col2im_1d op (f32/f16/bf16) (ggml-org#25176)

* metal : add set_rows with src0 f16 (ggml-org#25434)

* metal : add CONV_2D_DW (depthwise convolution) support (ggml-org#21565)

* metal : add Q2_0 support (ggml-org#25419)

* metal: fuse snake activation (mul, sin, sqr, mul, add) (ggml-org#25459)

* ggml-metal: FWHT kernel for metal backend (ggml-org#25924)

* metal : port new kernels into the split sources

Move the kernels added on master after the split (lightning indexer,
DSv4 hyper-connections, silu_back, f16 bin ops, TQ2_0, the flash-attn KV
dequantization pass, rope offset/inplace, ssm_scan rollback, packed q8_0
dequantization and the tensor-API mat-mat K clamp) into the corresponding
kernels/*.metal sources. Copied verbatim, no functional change.

---------

Co-authored-by: lvyichen <lvyichen@stepfun.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Apple Metal https://en.wikipedia.org/wiki/Metal_(API) ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants