-
Notifications
You must be signed in to change notification settings - Fork 27
Support metal cpp sdk #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| "relu_metal/relu.mm", | ||
| "relu_metal/relu.metal", | ||
| "relu_metal/common.h", | ||
| "relu_metal_cpp/relu.cpp", | ||
| "relu_metal_cpp/metallib_loader.mm", | ||
| "relu_metal_cpp/relu_cpp.metal", | ||
| "relu_metal_cpp/common.h", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be best to keep relu as is and add an extra relu-metal-cpp example.
|
|
||
| # Build inputs | ||
| apple-sdk_15, | ||
| metal-cpp, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep them lexicographically sorted.
| if [[ "$*" =~ "metallib" ]]; then | ||
| # If metallib is requested, find the air-lld from the Metal toolchain | ||
| METALLIB_BIN=$(ls /var/run/com.apple.security.cryptexd/mnt/com.apple.MobileAsset.MetalToolchain*/Metal.xctoolchain/usr/bin/air-lld 2>/dev/null | head -n 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
metallib is a binary too :)
Also, this path is not stable, e.g. it doesn't exist on my macOS 26 installation.
| # Remove the '-sdk macosx metallib' and other unsupported flags from the command arguments | ||
| ARGS=$(echo "$@" | sed 's/-sdk macosx metallib //' | sed 's/-mmacosx-version-min=[^ ]* //') | ||
| # Add platform version for macOS 15+ to support Metal 3.2 / AIR 2.7 | ||
| $METALLIB_BIN -platform_version macos 15.0 15.0 $ARGS | ||
| elif [[ "$*" =~ "metal" ]]; then | ||
| # If metal is requested, find the metal compiler from the Metal toolchain | ||
| METAL_BIN=$(ls /var/run/com.apple.security.cryptexd/mnt/com.apple.MobileAsset.MetalToolchain*/Metal.xctoolchain/usr/bin/metal 2>/dev/null | head -n 1) | ||
| if [ -z "$METAL_BIN" ]; then | ||
| echo "Error: Metal compiler not found" >&2 | ||
| exit 1 | ||
| fi | ||
| # Remove the '-sdk macosx metal' from the command arguments | ||
| ARGS=$(echo "$@" | sed 's/-sdk macosx metal //') | ||
| $METAL_BIN $ARGS | ||
| else | ||
| # In all other cases, just use the host xcrun | ||
| unset DEVELOPER_DIR | ||
| /usr/bin/xcrun $@ | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most of this is not needed with #290 merged, we do not call xcrun anymore for metal and metallib.
This PR adds support for a new
metal-cppkernel dependency. This is a follow up to the metal-cpp support in hf nix: huggingface/hf-nix#128 and enables kernels to use the cpp headers to drive metal kernels.Changes:
examples/relu/build.toml. since they both produce metal output we can only build one at a time..xcrunHostcommand to respect the cryptex location of the latest metal toolchain on the host. This may need to be improved in line with Metal 4 Update to macOS SDK 26 and Metal 4 #290example usage