Skip to content

metal : request Metal 4.0 language version for the tensor API - #27461

Draft
JamesFranc wants to merge 2 commits into
ggml-org:masterfrom
JamesFranc:metal-tensor-language-version
Draft

metal : request Metal 4.0 language version for the tensor API#27461
JamesFranc wants to merge 2 commits into
ggml-org:masterfrom
JamesFranc:metal-tensor-language-version

Conversation

@JamesFranc

@JamesFranc JamesFranc commented Aug 20, 2026

Copy link
Copy Markdown

Overview

  • Requests Metal 4.0 when the device reports tensor support using has_tensor so unsupported hardware is untouched
  • New guard clears has_tensor when the library came from a pre-compiled metallib.

Additional information

This issue was encountered when running main on an M5 Max. During some prefill and decode benchmarks I was noticing that prefill speeds seemed curiously slow.

image

The prefill tests used to generate the data above build a prompt of 6,000, random, six-letter words which should prevent cache hits.

This seems to be caused by MTLCompileOptions defaulting to an older Metal language version that doesn't expose tensor API headers (metal_tensor, MetalPerformancePrimitives) to the shader compiler. Both tensor API probes in ggml_metal_device_init() therefore fail:

ggml_metal_library_init_from_source: error compiling source
ggml_metal_device_init: - the tensor API is not supported in this environment - disabling

The compiler error behind it (visible only with verbose = true):

program_source:6:17: error: use of undeclared identifier 'mpp'
using namespace mpp::tensor_ops;
                ^
program_source:7:46: error: use of undeclared identifier 'dextents'

As a result has_tensor is disabled on every device, and prefill runs matmuls on general-purpose shader ALUs.

This fix will only impact prefill on Apple Silicon-based hardware

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes, AI was used to generate the code, evaluate model performance based on human defined evals and implement the solution

@JamesFranc
JamesFranc requested a review from a team as a code owner August 20, 2026 21:23
@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 20, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

Hi @JamesFranc, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

  • AI-generated content: While code is allowed to be generated by AI, please write the PR description and commit messages on your own without the help of AI.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Aug 20, 2026
@github-actions
github-actions Bot marked this pull request as draft August 20, 2026 21:28
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Aug 20, 2026
@JamesFranc
JamesFranc force-pushed the metal-tensor-language-version branch 4 times, most recently from aa59356 to 1b6c523 Compare August 21, 2026 06:13
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.

1 participant