Add metal::set_metallib_path() to override the metallib search path#3597
Open
olilarkin wants to merge 1 commit into
Open
Add metal::set_metallib_path() to override the metallib search path#3597olilarkin wants to merge 1 commit into
olilarkin wants to merge 1 commit into
Conversation
Allows overriding the default metallib search paths before Device initialization. Needed when MLX is embedded in plugin bundles (AU, VST3) where the standard search locations don't apply.
zcbenz
reviewed
May 28, 2026
Collaborator
zcbenz
left a comment
There was a problem hiding this comment.
I think this is a good API to have, better than adding numerous fallbacks for searching. But I would like another review from maintainers before merging.
| static std::string g_metallib_override_path; | ||
|
|
||
| namespace mlx::core::metal { | ||
| void set_metallib_path(const std::string& path) { |
Collaborator
There was a problem hiding this comment.
Can you move this to mlx/backend/metal/metal.cpp, and add a stub in mlx/backend/metal/no_metal.cpp? Probably also needs to add a get_metallib_path.
| namespace mlx::core::metal { | ||
|
|
||
| } // namespace std | ||
| static std::string g_metallib_override_path; |
Collaborator
There was a problem hiding this comment.
The globals are usually put in anonymous namespace rather than using static.
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.
What
Adds
mlx::core::metal::set_metallib_path(const std::string&), allowing a caller to specify an explicit path tomlx.metallibbefore the Metal device initializes. When set,load_default_library()tries this path first and falls back to the existing search logic if it fails to load.Why
When MLX is embedded inside a plugin bundle (e.g. Audio Unit / VST3), the host application — not MLX — owns the main bundle, so the default colocated / SwiftPM / bundle search paths don't resolve
mlx.metalliband Metal init fails. There is currently no public way to point MLX at the library.Notes
Companion PRs
This is the root of a three-PR chain (C++ → C → Swift):
set_metallib_path)GPU.setMetallibPath()Tracking issue: ml-explore/mlx-swift#415.