1
1
diff --git a/mkl/__init__.py b/mkl/__init__.py
2
- index d2fefc7..47f35b9 100644
2
+ index 4a86a64..1ebe93a 100644
3
3
--- a/mkl/__init__.py
4
4
+++ b/mkl/__init__.py
5
- @@ -23,7 +23,11 @@
5
+ @@ -23,7 +23,10 @@
6
6
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
7
7
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8
8
9
9
+ import contextlib
10
10
+ import os
11
11
import sys
12
12
+ from importlib.metadata import PackageNotFoundError, files
13
- +
14
13
15
- class RTLD_for_MKL():
16
- def __init__(self) :
17
- @@ -38 ,6 +42,20 @@ class RTLD_for_MKL() :
14
+
15
+ class RTLD_for_MKL :
16
+ @@ -41 ,6 +44,21 @@ class RTLD_for_MKL:
18
17
sys.setdlopenflags(self.saved_rtld | ctypes.RTLD_GLOBAL)
19
18
except AttributeError:
20
19
pass
@@ -23,12 +22,13 @@ index d2fefc7..47f35b9 100644
23
22
+ AttributeError, FileNotFoundError, StopIteration, PackageNotFoundError
24
23
+ ):
25
24
+ if os.name == "nt":
26
- + # Add MKL library to DLL search path on Windows.
25
+ + # Add MKL library path to DLL search path on Windows.
27
26
+ dll = next(p for p in files("mkl") if p.match("*mkl_rt*.dll"))
28
27
+ dll_dir = dll.locate().resolve().parent
29
28
+ os.add_dll_directory(dll_dir)
30
29
+ else:
31
- + # Preload MKL library on Linux.
30
+ + # There's no easy way to expand LD_LIBRARY_PATH at runtime in
31
+ + # Linux. Instead preload MKL library directly.
32
32
+ dll = next(p for p in files("mkl") if p.match("*libmkl_rt.so*"))
33
33
+ ctypes.CDLL(dll.locate().resolve(), mode=ctypes.RTLD_GLOBAL)
34
34
+
0 commit comments