Repository navigation
metal: fix metal tensor kernel_mul_mm error for large tensor - #28748
Merged
Merged
Conversation
Assisted-by: Codex
forforever73
approved these changes
Sep 18, 2026
Member
|
Do you have a |
Co-authored-by: YiChen Lv <63285796+forforever73@users.noreply.github.com>
Contributor
Author
Yes. Test cases:16,384 × 32,768 × 4 = 0x80000000 (2 GiB). The first two cases succeed because the tensor sizes do not exceed 2 GiB, while the last two fail because the tensor sizes exceed 2 GiB. Test result before the changeResult after the change |
ggerganov
approved these changes
Oct 12, 2026
1 task done
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 24, 2026
…g#28748) * metal: fix metal tensor kernel_mul_mm error for large tensor Assisted-by: Codex * Update ggml/src/ggml-metal/kernels/mul_mm.metal Co-authored-by: YiChen Lv <63285796+forforever73@users.noreply.github.com> --------- Co-authored-by: 向锡铭 <xiangximing@xiangximings-MacBook-Air.local> Co-authored-by: YiChen Lv <63285796+forforever73@users.noreply.github.com>
auRose94
pushed a commit
to auRose94/llama.cpp
that referenced
this pull request
Oct 28, 2026
…g#28748) * metal: fix metal tensor kernel_mul_mm error for large tensor Assisted-by: Codex * Update ggml/src/ggml-metal/kernels/mul_mm.metal Co-authored-by: YiChen Lv <63285796+forforever73@users.noreply.github.com> --------- Co-authored-by: 向锡铭 <xiangximing@xiangximings-MacBook-Air.local> Co-authored-by: YiChen Lv <63285796+forforever73@users.noreply.github.com>
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.
Assisted-by: Codex
Overview
In an experiment, I consistently observed that when the offset between the slice address and the tensor base address is greater than or equal to 2 GB, the actual address produced by the Metal Tensor API's
slicemethod differs from the expected address by -4 GB.This change modifies the
kernel_mul_mmimplementation inggml/src/ggml-metal/kernels/mul_mm.metalfor theGGML_METAL_HAS_TENSOR == truepath. Instead of using theslicemethod, it explicitly computes the address of each slice and constructs the tensor directly from the computed address.Related issue: #27784
After this change, the issue is no longer reproducible.
Additional information
Environment
Hardware: Apple MacBook Air 13 inch M5 16G
macOS: 26.6.2 (25G83)
Metal compiler: Apple metal version 32023.883 (metalfe-32023.883), Target: air64-apple-darwin25.6.0, Thread model: posix
Experiment Design
Each case runs the same matrix multiplication with a K dimension of
16, producing a cooperative tensorcT. The only difference between the two dispatches is the storage destination:flowchart TB A["A: K x tile_rows"] --> MM["Tensor API matmul"] B["B: K x tile_columns"] --> MM MM --> CT["cT: tile_rows x tile_columns"] CT --> P1["Path 1: calculate the dstTile pointer first<br/>then tensor(dstTile, tile shape)"] CT --> P2["Path 2: tensor(whole tensor)<br/>then whole.slice(row, column)"] P1 --> R1["direct_values"] P2 --> R2["slice_expected_values<br/>slice_wrapped_values"]Path 1 uses explicit 64-bit address calculation in the host language:
Path 2 wraps the complete output as a two-dimensional tensor:
Results
0x7ffffc000x7fffffc00x7ffffe000x800000000x800000400x80000400xychart-beta title "16 x 16 tile: slice start versus actual write displacement" x-axis ["-1024 B", "-64 B", "crossing tile", "0 B", "+64 B", "+1024 B"] y-axis "actual address - correct address (GiB)" -4 --> 0 line [0, 0, 0, -4, -4, -4]These results show a step with no transition interval. From
0x7fffffffto0x80000000, the displacement changes directly from 0 to -4 GiB.Requirements