Repository navigation
feat(efa): load libfabric at runtime instead of linking it - #4354
Conversation
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>
9388a43 to
4f85d6a
Compare
| 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; | ||
| } |
There was a problem hiding this comment.
In this case, should the application shut down gracefully?
There was a problem hiding this comment.
It already does. If libfabric can't be loaded (not found, missing symbols, or older than 1.18), nothing aborts:
EfaTransport::install()logs the reason (paths tried plus how to fix it:LD_LIBRARY_PATHorMC_LIBFABRIC_PATH) and returnsERR_CONTEXT.MultiTransport::installTransport()deletes the transport and returnsnullptr.- Transfer Engine init returns
-1, so the caller (e.g. Storesetup()) 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.
|
@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. |
|
@Aionw could you review the CI part when you have time? alogfans has approved the rest. The only |
Description
Step 1 of folding AWS EFA support into the default wheels. Wheels built with
USE_EFAno 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.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, ...) isstatic inlineand dispatches through provider ops tables.efa_fabric.hrenames those six tomc_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.cppimplements them viadlopen/dlsymon the firstEfaTransport::install(). It triesMC_LIBFABRIC_PATH, thenlibfabric.so.1, then/opt/amazon/efa/lib/libfabric.so.1, and rejects libfabric older than 1.18, the API the transport requests.USE_EFAonly needs the libfabric headers. The CXI transport still links libfabric.libfabric.soor leavesfi_*undefined.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
mooncake-transfer-engine)mooncake-store)mooncake-conductor)mooncake-reshard)mooncake-ep)mooncake-pg)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-common)mooncake-rl)Type of Change
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:latestwith the AWS EFA userspace under/opt/amazon, as in sgl-project/sglang#41518.Test commands:
Test results:
readelf/nmon all.soin the wheellibfabric.soNEEDED, no undefinedfi_*import mooncake.engineOK,protocol=tcpOK;efafails, listing the paths tried plus a hintefafails: "is libfabric 1.17, but the EFA transport needs 1.18 or newer"libefaon the pathefafails with thedlopenerror (EFA_1.7 not found)MC_LIBFABRIC_PATHset to a missing fileLD_LIBRARY_PATHPR CI passes, including the new checks in all five EFA wheel jobs (x86_64 and arm64).
efa_transport_testneeds EFA hardware and is not part of CI.Checklist
./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.AI Assistance Disclosure
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.