Skip to content

feat(efa): load libfabric at runtime instead of linking it - #4354

Merged
whn09 merged 1 commit into
kvcache-ai:mainfrom
whn09:feat/efa-dlopen-libfabric
Oct 12, 2026
Merged

whn09 merged 1 commit into
kvcache-ai:mainfrom
whn09:feat/efa-dlopen-libfabric

Conversation

@whn09

@whn09 whn09 commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Step 1 of folding AWS EFA support into the default wheels. Wheels built with USE_EFA no longer link libfabric (DT_NEEDED). They load it at runtime when the EFA transport is installed, so they import and serve other protocols on hosts without libfabric.

  • The EFA transport uses only six libfabric entry points that are real exported symbols: fi_getinfo, fi_freeinfo, fi_dupinfo, fi_fabric, fi_strerror, fi_version. The rest of the API it uses (fi_domain, fi_endpoint, fi_mr_regattr, fi_write/fi_read, fi_cq_*, fi_av_*, fi_allocinfo, ...) is static inline and dispatches through provider ops tables.
  • efa_fabric.h renames those six to mc_fi_* before including the libfabric headers. That rebinds every declaration and inline caller without touching the EFA sources. The prefix keeps them from interposing on other libfabric users in the process (NIXL, aws-ofi-nccl).
  • libfabric_loader.cpp implements them via dlopen/dlsym on the first EfaTransport::install(). It tries MC_LIBFABRIC_PATH, then libfabric.so.1, then /opt/amazon/efa/lib/libfabric.so.1, and rejects libfabric older than 1.18, the API the transport requests.
  • CMake: USE_EFA only needs the libfabric headers. The CXI transport still links libfabric.
  • CI: the EFA wheel job checks that no shared object in the wheel links libfabric.so or leaves fi_* undefined.
  • Docs: runtime loading, MC_LIBFABRIC_PATH, and the 1.18 minimum.

There is no data path change, and non-EFA builds are unaffected.

Related: vllm-project/vllm#55635, sgl-project/sglang#40995. Follow-ups: #4355 (runtime transport selection) and #4356 (EFA in the default wheels).

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

An EFA-cuda13 wheel was built from this branch and tested on 2x p5en.48xlarge (16 EFA NICs, H200). It ran inside lmsysorg/sglang:latest with the AWS EFA userspace under /opt/amazon, as in sgl-project/sglang#41518.

Test commands:

# no link-time libfabric dependency
for so in $(find wheel-unpacked -name '*.so*'); do
  readelf -d "$so" | grep 'libfabric.so'
  nm -D --undefined-only "$so" | grep -E ' fi_(getinfo|freeinfo|dupinfo|fabric|strerror|version)$'
done
# init checks, one per case
python3 -c 'from mooncake.engine import TransferEngine as T; print(T().initialize("127.0.0.1", "P2PHANDSHAKE", "efa", ""))'
# 2-node GPU transfer over EFA: write 64 MiB, read back and compare, then 1-256 MiB bandwidth
python3 mc_gpu_test.py {target|initiator} <ip> efa cuda

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (describe below)
Case Result
readelf/nm on all .so in the wheel no libfabric.so NEEDED, no undefined fi_*
No libfabric at all import mooncake.engine OK, protocol=tcp OK; efa fails, listing the paths tried plus a hint
Only distro libfabric 1.17 (Ubuntu 24.04) efa fails: "is libfabric 1.17, but the EFA transport needs 1.18 or newer"
AWS libfabric without its libefa on the path efa fails with the dlopen error (EFA_1.7 not found)
MC_LIBFABRIC_PATH set to a missing file only that path is tried; clear error
AWS EFA stack on LD_LIBRARY_PATH "loaded libfabric 2.6"; 16 NICs initialized; 2-node GPU transfer readback OK, ~24 GB/s (unchanged)

PR CI passes, including the new checks in all five EFA wheel jobs (x86_64 and arm64). efa_transport_test needs EFA hardware and is not part of CI.

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh. I used the same tools it runs: clang-format 20 with the repo .clang-format, and cmake-format 0.6.13 for the CMake files.
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective (CI wheel checks added; the EFA runtime paths need EFA hardware)
  • For changes >500 LOC: I have filed an RFC issue

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

Claude Code (Claude Opus 5.5) helped draft the code, run the validation on the p5en instances, and write this description. I reviewed the changes and the test results.

Wheels built with USE_EFA linked libfabric (DT_NEEDED), so they failed to
import on hosts without libfabric. That is the main blocker for shipping
EFA support in the default wheels.

Only six libfabric entry points used by the EFA transport are real
exported symbols (fi_getinfo, fi_freeinfo, fi_dupinfo, fi_fabric,
fi_strerror, fi_version); the rest of the API is static inline and goes
through provider ops tables. efa_fabric.h renames those six to mc_fi_*
before including the libfabric headers, and libfabric_loader.cpp
implements them by dlopen-ing libfabric.so.1 when the EFA transport is
installed. The prefix keeps them from interposing on other libfabric
users in the process (NIXL, aws-ofi-nccl).

The loader tries MC_LIBFABRIC_PATH, then libfabric.so.1, then
/opt/amazon/efa/lib/libfabric.so.1, and rejects libfabric older than 1.18
with an explicit error. Only the libfabric headers are needed at build
time now; the EFA wheel CI checks that no shared object in the wheel
links libfabric or leaves fi_* symbols undefined.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Comment on lines +83 to +90
if (!handle) {
g_load_error =
"cannot load libfabric. Install the AWS EFA userspace and put its "
"lib directory (e.g. /opt/amazon/efa/lib) on LD_LIBRARY_PATH, or "
"set MC_LIBFABRIC_PATH. Tried:" +
tried;
return;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, should the application shut down gracefully?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already does. If libfabric can't be loaded (not found, missing symbols, or older than 1.18), nothing aborts:

  1. EfaTransport::install() logs the reason (paths tried plus how to fix it: LD_LIBRARY_PATH or MC_LIBFABRIC_PATH) and returns ERR_CONTEXT.
  2. MultiTransport::installTransport() deletes the transport and returns nullptr.
  3. Transfer Engine init returns -1, so the caller (e.g. Store setup()) gets an error and decides whether to exit.

None of the mc_fi_* forwarders are reachable before a successful load. The two that error paths can hit early (mc_fi_strerror, mc_fi_version) check for a null pointer. So there's no null call and no crash, just a clear error at init. Processes that never use efa never call loadLibfabric(), so they start fine without libfabric installed.

@whn09

whn09 commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

@alogfans @ShangmingCai @stmatengss could you take a look when you have time? The question above is answered, and the branch has no conflicts with current main.

@alogfans alogfans left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@whn09

whn09 commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

@Aionw could you review the CI part when you have time? alogfans has approved the rest. The only .github change is a new step in .github/workflows/_build-efa-wheel.yaml. It checks that no .so in the EFA wheel has libfabric in NEEDED or leaves fi_* symbols undefined, so the runtime loading can't silently regress. The branch merges cleanly with current main.

@Aionw Aionw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@whn09
whn09 merged commit 6e8895c into kvcache-ai:main Oct 12, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/Build Common documentation Improvements or additions to documentation run-ci Transfer Engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants