Skip to content

Conversation

EricLBuehler
Copy link
Member

This embeds the .metallib file into the main .so, removing the difference when loading a CUDA vs Metal kenrnel. It is a breaking change to the metal kernel compilation strategy.

std::string moduleDir = getModuleDirectory();
std::string metallibPath = moduleDir + "/" + METALLIB_PATH;
// Load the embedded Metal library from memory
dispatch_data_t libraryData = dispatch_data_create(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could even make this friendlier for Metal kernels by generating/providing a header that does this for you? So something like

id<MTLLibrary> customKernelLibrary = [ourFunction args];

(Not sure what the exact syntax should look like, since I'm not familiar with ObjectiveC++).

Not 100% sure if this is useful, but maybe worth experimenting with?

It's nice to see the path handling go away!

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice idea! Added a function to deal with this, it's defined in the header with metallib_to_header.py and accessed with EMBEDDED_METALLIB_NAMESPACE.

Let me know what you think about this solution!

@EricLBuehler EricLBuehler requested a review from danieldk July 17, 2025 09:58
Copy link
Member

@danieldk danieldk left a comment

Choose a reason for hiding this comment

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

Awesome! 🔥

@EricLBuehler EricLBuehler merged commit 39cdfec into main Jul 17, 2025
8 checks passed
@EricLBuehler EricLBuehler deleted the embedded_metallib branch July 17, 2025 13:15
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.

2 participants