Skip to content
Merged
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
24 changes: 24 additions & 0 deletions mlx/backend/metal/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ MTL::Library* try_load_bundle(
}
return nullptr;
}

MTL::Library* try_load_framework(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in try_load_bundle isn't appropriate for a framework -- they have a different layout.

MTL::Device* device,
NS::URL* url,
const std::string& lib_name) {
std::string resource_path = std::string(url->fileSystemRepresentation()) +
"/" + lib_name + ".metallib";
auto [lib, error] = load_library_from_path(device, resource_path.c_str());
if (lib) {
return lib;
}
return nullptr;
}
#endif

// Firstly, search for the metallib in the same path as this binary
Expand Down Expand Up @@ -103,6 +116,17 @@ std::pair<MTL::Library*, NS::Error*> load_swiftpm_library(
return {library, nullptr};
}
}
// if SWIFTPM_BUNDLE is a framework identifier, try loading from that
auto frameworks = NS::Bundle::allFrameworks();
for (int i = 0, c = (int)frameworks->count(); i < c; i++) {
auto bundle = reinterpret_cast<NS::Bundle*>(frameworks->object(i));
if (!strcmp(bundle->bundleIdentifier()->utf8String(), SWIFTPM_BUNDLE)) {
library = try_load_framework(device, bundle->resourceURL(), lib_name);
if (library != nullptr) {
return {library, nullptr};
}
}
}
#endif
return {nullptr, nullptr};
}
Expand Down