Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions cmake/FindOpenMPMacOS.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
# Find OpenMP library on MacOS
# Automatically handle locating libomp from the Homebrew package manager
# Prefer libomp from the active Conda environment and fall back to Homebrew.

# lint_cmake: -package/consistency

macro(find_openmp_macos)
if(NOT APPLE)
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}() must only be used on MacOS")
endif()
find_package(OpenMP)

if(DEFINED ENV{CONDA_PREFIX} AND EXISTS "$ENV{CONDA_PREFIX}/lib/libomp.dylib")
set(CONDA_LIBOMP_PREFIX "$ENV{CONDA_PREFIX}")
set(OpenMP_C_FLAGS
"-Xpreprocessor -fopenmp -I${CONDA_LIBOMP_PREFIX}/include")
set(OpenMP_CXX_FLAGS
"-Xpreprocessor -fopenmp -I${CONDA_LIBOMP_PREFIX}/include")
set(OpenMP_C_LIB_NAMES omp)
set(OpenMP_CXX_LIB_NAMES omp)
set(OpenMP_omp_LIBRARY ${CONDA_LIBOMP_PREFIX}/lib/libomp.dylib)
find_package(OpenMP)
endif()

if(NOT OpenMP_FOUND)
find_package(OpenMP)
endif()
if(NOT OpenMP_FOUND)
# Try again with extra path info. This step is required for libomp 15+ from Homebrew,
# as libomp 15.0+ from brew is keg-only
Expand Down Expand Up @@ -106,6 +121,7 @@ function(patch_openmp_path_macos target target_default_output_name)
)
# Add RPATH entries to ensure the loader looks in the following, in the following order:
#
# - $CONDA_PREFIX/lib (when building inside a Conda environment)
# - /opt/homebrew/opt/libomp/lib (where 'brew install' / 'brew link' puts libomp.dylib)
# - ${__OpenMP_LIBRARY_DIR} (wherever find_package(OpenMP) found OpenMP at build time)
#
Expand All @@ -114,11 +130,15 @@ function(patch_openmp_path_macos target target_default_output_name)
execute_process(COMMAND brew --prefix libomp
OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(__OPENMP_RPATHS "${HOMEBREW_LIBOMP_PREFIX}/lib;${__OpenMP_LIBRARY_DIR}")
if(DEFINED ENV{CONDA_PREFIX} AND EXISTS "$ENV{CONDA_PREFIX}/lib/libomp.dylib")
set(__OPENMP_RPATHS "$ENV{CONDA_PREFIX}/lib;${__OPENMP_RPATHS}")
endif()
set_target_properties(
${target}
PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "${HOMEBREW_LIBOMP_PREFIX}/lib;${__OpenMP_LIBRARY_DIR}"
INSTALL_RPATH "${__OPENMP_RPATHS}"
INSTALL_RPATH_USE_LINK_PATH FALSE
)
endfunction()
6 changes: 6 additions & 0 deletions ops/pipeline/build-python-wheels-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ else
exit 2
fi

# Prefer Conda's OpenMP runtime for wheel builds on macOS. Homebrew's libomp can
# pull in Homebrew LLVM's libunwind, which raises the effective deployment target
# of the repaired wheel.
conda install -y llvm-openmp
export CMAKE_PREFIX_PATH="${CONDA_PREFIX}${CMAKE_PREFIX_PATH:+:${CMAKE_PREFIX_PATH}}"

# Tell delocate-wheel to not vendor libomp.dylib into the wheel
export CIBW_REPAIR_WHEEL_COMMAND_MACOS="delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} --exclude libomp.dylib"

Expand Down
8 changes: 1 addition & 7 deletions python-package/xgboost/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import pandas as pd
import pyarrow as pa

assert sys.version_info[0] == 3, "Python 2 is no longer supported."


def py_str(x: bytes | None) -> str:
"""convert c string back to python string"""
Expand All @@ -42,11 +40,7 @@ def lazy_isinstance(instance: Any, module: str, name: str) -> bool:
from sklearn.base import BaseEstimator as XGBModelBase
from sklearn.base import ClassifierMixin as XGBClassifierBase
from sklearn.base import RegressorMixin as XGBRegressorBase

try:
from sklearn.model_selection import StratifiedKFold as XGBStratifiedKFold
except ImportError:
from sklearn.cross_validation import StratifiedKFold as XGBStratifiedKFold
from sklearn.model_selection import StratifiedKFold as XGBStratifiedKFold

# sklearn.utils Tags types can be imported unconditionally once
# xgboost's minimum scikit-learn version is 1.6 or higher
Expand Down
Loading