Skip to content

Commit e5b85aa

Browse files
committed
Use llvm-openmp package for conda builds to avoid conflicts
- Other packages (e.g., numba 0.62+, openblas) may require llvm-openmp and bundling our own creates conflicst.
1 parent 884417c commit e5b85aa

3 files changed

Lines changed: 52 additions & 13 deletions

File tree

buildscripts/conda-recipes/pyomp/meta.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ build:
1919
- export CXX=${PREFIX}/bin/clang++
2020
- export VERBOSE=1
2121
- export CPPFLAGS="-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET} -isystem ${PREFIX}/include -D_FORTIFY_SOURCE=2" # [osx]
22+
- export DISABLE_BUNDLED_LIBOMP=1
2223
- rm -rf build dist src/*.egg-info
2324
- {{ PYTHON }} -m pip install -v .
2425

@@ -48,19 +49,23 @@ requirements:
4849
- clang-tools {{ LLVM_VERSION }}
4950
- llvmdev {{ LLVM_VERSION }}
5051
- zlib
52+
# require llvm-openmp for the openmp cpu runtime.
53+
- llvm-openmp
5154
- elfutils # [linux]
5255
- libffi # [linux]
5356
run:
5457
- python
5558
- setuptools
5659
- numba >=0.62, <0.64
60+
# require llvm-openmp for the openmp cpu runtime.
61+
- llvm-openmp
5762
- lark
5863
- cffi
5964

6065
test:
6166
commands:
62-
- test -f $SP_DIR/numba/openmp/libs/libomp/lib/libomp.dylib # [osx]
63-
- test -f $SP_DIR/numba/openmp/libs/libomp/lib/libomp.so # [linux]
67+
- test -f $SP_DIR/numba/openmp/libs/pass/libIntrinsicsOpenMP.dylib # [osx]
68+
- test -f $SP_DIR/numba/openmp/libs/pass/libIntrinsicsOpenMP.so # [linux]
6469
- test -f $SP_DIR/numba/openmp/libs/libomp/lib/libomptarget-amdgpu.bc # [linux]
6570
- test -f $SP_DIR/numba/openmp/libs/libomp/lib/libomptarget-nvptx.bc # [linux]
6671
- test -f $SP_DIR/numba/openmp/libs/libomp/lib/libomptarget.so # [linux]

setup.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,20 @@ def _prepare_source_openmp(sha256=None):
205205
return f"{sourcedir}/runtimes"
206206

207207

208-
setup(
209-
ext_modules=[
210-
CMakeExtension("pass", sourcedir="src/numba/openmp/libs/pass"),
208+
# Optionally disable bundled libomp build via DISABLE_BUNDLED_LIBOMP=1. Used on
209+
# conda builds to avoid duplicate OpenMP runtime conflicts (e.g., numba 0.62+
210+
# and libopenblas already require llvm-openmp).
211+
def _should_bundle_libomp():
212+
"""Check if we should build and bundle the libomp runtime."""
213+
disable = os.environ.get("DISABLE_BUNDLED_LIBOMP", "0")
214+
return disable.lower() not in ("1", "true", "yes")
215+
216+
217+
# Build extensions: always include 'pass', conditionally include 'openmp'
218+
ext_modules = [CMakeExtension("pass", sourcedir="src/numba/openmp/libs/pass")]
219+
220+
if _should_bundle_libomp():
221+
ext_modules.append(
211222
CMakeExtension(
212223
"libomp",
213224
sourcedir=_prepare_source_openmp(),
@@ -219,8 +230,11 @@ def _prepare_source_openmp(sha256=None):
219230
# under /usr/include and its gcc-toolset provided header files.
220231
"-DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON",
221232
],
222-
),
223-
],
233+
)
234+
)
235+
236+
setup(
237+
ext_modules=ext_modules,
224238
cmdclass={
225239
"clean": CleanCommand,
226240
"build_ext": BuildCMakeExt,

src/numba/openmp/__init__.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,45 @@
6060

6161
def _init():
6262
sys_platform = sys.platform
63+
from ctypes.util import find_library
6364

6465
omplib = (
6566
libpath
6667
/ "libomp"
6768
/ "lib"
6869
/ f"libomp{'.dylib' if sys_platform == 'darwin' else '.so'}"
6970
)
70-
if DEBUG_OPENMP >= 1:
71-
print("Found OpenMP runtime library at", omplib)
72-
ll.load_library_permanently(str(omplib))
71+
72+
# Prefer bundled libomp if it exists.
73+
if omplib.exists():
74+
if DEBUG_OPENMP >= 1:
75+
print("Found bundled OpenMP runtime library at", omplib)
76+
ll.load_library_permanently(str(omplib))
77+
else:
78+
# There is no bundled libomp, try to find it in standard library paths.
79+
system_omplib = find_library("omp")
80+
if system_omplib:
81+
if DEBUG_OPENMP >= 1:
82+
print(f"Found system OpenMP runtime library: {system_omplib}")
83+
ll.load_library_permanently(system_omplib)
84+
else:
85+
raise RuntimeError(
86+
f"OpenMP runtime not found. Bundled library missing at {omplib} "
87+
"and no system libomp found via ctypes.util.find_library('omp'). "
88+
"Ensure libomp is available in library paths."
89+
)
7390

7491
# libomptarget is unavailable on apple, windows, so return.
7592
if sys_platform.startswith("darwin") or sys_platform.startswith("win32"):
7693
return
7794

7895
omptargetlib = libpath / "libomp" / "lib" / "libomptarget.so"
79-
if DEBUG_OPENMP >= 1:
80-
print("Found OpenMP target runtime library at", omptargetlib)
81-
ll.load_library_permanently(str(omptargetlib))
96+
if omptargetlib.exists():
97+
if DEBUG_OPENMP >= 1:
98+
print("Found OpenMP target runtime library at", omptargetlib)
99+
ll.load_library_permanently(str(omptargetlib))
100+
elif DEBUG_OPENMP >= 1:
101+
print(f"OpenMP target runtime not found at {omptargetlib}")
82102

83103

84104
_init()

0 commit comments

Comments
 (0)