Add GPU.setMetallibPath() for plugin bundle support#416
Draft
olilarkin wants to merge 1 commit into
Draft
Conversation
Adds API to set a custom mlx.metallib path before MLX initializes. Plumbed through C++ -> C -> Swift layers. Required when running inside plugin bundles where default search paths fail since main bundle is the host
Collaborator
|
This would have to come through mlx and mlx-c rather than modify the files directly like this. |
Contributor
|
I tested this API shape while working on the SwiftPM metallib resource PR. The local proof branch is here:
It uses Validation passed:
So once the |
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
GPU.setMetallibPath(_ path: String), a Swift wrapper over the newmlx_metal_set_metallib_path()C API. Lets callers point MLX at a specificmlx.metallibbefore initialization. Also updates the vendored headerSource/Cmlx/include/mlx/c/metal.hto match the mlx-c change.Why
When MLX-Swift is embedded in a plugin bundle (AU/VST3), the host owns the main bundle and the default metallib search paths don't resolve. This provides a way to set the path explicitly. Must be called before the first MLX operation (e.g. before
Pipeline.load()).Caveat: single MLX instance required
The override is stored as process-global state inside a single MLX image. As noted in the README "XCode (2)" section, a diamond dependency (
YourApp -> MLXandYourApp -> YourFramework -> MLX) can put two copies of MLX in one process. In that casesetMetallibPath()may set the path on a different copy than the one that loads the device, and the override is silently ignored. Callers must ensure there is exactly one MLX instance in the process (single Library, or the Framework build viaxcode/MLX.xcodeproj).Note also that building MLX as a Framework may resolve the metallib via the colocated / dyld-relative search path without needing this override at all — this API is the explicit escape hatch for setups where that doesn't hold.
Depends on
set_metallib_path)mlx_metal_set_metallib_path)The
Source/Cmlx/mlxandSource/Cmlx/mlx-csubmodule pointers in this PR currently reference my forks. Once the two PRs above merge, the pointers should be re-pointed to the merged upstream commits (happy to do this, or for a maintainer to bump them).Context
Tracking issue: #415.