Files
pytorch/docs/cpp/source/api/c10/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

1.9 KiB

myst
myst
html_meta
description keywords
C10 core library API — fundamental types, device management, streams, and utilities used throughout PyTorch. PyTorch, C++, c10, core, Device, Stream, types

C10: Core Utilities

C10 (Caffe2 + ATen = C10) is the core library that provides fundamental utilities and data types used throughout PyTorch. It contains device abstractions, memory management utilities, and common data structures.

When to use C10:

  • When working with device-agnostic code (CPU, CUDA, XPU, etc.)
  • When you need efficient array views without copying data
  • When handling optional values or type-erased containers
  • When writing code that needs to work across different PyTorch backends

Basic usage:

#include <c10/core/Device.h>
#include <c10/util/ArrayRef.h>

// Device abstraction
c10::Device device(c10::kCUDA, 0);
if (device.is_cuda()) {
    std::cout << "Using CUDA device " << device.index() << std::endl;
}

// Efficient array views (no copy)
std::vector<int64_t> sizes = {3, 4, 5};
c10::ArrayRef<int64_t> sizes_ref(sizes);

// Optional values
c10::optional<int64_t> maybe_dim = 2;
int64_t dim = maybe_dim.value_or(-1);

Header Files

  • c10/core/Device.h - Device abstraction
  • c10/core/DeviceType.h - Device type enumeration
  • c10/util/ArrayRef.h - Non-owning array reference
  • c10/util/OptionalArrayRef.h - Optional array reference
  • c10/util/Optional.h - Optional value wrapper
  • c10/util/Half.h - Half-precision float
  • c10/util/Exception.h - Error checking macros (TORCH_CHECK, TORCH_INTERNAL_ASSERT, etc.)
  • c10/cuda/CUDAGuard.h - CUDA device guards (see {doc}../cuda/index)
  • c10/cuda/CUDAStream.h - CUDA stream management (see {doc}../cuda/index)
  • c10/xpu/XPUStream.h - Intel XPU stream management
  • ATen/core/ivalue.h - IValue for TorchScript interop

C10 Categories

:maxdepth: 1

device
guards
streams
types
utilities