Search code examples
javagradlend4j

Problems building using gradle with nd4j


I'm trying to build a module using nd4j.
It builds fine with maven but not with gradle.
I did an auto-conversion of the pom, I added the javacpp dependency by hand and
it builds but the tests fail with link error no jniopenblas_nolapack in java.library.path.
I've done a lot of net-searching to no avail.
This is my dependencies section:

dependencies {
implementation("org.bytedeco:openblas:0.3.17-1.5.6")
implementation("org.bytedeco:javacpp:1.5.6")
implementation("org.nd4j:nd4j-native:1.0.0-M1.1")
}

(I've removed deps not associated with this)
A bit at my wits end, actually.


Solution

  • in the comments I would appreciate comments on our docs to help improve the site. We cover this scenario explicitly. I'll summarize it below then comment with a link. If you see anything missing please do help us improve the website for the future.

    Nd4j uses javacpp which relies on classifiers to determine how to include native binaries. The way it works is the core classes are put in a standalone library/artifactId (nd4j-native) and it needs an accompanying classifier dependency to go with it. This will be an artifact id with the same name and version plus an additional classifier. This will usually be the OS and architecture name for your platform. This could be linux-x86_64 (linux on 64 bit intel) or android-arm64 (android on 64 bit ARM devices)

    These also usually have accompanying dependencies such as openblas (which we also use the javacpp bindings for) to enable us to access fast 3rd party math routines.

    With that in mind a dependency block like this is usually what you're looking for:

    dependencies {
        compile "org.nd4j:nd4j-native:1.0.0-M1.1"
        // Use windows-x86_64 or linux-x86_64 if you are not on macos
        compile "org.nd4j:nd4j-native:1.0.0-M1.1:macosx-x86_64"
        compile "org.bytedeco:openblas:0.3.17-1.5.6:macosx-x86_64" 
        compile "org.bytedeco:openblas:0.3.17-1.5.6" 
    }
    

    You can also do what Sam described earlier and use the -platform dependencies. These are going to be much easier to work with and are what we actually by default have on the docs site. This would then just be:

    dependencies {
        compile "org.nd4j:nd4j-native-platform:1.0.0-M1.1"
     
    }
    

    There are further docs on this on the site so I will try to omit all of that for simplicity. If you need follow up comments please do let me know or submit another question.