Agent skill · software engineering · pytorch
metal-kernel
Write Metal/MPS kernels for PyTorch operators. Use when adding MPS device support to operators, implementing Metal shaders, or porting CUDA kernels to Apple Silicon. Covers native_functions.yaml dispatch, host-side operators, and Metal kernel implementation.
Why this skill is useful
Adds specific Metal kernel implementation patterns and dispatch mechanisms for PyTorch operators on Apple Silicon that are not widely documented.
What it needs
Requires metal installed locally. About 9k tokens when loaded. Last updated 2026-08-07. 102,253 stars on the source repository.
What this skill does
Metal Kernel Writing Guide This skill guides you through implementing Metal kernels for PyTorch operators on Apple Silicon. Important: The goal of this skill is to use native Metal capabilities via the c10/metal/ infrastructure, NOT MPSGraph. Native Metal kernels provide better control, performance, and maintainability. Overview There are two workflows covered by this skill: 1. Adding new MPS support - Implementing a new operator from scratch 2. Migrating from MPSGraph - Converting existing MPSGraph-based operators to native Metal Both workflows involve: 1. Update dispatch in aten/src/ATen/native/nativefunctions.yaml 2. Write Metal kernel in aten/src/ATen/native/mps/kernels/ 3. Implement host-side stub in aten/src/ATen/native/mps/operations/ Step 1: Update nativefunctions.yaml Location: aten/src/ATen/native/nativefunctions.yaml For New Operators Find the operator entry and add MPS dispatch: For Migrating from MPSGraph When migrating an existing operator from MPSGraph to native Metal, consolidate the dispatch entry: Key change: Replace MPS: myopoutmps with adding MPS to the shared dispatch line (e.g., CPU, CUDA, MPS: myopout). Update every overload. A single op typically has several nativefunctions.yaml entries — functional / inplace / .out, plus Tensor and Scalar variants. Each entry has its own dispatch: block, and each one must be moved over. Any entry left pointing at MPS: myopmps still routes that overload to the MPSGraph code, so callers can silently land on the old path depending on which overload they hit. Before declaring the migration done, grep the legacy function name and confirm no entry still references it. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills pytorch/metal-kernel