This document is relevant for: Trn2, Trn3
nki.isa.sendrecv_compute#
- nki.isa.sendrecv_compute(src: NkiTensor, dst: NkiTensor, send_to_rank, recv_from_rank, reduce_op, name=None)[source]#
Perform point-to-point communication between NeuronCores and reduce the local and received tiles into a single result, using the DMA engine’s reduction capability.
Note
Available only when running with LNC (Logical NeuronCore) degree greater than 1.
This instruction combines a bidirectional data exchange (like
nisa.sendrecv) with a reduction. The current NeuronCore sends itssrctile to the target NeuronCore specified bysend_to_rank, simultaneously receives the peer tile fromrecv_from_rank, and writesreduce_op(src, peer)todst.The use case is fusing an inter-core exchange with an element-wise reduction, such as cross-core all-reduce-style accumulation, without a separate
nisa.tensor_tensorstep afternisa.sendrecv.The communication is between the physical NeuronCores that make up the same Logical NeuronCore (LNC), so this instruction requires an LNC degree greater than 1, and
send_to_rank/recv_from_rankmust be a valid rank within the LNC (0 or 1 for LNC degree 2).The
reduce_opparameter selects the reduction applied to the localsrcand the peer tile. Supported operations arenl.add,nl.maximum, andnl.minimum.Constraints.
srcanddsttiles must be in the same memory space: both in SBUF or both in private HBM (mixing SBUF and HBM, or using shared HBM, is not supported).srcanddstmust have the same data type.srcanddstmust have the same shape and layout.srcanddstmust have the same partition dimension size and the same number of elements per partition.
- Parameters:
src – the source tile on the current NeuronCore to be sent and reduced
dst – the destination tile on the current NeuronCore where the reduced result is stored
send_to_rank – rank ID of the target NeuronCore to send data to
recv_from_rank – rank ID of the source NeuronCore to receive data from
reduce_op – the reduction operation to apply:
nl.add,nl.maximum, ornl.minimum
Example:
# All-reduce-style accumulation across two cores in an LNC current_rank = nl.program_id() peer_rank = 1 - current_rank send_data = nl.ndarray((batch_size, hidden_dim), dtype=nl.float32, buffer=nl.sbuf) result = nl.ndarray((batch_size, hidden_dim), dtype=nl.float32, buffer=nl.sbuf) # result = send_data + peer's send_data sendrecv_compute( src=send_data, dst=result, send_to_rank=peer_rank, recv_from_rank=peer_rank, reduce_op=nl.add, )
This document is relevant for: Trn2, Trn3