Unified Communication X (UCX)

repository·master·Indexed 23 days ago

https://github.com/openucx/ucx

An optimized communication framework for high-bandwidth, low-latency networks. UCX provides abstract communication primitives leveraging hardware offloads like RDMA, GPUs, and shared memory. It is organized into functional layers: UCP (Protocol), UCT (Transport), UCS (Services), and UCM (Memory). It supports various transports including InfiniBand, RoCE, CUDA, ROCm, and TCP/IP, and provides bindings for Java (JUCX) and Go.

Tokens
22.3K
Snippets
46
Records
153
Agent score
80%

What's inside UCX

  1. Overview of Unified Communication X (UCX)

    master

    Unified Communication X (UCX) is an optimized communication framework designed for modern, high-bandwidth, and low-latency networks. It provides abstract communication primitives that leverage hardware resources and offloads, including:

    • RDMA (InfiniBand and RoCE)
    • TCP
    • GPUs
    • Shared memory
    • Network atomic operations

    UCX provides a high-level API to mask low-level communication details while maintaining high performance and scalability across various message sizes.

  2. What is Unified Communication X (UCX)?

    master

    Unified Communication X (UCX) is a set of network APIs and implementations designed for high-throughput computing. It acts as a communication middleware that abstracts vendor-specific software and hardware interfaces, bridging the gap between programming models (like MPI, OpenSHMEM, or task-based models) and network hardware.

    UCX is designed for functional and performance portability across diverse architectures and programming models. It provides optimized protocols for data transfer between various memories and manages network resources to support high-performance, scalable networking.

  3. UCX Connection Establishment and Resource Management

    master

    UCX offers flexible methods for managing connections and resources:

    Connection Models

    • Client/Server: Establish connections using a client/server model similar to TCP.
    • Direct Connection: Connect directly by passing a remote address blob.

    Resource and Progress Models

    • Threading: Supports sharing resources between multiple threads or allocating dedicated resources per thread.
    • Progress Mechanisms: Supports both event-driven (interrupt-based) and polling-driven (busy-wait) progress models.
  4. How UCX supports hybrid programming models

    master

    UCX provides native support for hybrid programming models (e.g., applications using both OpenSHMEM and MPI). It enables efficient resource sharing and progress engine coordination by allowing users to choose between:

    1. A single shared UCX network context across different programming models.
    2. Standalone UCX network contexts for each individual programming model.

    This flexibility helps optimize memory usage and improves overall network and application performance.

  5. How UCX components work together

    master

    UCX is organized into several functional layers:

    ComponentRoleDescription
    UCPProtocolImplements high-level abstractions like tag-matching, streams, connection negotiation/establishment, multi-rail, and handling different memory types.
    UCTTransportImplements low-level communication primitives like active messages, remote memory access (RMA), and atomic operations.
    UCSServicesA collection of data structures, algorithms, and system utilities for common use.
    UCMMemoryIntercepts memory allocation and release events, used by the memory registration cache.
  6. Understand the UCX architecture (UCT, UCP, and UCS)

    master

    UCX is composed of three primary layers that work together to provide high-performance communication:

    • UCT (Transport Layer): Provides a low-level API to abstract hardware differences (e.g., uGNI, Verbs, shared memory, ROCM, CUDA). It manages communication contexts and device-specific memory. UCT defines three main communication interfaces:
      • immediate (short): Optimized for small messages.
      • bcopy (buffered copy-and-send): Optimized for medium messages using a bouncing-buffer.
      • zcopy (zero-copy): Exposes zero-copy memory-to-memory semantics.
    • UCP (Protocol Layer): Implements higher-level protocols used by MPI and PGAS models. It handles library initialization, transport selection, message fragmentation, and multi-rail communication. Key interfaces include Initialization, RMA, AMO, Active Message, Tag-Matching, and Collectives.
    • UCS (Service Layer): Provides portable and efficient utility functions.
  7. Core UCX Communication APIs

    master

    UCX provides several high-level communication patterns for data transfer and synchronization. Developers can choose from the following API models depending on their application requirements:

    • Stream-oriented operations: Send and receive operations based on a continuous stream of data.
    • Tag-matched operations: Send and receive operations that use tags to match specific messages, similar to MPI semantics.
    • Remote Memory Access (RMA): Direct access to memory on a remote node.
    • Remote Atomic Operations: Performing atomic operations (like fetch-and-add or compare-and-swap) on remote memory.
  8. Understand blocking vs non-blocking UCX routines

    master

    UCX distinguishes between blocking and non-blocking routines, which affects how you manage resources and control program flow:

    • Blocking routines: These return only when the UCX operation is fully complete. Once the routine returns, you can safely reuse the resources involved in that operation.
    • Non-blocking routines: These return immediately, regardless of whether the operation has finished. You must not reuse the resources used by the routine until the operation is confirmed complete.
  9. Use GPU memory with UCX APIs

    master

    UCX supports NVIDIA (CUDA) and AMD (ROCm) GPUs. Protocol operations can accept GPU memory pointers directly in place of host memory pointers.

    Supported APIs

    API CategorySupported MethodsSupport Level
    Tagucp_tag_send_XX, ucp_tag_recv_XXFull
    Streamucp_stream_send, ucp_stream_recv_XXFull
    Active Messagesucp_am_send_XX, ucp_am_recv_data_XXFull
    Remote Memory Accessucp_put_XX, ucp_get_XXPartial
    Atomic Operationsucp_atomic_XXPartial

    Troubleshooting GPU Memory

    • Segfaults: Usually caused by UCX failing to recognize a pointer as GPU memory. Ensure UCX was compiled with GPU support and that cuda or rocm is included in UCX_TLS.
    • Verify Support: Run ucx_info -d | grep cuda or ucx_info -d | grep rocm.
    • Memory Type Cache Issues: If UCX misdetects GPU memory as host memory, disable the cache with UCX_MEMTYPE_CACHE=n.
    • PTX Toolchain Errors: If you see "provided PTX was compiled with an unsupported toolchain", your application's CUDA binary is newer than the installed CUDA version. Recompile with the correct -arch option for your target hardware.
  10. Write boolean expressions according to UCX style

    master

    To avoid ambiguity and precedence issues, follow these rules for boolean logic:

    • Explicit Comparisons: Use explicit comparisons for non-boolean values (pointers, counts, status/enum codes). Example: if (ptr == NULL) instead of if (!ptr).
    • Direct Testing: Test boolean flags (integers holding 0/1, e.g., is_*, has_*) directly. Example: if (is_enabled).
    • Parentheses: Add parentheses around every comparison in compound expressions to ensure correct precedence.
    • Negation: Use ! without parentheses for single flags or predicate calls (e.g., !is_enabled).
  11. Optimize memory footprint in UCX modules

    master

    When developing or extending UCX modules, memory optimization should focus on scalability. The goal is to ensure memory usage scales with the number of in-flight operations rather than the number of connections.

    Key principles:

    • Scalability: Minimize the dependency of memory usage on the number of connections created.
    • Structure Size: Avoid enlarging the endpoint structure and remote memory key structure.
    • Descriptor Scaling: The number of requests and other descriptors must be proportional to the number of in-flight operations, not the total number of connections.
    • Memory Pools: Limit the number of buffers used from memory pools.
    • Acceptable Overhead: Adding small fields to structures that exist per thread, process, or device (e.g., iface, worker, context, md) is acceptable.
  12. How UC-Protocols (UCP) interfaces work

    master

    UCP provides high-level communication interfaces categorized by their programming model requirements:

    • Initialization: Handles communication context setup (the UCX context, an abstraction of network transport resources) and initializes UCP endpoints (abstractions of resources for a specific connection). Endpoints are used as inputs for all communication operations.
    • RMA (Remote Memory Access): Provides one-sided operations like PUT and GET. It includes specialized interfaces for non-contiguous data to leverage hardware scatter/gather capabilities.
    • AMO (Atomic Memory Operations): Supports performing atomic operations on remote memory, essential for PGAS models like OpenSHMEM.
    • Tag Matching: Supports send-receive semantics based on tags, matching the requirements of the MPI specification.
    • Stream: Provides ordered and reliable byte-stream communication, similar to BSD-socket programming models. Unlike tag-matching, individual send sizes do not need to match receive sizes, provided the total byte count is consistent.
    • Active Message: Allows incoming packets to invoke a sender-specified callback on the receiving process. This is useful for paradigms where the receiver reacts to incoming packets rather than pre-posting receives.
    • Collectives: Defines group communication and synchronization operations, such as barrier, all-to-one, all-to-all, and reduction. These may leverage hardware acceleration (e.g., InfiniBand Switch acceleration) when available.