Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/msrocka/olca-mkl
Browse files Browse the repository at this point in the history
  • Loading branch information
msrocka committed Jul 20, 2023
2 parents 7b16711 + ec9d39c commit d81f3a4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@ This is an experimental project that links the Intel Math Kernel (MKL) as calcul

## Building

The build scripts are written in Dart so that you need to have a current version of Dart (3.x) installed.
The build scripts are written in Dart so that you need to have a current version of Dart (3.x) installed as well as the `archive`
library. To install the library, run:
```bash
dart pub add archive
```

On macOS with Apple M1/M2, one will need to set the Rust toolchain to `stable-x86_64-apple-darwin`:
```bash
rustup install stable-x86_64-apple-darwin
rustup default stable-x86_64-apple-darwin
```

Then to build:

```bash
cd olca-mkl
Expand All @@ -19,6 +31,15 @@ The Java part has an `MKL` class with the native method-bindings and methods for

**Note** that there is only support for `x64` CPUs, e.g. on macOS M1/2, you need to run a `x64` JVM using the compatibility layer.

## Python scripts

On macOS Apple M1/M2, one needs to use `python3-intel64`:

```bash
python3-intel64 -m pip install scipy numpy
python3-intel64 scripts/pardiso_example.py
```

## TODO

* test performance on AMD processors (we added a method `mkl_serv_intel_cpu_true`, see https://danieldk.eu/mkl-amd-zen/)
Expand Down
2 changes: 1 addition & 1 deletion build/deps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fetch() async {
e.name.contains("third-party-programs.txt")) {
var name = lib.name + "_" + e.name.split("/").last;
var licenseFile = File(workDir.path + "/" + name);
print("consinder the license(s) in ${licenseFile.path}");
print("consider the license(s) in ${licenseFile.path}");
if (!licenseFile.existsSync()) {
licenseFile
..createSync()
Expand Down
11 changes: 10 additions & 1 deletion scripts/pardiso_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

import ctypes
import numpy as np
from sys import platform

if platform == "darwin":
lib = ctypes.CDLL("./bin/libmkl_rt.2.dylib")
elif platform == "win32":
lib = ctypes.CDLL("./bin/mkl_rt.2.dll")
elif platform == "linux" or platform == "linux2":
lib = ctypes.CDLL("./bin/mkl_rt.2.so")
else:
raise Exception("Could not detect the OS.")

lib = ctypes.CDLL("./bin/mkl_rt.2.dll")
# lib = ctypes.CDLL("./bin/libmkl_rt.so.2")
pardiso = lib.pardiso
pardiso.argtypes = [
Expand Down
11 changes: 10 additions & 1 deletion scripts/solve_sparse_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import ctypes
import numpy as np

from scipy.sparse import csc_matrix
from sys import platform

if platform == "darwin":
lib = ctypes.CDLL("./bin/libolcamkl.dylib")
elif platform == "win32":
lib = ctypes.CDLL("./bin/olcamkl.dll")
elif platform == "linux" or platform == "linux2":
lib = ctypes.CDLL("./bin/olcamkl.so")
else:
raise Exception("Could not detect the OS.")

lib = ctypes.CDLL("./bin/olcamkl.dll")
solve = lib.solve_sparse
float_ptr = ctypes.POINTER(ctypes.c_double)
int_ptr = ctypes.POINTER(ctypes.c_int32)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/openlca/mkl/OS.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum OS {
}),

MacOS(new String[]{
"libmkl_rt.dylib",
"libmkl_rt.2.dylib",
"libolcamkl.dylib"
}),

Expand Down
2 changes: 1 addition & 1 deletion src/mkl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ffi::c_char;
#[allow(non_snake_case)]
#[cfg_attr(target_os = "windows", link(name = "mkl_rt.2"))]
#[cfg_attr(target_os = "linux", link(name = "mkl_rt"))]
#[cfg_attr(target_os = "macos", link(name = "mkl_rt"))]
#[cfg_attr(target_os = "macos", link(name = "mkl_rt.2"))]
extern "C" {

/// [DGEMV](http://www.netlib.org/lapack/explore-html/dc/da8/dgemv_8f.html)
Expand Down

0 comments on commit d81f3a4

Please sign in to comment.