Skip to content

Commit

Permalink
Detect and honour an MKL numpy when building adccore (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherbst authored Nov 9, 2019
1 parent aff09b8 commit 06532a8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
17 changes: 17 additions & 0 deletions docs/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ This is done to avoid automatically overwriting some development changes
you might have made inside ``adccore``.


Building adccore with MKL support
---------------------------------

If you have full source code access
and you are able to follow the :ref:`adccore-sources`,
the `Intel Math Kernel Library (R) <https://software.intel.com/en-us/mkl>`_
can also be integrated into adccore and thus adcc.
In fact this integration happens automatically during the build
process of adccore, given that a numpy linked to the MKL was
detected. For this reason proceed as follows:

1. Load the MKL modules or activate the MKL in your shell as you usally do.
2. Build and install numpy with linkage to this MKL,
e.g. `Build numpy from source <https://docs.scipy.org/doc/numpy/user/building.html>`_.
3. Build adcc and adccore as described in :ref:`adccore-sources`.


``setup.py`` reference
----------------------
The ``setup.py`` script of adcc is a largely a typical setuptools script,
Expand Down
27 changes: 26 additions & 1 deletion extension/AdcCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ def get_platform():
return result


def has_mkl_numpy():
"""Has numpy been installed and linked against MKL"""
try:
import numpy.__config__

if not hasattr(numpy.__config__, "blas_mkl_info"):
return False
return any("mkl" in lib
for lib in numpy.__config__.blas_mkl_info.get("libraries", {}))
except ImportError as e:
if "mkl" in str(e):
# numpy seems to be installed and linked against MKL, but mkl was not found.
raise ImportError("Trying to import numpy for MKL check, but obtained an "
"import error indicating a missing MKL dependency. "
"Did you load the MKL modules properly?") from e

# This indicates a missing numpy or a big error in numpy. It's best to assume
# MKL is not there and (potentially) install the non-mkl version from pypi
return False


def request_urllib(url, filename):
"""Download a file from the net using requests, displaying
a nice progress bar along the way"""
Expand Down Expand Up @@ -123,8 +144,12 @@ def build(self):

import build_adccore

features = []
if has_mkl_numpy():
features += ["mkl"]

build_dir = join(self.source_dir, "build")
build_adccore.build_install(build_dir, self.install_dir)
build_adccore.build_install(build_dir, self.install_dir, features=features)

def build_documentation(self):
"""Build adccore documentation. Only valid if has_source is true"""
Expand Down

0 comments on commit 06532a8

Please sign in to comment.