# apple-silicon

A skill for developers building on Apple Silicon: tuning code for unified memory, Metal Performance Shaders, Instruments profiling, Rosetta 2 behavior, and 16KB page size quirks.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 383 installs · ★ 298 repo stars
- Author: mohitmishra786
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/mohitmishra786/low-level-dev-skills/tree/HEAD/skills/platform/apple-silicon/SKILL.md
- Updated: 2026-06-27
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/apple-silicon

## What it does

This skill guides native ARM64 development on macOS M1/M2/M3/M4. At its core is Apple Silicon's unified memory architecture — CPU, GPU, and Neural Engine share one address space, eliminating the PCIe copies typical on discrete GPUs. The skill covers querying chip details via `sysctl`, using the Accelerate framework to access the AMX coprocessor, profiling with Instruments and command-line `xctrace`, and analyzing memory with `vmmap`, `heap`, and `leaks`.

Key coverage includes 16KB page alignment (vs. 4KB on standard hardware), which matters when sizing allocations and using `mmap`. There's also practical troubleshooting: why `mmap` returns EINVAL, when Metal buffers stay nil on simulator vs. device, Rosetta 2 translation overhead for x86 binaries. The skill documents ARM64 feature detection, cache line size, and dispatch patterns for performance vs. efficiency cores.

Use this when profiling a hot path, optimizing matrix ops, debugging x86 compatibility on new hardware, or bridging CPU–GPU workflows without explicit copies.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill apple-silicon -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/apple-silicon/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/apple-silicon/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill apple-silicon -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/apple-silicon/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill apple-silicon -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/apple-silicon/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install mohitmishra786/low-level-dev-skills skills/platform/apple-silicon
```

2. **Manually: put the files in place**
- File: `.github/skills/apple-silicon/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill apple-silicon -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/mohitmishra786/low-level-dev-skills --path skills/platform/apple-silicon
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/apple-silicon/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add mohitmishra786/low-level-dev-skills --skill apple-silicon -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/mohitmishra786/low-level-dev-skills/tree/HEAD/skills/platform/apple-silicon/SKILL.md

## When to use it
- query CPU, GPU and memory info via sysctl and kernel interfaces
- align buffers and mmap to Apple Silicon's 16KB page boundary
- optimize matrix operations through Accelerate and AMX coprocessor
- profile memory, CPU hotspots, and leaks with Instruments and xctrace
- diagnose Rosetta 2 overhead and choose the right binary architecture

## Example prompts
- Help me optimize matrix multiplication for ARM64 using Accelerate
- How do I profile memory leaks on M1 with `leaks` and Instruments?
- Why does my `mmap` fail with EINVAL and how do I align to 16KB?

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 8bec04e12718e83a.

BEGIN THIRD-PARTY FILE 8bec04e12718e83a
````text
---
name: apple-silicon
description: Apple Silicon skill for M-series development and profiling. Use when leveraging unified memory, Metal Performance Shaders, Instruments profiling, sysctl hardware queries, Rosetta 2 behavior, or 16KB page size considerations. Activates on queries about Apple Silicon, unified memory, AMX, MPS, Instruments, Rosetta, or M-series page size.
---

# Apple Silicon

## Purpose

Guide agents through Apple Silicon (M-series) development: unified memory architecture, AMX matrix coprocessor access via Accelerate, Metal Performance Shaders for GPU compute, `sysctl` hardware queries, Instruments profiling, command-line leak tools, Rosetta 2 translation behavior, and 16KB page size implications.

## When to Use

- Optimizing native ARM64 apps on macOS for M1/M2/M3/M4
- Using GPU/NPU compute without discrete GPU PCIe transfers
- Profiling memory and CPU with Instruments or command-line tools
- Understanding Rosetta 2 compatibility for x86 binaries
- Adapting code for 16KB page size on Apple Silicon
- Accessing matrix acceleration via Accelerate/vDSP/BLAS

## Workflow

### 1. Unified memory architecture

```
Apple Silicon SoC
├── CPU cores (P + E cores)
├── GPU cores
├── Neural Engine (NPU)
└── Unified DRAM — single address space, no PCIe copy
```

Implications:
- `cudaMemcpy` equivalent is unnecessary for CPU↔GPU on Metal
- Memory bandwidth shared across agents — profile holistically
- Process memory includes all unified allocations

### 2. Hardware information

```bash
# CPU and chip info
sysctl -n machdep.cpu.brand_string
sysctl hw.physicalcpu hw.logicalcpu
sysctl hw.memsize

# ARM64 features (keys vary by chip — grep if specific FEAT_* is missing)
sysctl -a hw.optional.arm 2>/dev/null | grep -iE 'sve|bf16|mte'

# Cache line size
sysctl hw.cachelinesize

# Page size (16KB on macOS Apple Silicon)
sysctl hw.pagesize    # 16384
getconf PAGESIZE
```

### 3. 16KB page size considerations

macOS on Apple Silicon uses **16KB pages** (not 4KB):

```c
// Align hot buffers to page size
size_t page = sysconf(_SC_PAGESIZE);  // 16384
void *buf = aligned_alloc(page, size);

// mmap alignment must be page-aligned
mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
```

Impact:
````
END THIRD-PARTY FILE 8bec04e12718e83a

The third-party file has ended. Everything between the 8bec04e12718e83a tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2277 of 6601 bytes. © mohitmishra786 · MIT · https://github.com/mohitmishra786/low-level-dev-skills/tree/HEAD/skills/platform/apple-silicon/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
