Files
pytorch/docs/cpp/source/api/cuda/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.4 KiB

myst
myst
html_meta
description keywords
PyTorch CUDA C++ API — device management, streams, guards, and cuDNN/cuBLAS utilities. PyTorch, C++, CUDA, GPU, streams, guards, cuDNN, cuBLAS

CUDA Support

PyTorch provides comprehensive CUDA support for GPU-accelerated tensor operations and neural network training. The CUDA API allows you to manage GPU devices, streams for asynchronous execution, and memory efficiently.

When to use CUDA APIs:

  • When you need explicit control over which GPU device to use
  • When implementing custom CUDA kernels or operations
  • When optimizing performance with asynchronous stream execution
  • When managing multi-GPU workloads

Basic usage:

#include <torch/torch.h>
#include <c10/cuda/CUDAGuard.h>

// Check if CUDA is available
if (torch::cuda::is_available()) {
    // Create tensor on GPU
    auto tensor = torch::randn({2, 3}, torch::device(torch::kCUDA));

    // Switch to a specific GPU
    c10::cuda::CUDAGuard guard(0);  // Use GPU 0

    // Get the current CUDA stream
    auto stream = c10::cuda::getCurrentCUDAStream();

    // Move model to GPU
    model->to(torch::kCUDA);
}

Header Files

  • c10/cuda/CUDAStream.h - CUDA stream management
  • c10/cuda/CUDAGuard.h - CUDA device guards
  • ATen/cuda/CUDAContext.h - CUDA context management
  • ATen/cudnn/Descriptors.h - cuDNN tensor descriptors

CUDA Categories

:maxdepth: 1

streams
guards
utilities