Skip to content

Commit

Permalink
Vendor blas routines [wheel build]
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed Jul 9, 2024
1 parent 279d71f commit f39bcef
Show file tree
Hide file tree
Showing 7 changed files with 1,274 additions and 275 deletions.
53 changes: 9 additions & 44 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
echo github.ref ${{ github.ref }}
build_wheels:
name: Wheel, ${{ matrix.python }}-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}
name: Wheel, ${{ matrix.python }}-${{ matrix.buildplat[1] }}
needs: parse_commit_info
if: contains(needs.parse_commit_info.outputs.can_build, 'true')
runs-on: ${{ matrix.buildplat[0] }}
Expand All @@ -103,11 +103,10 @@ jobs:
# should also be able to do multi-archs on a single entry, e.g.
# [windows-2019, win*, "AMD64 x86"]. However, those two require a different compiler setup
# so easier to separate out here.
- [ubuntu-22.04, manylinux_x86_64, ""]
- [macos-13, macosx_x86_64, openblas]
# - [macos-13, macosx_x86_64, accelerate]
# - [macos-14, macosx_arm64, accelerate] # always use accelerate
# - [windows-2019, win_amd64, ""]
- [ubuntu-22.04, manylinux_x86_64]
- [macos-13, macosx_x86_64]
- [macos-14, macosx_arm64]
- [windows-2019, win_amd64]

# python: ["cp310", "cp311", "cp312", "cp13"]
python: ["cp312"]
Expand Down Expand Up @@ -146,18 +145,6 @@ jobs:
choco install rtools -y --no-progress --force --version=4.0.0.20220206
echo "c:\rtools40\ucrt64\bin;" >> $env:GITHUB_PATH
- name: Windows - PKG_CONFIG
if: runner.os == 'Windows'
run: |
choco install -y --no-progress --stoponfirstfailure --checksum 6004DF17818F5A6DBF19CB335CC92702 pkgconfiglite
$CIBW = "${{ github.workspace }}/.openblas"
# pkgconfig needs a complete path, and not just "./openblas since the
# build is run in a tmp dir (?)
# It seems somewhere in the env passing, `\` is not
# passed through, so convert it to '/'
$CIBW = $CIBW.replace("\","/")
echo "CIBW_ENVIRONMENT_WINDOWS=PKG_CONFIG_PATH=$CIBW" >> $env:GITHUB_ENV
- name: macOS - Setup
if: matrix.buildplat[0] == 'macos-13' || matrix.buildplat[0] == 'macos-14'
run: |
Expand All @@ -166,30 +153,8 @@ jobs:
echo "FC=gfortran-13" >> "$GITHUB_ENV"
echo "F77=gfortran-13" >> "$GITHUB_ENV"
echo "F90=gfortran-13" >> "$GITHUB_ENV"
if [[ ${{ matrix.buildplat[2] }} == 'accelerate' ]]; then
# macosx_arm64 and macosx_x86_64 with accelerate
# only target Sonoma onwards
CIBW="MACOSX_DEPLOYMENT_TARGET=14.0 INSTALL_OPENBLAS=false RUNNER_OS=macOS"
echo "CIBW_ENVIRONMENT_MACOS=$CIBW" >> "$GITHUB_ENV"
# the macos-13 image that's used for building the x86_64 wheel can't test
# a wheel with deployment target >= 14 without further work
echo "CIBW_TEST_SKIP=*-macosx_x86_64" >> "$GITHUB_ENV"
else
# macosx_x86_64 with OpenBLAS
# if INSTALL_OPENBLAS isn't specified then scipy-openblas is automatically installed
CIBW="RUNNER_OS=macOS"
PKG_CONFIG_PATH="$PWD/.openblas"
DYLD="$DYLD_LIBRARY_PATH:/$PWD/.openblas/lib"
echo "CIBW_ENVIRONMENT_MACOS=$CIBW PKG_CONFIG_PATH=$PKG_CONFIG_PATH DYLD_LIBRARY_PATH=$DYLD" >> "$GITHUB_ENV"
fi
- name: Linux - Setup
if: runner.os == 'Linux'
run: |
CIBW="RUNNER_OS=Linux"
PKG_CONFIG_PATH="/project/.openblas"
LD="$LD_LIBRARY_PATH:/project/.openblas/lib"
echo "CIBW_ENVIRONMENT_LINUX=$CIBW PKG_CONFIG_PATH=$PKG_CONFIG_PATH LD_LIBRARY_PATH=$LD" >> "$GITHUB_ENV"
CIBW="RUNNER_OS=macOS"
echo "CIBW_ENVIRONMENT_MACOS=$CIBW" >> "$GITHUB_ENV"
- name: Build wheels
uses: pypa/[email protected]
Expand All @@ -215,7 +180,7 @@ jobs:
# @v4 does not merge artifacts with the name (even if the contents)
# are different. So in a matrix, we have to give each artifact a
# unique name. We merge these later in another job.
name: wheel-${{ matrix.python }}-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}
name: wheel-${{ matrix.python }}-${{ matrix.buildplat[1] }}
path: ./wheelhouse/*.whl

build_sdist:
Expand Down Expand Up @@ -248,7 +213,7 @@ jobs:
- name: Install Ubuntu dependencies
run: |
sudo apt-get update
sudo apt-get install libopenblas-dev liblapack-dev gfortran
sudo apt-get install gfortran
- name: Install requirements
run: |
Expand Down
50 changes: 1 addition & 49 deletions .spin/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,7 @@ def sdist():
".",
], replace=True)

@click.command(context_settings={
'ignore_unknown_options': True
})
@click.option(
"--with-scipy-openblas", type=click.Choice(["32", "64"]),
default=None, required=True,
help="Build with pre-installed scipy-openblas32 or scipy-openblas64 wheel"
)
def config_openblas(with_scipy_openblas):
"""🔧 Create .openblas/scipy-openblas.pc file
Also create _distributor_init_local.py
Requires a pre-installed scipy-openblas64 or scipy-openblas32
"""
_config_openblas(with_scipy_openblas)


# from numpy
@click.option(
"--with-scipy-openblas", type=click.Choice(["32", "64"]),
default=None,
help="Build with pre-installed scipy-openblas32 or scipy-openblas64 wheel"
)
@click.option(
"--clean", is_flag=True,
help="Clean build directory before build"
Expand All @@ -135,30 +112,5 @@ def config_openblas(with_scipy_openblas):
)
@click.argument("meson_args", nargs=-1)
@click.pass_context
def build(ctx, meson_args, with_scipy_openblas, jobs=None, clean=False, verbose=False, quiet=False, *args, **kwargs):
# XXX keep in sync with upstream build
if with_scipy_openblas:
_config_openblas(with_scipy_openblas)
ctx.params.pop("with_scipy_openblas", None)
def build(ctx, meson_args, jobs=None, clean=False, verbose=False, quiet=False, *args, **kwargs):
ctx.forward(meson.build)


def _config_openblas(blas_variant):
import importlib
basedir = os.getcwd()
openblas_dir = os.path.join(basedir, ".openblas")
pkg_config_fname = os.path.join(openblas_dir, "scipy-openblas.pc")
if blas_variant:
module_name = f"scipy_openblas{blas_variant}"
try:
openblas = importlib.import_module(module_name)
except ModuleNotFoundError:
raise RuntimeError(f"'pip install {module_name} first")
local = os.path.join(basedir, "skmisc", "_distributor_init_local.py")
with open(local, "wt", encoding="utf8") as fid:
fid.write(f"import {module_name}\n")
os.makedirs(openblas_dir, exist_ok=True)
with open(pkg_config_fname, "wt", encoding="utf8") as fid:
fid.write(
openblas.get_pkg_config(use_preloading=True)
)
16 changes: 0 additions & 16 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
option('blas', type: 'string', value: 'auto',
description: 'Option for BLAS library selection. By default, try to find any in the order given by `blas-order`')
option('lapack', type: 'string', value: 'auto',
description: 'Option for LAPACK library selection. By default, try to find any in the order given by `lapack-order`')
option('blas-order', type: 'array', value: ['auto'],
description: 'Order of BLAS libraries to search for. E.g.: mkl,openblas,blis,blas')
option('lapack-order', type: 'array', value: ['auto'],
description: 'Order of LAPACK libraries to search for. E.g.: mkl,openblas,lapack')
option('use-ilp64', type: 'boolean', value: false,
description: 'Use ILP64 (64-bit integer) BLAS and LAPACK interfaces')
option('blas-symbol-suffix', type: 'string', value: 'auto',
description: 'BLAS and LAPACK symbol suffix to use, if any')
option('use-g77-abi', type: 'boolean', value: false,
description: 'If set to true, forces using g77 compatibility wrappers ' +
'for LAPACK functions. The default is to use gfortran ' +
'ABI for all LAPACK libraries except MKL.')

# We do not use this option
option('allow-noblas', type: 'boolean', value: false,
description: 'If set to true, allow building with (slow!) internal fallback routines')
13 changes: 2 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ Build = [
".spin/cmds.py:docs",
".spin/cmds.py:coverage",
".spin/cmds.py:coverage_html",
".spin/cmds.py:config_openblas",
".spin/cmds.py:sdist",
]
Environments = [
Expand All @@ -156,8 +155,6 @@ Environments = [
build-frontend = "build"
skip = "cp36-* cp37-* cp-38* pp37-* *-manylinux_i686 *_ppc64le *_s390x *_universal2"
before-build = "bash {project}/tools/wheels/cibw_before_build.sh {project}"
# The build will use openblas64 everywhere, except on arm64 macOS >=14.0 (uses Accelerate)
config-settings = "setup-args=-Duse-ilp64=true setup-args=-Dallow-noblas=false build-dir=build"
# before-test = "pip install -r {project}/requirements/test_requirements.txt"
test-command = "bash {project}/tools/wheels/cibw_test_command.sh {project}"
test-requires = [
Expand All @@ -172,10 +169,6 @@ manylinux-aarch64-image = "manylinux2014"
[tool.cibuildwheel.linux.environment]
# RUNNER_OS is a GitHub Actions specific env var; define it here so it works on Cirrus CI too
RUNNER_OS="Linux"
# /project will be the $PWD equivalent inside the docker used to build the wheel
# PKG_CONFIG_PATH="/project/.openblas"
PKG_CONFIG_PATH="/project/.openblas"
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/project/.openblas/lib"


[tool.cibuildwheel.macos]
Expand All @@ -184,7 +177,6 @@ LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/project/.openblas/lib"
# section
# Not clear why the DYLD_LIBRARY_PATH is not passed through from the environment
repair-wheel-command = [
"export DYLD_LIBRARY_PATH=$PWD/.openblas/lib",
"echo DYLD_LIBRARY_PATH $DYLD_LIBRARY_PATH",
"delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}",
]
Expand All @@ -195,11 +187,10 @@ PKG_CONFIG_PATH="{project}"

[tool.cibuildwheel.windows]
# This does not work, use CIBW_ENVIRONMENT_WINDOWS
environment = {PKG_CONFIG_PATH="./.openblas"}
config-settings = "setup-args=--vsenv setup-args=-Dallow-noblas=false build-dir=build"
config-settings = "setup-args=--vsenv build-dir=build"
repair-wheel-command = "bash -el ./tools/wheels/repair_windows.sh {wheel} {dest_dir}"

[[tool.cibuildwheel.overrides]]
select = "*-win32"
config-settings = "setup-args=--vsenv setup-args=-Dallow-noblas=true build-dir=build"
config-settings = "setup-args=--vsenv build-dir=build"
repair-wheel-command = ""
4 changes: 2 additions & 2 deletions skmisc/loess/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ floess_lib = static_library(
'floess',
sources: [
'src/loessf.f',
'src/linpack_lite.f'
'src/linpack_lite.f',
'src/blas_lite.f'
],
fortran_args: [fortran_ignore_warnings],
dependencies: [blas_dep, lapack_dep],
)
###

Expand Down
Loading

0 comments on commit f39bcef

Please sign in to comment.