NcclBackend

Struct NcclBackend 

Source
pub struct NcclBackend { /* private fields */ }
Expand description

2026-09-26: NCCL communicator plus the streams, events and receive buffer its operations use.

Implementations§

Source§

impl NcclBackend

Source

pub fn new( rank: usize, world_size: usize, master_addr: &str, master_port: u16, stream: u64, recv_capacity: usize, ) -> Result<Self>

2026-09-26: Bootstrap the communicator. Rank 0 binds 0.0.0.0:master_port and sends the unique id to world_size - 1 connections; other ranks connect to master_addr:master_port, retrying once a second for up to 600 attempts. recv_capacity is the largest 2-rank all-reduce payload in bytes (serve passes required_model_recv_bytes); it is used only when world_size == 2.

§Errors

An invalid METRALE_COMM_DIAGNOSTICS value or rank/world pair, a failed bootstrap or NCCL init, a failed stream or event creation, a zero recv_capacity at world_size == 2, or a failed receive-buffer allocation. A failed registration of the receive buffer is only logged.

Trait Implementations§

Source§

impl CommBackend for NcclBackend

Source§

fn all_reduce(&self, ptr: u64, bytes: usize) -> Result<()>

2026-09-26: Sum bytes at ptr across all ranks, in place; every rank gets the result. NcclBackend reduces BF16 elements.
Source§

fn all_reduce_async( &self, ptr: u64, bytes: usize, compute_stream: u64, ) -> Result<()>

2026-09-26: All-reduce ordered against compute_stream on the device: the reduce starts after the work already queued there and later work there waits for it. The host does not wait. The default ignores compute_stream and calls all_reduce.
Source§

fn register_buffer(&self, ptr: u64, bytes: usize) -> Result<u64>

2026-09-26: Register a device buffer with the backend and return an opaque handle (ncclCommRegister in NcclBackend). The default registers nothing and returns 0.
Source§

fn deregister_buffer(&self, handle: u64) -> Result<()>

2026-09-26: Deregister a handle from register_buffer.
Source§

fn symmetric_alloc(&self, bytes: usize) -> Result<u64>

2026-09-26: Allocate bytes of device memory from the backend’s allocator (ncclMemAlloc in NcclBackend) and return the pointer. The default returns Err.
Source§

fn symmetric_free(&self, ptr: u64) -> Result<()>

2026-09-26: Free a pointer from symmetric_alloc. The default returns Err.
Source§

fn set_add_kernel(&self, handle: u64)

2026-09-26: Hand the backend the bf16_add_inplace kernel handle. The model engine looks it up and passes it after registering its buffers. NcclBackend takes its 2-rank send/recv all-reduce path only once it is set.
Source§

fn all_gather(&self, send_ptr: u64, recv_ptr: u64, bytes: usize) -> Result<()>

2026-09-26: Each rank contributes bytes from send_ptr; every rank receives all contributions, in rank order, at recv_ptr.
Source§

fn reduce_scatter( &self, send_ptr: u64, recv_ptr: u64, bytes: usize, ) -> Result<()>

2026-09-26: Sum across ranks and give each rank its bytes-sized share at recv_ptr. NcclBackend sums u8 elements.
Source§

fn broadcast(&self, ptr: u64, bytes: usize, root: usize) -> Result<()>

2026-09-26: Copy bytes at ptr from rank root to every rank, in place.
Source§

fn recv_command_u32(&self, ptr: u64, root: usize) -> Result<()>

2026-09-26: On a non-root rank, receive the first u32 of the next worker command from root, the receive side of a 4-byte broadcast. Unlike broadcast, it may wait without a deadline, so an implementation must keep checking for transport errors while it waits. The command’s later words use broadcast. The default refuses root and otherwise calls broadcast(ptr, 4, root).
Source§

fn barrier(&self) -> Result<()>

2026-09-26: A barrier across ranks. NcclBackend enqueues a zero-count all-reduce on its stream and returns without waiting for it.
Source§

fn send_to( &self, ptr: u64, bytes: usize, dest_rank: usize, stream: u64, ) -> Result<()>

2026-09-26: Send bytes at ptr to dest_rank, enqueued on stream. Pairs with a recv_from of the same size on dest_rank.
Source§

fn recv_from( &self, ptr: u64, bytes: usize, src_rank: usize, stream: u64, ) -> Result<()>

2026-09-26: Receive bytes into ptr from src_rank, enqueued on stream. Pairs with a send_to of the same size on src_rank.
Source§

fn group_start(&self) -> Result<()>

2026-09-26: Open a group: NcclBackend calls ncclGroupStart, so the operations up to group_end are submitted together. The default does nothing.
Source§

fn group_end(&self) -> Result<()>

2026-09-26: Close the group opened by group_start.
Source§

fn is_healthy(&self) -> bool

2026-09-26: false after the backend has seen a transport error or a completion timeout, until a successful attempt_reconnect. NcclBackend also queries ncclCommGetAsyncError. The default returns true.
Source§

fn attempt_reconnect(&self) -> Result<()>

2026-09-26: Replace a failed communicator. NcclBackend aborts it and repeats the TCP bootstrap, so every rank must call this at the same time. The default does nothing.
Source§

fn rank(&self) -> usize

2026-09-26: This rank’s index, from 0.
Source§

fn world_size(&self) -> usize

2026-09-26: Number of ranks.
Source§

impl Drop for NcclBackend

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for NcclBackend

Source§

impl Sync for NcclBackend

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more