Skip to content

Commit

Permalink
more tweaks to globally load the dll, run aarch64 wheel build inside …
Browse files Browse the repository at this point in the history
…docker
  • Loading branch information
mattip committed Sep 14, 2023
1 parent faa9a55 commit 6be4a46
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ install:
script:
# Build library and collect into libs subdirectory
- build_lib "$PLAT" "$INTERFACE64"
- source travis-ci/build_wheel.sh
- libc=${MB_ML_LIBC:-manylinux}
- docker_image=quay.io/pypa/${libc}${MB_ML_VER}_${PLAT}
- docker run --rm -e INTERFACE64="${INTERFACE64}" -v $(pwd):/openblas $docker_image /bin/bash -xe /openblas/travis-ci/build_wheel.sh

after_success:
# Upload libraries to the shared staging area on anaconda.org
Expand Down
45 changes: 25 additions & 20 deletions local/scipy_openblas64/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

_HERE = Path(__file__).resolve().parent

__all__ = ["get_include_dir", "get_lib_dir", "get_library", "get_pkg_config", "openblas_config"]
__all__ = ["get_include_dir", "get_lib_dir", "get_library", "get_pkg_config",
"get_openblas_config"]

# Use importlib.metadata to single-source the version

Expand Down Expand Up @@ -61,16 +62,16 @@ def get_pkg_config():
return dedent(f"""\
libdir={get_lib_dir()}
includedir={get_include_dir()}
openblas_config= {openblas_config}
version={openblas_config.split(" ")[1]}
openblas_config= {get_openblas_config()}
version={get_openblas_config().split(" ")[1]}
extralib={extralib}
Name: openblas
Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version
Version: ${{version}}
URL: https://github.com/xianyi/OpenBLAS
Libs: -L${libdir} -l{get_library()}
Libs.private: ${extralib}
Cflags: -I${includedir}
Libs: -L${{libdir}} -l{get_library()}
Libs.private: ${{extralib}}
Cflags: -I${{includedir}}
""")


Expand All @@ -92,22 +93,26 @@ def write__distributor_init(target):
import scipy_openblas64
"""))

def _get_openblas_config():
dll = None
def get_openblas_config():
"""Use ctypes to pull out the config string from the OpenBLAS library.
It will be available as `openblas_config`
"""
lib_dir = get_lib_dir()
if sys.platform == "win32":
# Get libopenblas*.lib
libnames = [x for x in os.listdir(lib_dir) if x.endswith(".dll")]
else:
# Get openblas*
libnames = [x for x in os.listdir(lib_dir) if x.startswith("libopenblas")]
# Keep the dll alive
global dll
if not dll:
lib_dir = get_lib_dir()
if sys.platform == "win32":
# Get libopenblas*.lib
libnames = [x for x in os.listdir(lib_dir) if x.endswith(".dll")]
else:
# Get openblas*
libnames = [x for x in os.listdir(lib_dir) if x.startswith("libopenblas")]

dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0]))
dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0]))
openblas_config = dll.openblas_get_config64_
openblas_config.restype = ctypes.c_char_p
return openblas_config()

# This global will keep the shared object in memory
openblas_config = _get_openblas_config()
bytes = openblas_config()
return bytes.decode("utf8")

# Import the DLL which will make the namespace available to NumPy/SciPy
get_openblas_config()
2 changes: 1 addition & 1 deletion local/scipy_openblas64/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import scipy_openblas64

if __name__ == "__main__":
print(f"OpenBLAS using '{scipy_openblas64.openblas_config}'")
print(f"OpenBLAS using '{scipy_openblas64.get_openblas_config()}'")
6 changes: 6 additions & 0 deletions travis-ci/build_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if [ "${INTERFACE64}" != "1" ]; then
rm local/scipy_openblas32/*.bak
fi

rm -rf dist/*
python3.7 -m pip wheel -w dist -vv .

if [ $(uname) == "Darwin" ]; then
Expand All @@ -56,6 +57,11 @@ if [ $(uname) == "Darwin" ]; then
else
auditwheel repair -w dist --lib-sdir /lib dist/*.whl
rm dist/scipy_openblas*-none-any.whl
# Add an RPATH to libgfortran:
# https://github.com/pypa/auditwheel/issues/451
unzip dist/*.whl "*libgfortran*"
patchelf --force-rpath --set-rpath '$ORIGIN' */lib/libgfortran*
zip dist/*.whl */lib/libgfortran*
fi

if [ "${PLAT}" == "arm64" ]; then
Expand Down

0 comments on commit 6be4a46

Please sign in to comment.