# sam3.c

A dependency-free C11 implementation of Meta's Segment Anything Model 3 for image and video segmentation, with a Metal GPU backend and a multithreaded CPU backend.

sam3.c reimplements the full SAM3 pipeline, including the image encoder, prompt encoder, and mask decoder, from scratch in about 57,000 lines of portable C with no Python or PyTorch dependency. It supports Apple Metal for GPU acceleration and multithreaded SIMD kernels on CPU, half and mixed precision, and a custom mmap-friendly weight format for near-instant startup.

It ships as a single static binary with a unified command-line interface offering segment, convert, and info subcommands, supports stdin and stdout piping and JSON output, and includes video object tracking that propagates point, box, or mask prompts across frames. Multiple backbones are supported, including Hiera for full accuracy and lighter EfficientViT and TinyViT variants, along with 48 unit tests and built-in latency profiling.

Website: https://github.com/NetraRuntime/sam3.c
