首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >线程"main“java.lang.NoClassDefFoundError中的异常:jcuda/驱动程序/JCudaDriver

线程"main“java.lang.NoClassDefFoundError中的异常:jcuda/驱动程序/JCudaDriver
EN

Stack Overflow用户
提问于 2019-03-25 18:01:12
回答 1查看 213关注 0票数 1

我正在尝试设置JCuda并执行示例添加内核。当我在编译JCudaVectorAdd之后尝试执行JCudaVectorAdd.java时,会得到以下错误:

代码语言:javascript
复制
Exception in thread "main" java.lang.NoClassDefFoundError: jcuda/driver/JCudaDriver
        at JCudaVectorAdd.main(JCudaVectorAdd.java:38)
Caused by: java.lang.ClassNotFoundException: jcuda.driver.JCudaDriver
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more

我创建了一个bash文件,其中包含了我执行的步骤,以达到我所处的位置:

代码语言:javascript
复制
#!/bin/bash

# This system has multiple Cuda instances, so we need to load the correct one
module load cuda-9.2

# Try to remove any jcuda zip files that may have been created previously
rm $HOME/jcuda.zip

# Get jcuda zip file from online, storing into $HOME directory
wget http://www.jcuda.org/downloads/JCuda-All-0.9.2.zip -O $HOME/jcuda.zip

# Remove the 0.9.2 directory in case it exists to get ready for a clean install
rm -rf $HOME/jcuda/JCuda-All-0.9.2

# Unzip the file and store within jcuda directory. NOTE: The version number will be maintained as jcuda/JCuda-ALL-0.9.2.zip, so multiple versions of jcuda can be installed using this script
unzip $HOME/jcuda.zip -d $HOME/jcuda

# Remove the zipped file now that it is no longer needed
rm $HOME/jcuda.zip

# Move into the newly create jcuda directory
cd $HOME/jcuda/JCuda-All-0.9.2/

# Get the example Main program for Vector addition from Jcuda site
wget http://www.jcuda.org/samples/JCudaVectorAdd.java

# Create a sample kernel
echo 'extern "C"'                                                   >  JCudaVectorAddKernel.cu
echo '__global__ void add(int n, float *a, float *b, float *sum)'   >> JCudaVectorAddKernel.cu
echo '{'                                                            >> JCudaVectorAddKernel.cu
echo '    int i = blockIdx.x * blockDim.x + threadIdx.x;'           >> JCudaVectorAddKernel.cu
echo '    if (i<n)'                                                 >> JCudaVectorAddKernel.cu
echo '    {'                                                        >> JCudaVectorAddKernel.cu
echo '        sum[i] = a[i] + b[i];'                                >> JCudaVectorAddKernel.cu
echo '    }'                                                        >> JCudaVectorAddKernel.cu
echo '}'                                                            >> JCudaVectorAddKernel.cu

# Create a .ptx file from the cuda kernel to be consumed by the Main java program later
# The sample Main program also performs this action, but we have it here as well
nvcc -ptx JCudaVectorAddKernel.cu -o JCudaVectorAddKernel.ptx

# Try to generate a class file from the example Main .java file
javac -cp ".:jcuda-0.9.2.jar:jcuda-natives-0.9.2-linux-x86_64.jar" JCudaVectorAdd.java

# Run the compiled executable
java JCudaVectorAdd

我似乎遗漏了一个步骤,尽管我对java或cuda/jcuda还不太熟悉,无法识别我所缺少的东西。有人能指出我如何解决这个问题的方向吗?是否是额外的步骤在修改我已经执行的步骤?

编辑:看来我仍然需要在我的执行中引用其他.jar文件(就像在http://www.jcuda.org/tutorial/TutorialIndex.html basic测试中那样),所以我的最后一个命令可能是错误的。将其更改为以下内容所显示的结果略有不同:

代码语言:javascript
复制
java JCudaVectorAdd -> java -cp ".:jcuda-0.9.2.jar:jcuda-natives-0.9.2-linux-x86_64.jar" JCudaVectorAdd

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error while loading native library "JCudaDriver-0.9.2-linux-x86_64"
Operating system name: Linux
Architecture         : amd64
Architecture bit size: 64
---(start of nested stack traces)---
Stack trace from the attempt to load the library as a file:
java.lang.UnsatisfiedLinkError: no JCudaDriver-0.9.2-linux-x86_64 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 jcuda.LibUtils.loadLibrary(LibUtils.java:143)
        at jcuda.driver.JCudaDriver.<clinit>(JCudaDriver.java:296)
        at JCudaVectorAdd.main(JCudaVectorAdd.java:38)
Stack trace from the attempt to load the library as a resource:
java.lang.UnsatisfiedLinkError: /tmp/libJCudaDriver-0.9.2-linux-x86_64.so: libcuda.so.1: cannot open shared object file: No such file or directory
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
        at java.lang.Runtime.load0(Runtime.java:809)
        at java.lang.System.load(System.java:1086)
        at jcuda.LibUtils.loadLibraryResource(LibUtils.java:260)
        at jcuda.LibUtils.loadLibrary(LibUtils.java:158)
        at jcuda.driver.JCudaDriver.<clinit>(JCudaDriver.java:296)
        at JCudaVectorAdd.main(JCudaVectorAdd.java:38)
---(end of nested stack traces)---

        at jcuda.LibUtils.loadLibrary(LibUtils.java:193)
        at jcuda.driver.JCudaDriver.<clinit>(JCudaDriver.java:296)
        at JCudaVectorAdd.main(JCudaVectorAdd.java:38)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-25 19:04:11

似乎您需要告诉JRE在哪里可以找到相应的操作系统库来运行cuda。如果您查看输出,它会声明它找不到libcuda.so.1

找到这些库在您的文件系统中的位置,并将您的java.library.path属性设置为指向那里。java -Djava.library.path=/path/to/cudalibdir/ <rest of commandline>

如果您的系统没有库,则可能需要在本地安装或编译它。

免责声明:我没有具体使用cuda的经验,但与其他jars一起工作过,这些jars需要操作系统级别的库才能工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55343946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档