Collective Communication

Huawei Collective Communication Library (HCCL) is a high-performance collective communication library based on Ascend hardware. It provides a high-performance and high-reliability communication solution for compute clusters.

This section briefly describes HCCL. For details about how to use HCCL, see Huawei Collective Communication Library (HCCL).

Key Functions

  • Provides high-performance collective communication and point-to-point communication in single-server and multi-server environments.
  • Supports collective communication primitives such as AllReduce, Broadcast, AllGather, ReduceScatter, AlltoAll, Send, and Receive.
  • Supports communication algorithms such as Ring, Mesh, and Recursive Halving-Doubling (RHD).
  • Supports high-speed communication links such as HCCS, RoCE, PCIe, and Unified Bus (UB).
  • Supports two execution modes: single-operator and graph.
  • Supports custom development of communication operators.

Software Architecture

HCCL is a core component of CANN and provides a high-performance and high-reliability communication solution for NPU clusters. HCCL supports multiple AI frameworks and implements efficient interconnection between multiple Ascend AI processors, as shown in the following figure.

Figure 1 HCCL software architecture
HCCL consists of the HCCL and Huawei Communication (HCOMM) libraries.
  • HCCL: includes built-in communication operators and extended communication operators, and provides external communication operator APIs.
    • Built-in communication operators: basic communication operators provided by HCCL, including collective communication operators and point-to-point communication operators.
    • Extended communication operators: communication operators customized using the APIs provided by the HCOMM library.
  • HCOMM library: uses the layered decoupling design to divide communication capabilities into the control plane and data plane capabilities.
    • Control plane: provides topology information query and communication resource management functions.
    • Data plane: provides data movement and computing functions such as local operations, inter-operator synchronization, and communication operations.

    The control plane provides communication resources, and the data plane provides methods for operating resources. The provided APIs enable communication operator developers to focus on service innovation without paying attention to complex implementation details at the bottom layer of the chip.

Quick Experience

The following uses the AllReduce operator as an example to describe how to use the operator in single-operator execution mode, helping you quickly experience the collective communication function.

  • AllReduce operator

    The AllReduce operation performs reduction (sum, prod, max, and min) over the input data of all ranks in a communicator, and then sends the result to the output buffers of all ranks.

    Note: Each rank has only one input.

  • Sample

    You can click here to obtain the complete sample code. In this sample, a communicator is created based on the root rank information, and one AI server is managed in one process. Each NPU is managed by one thread. The main functions are as follows:

    1. Detects devices and queries the number of available devices by calling aclrtGetDeviceCount().
    2. Uses rank 0 as the root rank and calls HcclGetRootInfo() to generate the rootInfo identifier of the root rank.
    3. Initializes the communicator in each thread based on rootInfo by calling HcclCommInitRootInfo().
    4. Calls HcclAllReduce() to add the input data of all ranks in the communicator, sends the result to all ranks, and prints the result.
  • Compilation and running

    Run the following commands in the sample code directory:

    1
    2
    make
    make test
    
  • Result analysis

    The data of each rank is initialized to 0–7. After the AllReduce operation, the result of each rank is the sum of the data at the corresponding positions of all ranks (the data of eight ranks is added).

    Found 8 NPU device(s) available
    rankId: 0, output: [ 0 8 16 24 32 40 48 56 ]
    rankId: 1, output: [ 0 8 16 24 32 40 48 56 ]
    rankId: 2, output: [ 0 8 16 24 32 40 48 56 ]
    rankId: 3, output: [ 0 8 16 24 32 40 48 56 ]
    rankId: 4, output: [ 0 8 16 24 32 40 48 56 ]
    rankId: 5, output: [ 0 8 16 24 32 40 48 56 ]
    rankId: 6, output: [ 0 8 16 24 32 40 48 56 ]
    rankId: 7, output: [ 0 8 16 24 32 40 48 56 ]