Memory Management
NCCL-backed device memory allocation; see Memory Allocator for
usage details. For zero-copy registration of existing buffers, see
Communicator.register_buffer() and
Communicator.register_window().
mem_alloc
- nccl.core.mem_alloc(size: int, device: Device | int | None = None) Buffer
Allocates GPU buffer memory using NCCL’s memory allocator.
The actual allocated size may be larger than requested due to buffer granularity requirements from NCCL optimizations. The returned buffer can be explicitly freed with
mem_free()or automatically freed when garbage collected.- Parameters:
size – Number of bytes to allocate.
device – Target CUDA device. Defaults to the current device.
- Returns:
A CUDA buffer object backed by NCCL-managed memory. The buffer is allocated on the specified device; the current device is restored after allocation.
mem_free
- nccl.core.mem_free(buf: Buffer) None
Frees memory allocated by
mem_alloc().Explicit deallocation is optional. Memory is automatically freed when the Buffer object is garbage collected.
- Parameters:
buf – The buffer to free.