Skip to content

Commit

Permalink
* Allow MKL-DNN to link with the full version of MKL at runtime (issue
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Oct 29, 2018
1 parent 2e604bf commit 3b3f34d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Allow MKL-DNN to link with the full version of MKL at runtime ([issue #629](https://github.com/bytedeco/javacpp-presets/issues/629))
* Add builds for `linux-mips64el` to presets for ARToolKitPlus, Chilitags, flandmark, OpenBLAS, and FFTW ([pull #637](https://github.com/bytedeco/javacpp-presets/pull/637))
* Update sample code for GSL with a more complex example ([issue #636](https://github.com/bytedeco/javacpp-presets/issues/636))
* Fix CUDA build for OpenCV on Mac OS X missing `libopencv_cudev.dylib` ([issue #626](https://github.com/bytedeco/javacpp-presets/issues/626))
Expand Down
6 changes: 4 additions & 2 deletions mkl-dnn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Java API documentation is available here:

* http://bytedeco.org/javacpp-presets/mkl-dnn/apidocs/

∗ Although MKL-DNN comes bundled with a stripped-down version of MKL known as "MKLML", it is sometimes desirable to link instead with the full version of [Intel MKL](https://software.intel.com/intel-mkl). For that, MKL first needs to be installed in its default location, or available in the system PATH or in the `java.library.path`, then we can set the "org.bytedeco.javacpp.mklml.load" system property to `mkl_rt`. We should also set the "org.bytedeco.javacpp.pathsfirst" system property to `true` to ensure that all libraries are actually loaded from the system.


Sample Usage
------------
Expand All @@ -34,15 +36,15 @@ We can use [Maven 3](http://maven.apache.org/) to download and install automatic
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco.javacpp-presets.mkl-dnn</groupId>
<artifactId>mkl-dnn</artifactId>
<version>1.4.3</version>
<version>1.4.4-SNAPSHOT</version>
<properties>
<exec.mainClass>SimpleNetInt8</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>mkl-dnn-platform</artifactId>
<version>0.16-1.4.3</version>
<version>0.16-1.4.4-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Expand Down
2 changes: 1 addition & 1 deletion mkl-dnn/src/main/java/org/bytedeco/javacpp/mkldnn.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Targeted by JavaCPP version 1.4.3: DO NOT EDIT THIS FILE
// Targeted by JavaCPP version 1.4.4-SNAPSHOT: DO NOT EDIT THIS FILE

package org.bytedeco.javacpp;

Expand Down
2 changes: 1 addition & 1 deletion mkl-dnn/src/main/java/org/bytedeco/javacpp/mklml.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Targeted by JavaCPP version 1.4.3: DO NOT EDIT THIS FILE
// Targeted by JavaCPP version 1.4.4-SNAPSHOT: DO NOT EDIT THIS FILE

package org.bytedeco.javacpp;

Expand Down
50 changes: 46 additions & 4 deletions mkl-dnn/src/main/java/org/bytedeco/javacpp/presets/mklml.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@

package org.bytedeco.javacpp.presets;

import java.util.List;
import org.bytedeco.javacpp.annotation.NoException;
import org.bytedeco.javacpp.annotation.Platform;
import org.bytedeco.javacpp.annotation.Properties;
import org.bytedeco.javacpp.ClassProperties;
import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.LoadEnabled;
import org.bytedeco.javacpp.tools.Info;
import org.bytedeco.javacpp.tools.InfoMap;
import org.bytedeco.javacpp.tools.InfoMapper;
Expand All @@ -41,19 +45,57 @@
"mkl_dnn_types.h", "mkl_dnn.h", /*"mkl_lapack.h", "mkl_lapacke.h", "mkl_service.h",
"mkl_vml.h", "mkl_vml_defines.h", "mkl_vml_types.h", "mkl_vml_functions.h",
"mkl_vsl.h", "mkl_vsl_defines.h", "mkl_vsl_types.h", "mkl_vsl_functions.h", "i_malloc.h"*/},
link = "mklml_intel", preload = {"gomp@.1", "iomp5"}, resource = {"include", "lib"}),
link = "mklml_intel", preload = {"gomp@.1", "iomp5"}, resource = {"include", "lib"},
preloadpath = {"/opt/intel/lib/intel64/", "/opt/intel/mkl/lib/intel64/"}),
@Platform(
value = "macosx-x86_64",
link = "mklml",
preload = {"gcc_s@.1", "gomp@.1", "stdc++@.6", "iomp5"},
preloadpath = {"/usr/local/lib/gcc/8/", "/usr/local/lib/gcc/7/", "/usr/local/lib/gcc/6/", "/usr/local/lib/gcc/5/"}),
preloadpath = {"/usr/local/lib/gcc/8/", "/usr/local/lib/gcc/7/", "/usr/local/lib/gcc/6/", "/usr/local/lib/gcc/5/",
"/opt/intel/lib/", "/opt/intel/mkl/lib/"}),
@Platform(
value = "windows-x86_64",
link = "mklml",
preload = {"libwinpthread-1", "libgcc_s_seh-1", "libgomp-1", "libstdc++-6", "msvcr120", "libiomp5md"})},
preload = {"libwinpthread-1", "libgcc_s_seh-1", "libgomp-1", "libstdc++-6", "msvcr120", "libiomp5md"},
preloadpath = {"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/redist/intel64/compiler/",
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/redist/intel64/mkl/"})},
target = "org.bytedeco.javacpp.mklml")
@NoException
public class mklml implements InfoMapper {
public class mklml implements LoadEnabled, InfoMapper {

@Override public void init(ClassProperties properties) {
String platform = properties.getProperty("platform");
List<String> preloads = properties.get("platform.preload");

// Only apply this at load time
if (!Loader.isLoadLibraries()) {
return;
}

// Let users enable loading of the full version of MKL
String lib = System.getProperty("org.bytedeco.javacpp.mklml.load", "").toLowerCase();

int i = 0;
if (lib.equals("mkl") || lib.equals("mkl_rt")) {
String[] libs = {"iomp5", "libiomp5md", "mkl_core", "mkl_avx", "mkl_avx2", "mkl_avx512", "mkl_avx512_mic",
"mkl_def", "mkl_mc", "mkl_mc3", "mkl_intel_lp64", "mkl_intel_thread", "mkl_rt"};
for (i = 0; i < libs.length; i++) {
preloads.add(i, libs[i] + "#" + libs[i]);
}
lib = "mkl_rt";
}

if (lib.length() > 0) {
if (platform.startsWith("linux")) {
preloads.add(i, lib + "#mklml_intel");
} else if (platform.startsWith("macosx")) {
preloads.add(i, lib + "#mklml");
} else if (platform.startsWith("windows")) {
preloads.add(i, lib + "#mklml");
}
}
}

public void map(InfoMap infoMap) {
infoMap.put(new Info("MKL_INT64", "MKL_UINT64", "MKL_INT", "MKL_UINT", "MKL_LONG",
"MKL_UINT8", "MKL_INT8", "MKL_INT16", "MKL_INT32",
Expand Down

0 comments on commit 3b3f34d

Please sign in to comment.