# rocm/rccl architecture

> Architecture diagram of the GitHub repository rocm/rccl, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rocm/rccl
- Repository: https://github.com/rocm/rccl

## Overview

##### Main Components
- Core Library – Represent the central “RCCL Engine”, which provides the collective operations. This includes:
- The API and header files (found in src/include) that define the NCCL-like interface.
- Core implementation files in the src folder (e.g., bootstrap.cc, channel.cc, collectives.cc, graph-related files, etc.).
- Device and Kernel Layer – Highlight the modules that manage GPU-level operations:
- src/device: kernels, CUDA/C++ code for all the collective primitives, and device-specific optimizations.
- Communication/Transport Layer – Capture the networking and inter-node communication aspects:
- src/transport: multiple implementations such as net.cc, net_ib.cc, net_socket.cc, and p2p communication.
- Components handling low-level interconnects (InfiniBand, TCP sockets, etc.).
- Files in src/graph (e.g., rings, trees, and topology discovery routines) that compute the optimal collective communication pattern.
- External Modules – Represent the optionally integrated modules that can extend or tune the library:
- ext-net and ext-tuner directories provide examples and plugins for networking and tuning, respectively.
- CMakeLists.txt, Makefile, cmake scripts, and packaging directories (pkg, makefiles) indicate a carefully layered build process.
- CI/CD configuration folders (.azuredevops, .github, .jenkins) show automated testing and integration.
- The test directory for unit tests (using Googletest) and multiple tools in the tools folder for benchmarking, timing, topology visualization, and diagnostics.
- Documentation – A separate block for docs, showcasing that the project also maintains comprehensive user and API documentation (docs, .readthedocs.yaml, Sphinx requirements).

##### Relationships & Data Flow
- User-level Application ↔ RCCL Library API: Indicate that external applications or MPI frameworks call into the RCCL API, which is defined in the include files.
- Core Operations Flow: Show that when a collective call is made, the RCCL Engine uses its graph algorithms to choose the routes (rings, trees) and then dispatches work to the device layer (kernel launches) and transport layer.
- Build/CI/Packaging: Illustrate that the build system (CMake, Makefile, etc.) ties everything together and that CI systems validate the integration and performance via tests and tools.
- External Plugins/Extensions: Demonstrate how ext-net and ext-tuner can plug into the core system, perhaps enhancing functionalities without disturbing the main architecture.

##### Architectural Patterns & Design Principles
- Modular Separation: Emphasize the separation of concerns (API, algorithm, device handling, transport, testing).
- Layered Architecture: Show that higher-level collective function calls are abstracted from low-level device or kernel implementations.
- Extensibility: Illustrate extension points by highlighting directories and plugins (ext-net, ext-tuner, external dependencies via CMake).
- CI/CD Integration: Note the robust integration of multiple CI systems (Azure, GitHub, Jenkins) to support continuous testing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User Application"]:::user

    subgraph "Core Compute Layers"
        RCCL["RCCL API & Core Engine\n(API: src/include, Core: src/bootstrap.cc, src/channel.cc, src/collectives.cc)"]:::core
        Graph["Graph & Algorithm Module\n(src/graph: rings, trees, topo, tuning)"]:::device
        Device["Device/Kernels\n(src/device)"]:::device
        Transport["Transport/Communication\n(src/transport: net.cc, net_ib.cc, net_socket.cc, p2p.cc)"]:::device
    end

    subgraph "Extension and Support"
        Extensions["External Extensions (Net & Tuner)\n(ext-net, ext-tuner)"]:::external
        Build["Build & Packaging Infrastructure\n(CMakeLists.txt, Makefile, cmake, pkg, CI/CD: .azuredevops, .github, .jenkins)"]:::build
        Testing["Tests & Tools\n(test, tools)"]:::testing
        Docs["Documentation\n(docs, .readthedocs.yaml)"]:::docs
    end

    %% Relationships
    User -->|"calls"| RCCL
    RCCL -->|"uses"| Graph
    RCCL -->|"dispatches_to"| Device
    RCCL -->|"communicates_via"| Transport
    Extensions -->|"enhances"| RCCL
    Build -->|"assembles"| RCCL
    Build -->|"assembles"| Graph
    Build -->|"assembles"| Device
    Build -->|"assembles"| Transport
    Testing -->|"validates"| RCCL
    Testing -->|"validates"| Build
    Docs -->|"documents"| RCCL
    Docs -->|"documents"| Extensions

    %% Click Events
    click RCCL "https://github.com/rocm/rccl/tree/develop/src/include"
    click RCCL "https://github.com/rocm/rccl/blob/develop/src/bootstrap.cc"
    click RCCL "https://github.com/rocm/rccl/blob/develop/src/channel.cc"
    click RCCL "https://github.com/rocm/rccl/blob/develop/src/collectives.cc"
    click Device "https://github.com/rocm/rccl/tree/develop/src/device"
    click Transport "https://github.com/rocm/rccl/tree/develop/src/transport"
    click Graph "https://github.com/rocm/rccl/tree/develop/src/graph"
    click Extensions "https://github.com/rocm/rccl/tree/develop/ext-net"
    click Extensions "https://github.com/rocm/rccl/tree/develop/ext-tuner"
    click Build "https://github.com/rocm/rccl/blob/develop/CMakeLists.txt"
    click Build "https://github.com/rocm/rccl/tree/develop/Makefile"
    click Build "https://github.com/rocm/rccl/tree/develop/cmake"
    click Build "https://github.com/rocm/rccl/tree/develop/pkg"
    click Build "https://github.com/rocm/rccl/blob/develop/.azuredevops"
    click Build "https://github.com/rocm/rccl/blob/develop/.github"
    click Build "https://github.com/rocm/rccl/blob/develop/.jenkins"
    click Testing "https://github.com/rocm/rccl/tree/develop/test"
    click Testing "https://github.com/rocm/rccl/tree/develop/tools"
    click Docs "https://github.com/rocm/rccl/tree/develop/docs"
    click Docs "https://github.com/rocm/rccl/blob/develop/.readthedocs.yaml"

    %% Styles
    classDef core fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef device fill:#D2B4DE,stroke:#7D3C98,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef build fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef testing fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef docs fill:#FAD7A0,stroke:#CA6F1E,stroke-width:2px;
    classDef user fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
```
