You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c7a73e6
Browse filesBrowse the repository at this point in the historyBrowse files
Load AOTI plugins into hosts that don't share their C++ runtime
Summary:
An AOTInductor plugin is compiled separately from the program that loads it, so the two don't have to share a C++ standard library. Two places in the CUDA backend assume they do.
- **Constants pass through a `std::unordered_map`.** Cross-method weight sharing, mutable-state sessions and the CUDA graph host-constant check read a method's constants with `AOTInductorModelContainerExtractConstantsMap`, which hands the plugin a pointer to the host's map to fill in. That's only safe when both sides use the same standard library. It isn't safe for a Windows plugin cross-compiled with MinGW and loaded by an MSVC host, or a plugin loaded by a libc++ host. PyTorch's AOTI interface marks that call deprecated in favour of `AOTInductorModelContainerExtractConstantsMapEntries`, which returns a container-owned array of `{name, handle}` C structs. The backend now reads constants only through that call, so no C++ container crosses the plugin boundary.
- **The plugin's C++ runtime has to already be in the process.** On Linux an x86 plugin references libstdc++ (`std::cerr`, exception handling, `operator new`) without listing `libstdc++.so.6` as a dependency. Loaded from a process that doesn't link libstdc++, `dlopen` fails with `undefined symbol: _ZSt4cerr`. When the host does link libstdc++, the plugin loads only if the host's dynamic symbol table happens to include every libstdc++ symbol the plugin uses. `load_library` now opens `libstdc++.so.6` with `RTLD_GLOBAL` once before the first plugin, and returns `AccessFailed` if it can't, since such a plugin can't load anyway. The preload adds libstdc++ to the global lookup scope after the host, so symbols the host already defines still win.
Plugins that don't export the entries call still run, with reduced features:
- each method loads its own weights from the blob, without cross-method sharing;
- mutable-state sessions report `NotSupported`;
- CUDA graphs stay off, since their constants can't be checked for host memory.
Malformed results are never dereferenced: a null array with a nonzero count, a null name or handle, or an extraction error is rejected with `InvalidProgram`, or keeps graphs off.
`test_cuda_mutable_state` gains cases for the graph check (no entries call, no constants, a host constant, a device constant, malformed results) and for mutable-state extraction failures. It also builds outside fbcode as `test_cuda_mutable_state_native`.
Differential Revision: D129654474
0 commit comments