Files
pytorch/docs/cpp/source/api/stable/index.md
T
Svetlana Karslioglu 19da3da3d3 Restructure C++ docs (#174096)
The fix-cpp-build branch is a major restructuring that:

- Drops Exhale (which auto-generated API docs but caused OOM in CI) in favor of hand-written RST pages using Breathe directives
- Reorganizes notes into a hierarchical API reference with proper categories
- Adds new content: XPU docs, stable ABI docs, DeviceGuard/Stream docs
- Always runs Doxygen instead of gating on an env var

Pull Request resolved: https://github.com/pytorch/pytorch/pull/174096
Approved by: https://github.com/janeyx99, https://github.com/seemethere, https://github.com/albanD
2026-04-07 17:24:38 +00:00

2.1 KiB

myst
myst
html_meta
description keywords
PyTorch Stable ABI C++ API — binary-compatible operator registration across PyTorch versions. PyTorch, C++, stable ABI, binary compatibility, operator registration

Torch Stable API

The PyTorch Stable C++ API provides a binary-compatible interface for calling tensor operations and utilities that is guaranteed to remain stable across PyTorch versions. This enables ahead-of-time compiled extensions that don't need recompilation when PyTorch is updated.

When to use the Stable API:

  • When building extensions that must work across multiple PyTorch versions
  • When distributing pre-compiled binaries
  • When binary compatibility is more important than access to the latest features
  • When writing custom operators for production deployment

Basic usage:

#include <torch/csrc/stable/library.h>
#include <torch/csrc/stable/ops.h>

// Create a tensor using stable API
auto tensor = torch::stable::empty(
    {3, 4},
    torch::headeronly::ScalarType::Float,
    torch::headeronly::Layout::Strided,
    torch::stable::Device(torch::headeronly::DeviceType::CPU),
    false,
    torch::headeronly::MemoryFormat::Contiguous);

// Register operators with stable ABI
STABLE_TORCH_LIBRARY(myops, m) {
    m.def("my_op(Tensor input) -> Tensor");
}

STABLE_TORCH_LIBRARY_IMPL(myops, CPU, m) {
    m.impl("my_op", TORCH_BOX(&my_cpu_kernel));
}

For more information on the stable ABI, see the Stable ABI notes.

Header Files

  • torch/csrc/stable/library.h - Stable library registration
  • torch/csrc/stable/ops.h - Stable operator definitions
  • torch/csrc/stable/tensor_struct.h - Stable tensor structures
  • torch/csrc/stable/device_struct.h - Stable device structures
  • torch/csrc/stable/accelerator.h - Accelerator support
  • torch/csrc/stable/macros.h - Stable API macros

Stable API Categories

:maxdepth: 1

registration
operators
utilities

See Also