ronaldoussoren / pyobjc

The Python <-> Objective-C Bridge with bindings for macOS frameworks
https://pyobjc.readthedocs.io
563 stars 47 forks source link

Metal.framework. path has been changed on macOS 14 #626

Closed aestriplex closed 1 month ago

aestriplex commented 1 month ago

Platform information

Describe the bug Running the tests I got the following error message:

Invalid Metal library. Could be due to using conda. Try system python or METAL_XCODE=1 DISABLE_COMPILER_CACHE=1.

So I checked the path of the Metal library in tinygrad/runtime/ops_metal.py

libmetal = ctypes.CDLL("/System/Library/Frameworks/Metal.framework/Metal")

Unfortunately, it turned out that this is an invalid path on my system.

Solution Apparently, on macOS Sonoma (14), the metal framework has been moved to /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Metal.framework.

MacOSX.sdk is just a symbolic link to the latest SDK have installed on your system. In my case MacOSX14.4.sdk:

> ls -la /Library/Developer/CommandLineTools/SDKs
.
..
MacOSX.sdk -> MacOSX14.4.sdk
MacOSX13.3.sdk
MacOSX13.sdk -> MacOSX13.3.sdk
MacOSX14.4.sdk
MacOSX14.sdk -> MacOSX14.4.sdk

Thus, changing the libmetal path in tinygrad/runtime/ops_metal.py to

libmetal = ctypes.CDLL("/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Metal.framework")

solved the problem for me. Perhaps we should check the macOS version to select the correct Metal path (if we still want to load the lib that way). If so, it can be easily done with platform:

>>> import platform
>>> platform.mac_ver()[0]
'14.5'

Conclusion I don't have any earlier version of macOS on my machines, so I couldn't check if this problem was introduced with Sonoma. I know there is an open issue (https://github.com/tinygrad/tinygrad/issues/2226) for a bug related to the Metal framework. Do you think it could be related to this (i.e. to some sneaky change on the Metal.framework)?

ronaldoussoren commented 1 month ago

Note that the code you mention in your description, as well as the tinygrad project do not involve PyObjC. That means there's little I can do about this.

aestriplex commented 1 month ago

@ronaldoussoren Yes, I closed this issue yesterday because I posted on the wrong project. Sorry