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.4 KiB
1.4 KiB
myst
| myst | ||||||
|---|---|---|---|---|---|---|
|
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 managementc10/cuda/CUDAGuard.h- CUDA device guardsATen/cuda/CUDAContext.h- CUDA context managementATen/cudnn/Descriptors.h- cuDNN tensor descriptors
CUDA Categories
:maxdepth: 1
streams
guards
utilities