问题在于使用CUDA运行Dl4j时

huangapple go评论97阅读模式
英文:

Problems running Dl4j with CUDA

问题

我正在尝试在GPU上运行dl4j模型,而不是使用CPU。该模型在CPU上运行得非常好。
因此,我决定尝试使用CUDA来利用我的GPU。我按照这里中描述的每个步骤进行操作,并且在CUDA安装方面,我按照NVIDIA的指示从这里安装了CUDA Toolkit。代码编译正常,但是我遇到了一个错误:

Skipped [JCublasBackend] backend (unavailable): java.lang.UnsatisfiedLinkError: C:\Users\albertb\.javacpp\cache\cuda-10.2-7.6-1.5.3-windows-x86_64.jar\org\bytedeco\cuda\windows-x86_64\jnicudart.dll: 找不到依赖库
Exception in thread "main" java.lang.ExceptionInInitializerError
	at TestCUDA.run(TestCUDA.java:12)
	at TestCUDA.main(TestCUDA.java:7)
Caused by: java.lang.RuntimeException: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: 请确保您的类路径上有nd4j后端。请参阅:https://deeplearning4j.konduit.ai/nd4j/backend
	at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5094)
	at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:270)
	... 2 more
Caused by: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: 请确保您的类路径上有nd4j后端。请参阅:https://deeplearning4j.konduit.ai/nd4j/backend
	at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:221)
	at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5091)
	... 3 more

我的项目是在IntelliJ上使用Maven创建的。我认为所有的依赖关系都没问题,否则代码就无法编译。某个后端依赖项、库或安装可能是缺失的。
也许版本不兼容是问题所在。
消息“请确保您的类路径上有nd4j后端”给了我一些关于必须存在某个后端jar的提示。但据我所知,Maven应该会处理这个问题……

我在互联网上搜索了一些解决方案、示例或教程…… 什么都有!
所有的链接都指向相同的指令。

一些技术信息:

  • Windows 10
  • Java 1.8 IntelliJ + Maven
  • dl4j 1.0.0-beta7
  • nd4j-cuda-10.2
  • CUDA 11.1 - 截至今天的最新版本

我会继续努力解决这个问题,但我会非常感谢任何帮助。
谢谢。

英文:

I'm trying to run a dl4j model using GPU instead of CPU. The model runs perfectly well using CPU.
So I decided to try CUDA to be able to to take advantage of the my GPU. I followed every step described in here and for the CUDA install I followed the instructions from NVIDIA to install CUDA Toolkit from here. The code compiles ok but I get an error:

Skipped [JCublasBackend] backend (unavailable): java.lang.UnsatisfiedLinkError: C:\Users\albertb\.javacpp\cache\cuda-10.2-7.6-1.5.3-windows-x86_64.jar\org\bytedeco\cuda\windows-x86_64\jnicudart.dll: Can&#39;t find dependent libraries
Exception in thread &quot;main&quot; java.lang.ExceptionInInitializerError
	at TestCUDA.run(TestCUDA.java:12)
	at TestCUDA.main(TestCUDA.java:7)
Caused by: java.lang.RuntimeException: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: Please ensure that you have an nd4j back-end on your classpath. Please see: https://deeplearning4j.konduit.ai/nd4j/backend
	at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5094)
	at org.nd4j.linalg.factory.Nd4j.&lt;clinit&gt;(Nd4j.java:270)
	... 2 more
Caused by: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: Please ensure that you have an nd4j backend on your classpath. Please see: https://deeplearning4j.konduit.ai/nd4j/backend
	at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:221)
	at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5091)
	... 3 more

My project was created using Maven on IntelliJ. All the dependencies are ok I guess otherwise the code would not compile. Some back-end dependency or library or install must be missing.
May be a version incompatibility is the problem.
The message Please ensure that you have an nd4j backend on your classpath gives me some hint about some back-end jar that must be there. But Maven is supposed to take care of that... as far as I know.

I searched internet for some solution or example or tutorial.. anything !!
There are all colones of the same instruction from the links above.

Some technical info:

  • Windows 10
  • Java 1.8 IntelliJ + Maven
  • dl4j 1.0,0-beta7
  • nd4j-cuda-10.2
  • CUDA 11.1 - latest version today

I'll keep trying to solve the problem but I would appreciate any help.
Thanks.

答案1

得分: 1

你可能安装了错误的CUDA版本。ND4J CUDA版本在构件ID中指定,如:nd4j-cuda-11.0/10.2。

如果你愿意,你可以使用javacpp提供的redist构件:https://search.maven.org/artifact/org.bytedeco/cuda-platform-redist/11.0-8.0-1.5.4/jar

这是适用于CUDA 11的最新版本。Nd4j只是在其所有本地交互操作下使用javacpp。

英文:

You likely have the wrong cuda version installed. The nd4j cuda version is specified in the artifact id like: nd4j-cuda-11.0/10.2.

If you want, you can use the redist artifacts from javacpp for this: https://search.maven.org/artifact/org.bytedeco/cuda-platform-redist/11.0-8.0-1.5.4/jar

This is the latest version for cuda 11. Nd4j just uses javacpp underneath for all of its native interop.

答案2

得分: 0

我解决了!现在我的示例在GeForce 3090上运行!

我的POM的一部分:

<dependency>
    <groupId>org.deeplearning4j</groupId>
    <artifactId>deeplearning4j-cuda-11.0</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>org.deeplearning4j</groupId>
    <artifactId>deeplearning4j-core</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

另外,您需要从源代码构建nd4j-cuda-11.0,并将所有的 *jar 和 dll 文件添加到您的项目中!

英文:

I’m resolved it! Now my example working on GeForce3090!!!

Part of My POM:

 org.example
    dl4jCuda
    1.0-SNAPSHOT

        &lt;dependency&gt;
            &lt;groupId&gt;org.deeplearning4j&lt;/groupId&gt;
            &lt;artifactId&gt;deeplearning4j-cuda-11.0&lt;/artifactId&gt;
            &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.deeplearning4j&lt;/groupId&gt;
            &lt;artifactId&gt;deeplearning4j-core&lt;/artifactId&gt;
            &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
        &lt;/dependency&gt;

Also you need build nd4j-cuda-11.0 from sources and add all *jar and dll files to your project!

huangapple
  • 本文由 发表于 2020年9月25日 05:36:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/64054762.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定