How To Write C++ Extensions in 2026
summary
Shows how to build a real C++ custom op (a fused multiply‑add with a CUDA kernel) that compiles against the stable ABI so one binary replaces an M×N wheel matrix and runs on torch ≥2.10 and multiple CPython builds. Uses torch::stable::Tensor and the C shim wrappers, registers via the stable torch library + torch box, and enforces CPython compatibility with py_limited_api and TORCH_TARGET_VERSION. Example repo and real users (FA3, xformers, torchao, torchaudio) exist.
AI-written summary · about
chapters (7)
- 0:00C++ extensions in PyTorch
- 1:47Why write C++ extensions
- 7:30Stable ABI benefits
- 12:45CUDA kernel with stable APIs
- 16:13Registering and compiling
- 21:05Calling from Python
- 22:48Conclusion
related talks
25m"Boosting Python Numeric Computations with Dynamic C++ Integration"
29mC++ ♥ Python: from modules to hybrid applications
12mLightning Talk: Accelerating Inference on CPU with Torch.Compile
49mHow to build Python-C++ libraries
04mMachine Learning in C++ with PyTorch
25mLeveraging AI Ecosystem for Portable and Sustainable GPU Kernels in HPC
11mHardware-Aware Python Packages ~ PyTorch and...
25mMojo + PyTorch: A Simpler, Faster Path To Custom Kernels
