Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metal support. #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Metal support. #29

wants to merge 2 commits into from

Conversation

Priva28
Copy link

@Priva28 Priva28 commented Oct 16, 2023

This PR updates whisper.cpp and adds metal support.

This PR should not be merged to master, however I'm opening it regardless since it provides an example others might find useful in getting whisper.cpp working on Metal. In my experience, combining the WHISPER_USE_COREML and GGML_USE_METAL flags results in a significant performance improvement.

How it works

It relies heavily on symlinks to ensure the correct files are compiled with the correct flags. It was necessary to create two targets:

  • whisper_cpp
  • whisper_cpp_metal

This is because ggml-metal.m must be compiled with the -fno-objc-arc flag, but whisper-encoder-impl.m will not compile with this flag.

Therefore:

  • whisper_cpp has a symlink to ../whisper_cpp_metal/ggml-metal.h
  • whisper_cpp_metal has symlinks to ggml header files required by ggml-metal.m as well as the whisper.h overall header file.

Issues

Because of the way SPM works, it isn't capable of including the ggml-metal.metal file as a resource that can be easily accessed and therefore still requires you to manually include it in your Xcode project in the "Copy Files" Build Phase. If anyone can find a way to get this working automatically, please contribute or let me know!

You can get the metal file from here.

Screenshot 2023-10-16 at 3 33 42 pm

Another reason this would probably have to retain in PR state or another branch at least is that SPM has no way of dynamically defining what cSettings flags should be used. Ideally the user of the package would be able to somehow define that they want to use Metal, and only if they do should the DGGML_USE_METAL flag be added.

For now though, this is here for anyone that wants to play around with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant