cuda-streams

Installation
SKILL.md

CUDA Streams and record_stream

The caching allocator only reuses a block on the stream that allocated it. If a tensor is used on some other stream, then before it is freed you need either (a) a sync from that stream back to the creation stream (an event, or creation_stream.wait_stream(side_stream)), or (b) record_stream() / CUDACachingAllocator::recordStream(). (a) is deterministic. (b) is not: on later allocations the allocator polls the recorded streams, so whether memory gets reused depends on how far the GPU has gotten, and memory usage can blow up when the CPU runs ahead. Prefer (a) where possible.

When writing or reviewing code that needs one of these, work out which of the following cases applies:

Installs
16
Repository
pytorch/pytorch
GitHub Stars
105.8K
First Seen
Oct 10, 2026