mlx icon indicating copy to clipboard operation
mlx copied to clipboard

[BUG] metal_capture does not capture working GPU trace in MacOS 26+ On Mac Mini M1

Open mrcodechef opened this issue 1 year ago • 17 comments

Describe the bug metal_capture does not capture a working GPU trace on MacOS 26.1 It generates the file mlx_trace.gputrace, but opening it results in multiple errors

To Reproduce With Xcode 26.1.1 on MacOS 26.1 on MacMini M1:

git clone https://github.com/ml-explore/mlx.git
mkdir build && cd build
cmake .. -DMLX_METAL_DEBUG=ON -G Xcode
open mlx.xcodeproj

Enable 'Automatically managing signing' and set Team in 'Signing & Capabilities' for metal_capture Run metal_capture

open examples/cpp/Debug/mlx_trace.gputrace

enable 'Profile after replay' IMPORTANT: (You won't see the errors unless you enable this, or click the Profile button (in the Performance section) afterwards) click replay 'Unexpected Replayer Termination' see below [1] for error text

// secondary error, likely partially resolved if the above is fixed. Debugging (somewhat) seems to work if you don't try to profile first. MacOS 15.7 also gives the 'No Function Found' error, so likely a seperate issue.

Switch to Group by Pipeline State Open the first Compute Pipeline Click arrangefloat32 Right click in shader source and select 'Debug Function...' Click OK on 'No Function Found' error Click Debug 'No Replay Device' see below [2] for error text

[1]

=== Crash Info ===
Signal: SIGABRT

=== Error summary: ===
1x DYErrorDomain (512) - guest app crashed (512)
1x com.apple.gputools.MTLReplayer (150) - Metal object creation failed.
25x com.apple.gputools.MTLReplayer (200) - The replayer encountered a Metal validation layer error.
1x com.apple.gputools.MTLReplayer (100) - Abort trap: 6

=== First Error ===
Domain: com.apple.gputools.MTLReplayer
Error code: 150

Description: Metal object creation failed.

=== Setup ===
Capture device:	Macmini9,1 - macOS 26.1 (25B78)
Replay device:	Macmini9,1 - macOS 26.1 (25B78)
Host:			Macmini9,1 - macOS 26.1 (25B78)
Tool:			Xcode (17B100)

Known SDKs:

[2]

=== First Error ===
Domain: GPUShaderDebuggerTraceErrorDomain
Error code: 0

Description: Internal error: No replay device

=== GPUDebugger Item ===
API Call: 43 [dispatchThreads:{9, 1, 1} threadsPerThreadgroup:{9, 1, 1}]
Resource: arangefloat32

=== Setup ===
Capture device:	Macmini9,1 - macOS 26.1 (25B78)
Replay device:	Macmini9,1 - macOS 26.1 (25B78)
Host:			Macmini9,1 - macOS 26.1 (25B78)
Tool:			Xcode (17B100)

Known SDKs:

Expected behavior metal_capture should generate a working GPU trace on MacOS 26.1 with XCode 26.1.1

Desktop (please complete the following information):

  • OS Version: MacOS 26.1
  • Version XCode 26.1.1

Additional context GPU traces from frame captures of various samples in Metal Sample Code work correctly in MacOS 26.1 with XCode 26.1.1 metal_capture generates a working trace on MacOS 15.7.2 with XCode 26.1.1 (and XCode 16.4) I believe metal_capture generates similar errors on MacoS 26.1.1 with XCode 16.4, so more likely an OS compatibility issue than XCode issue.

mrcodechef avatar Nov 27 '25 20:11 mrcodechef

@mrcodechef can i work on this bug? if you need a planning map i can provide you one of solving this issue.

Sahilbhatane avatar Nov 28 '25 15:11 Sahilbhatane

@mrcodechef can i work on this bug?

@Sahilbhatane I'm not the one to ask. I only reported the bug and don't have any association with the mlx project.

mrcodechef avatar Nov 28 '25 15:11 mrcodechef

@mrcodechef can i work on this bug?

@Sahilbhatane I'm not the one to ask. I only reported the bug and don't have any association with the mlx project.

are you working on this? by any chances, if not @kashif or @jaju please check this issue and assign to me.

Sahilbhatane avatar Nov 28 '25 15:11 Sahilbhatane

@Sahilbhatane Given this issue seems to be MacOS 26+ specific, it may be an OS issue. Unless you have access to fix the MacOS source code, it seems likely there is nothing you can do for this.

(I've tested back to v.27.1, so I don't think it's specific to the Metal 4 stuff.)

mrcodechef avatar Nov 28 '25 15:11 mrcodechef

Still broken in MacOS 26.2rc and Xcode 26.2rc

mrcodechef avatar Dec 04 '25 18:12 mrcodechef

I reran the example on 26.2 (most recent beta) and it worked fine for me.

awni avatar Dec 04 '25 21:12 awni

I ran it on an M5 however.. so it's possible it doesn't work on M1

awni avatar Dec 04 '25 21:12 awni

It still works in MacOS 15.7 on M1, so likely a MacOS 26+ M1-M? issue? I've submitted the error via the Feeback tool, but is there a better way to get it looked at? I've never had any success getting a feedback issue resolved in the past.

mrcodechef avatar Dec 04 '25 21:12 mrcodechef

Still broken in release version of Xcode 26.2 and MacOS 26.2 on Mac Mini M1

mrcodechef avatar Dec 12 '25 22:12 mrcodechef

Still broken in Xcode 26.2 and MacOS 26.3 Beta 2 on Mac Mini M1 (through Mx ??)

mrcodechef avatar Jan 13 '26 04:01 mrcodechef

Still broken in Xcode 26.3 RC and MacOS 26.3 current beta on Mac Mini M1 (through M? - works on M5)

mrcodechef avatar Feb 03 '26 23:02 mrcodechef

Image

@mrcodechef I followed the repro on an M1 Ultra running macOS 26 and I wasn’t able to reproduce the replay/crash errors — the .gputrace opened and replayed cleanly for me.

Since this issue seems to reproduce for some M1 systems but not others (and works on newer chips), it’d be useful to rule out an environment / build configuration difference.

Could you share the output of:

  • sw_vers (already present in your bug report, useful for anyone else trying to reproduce the issue)
  • xcodebuild -version (already present)
  • cmake --version (and where it comes from: which cmake)
  • xcodebuild -showsdks | grep "macOS" (or at least the macOS SDK version used)

Also to rule out any sneaky environment variables, you might try the reproduction steps using /bin/zsh -f -c 'cmake .. -DMLX_METAL_DEBUG=ON -G Xcode'.

On my end, if you share the exact mlx version or commit hash you have checked out I'd like to try it with that specific version for consistent reproducibility.

robertmsale avatar Feb 08 '26 00:02 robertmsale

@robertmsale (CC: @awni in case this is why he couldn't reproduce it as well) There is another necessary condition, that you seem to have missed. Sorry it wasn't more explicit.

Turn on "Profile after replay" (or click the Profile button (in Performance) after loading the replay). I also don't see an errors without it.

I rebuilt with latest commit (8fe1d09207c671309a675aab9e5970d0763e8987) and the error still occurs.

dmelchio@dmmini20 build % sw_vers
ProductName:		macOS
ProductVersion:		26.3
BuildVersion:		25D122
dmelchio@dmmini20 build % xcodebuild -version
Xcode 26.3
Build version 17C519
dmelchio@dmmini20 build % cmake --version
cmake version 4.2.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).
dmelchio@dmmini20 build % xcodebuild -showsdks | grep "macOS" 
macOS SDKs:
	macOS 26.2                    	-sdk macosx26.2
	macOS 26.2                    	-sdk macosx26.2
dmelchio@dmmini20 build % git rev-parse HEAD
8fe1d09207c671309a675aab9e5970d0763e8987
dmelchio@dmmini20 build % /bin/zsh -f -c 'cmake .. -DMLX_METAL_DEBUG=ON -G Xcode'
-- Building MLX for arm64 processor on Darwin
-- Metal found /Applications/Xcode-26.3RC.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.2.sdk/System/Library/Frameworks/Metal.framework
-- Building with macOS SDK version 26.2
-- Accelerate found /Applications/Xcode-26.3RC.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.2.sdk/System/Library/Frameworks/Accelerate.framework
-- Downloading json
-- Using the multi-header code from /Users/dmelchio/src/mlx/build/_deps/json-src/include/
-- Downloading gguflib
-- {fmt} version: 12.1.0
-- Build type: 
CMake Deprecation Warning at build/_deps/doctest-src/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- Configuring done (10.6s)
-- Generating done (0.1s)
-- Build files have been written to: /Users/dmelchio/src/mlx/build
Image

mrcodechef avatar Feb 08 '26 02:02 mrcodechef

@mrcodechef I have good news! Xcode crashed when I tried to profile the gputrace. Sorry I missed that detail in the original post.

Image

I was able to get more diagnostic information:

=== Crash Info ===
Signal: SIGABRT

=== Error summary: ===
1x DYErrorDomain (512) - guest app crashed (512)
1x com.apple.gputools.MTLReplayer (150) - Metal object creation failed.
25x com.apple.gputools.MTLReplayer (200) - The replayer encountered a Metal validation layer error.
1x com.apple.gputools.MTLReplayer (100) - Abort trap: 6

=== First Error ===
Domain: DYErrorDomain
Error code: 512

Description: guest app crashed (512)

GTErrorKeyProcessName: GPUToolsReplayService

GTErrorKeyCrashDate: 2026-02-08 03:33:22 +0000

GTErrorKeyPID: 38177

=== Underlying Error #1 ===
Domain: com.apple.gputools.MTLReplayer
Error code: 150

Description: Metal object creation failed.

GTErrorKeyTraceStreamID: 7

=== Underlying Error #2 ===
Domain: com.apple.gputools.MTLReplayer
Error code: 200

Description: The replayer encountered a Metal validation layer error.
Reason: IOGPUMetalCommandQueue: command queue residency set limit of 32 exceeded

Location in source code: _addResidencySets, line 453

I think this is something that can be fixed! When I get back to my desk tomorrow I'll dig into it further :)

robertmsale avatar Feb 08 '26 03:02 robertmsale

I think this is something that can be fixed!

I hope so! Based on the fact it works on older MacOS versions, yet fails in MacOS 26+ even with the same build of XCode, I suspect it's an OS issue. No luck getting any response from my Feedback submissions though.

mrcodechef avatar Feb 08 '26 04:02 mrcodechef

I suspect it's an OS issue.

Good news! It's not an OS issue, but I bet in macOS 26.x.x the Metal library imposed a limit on the number of mutations to a residency set during gputrace replaying. And perhaps the limit is hardware-based, which would explain why @awni was unable to reproduce it on a M5 chip.

The problem is the allocator is performing residency set mutations during GPU capture, and there is a hard limit during replay (32 on our machines, test was performing 56 adds, giving us 24 add errors). The fix was to disable residency set mutations during capture, and I was able to run a complete profile and view all of the execution paths in the graphs! You're welcome to give my PR a spin just to double-confirm the fix works.

robertmsale avatar Feb 08 '26 17:02 robertmsale

I'm closing this since this is a macOS issue and we haven't seen similar reports recently.

zcbenz avatar Aug 16 '26 04:08 zcbenz