Repository navigation
Conversation
delocate copies libomp into suitesparse_graphblas/.dylibs/, gives the copy the install name /DLC/suitesparse_graphblas/.dylibs/libomp.dylib, and links libgraphblas to it by path. A process that already has an LLVM OpenMP runtime, such as conda-forge's NumPy (whose OpenBLAS uses llvm-openmp) or numba's omp threading layer, then loads a second one, and libomp aborts with "OMP: Error GraphBLAS#15" when GraphBLAS starts it. With KMP_DUPLICATE_LIB_OK=TRUE the two runtimes deadlock instead. Loading the bundled copy privately can't avoid this. libomp registers itself per process, whatever its file name, install name or dlopen mode, and dyld binds the weak symbols of both copies to whichever was loaded first, so a second copy can crash the process even if it is never started. conda-forge's libomp has the install name @rpath/libomp.dylib, which is also what numba and conda-forge's OpenBLAS link, and dyld resolves @rpath/libomp.dylib to an already-loaded image with that install name before it searches any LC_RPATH. So the new script continuous_integration/share_libomp.py, run after delocate in the macOS repair command, gives the bundled copy that install name and links libgraphblas to @rpath/libomp.dylib, with an LC_RPATH of @loader_path. GraphBLAS then uses a libomp that is already loaded, or loads its own, which libraries loaded later share: one runtime, whatever the order. The file stays at suitesparse_graphblas/.dylibs/libomp.dylib, where python-graphblas looks for it. The script fails if the wheel is not laid out as it expects, and changes nothing on a second run. A libomp loaded before GraphBLAS must be LLVM 19 or newer, which has __kmpc_dispatch_deinit; with an older one, importing suitesparse_graphblas now fails with "Symbol not found: ___kmpc_dispatch_deinit" instead of aborting or crashing later. Wheels that load their own libomp by path still start a second runtime, as before. test_bundled_libomp_is_shared loads a copy of the bundled libomp before GraphBLAS, runs a parallel GraphBLAS operation, and checks that the copy is the only libomp in the process. It fails with the 10.5.2.0 wheel (two libomp images) and passes once that wheel is repaired. The README says what to expect.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #171 +/- ##
==========================================
- Coverage 98.91% 98.66% -0.25%
==========================================
Files 42 42
Lines 4706 4735 +29
Branches 395 396 +1
==========================================
+ Hits 4655 4672 +17
- Misses 27 39 +12
Partials 24 24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The macOS wheels now use an LLVM OpenMP runtime that another package
already loaded as @rpath/libomp.dylib. If that runtime is older than
LLVM 19, it lacks __kmpc_dispatch_deinit, which libgraphblas calls, and
dyld refuses to load libgraphblas ("Symbol not found:
___kmpc_dispatch_deinit"). The same setups used to abort or crash.
When the import fails with dyld's "Symbol not found" for an OpenMP
function, raise an ImportError, chained to dyld's, that says what
happened and what to do: update that libomp (in conda,
llvm-openmp>=19), or in a conda environment use conda-forge's
python-suitesparse-graphblas. Importing suitesparse_graphblas first
helps only if the package that loaded the old libomp is not NumPy:
suitesparse_graphblas imports NumPy (through utils) before _graphblas,
and conda-forge's NumPy loads conda's libomp.
dyld's error comes out of `from . import utils`, which imports
_graphblas, so the try covers both imports. Their order stays, so
NumPy's libomp, if it has one, is still loaded first.
test_old_libomp_error checks the message against what dyld printed with
conda-forge's llvm-openmp 18.1.8 loaded first. A test with a real old
libomp would have to download one.
- Run /usr/bin/otool, install_name_tool, codesign and nm, not whichever comes first on PATH: a conda environment can put cctools-port's first. - Require each file that links libomp to have exactly one LC_RPATH, the one that reaches the bundled copy. When no libomp is loaded yet, dyld tries a file's LC_RPATHs in order, so another one could load some other libomp. delocate removes absolute ones today; this keeps it so. - Fail if libgraphblas imports an OpenMP function other than the 23 that 10.5.2 and 10.5.3 import. A libomp that is already loaded must export all of them, and the newest, __kmpc_dispatch_deinit, is what makes the minimum LLVM 19. A new one may raise that minimum, so it needs a look, and then the README and the ImportError message may need an update. - Write the repaired wheel to a temporary file and replace the original only once it is complete, so that a failure while zipping can't leave a truncated wheel behind.
test_bundled_libomp_is_shared covered a libomp loaded before GraphBLAS. Run it also with nothing loaded first: after GraphBLAS has loaded its own copy and run in parallel, a dlopen of @rpath/libomp.dylib, as a library that links it would do, must get GraphBLAS's copy (dladdr on omp_get_max_threads says which file), and the process must still have one libomp. dyld finds it as "already-loaded-by-rpath", the same lookup it does for a library's @rpath dependency. With 10.5.2.0's layout the dlopen finds no libomp, or the interpreter's own (conda), and the test fails. Use ctypes.CDLL(None) to reach dyld's functions instead of naming libSystem's path.
Libraries loaded after GraphBLAS that link @rpath/libomp.dylib now get the libomp the wheel bundles. One that needs a function this libomp lacks fails to load, so take the newest llvm-openmp at each release.
Say what to do when an older libomp loaded first makes the import fail: update it, or import suitesparse_graphblas first, which cannot help when it came with NumPy because suitesparse_graphblas imports NumPy first. Say which cases still give two runtimes: Homebrew's libomp (the xgboost and lightgbm wheels) shares only if suitesparse_graphblas loads first, and the copies in the scikit-learn wheel and recent PyTorch wheels, linked by path, never do.
With nothing preloaded, test_bundled_libomp_is_shared[graphblas] required the bundled libomp to be the process's only one. But with conda-forge's NumPy, OpenBLAS loads conda's libomp before GraphBLAS does, GraphBLAS then shares it, and the test failed although that is the intended behavior. Check instead that there is one libomp and that a later request for @rpath/libomp.dylib gets it. The original 10.5.2.0 wheel still fails both cases; a repaired one passes both, with PyPI's NumPy and with conda-forge's.
eriknw
marked this pull request as ready for review
December 2, 2026 06:39
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The macOS wheels bundle LLVM's OpenMP runtime the way delocate does by default: a copy in
suitesparse_graphblas/.dylibs/libomp.dylibwith an install name of its own (/DLC/suitesparse_graphblas/.dylibs/libomp.dylib), linked from libgraphblas by path. Any process that already has an LLVM OpenMP runtime then starts a second one, and libomp aborts:Two common ways to get there (both reproduced on macOS arm64 with the 10.5.2.0 wheel):
import numpystarts that runtime, andinitialize()(GrB_init) starts ours. It aborts in either order.compactify,scanand others are parallel numba functions).Why not load the copy privately
That can't avoid it. libomp registers itself per process when it starts (on macOS, in
/tmp/__KMP_REGISTERED_LIB_<pid>), whatever its file name, install name or dlopen mode. Renamed copies and copies loaded withRTLD_LOCALabort the same way.KMP_DUPLICATE_LIB_OK=TRUEturns the abort into a deadlock, because dyld binds the weak symbols that libomp exports to whichever copy loaded first, so the two runtimes call into each other. For the same reason a second copy that is loaded but never started can crash the process.What this does
conda-forge's libomp has the install name
@rpath/libomp.dylib, which is also what numba's omp layer and conda-forge's OpenBLAS link. dyld resolves a request for@rpath/libomp.dylibto an already-loaded image with that install name before it searches any LC_RPATH (dyld 4, macOS 12 and later; dyld 3 has an equivalent rule). A new script,continuous_integration/share_libomp.py, runs after delocate in the macOS repair command and:@rpath/libomp.dylib;@rpath/libomp.dylib, with an LC_RPATH of@loader_paththat reaches the copy;GraphBLAS then uses a libomp that is already loaded, or else loads its own copy, which libraries loaded later share. So there is one runtime whatever the order. PyTorch's macOS wheels did the same from 2.5 (pytorch/pytorch#129473). The file stays at
suitesparse_graphblas/.dylibs/libomp.dylib, where python-graphblas looks for it.Caveats
__kmpc_dispatch_deinit. With an older one, dyld can't load libgraphblas, andimport suitesparse_graphblasnow raises an ImportError (chained to dyld's) that names the loaded libomp and says what to do: update it (in conda,llvm-openmp>=19) or use conda-forge's package. With the old layout, the same setup aborted or segfaulted.@rpath/libomp.dylibloaded first (old conda envs). Its runtime registered differently, so the two copies never noticed each other.Testing
test_bundled_libomp_is_shared(macOS wheels only; skipped where there is no bundled libomp) runs both directions in a subprocess:other: a copy of the bundled libomp is loaded first; GraphBLAS must use it.graphblas: GraphBLAS loads first; a laterdlopen("@rpath/libomp.dylib"), the lookup numba's omppool makes, must get the same image.Both cases also run a parallel GraphBLAS operation and require exactly one libomp in the process. Both fail on the 10.5.2.0 wheels (arm64 cp313 and cp314t, x86_64 cp311) and pass once those wheels are repaired, with PyPI's NumPy and with conda-forge's (whose OpenBLAS then provides the shared libomp).
test_old_libomp_errorchecks the ImportError rewrite against dyld's message for conda-forge's llvm-openmp 18.1.8. With 18.1.8 or 11.1.0 really loaded first, the import raises it; with 19.1.7 it imports fine.compactify.