ofi-rma moves data out of band into memory that a peer lends, over libfabric. The library is written in C11, and it depends only on libfabric and POSIX threads.
A window owner registers memory and hands out a token that names it. Any writer that holds the token and speaks the same wire protocol writes into that memory. The writer needs no connection to the owner, and the owner never adds the writer to its address vector.
Ceph uses ofi-rma for the out-of-band legs that its OSDs and gateway run. A client of Ceph's S3-over-RDMA data path, such as a NIXL object engine, uses it to lend the memory that the OSDs write into.
ofi_rma/ofi_rma.his the C interface. Its functions start withofi_rma_, and they return a negative errno on failure.ofi_rma/ofi_rma.hppis a header-only C++17 wrapper in the namespaceofi_rma. A C++ program links with the C library only.
This README uses the C++ names. Each one has a C counterpart. For example, config_t::hmem is ofi_rma_config.hmem, and Endpoint::hmem() is ofi_rma_ep_hmem().
<base>:<size>:ofi1:<wire>:<address>:<key>[:<auth>]
baseis the remote address of window byte 0, as the owner's provider reads it. That is a virtual address underFI_MR_VIRT_ADDRand a region offset otherwise. A writer writes window byteiatbase + i.sizeis the length of the window.wireis the wire protocol and its version, from the provider'sfi_ep_attr: for examplerxm.1forverbs;ofi_rxm, orxnet.1fortcp. A writer takes only tokens of its own wire.addressis the owner'sfi_getname()bytes, at most 192 bytes.keyis the region'sfi_mr_key(). A provider with keys longer than 8 bytes, or withFI_MR_RAW, is refused.authis optional: the authorization key that the region is bound to, such as a UET JobID. This version parses it but does not use it yet. A write or read with such a token fails with-EPROTONOSUPPORT.
Every field except the tag and the wire is lowercase hex. The token starts with the same addr:size fields as a cuObject descriptor. A server that only forwards tokens can read the window size without parsing the rest. token_family() tells an ofi<N> token from a cuObject descriptor.
The wire names the protocol, not the provider. Two vendors' UET providers thus take each other's tokens. See doc/wire-tokens.md for the reasons, and for the way a server picks one of its endpoints for a token.
| Provider | Wire | Notes |
|---|---|---|
tcp |
xnet.1 |
Needs no special hardware. It cannot cut off a late write, so use it for tests only. |
shm |
shm.1 |
Works between processes on one host. |
verbs;ofi_rxm |
rxm.1 |
RDMA reliable connections on any verbs device. On soft-RoCE, set FI_UNIVERSE_SIZE=16 in every process. See the notes below. |
uet |
uet.1 |
Ultra Ethernet, through a libfabric wrapper for the UEC reference provider. |
A provider with manual progress places incoming data only while the owner polls its endpoint. Set config_t::progress_thread for an endpoint that lends windows, or poll it with progress().
Notes for verbs;ofi_rxm:
- The verbs provider caches memory registrations by default. With the cache, a region that is closed stays registered, so its key keeps working, and registering the memory again returns the same key.
rekey_window()then fails with-EOPNOTSUPPrather than report a new key. If you re-key windows, or if a deregistered window must revoke its key, setFI_MR_CACHE_MONITOR=disabledin the environment before the first libfabric call. - A write that carries a revoked key is a remote access error, which breaks the reliable connection to that peer. Writes to the peer then fail with
-ECANCELEDuntil the provider reconnects, a few hundred milliseconds on soft-RoCE. - If libfabric 2.3.1 closes a
verbs;ofi_rxmendpoint that still has credit completions queued, it can crash. Upstream commit 697688386 ("prov/rxm: fix the msg_ep use-after-free at connection teardown") fixes it. Until a release has the fix, ofi-rma polls the completion queue of averbs;...endpoint for up to 50 ms, and then closes the endpoint. The provider thus handles those completions first.
A window owner can lend a window in GPU memory. Set config_t::hmem, then register the window with a memory_t that names the memory kind: cuda, rocr or ze.
- The provider must offer
FI_HMEM, andEndpoint::hmem()says whether it does. Without it, the registration fails with-EOPNOTSUPP. - libfabric itself must have the runtime for that memory kind. A provider can offer
FI_HMEMwhile libfabric lacks the runtime, and the registration then fails with-ENOSYS. For example, the Fedora libfabric 2.3.1 package has no ROCr support. Run withFI_LOG_LEVEL=infoto see the memory interfaces that libfabric initialized. - A writer does not ask for device memory. It writes into a GPU window as into a host window.
- For a NIC to write straight into GPU memory, the provider and the NIC driver must support it, usually through dma-buf. The platform must also give the NIC a PCIe path to the GPU. A software provider such as
shmcopies into the GPU instead. - If
rekey_window()or a cut-off registers a window again, the window keeps its memory kind. WindowPoollends host memory only.
A NIC can write into GPU memory only through a dma-buf: the GPU driver exports the memory, and the RDMA driver registers the export. Set memory_t::dmabuf_fd and memory_t::dmabuf_offset to a dma-buf that you exported, for example with ROCr's hsa_amd_portable_export_dmabuf(), and ofi-rma registers it with FI_MR_DMABUF. Keep the fd open while the window is registered. Do it this way rather than leave the export to libfabric, for two reasons:
- libfabric exports ROCr memory only with
FI_HMEM_ROCR_USE_DMABUF=1and only on a kernel built withCONFIG_DMABUF_MOVE_NOTIFY=y. The Fedora 6.19 kernel lacks that option, althoughirdmaregisters the export without it. - libfabric 2.3.1 offers
FI_HMEMon verbs only for devices namedmlx*orbnxt_re*. Upstream commits e755fe9cd and 2a8e74e39, in 2.7.0, add RoCE devices and a per-device dma-buf probe.
If OFI_RMA_TEST_VERBS_NODE names a device that takes dma-bufs, the verbs;ofi_rxm test writes into a dma-buf window in AMD GPU memory. Over an Intel E810 with irdma, the NIC places the data in the GPU memory with no copy.
A peer can also pull bytes out of a window, as a Ceph OSD pulls the payload of a PUT out of a client's memory.
- Set
config_t::readson both endpoints.Endpoint::reads()says whether the provider offers RMA reads. A provider without them still opens the endpoint, for writes only. - Register a window that peers can read with
register_window(ptr, len, mem, access, &w).accessis a mask ofEndpoint::remote_writeandEndpoint::remote_read. The provider fails a read of a window that was registered for writes only. read()reads into a staging buffer. It copies into the caller's buffers only after every read completed, so a failed read leaves them unchanged. The ranges must cover the caller's buffers exactly once.- Reads share the staging buffers, the budget and the cut-offs with writes.
- A token for a readable window lets any holder read that memory. When the operation that you lent the window for is complete, re-key the window with
rekey_window().
The verbs;ofi_rxm GPU test also reads out of a dma-buf window in AMD GPU memory. The GPU verbs tests need a NIC that registers dma-bufs, such as the E810. On soft-RoCE, the dma-buf registration crashes the test process.
The GPU tests in test/test_ofi_rma_hip.cc run over shm on an AMD GPU. If there is no GPU, or if libfabric has no ROCr support, they skip. To build libfabric with ROCr support, configure it with --with-rocr=/usr, or with the path of your ROCm installation.
You need a C11 compiler and libfabric 1.18 or later, with its headers. The tests also need a C++17 compiler and GoogleTest.
To build and test with CMake:
cmake -S . -B build -G Ninja
ninja -C build
ctest --test-dir build
To build and test with meson (the tests and hip options are features, auto by default):
meson setup build-meson
meson test -C build-meson
The CMake build has these options:
| Option | Default for a top-level build | Default under add_subdirectory |
|---|---|---|
OFI_RMA_SHARED |
ON |
OFF: a static library with position-independent code |
OFI_RMA_BUILD_TESTS |
ON |
OFF |
OFI_RMA_INSTALL |
ON |
OFF |
OFI_RMA_HIP |
AUTO: if CMake finds the HIP runtime, build the GPU tests |
AUTO, with tests off |
unittest_ofi_rma_c builds the C interface as strict C11 and checks tokens, a write, a read and a window pool over tcp. The C++ tests run over tcp and shm. They skip a provider that is not available. A full run takes about 40 seconds. To also run them over verbs;ofi_rxm, set OFI_RMA_TEST_VERBS_NODE to the IP address of an RDMA device, such as a soft-RoCE device. The tests then set FI_UNIVERSE_SIZE=16 and FI_MR_CACHE_MONITOR=disabled unless they are already set.
An installed ofi-rma ships a pkg-config file and a CMake package.
- pkg-config:
pkg-config --cflags --libs ofi-rma. - CMake:
find_package(ofi_rma), then linkofi_rma::ofi_rma. - CMake, from source:
add_subdirectory(ofi-rma), then linkofi_rma. - meson:
dependency('ofi-rma'). With a wrap file, the dependency also resolves from a subproject.
From C, include <ofi_rma/ofi_rma.h>. From C++, include <ofi_rma/ofi_rma.hpp> and compile as C++17 or later.
ofi-rma is licensed under the MIT license. See LICENSE.

