From a657b81354f0818802a11ba0214ab0c5c2551f1e Mon Sep 17 00:00:00 2001 From: Joost van Zwieten Date: Fri, 21 Oct 2022 11:03:20 +0200 Subject: [PATCH] add envvar NUTILS_MATRIX_MKL_LIB In GitHub Actions we've not been able to load MKL with `util.loadlib`, even when adding the path to `mkl_rt.?.dll` or `libmkl_rt.?.dylib` to `PATH` or `DYLD_LIBRARY_PATH`. To be able to test MKL and to aid users of the aformentioned platforms having the same problem, this patch adds the environment variable `NUTILS_MATRIX_MKL_LIB`, which should be a path to `mkl.?.dll` on Windows, `libmkl_rt.?.dylib` on MacOS and `libmkl.so.?` on Linux. If unempty, Nutils tries to load MKL from the provided path. If this fails, an execption will be raised. If the user provides a path to a different library, the behavior is undefined. --- nutils/matrix/_mkl.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/nutils/matrix/_mkl.py b/nutils/matrix/_mkl.py index e9e306bc5..45a2f2acf 100644 --- a/nutils/matrix/_mkl.py +++ b/nutils/matrix/_mkl.py @@ -1,17 +1,21 @@ from ._base import Matrix, MatrixError, BackendNotAvailable from .. import numeric, _util as util, warnings from contextlib import contextmanager -from ctypes import c_int, byref +from ctypes import c_int, byref, CDLL import treelog as log import os import numpy -for v in '.2', '.1', '': - libmkl = util.loadlib(linux=f'libmkl_rt.so{v}', darwin=f'libmkl_rt{v}.dylib', win32=f'mkl_rt{v}.dll') - if libmkl: - break +libmkl_path = os.environ.get('NUTILS_MATRIX_MKL_LIB', None) +if libmkl_path: + libmkl = CDLL(libmkl_path) else: - raise BackendNotAvailable('the Intel MKL matrix backend requires libmkl to be installed (try: pip install mkl)') + for v in '.2', '.1', '': + libmkl = util.loadlib(linux=f'libmkl_rt.so{v}', darwin=f'libmkl_rt{v}.dylib', win32=f'mkl_rt{v}.dll') + if libmkl: + break + else: + raise BackendNotAvailable('the Intel MKL matrix backend requires libmkl to be installed (try: pip install mkl)') def assemble(data, index, shape):