Skip to content

Commit

Permalink
Add sklearn way of installing omp
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesYang007 committed May 26, 2024
1 parent c15bc2d commit 78093b1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.32.dev4
1.1.32.dev5
34 changes: 20 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,27 @@ def run_cmd(cmd):

system_name = platform.system()
if (system_name == "Darwin"):
# check if OpenMP is installed
no_omp_msg = (
"OpenMP is not detected. "
"MacOS users should install Homebrew and run 'brew install libomp' "
"to install OpenMP. "
)
try:
libomp_info = run_cmd("brew info libomp")
except:
raise RuntimeError(no_omp_msg)
if "Not installed" in libomp_info:
raise RuntimeError(no_omp_msg)
# if user provides OpenMP install prefix (containing lib/ and include/)
if "OPENMP_PREFIX" in os.environ and os.environ["OPENMP_PREFIX"] != "":
omp_prefix = os.environ["OPENMP_PREFIX"]
# otherwise check brew installation
else:
# check if OpenMP is installed
no_omp_msg = (
"OpenMP is not detected. "
"MacOS users should install Homebrew and run 'brew install libomp' "
"to install OpenMP. "
)
try:
libomp_info = run_cmd("brew info libomp")
except:
raise RuntimeError(no_omp_msg)
if "Not installed" in libomp_info:
raise RuntimeError(no_omp_msg)

# grab include and lib directory
omp_prefix = run_cmd("brew --prefix libomp")

# grab include and lib directory
omp_prefix = run_cmd("brew --prefix libomp")
omp_include = os.path.join(omp_prefix, "include")
omp_lib = os.path.join(omp_prefix, "lib")

Expand Down
38 changes: 31 additions & 7 deletions tools/wheels/cibw_before_build.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
# install homebrew + libomp
if [[ "$OSTYPE" == "darwin"* ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install libomp

# See https://github.com/scikit-learn/scikit-learn/blob/09781c540077a7f1f4f2392c9287e08e479c4f29/build_tools/wheels/build_wheels.sh#L18-L50
# See https://cibuildwheel.pypa.io/en/stable/faq/#macos-library-dependencies-do-not-satisfy-target-macos
if [[ "$CIBW_BUILD" == *-macosx_arm64 ]]; then
echo "yay"
export MACOSX_DEPLOYMENT_TARGET=14.0
# install conda
set -ex
# macos arm64 runners do not have conda installed. Thus we much install conda manually
EXPECTED_SHA="dd832d8a65a861b5592b2cf1d55f26031f7c1491b30321754443931e7b1e6832"
MINIFORGE_URL="https://github.com/conda-forge/miniforge/releases/download/23.11.0-0/Mambaforge-23.11.0-0-MacOSX-arm64.sh"
curl -L --retry 10 $MINIFORGE_URL -o miniforge.sh

# Check SHA
file_sha=$(shasum -a 256 miniforge.sh | awk '{print $1}')
if [ "$EXPECTED_SHA" != "$file_sha" ]; then
echo "SHA values did not match!"
exit 1
fi

# Install miniforge
MINIFORGE_PATH=$HOME/miniforge
bash ./miniforge.sh -b -p $MINIFORGE_PATH
echo "$MINIFORGE_PATH/bin" >> $GITHUB_PATH
echo "CONDA_HOME=$MINIFORGE_PATH" >> $GITHUB_ENV

export MACOSX_DEPLOYMENT_TARGET=12.0
OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-arm64/llvm-openmp-11.1.0-hf3c4609_1.tar.bz2"
else
echo "no yay"
export MACOSX_DEPLOYMENT_TARGET=13
# Non-macos arm64 envrionments already have conda installed
echo "CONDA_HOME=/usr/local/miniconda" >> $GITHUB_ENV

export MACOSX_DEPLOYMENT_TARGET=10.9
OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-64/llvm-openmp-11.1.0-hda6cdc1_1.tar.bz2"
fi

sudo conda create -n build $OPENMP_URL
OPENMP_PREFIX="$CONDA_HOME/envs/build"
fi

0 comments on commit 78093b1

Please sign in to comment.