PyTorchMetalDemo
This is a simple demo that implements a custom operation in PyTorch that uses Metal kernels in cpp.
Install / Use
/learn @JohanLi233/PyTorchMetalDemoREADME
PyTorchMetalDemo
PyTorchMetalDemo is a demonstration project showcasing how to use Apple's Metal API with PyTorch to perform custom tensor operations on macOS devices with MPS (Metal Performance Shaders) support.
Features
- Implements a custom tensor fill operation using Metal.
- Implements a custom tensor add operation using Metal.
- Demonstrates integration of Metal with PyTorch.
Requirements
- macOS with Metal support
- PyTorch with MPS backend support
- Xcode command line tools
- Python 3.12
- uv package manager (https://github.com/astral-sh/uv) or any other python package manager
Metal CPP
The metal-cpp package was downloaded from here. If you are not using macOS 15, please download the appropriate version from this link.
Check Real Use Cases of Customizing kernels Here
Usage
git clone https://github.com/JohanLi233/PyTorchMetalDemo.git
cd PyTorchMetalDemo
# create venv
uv venv --python=3.12
source .venv/bin/activate
uv pip install -r requirements.txt
uv pip install -e .
python test.py
Related Skills
node-connect
353.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
353.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
353.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
