diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2a44674ef8610..020d007acc651 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -71,6 +71,40 @@ jobs: # Here we make sure, that they are still run on a regular basis. SKLEARN_SKIP_NETWORK_TESTS: '0' +- template: build_tools/azure/posix.yml + # Experimental CPython branch without the Global Interpreter Lock: + # https://github.com/colesbury/nogil/ + # + # The nogil build relies on a dedicated PyPI-style index to install patched + # versions of NumPy, SciPy and Cython maintained by @colesbury and that + # include specifc fixes to make them run correctly without relying on the GIL. + # + # The goal of this CI entry is to make sure that we do not introduce any + # dependency on the GIL in scikit-learn itself. An auxiliary goal is to early + # detect any regression in the patched build dependencies to report them + # upstream. The long-term goal is to be able to stop having to maintain + # multiprocessing based workaround / hacks in joblib / loky to make multi-CPU + # computing in scikit-learn efficient by default using regular threads. + # + # If this experimental entry becomes too unstable, feel free to disable it. + parameters: + name: Linux_nogil + vmImage: ubuntu-20.04 + dependsOn: [git_commit, linting] + condition: | + and( + succeeded(), + not(contains(dependencies['git_commit']['outputs']['commit.message'], '[ci skip]')), + or(eq(variables['Build.Reason'], 'Schedule'), + contains(dependencies['git_commit']['outputs']['commit.message'], '[nogil]' + ) + ) + ) + matrix: + pylatest_pip_nogil: + DISTRIB: 'pip-nogil' + COVERAGE: 'false' + # Check compilation with intel C++ compiler (ICC) - template: build_tools/azure/posix.yml parameters: diff --git a/build_tools/azure/install.sh b/build_tools/azure/install.sh index ff89358c0c1f6..cfc563a4f9f65 100755 --- a/build_tools/azure/install.sh +++ b/build_tools/azure/install.sh @@ -8,6 +8,9 @@ source build_tools/shared.sh UNAMESTR=`uname` +CCACHE_LINKS_DIR="/tmp/ccache" + + make_conda() { TO_INSTALL="$@" if [[ "$DISTRIB" == *"mamba"* ]]; then @@ -20,14 +23,21 @@ make_conda() { } setup_ccache() { - echo "Setting up ccache with CCACHE_DIR=${CCACHE_DIR}" - mkdir /tmp/ccache/ - which ccache - for name in gcc g++ cc c++ clang clang++ i686-linux-gnu-gcc i686-linux-gnu-c++ x86_64-linux-gnu-gcc x86_64-linux-gnu-c++ x86_64-apple-darwin13.4.0-clang x86_64-apple-darwin13.4.0-clang++; do - ln -s $(which ccache) "/tmp/ccache/${name}" - done - export PATH="/tmp/ccache/:${PATH}" - ccache -M 256M + CCACHE_BIN=`which ccache || echo ""` + if [[ "${CCACHE_BIN}" == "" ]]; then + echo "ccache not found, skipping..." + elif [[ -d "${CCACHE_LINKS_DIR}" ]]; then + echo "ccache already configured, skipping..." + else + echo "Setting up ccache with CCACHE_DIR=${CCACHE_DIR}" + mkdir ${CCACHE_LINKS_DIR} + which ccache + for name in gcc g++ cc c++ clang clang++ i686-linux-gnu-gcc i686-linux-gnu-c++ x86_64-linux-gnu-gcc x86_64-linux-gnu-c++ x86_64-apple-darwin13.4.0-clang x86_64-apple-darwin13.4.0-clang++; do + ln -s ${CCACHE_BIN} "${CCACHE_LINKS_DIR}/${name}" + done + export PATH="${CCACHE_LINKS_DIR}:${PATH}" + ccache -M 256M + fi } pre_python_environment_install() { @@ -48,6 +58,12 @@ pre_python_environment_install() { apt-get -yq update apt-get -yq install build-essential + elif [[ "$DISTRIB" == "pip-nogil" ]]; then + echo "deb-src http://archive.ubuntu.com/ubuntu/ focal main" | sudo tee -a /etc/apt/sources.list + sudo apt-get -yq update + sudo apt-get install -yq ccache + sudo apt-get build-dep -yq python3 python3-dev + elif [[ "$BUILD_WITH_ICC" == "true" ]]; then wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB @@ -56,6 +72,7 @@ pre_python_environment_install() { sudo apt-get update sudo apt-get install intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic source /opt/intel/oneapi/setvars.sh + fi } @@ -120,6 +137,26 @@ python_environment_install() { pip install https://github.com/joblib/joblib/archive/master.zip echo "Installing pillow master" pip install https://github.com/python-pillow/Pillow/archive/main.zip + + elif [[ "$DISTRIB" == "pip-nogil" ]]; then + setup_ccache # speed-up the build of CPython it-self + ORIGINAL_FOLDER=`pwd` + cd .. + git clone --depth 1 https://github.com/colesbury/nogil + cd nogil + ./configure && make -j 2 + ./python -m venv $ORIGINAL_FOLDER/$VIRTUALENV + cd $ORIGINAL_FOLDER + source $VIRTUALENV/bin/activate + + python -m pip install -U pip + # The pip version that comes with the nogil branch of CPython + # automatically uses the custom nogil index as its highest priority + # index to fetch patched versions of libraries with native code that + # would otherwise depend on the GIL. + echo "Installing build dependencies with pip from the nogil repository: https://d1yxz45j0ypngg.cloudfront.net/" + pip install numpy scipy cython joblib threadpoolctl + fi python -m pip install $(get_dep threadpoolctl $THREADPOOLCTL_VERSION) \ diff --git a/build_tools/azure/test_docs.sh b/build_tools/azure/test_docs.sh index 18b3ccb148b5e..1d28f64a036cd 100755 --- a/build_tools/azure/test_docs.sh +++ b/build_tools/azure/test_docs.sh @@ -4,7 +4,7 @@ set -e if [[ "$DISTRIB" =~ ^conda.* ]]; then source activate $VIRTUALENV -elif [[ "$DISTRIB" == "ubuntu" ]]; then +elif [[ "$DISTRIB" == "ubuntu" || "$DISTRIB" == "pip-nogil" ]]; then source $VIRTUALENV/bin/activate fi diff --git a/build_tools/azure/test_script.sh b/build_tools/azure/test_script.sh index c083114df60a4..3d74a0d98b374 100755 --- a/build_tools/azure/test_script.sh +++ b/build_tools/azure/test_script.sh @@ -7,7 +7,7 @@ source build_tools/shared.sh if [[ "$DISTRIB" =~ ^conda.* ]]; then source activate $VIRTUALENV -elif [[ "$DISTRIB" == "ubuntu" ]] || [[ "$DISTRIB" == "debian-32" ]]; then +elif [[ "$DISTRIB" == "ubuntu" || "$DISTRIB" == "debian-32" || "$DISTRIB" == "pip-nogil" ]]; then source $VIRTUALENV/bin/activate fi diff --git a/doc/developers/contributing.rst b/doc/developers/contributing.rst index 445a9d2211733..a8ab323daefb3 100644 --- a/doc/developers/contributing.rst +++ b/doc/developers/contributing.rst @@ -552,6 +552,7 @@ message, the following actions are taken. [cd build gh] CD is run only for GitHub Actions [lint skip] Azure pipeline skips linting [scipy-dev] Build & test with our dependencies (numpy, scipy, etc ...) development builds + [nogil] Build & test with the nogil experimental branches of CPython, Cython, NumPy, SciPy... [icc-build] Build & test with the Intel C compiler (ICC) [pypy] Build & test with PyPy [doc skip] Docs are not built