UCX (Unified Communication X) for CUDA 12

1.19.0 · active · verified Fri Apr 17

libucx-cu12 is a Python package that provides the Unified Communication X (UCX) C library, specifically compiled with CUDA 12 support, as a distributable wheel. UCX is a low-level, high-performance communication framework for HPC applications, enabling optimized data exchange between CPUs, GPUs, and network interfaces (e.g., InfiniBand, RoCE). This package serves as a backend dependency for Python bindings like `ucx-py` (now `ucxx`), allowing Python applications to leverage UCX capabilities. The current version available on PyPI is `1.19.0`, with upstream UCX having a frequent release cadence including point releases and release candidates.

Common errors

Warnings

Install

Imports

Quickstart

Install `libucx-cu12` to provide the CUDA 12-enabled UCX shared libraries. Then, install `ucxx` to get the Python bindings and verify UCX functionality and its underlying version. The example demonstrates basic initialization through `ucxx`.

import os
import subprocess
import sys

# Ensure libucx-cu12 is installed (it provides the C library)
# and then ucxx (for Python bindings)
try:
    import ucxx
    print(f"ucxx version: {ucxx.__version__}")
    print(f"Underlying UCX version: {ucxx.get_version_info()}")

    # A simple UCX initialization example via ucxx
    # Note: UCX often requires specific environment variables for optimal performance.
    # For a basic test, default initialization might work.
    # For distributed setup, UCP_RNDV_THRESH is often set.
    # os.environ['UCX_TLS'] = 'rc_x,sm,self'
    # os.environ['UCX_NET_DEVICES'] = 'mlx5_0:1' # Example for InfiniBand

    # Initialize UCX context (from ucxx)
    ctx = ucxx.init(enable_delayed_start=False)
    print("UCX context initialized successfully via ucxx.")
    print(f"UCX context info: {ctx}")
    # Additional UCX operations would follow here.
    # For a complete example involving communication, see ucxx documentation.

except ImportError:
    print("Error: 'ucxx' not found. Please install it after 'libucx-cu12'.")
    print("Run: pip install ucxx")
except Exception as e:
    print(f"An error occurred during UCX initialization: {e}")
    print("Please check UCX environment variables and system dependencies (e.g., CUDA drivers).")

# You can also verify the installed UCX library version directly from the command line
# This would typically be from the C library provided by libucx-cu12
print("\nVerifying UCX shared library version (if ucx_info is in PATH):")
try:
    # This might not always be in PATH depending on how libucx-cu12 is installed.
    # For wheels, it typically installs to site-packages, not system PATH.
    # However, ucxx.get_version_info() above is the primary way.
    result = subprocess.run(['ucx_info', '-v'], capture_output=True, text=True, check=True)
    print(result.stdout)
except FileNotFoundError:
    print("`ucx_info` command not found. This is normal if UCX is only installed via Python wheels.")
    print("The `ucxx.get_version_info()` call above is the recommended way to check.")
except subprocess.CalledProcessError as e:
    print(f"Error running ucx_info: {e}\n{e.stderr}")

view raw JSON →