Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions mlx/backend/metal/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ MTL::Library* try_load_bundle(
MTL::Device* device,
NS::URL* url,
const std::string& lib_name) {
std::string path =
std::string(url->fileSystemRepresentation()) +
"/" + lib_name + ".metallib";

auto [lib, error] = load_library_from_path(device, path.c_str());
if (lib) {
return lib;
}

// url contains already the resource path. Why to rebuild it here again ?
std::string bundle_path = std::string(url->fileSystemRepresentation()) + "/" +
SWIFTPM_BUNDLE + ".bundle";
auto bundle = NS::Bundle::alloc()->init(
Expand Down Expand Up @@ -115,6 +125,11 @@ std::pair<MTL::Library*, NS::Error*> load_swiftpm_library(
if (library != nullptr) {
return {library, nullptr};
}
// MetalCompilerPlugin does not generate a resource, but puts it into the bundle
library = try_load_bundle(device, bundle->bundleURL(), lib_name);
if (library != nullptr) {
return {library, nullptr};
}
}
// if SWIFTPM_BUNDLE is a framework identifier, try loading from that
auto frameworks = NS::Bundle::allFrameworks();
Expand Down