mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
19da3da3d3
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
1.9 KiB
1.9 KiB
myst
| myst | ||||||
|---|---|---|---|---|---|---|
|
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 abstractionc10/core/DeviceType.h- Device type enumerationc10/util/ArrayRef.h- Non-owning array referencec10/util/OptionalArrayRef.h- Optional array referencec10/util/Optional.h- Optional value wrapperc10/util/Half.h- Half-precision floatc10/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 managementATen/core/ivalue.h- IValue for TorchScript interop
C10 Categories
:maxdepth: 1
device
guards
streams
types
utilities