pytorch/extension-cpp

C++ extensions in PyTorch

What it solves

It provides reference implementations for creating custom C++/CUDA operations in PyTorch, allowing developers to implement high-performance kernels that can run on both CPU and GPU.

How it works

The repository contains two different approaches to building extensions:

  • Standard ATen API: The traditional method using the full ATen/LibTorch API.
  • Stable ABI: A method using the LibTorch Stable ABI (for PyTorch 2.10+), which allows extensions to be compatible across multiple PyTorch versions without requiring recompilation.

Who it’s for

Developers who need to write custom, high-performance operators for PyTorch and want to see how to implement them using either the standard API or the stable ABI.

Highlights

  • Demonstrates a mymuladd custom operation.
  • Includes both CPU and CUDA kernels.
  • Supports the LibTorch Stable ABI for cross-version compatibility.

Related

  • Project
  • Project
  • Project
  • Project