Rate this Page

monarch.rdma#

The monarch.rdma module provides Remote Direct Memory Access (RDMA) support for high-performance networking and zero-copy data transfers between processes. See the Point-to-Point RDMA guide for an overview.

RDMA Buffer#

class monarch.rdma.RDMABuffer(data)[source]#

Bases: object

__init__(data)[source]#

RDMABuffer supports 1d contiguous tensors (including tensor views/slices) or 1d c-contiguous memoryviews.

Parameters:

data (torch.Tensor | memoryview) – torch.Tensor or memoryview to create the buffer from. Must be 1d and contiguous. If provided, addr and size must not be specified.

Raises:
  • ValueError – If data is not 1d contiguous, if size is 0, or if data is a GPU tensor.

  • RuntimeError – If no RDMA backend is available on this platform.

Note

Currently only CPU tensors are supported. GPU tensor support will be added in the future.

TODO: Create TensorBuffer, which will be main user API supporting non-contiguous tensors

property backend: str#

Return the RDMA backend in use (‘ibverbs’).

size()[source]#
read_into(dst, *, timeout=60)[source]#

Read data from this RDMABuffer into dst.

dst must be a 1D contiguous tensor or c-contiguous memoryview whose byte-size is at least self.size().

Parameters:

dst (torch.Tensor | memoryview) – Destination tensor or memoryview to read into.

Keyword Arguments:

timeout (int, optional) – Timeout in seconds. Defaults to 60s.

Returns:

A Monarch Future that resolves to None when

the read completes.

Return type:

Future[None]

Raises:

ValueError – If dst is smaller than the RDMA buffer.

write_from(src, *, timeout=60)[source]#

Write data from src into this RDMABuffer.

src must be a 1D contiguous tensor or c-contiguous memoryview whose byte-size is at most self.size().

Parameters:

src (torch.Tensor | memoryview) – Source tensor or memoryview containing the bytes to write to the RDMA buffer.

Keyword Arguments:

timeout (int, optional) – Timeout in seconds. Defaults to 60s.

Returns:

A Monarch Future that resolves to None when

the write completes.

Return type:

Future[None]

Raises:

ValueError – If src exceeds the RDMA buffer size.

drop()[source]#

Release the handle on the memory that the src holds to this memory.

property owner: str#

The owner reference (str)

RDMA Actions#

class monarch.rdma.RDMAAction[source]#

Bases: object

Schedule a batch of RDMA operations and submit them as one unit.

All bookkeeping (per-op validation, intra-batch local-memory race detection, backend grouping, parallel dispatch) lives in the Rust _RdmaAction; this class is a thin wrapper around it.

__init__()[source]#
read_remote(dst, src)[source]#

Queue a read from RDMA buffer src into local memory dst.

write_remote(dst, src)[source]#

Queue a write from local memory src into RDMA buffer dst.

fetch_add(src, dst, add)[source]#
compare_and_swap(src, dst, compare, swap)[source]#
submit(*, timeout=60)[source]#

Schedule the queued ops. Safe to call multiple times.

The returned Future does not resolve until every op in the batch completes, or until the timeout is reached. If any op fails, the Future resolves with an exception.

Utility Functions#

monarch.rdma.is_ibverbs_available()[source]#

Whether ibverbs RDMA hardware is available on this system.

monarch.rdma.is_rdma_available()[source]#

Whether RDMA over ibverbs is available on this system.

Deprecated since version Monarch: now supports multiple RDMA backends, so is_rdma_available is ambiguous and will be removed in a future release. Use is_ibverbs_available() or get_rdma_backend() instead.

monarch.rdma.get_rdma_backend()[source]#

Return available RDMA backend.

Returns:

One of ‘ibverbs’, ‘tcp’, or ‘none’ indicating the available backend.

Both Mellanox and EFA hardware are accessed through ibverbs. ‘tcp’ indicates the TCP fallback transport is enabled.

Return type:

str