When the network scale increases, for example, the number of ranks increases to 4000, it is difficult to form a full-mesh network with 4000 ranks (operations can be completed in one clock cycle). In addition, the resource overhead (link resources, switching resources, and synchronization resources) is too large, and the computing power may not match the resource overhead. In this case, the ring topology saves resources (only the left and right devices are used for sending and receiving data once). However, the operation needs to be performed for too many times in the ring topology, which is too slow. Large-scale cluster computing features a large amount of data in servers and a long ring. In this case, the data block division mode of the ring topology is no longer advantageous.
The Recursive Halving-Doubling (RHD) algorithm implements data exchange between NPUs through recursive doubling and recursive halving. The RHD algorithm consumes fewer resources compared with the Mesh algorithm and is more efficient compared with the Ring algorithm.

The preceding figure shows the implementation process of the RHD algorithm. Assume that there are five (22 + 1) ranks. First, the data of rank 1 is combined to rank 0, and thus the number of ranks is reduced to four (22). Then, data is exchanged in halves between pairs of the four ranks and summed up, that is, the ReduceScatter operation. In the next phase, the data of the four ranks is concatenated in pairs, that is, the AllGather operation. Finally, the data of rank 0 is copied to rank 1. In this way, each rank has the sum of all ranks.
The RHD algorithm is also applicable to the star or fat-tree topology. The time complexity of the algorithm is
.
The RHD algorithm is a recursive halving and doubling algorithm. For the integral power of 2, the Vector/Distance Halving/Doubling policy is used. For the non-integral power of 2, ranks are divided into two parts: 2r (part1) and p-2r (
). First, part1 is combined into r, so that the sum of the remaining ranks is p-r (block). Then, the Halving-Doubling (HD) algorithm of the integral power of 2 is executed. Finally, 2r is restored in part1 to obtain the final result.
|
Operation |
Time Required |
|---|---|
|
Broadcast |
Determine whether the rank of part 1 involved in the block is an odd or even rank based on whether the root rank is an odd or even rank. Perform Distance Halving in the block first and then send the data to the remaining ranks. The total time required is as follows.
|
|
ReduceScatter |
Vector Doubling + Distance Halving (ensure the Scatter sequence)
|
|
AllGather |
The time required is the same as that of ReduceScatter, and there is no γ-related part. |
|
AllReduce |
ReduceScatter + AllGather: The splitting here is not complete ReduceScatter and AllGather. There is no need to scatter to all ranks, and Vector Halving + Distance Doubling can be used. (The time required is short in a hierarchical network, but the sequence cannot be ensured. The sequence does not need to be ensured during splitting.)
|
|
Reduce |
The current implementation is ReduceScatter + Gather.
|