0

I'm trying to use Nd4j in a Kotlin project in Intellij IDEA. In Project Structure -> Libraries, I used the "From Maven" command to add the following libraries.

org.deeplearning4j:deeplearning4j-core:1.0.0-beta
org.nd4j:nd4j-native-platform:1.0.0-beta
org.datavec:datavec-api:1.0.0-beta

With those libraries I can compile my project, but when I run it fails with an exception.

Caused by: java.lang.RuntimeException: ND4J is probably missing dependencies. For more information, please refer to: http://nd4j.org/getstarted.html
    at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:51)
    at org.nd4j.nativeblas.NativeOpsHolder.<clinit>(NativeOpsHolder.java:19)
    ... 10 more
Caused by: java.lang.UnsatisfiedLinkError: no jnind4jcpu in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1220)
    at org.bytedeco.javacpp.Loader.load(Loader.java:980)
    at org.bytedeco.javacpp.Loader.load(Loader.java:879)
    at org.nd4j.nativeblas.Nd4jCpu.<clinit>(Nd4jCpu.java:10)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.bytedeco.javacpp.Loader.load(Loader.java:938)
    at org.bytedeco.javacpp.Loader.load(Loader.java:879)
    at org.nd4j.nativeblas.Nd4jCpu$NativeOps.<clinit>(Nd4jCpu.java:1310)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:29)
    ... 11 more
Caused by: java.lang.UnsatisfiedLinkError: no nd4jcpu in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1220)
    at org.bytedeco.javacpp.Loader.load(Loader.java:965)
    ... 21 more

Looking through the project folder I see that IDEA has downloaded lots of jar files for nd4j-native-platform, but there's no sign of any JNI libraries. What else do I have to do?

peastman
  • 1,239
  • 1
  • 13
  • 18
  • How do you run the program? – Zoe Oct 07 '18 at 19:00
  • With the "Run" command in IDEA. I tried editing the run configuration to add the directory with all the jars to java.library.path, but that doesn't help. – peastman Oct 07 '18 at 19:50
  • Run as a gradle task instead. I've had problems myself with the IntelliJ run configuration not finding Gradle dependencies. No clue why, might be a bug in IntelliJ, or by design, but that's beside the point. You might need to add a custom task to run it though, but there are posts on SO too that cover it – Zoe Oct 07 '18 at 20:16
  • Could you explain? I haven't used Gradle. I just have an ordinary IDEA project, created with the "New Project" command. Also, the libraries are defined as Maven dependencies, not Gradle dependencies. – peastman Oct 07 '18 at 20:52
  • Sorry, my bad. Just ignore that, for some reason I thought you used Gradle. (even though it's tagged with maven, not sure why I missed that) – Zoe Oct 07 '18 at 21:02

2 Answers2

1

Intellij's "From Maven" feature doesn't support the classifiers that JavaCPP and ND4J (and other libraries that use native code) use. Maven will work great but if you really can't use it for some reason, you can manually add the nd4j-native-1.0.0-beta2-macosx-x86_64.jar file and openblas-0.3.0-1.4.2-macosx-x86_64.jar file. That should be enough to run simple things, but you'll have to manually do that for every other native dependency as you use more and more stuff (like OpenCV). That's why Maven is recommended.

wm_eddie
  • 3,938
  • 22
  • 22
0

If you include those 3 dependencies, there are zero reasons why it should fail unless you're on an unsupported OS for some reason.

We support everything from android to IBM power so that is unlikely though.

I'm also confused by what you mean about not seeing any JNI libraries. Those are all in the jar files. We use javacpp (which we also maintain) to manage those things. You will find those libraries under ~/.javacpp/cache - you should not have any reason to touch those though.

Could you clarify what you are looking for there?

Beyond that, there is nothing else you have to do. I'm assuming something just didn't load correctly.

Our standalone pom works out of the box: https://github.com/deeplearning4j/dl4j-examples/blob/master/standalone-sample-project/pom.xml - maybe double check this, that or reload. I can only assume you created the project wrong somehow. File -> New Maven project should be all you need to do.

Adam Gibson
  • 3,055
  • 1
  • 10
  • 12
  • I'm using a Mac, nothing unusual. You can reproduce it with these steps. 1. Create a new project following the steps at https://kotlinlang.org/docs/tutorials/getting-started.html. Make sure everything works and you can run it. 2. Select File->Project Structure. On the Libraries tab, click the + button and use "From Maven" to add the three dependencies. 3. Add a line to main() that creates an NDArray, for example "val x = Nd4j.ones(3)". 4. Try to run it and you should get the error. – peastman Oct 08 '18 at 16:48
  • Can you please file an issue? We have numerous mac users and have not encountered this. A self contained project would help a ton. – Adam Gibson Oct 09 '18 at 03:50