我正在学习使用Rootbeer,所以我做了以下事情:
[1]下载了Rootbeer-1.2.3.jar
[2]安装了来自http://www.nvidia.com/content/cuda/cuda-downloads.html
的CUDA工具包和CUDA驱动程序[3]编写了以下示例程序。
[4]来自NetBeans 8.0.2的Ran ArrayMultApp
import java.util.List;
import java.util.ArrayList;
import org.trifort.rootbeer.runtime.Kernel;
import org.trifort.rootbeer.runtime.Rootbeer;
public class ArrayMultApp
{
public void multArray(int[] array)
{
List<Kernel> jobs=new ArrayList();
for (int i=0;i<array.length;++i) jobs.add(new ArrayMult(array,i));
Rootbeer rootbeer=new Rootbeer();
rootbeer.run(jobs);
}
public static void main(String[] args)
{
ArrayMultApp app=new ArrayMultApp();
int[] array=new int[10];
for (int i=0;i<array.length;++i) array[i]=i;
for (int i=0;i<array.length;++i) System.out.println("start array["+i+"]: "+array[i]);
app.multArray(array);
for (int i=0;i<array.length;++i) System.out.println("final array["+i+"]: "+array[i]);
}
}
class ArrayMult implements Kernel
{
private int[] m_source;
private int m_index;
public ArrayMult(int[] source,int index)
{
m_source=source;
m_index=index;
}
public void gpuMethod()
{
m_source[m_index]*=11;
}
}
但是我收到以下错误消息:
start array[0]: 0
start array[1]: 1
start array[2]: 2
start array[3]: 3
start array[4]: 4
start array[5]: 5
start array[6]: 6
start array[7]: 7
start array[8]: 8
start array[9]: 9
Exception in thread "main" java.lang.ClassCastException: ArrayMult cannot be cast to org.trifort.rootbeer.runtime.CompiledKernel
at org.trifort.rootbeer.runtime.CUDAContext.setKernel(CUDAContext.java:119)Java Result: 1
我在Win 7 64位上安装了英特尔酷睿i7 x 980,NVIDA GeForce GTX 780和Java 8。
我从Rootbeer网站复制了示例应用,为什么会收到错误消息,以及如何修复它?
编辑:我忘了提一件事,在安装过程中,它说我没有Microsoft Visual Studio,就像那样,并说有些部分没有安装,我以为我是Java开发人员,我不需要Visual Studio,我不介意没有这些部分,这可能是问题吗?这是否意味着我必须首先购买并安装Microsoft Visual Studio才能使用Rootbeer进行Java开发?我按照说明进入[C:\ ProgramData \ NVIDIA Corporation \ CUDA Samples \ v6.5 \ bin \ win64 \ Release&gt;并且进行了大量测试,它们都工作正常,我可以看到正确处理小窗口中的图像。
当我试图将它jar起来时,我收到以下错误:
C:\Dir_Rootbeer_Samples\dist>java -jar lib/Rootbeer-1.2.3.jar Rootbeer_Samples.jar Rootbeer_Samples-GPU.jar
warning: sm_12 and sm_11 not supported with recursion. use -norecursion to enable.
warning: sm_12 and sm_11 not supported with doubles. use -nodoubles to enable.
caching package names for: C:\Dir_Rootbeer_Samples\dist\Rootbeer_Samples.jar
cpool == null
java.lang.NullPointerException
at soot.rbclassload.RootbeerClassLoader.loadHierarchySootClasses(RootbeerClassLoader.java:963)
at soot.rbclassload.RootbeerClassLoader.loadNecessaryClasses(RootbeerClassLoader.java:294)
at org.trifort.rootbeer.entry.RootbeerCompiler.setupSoot(RootbeerCompiler.java:198)
at org.trifort.rootbeer.entry.RootbeerCompiler.compile(RootbeerCompiler.java:219)
at org.trifort.rootbeer.entry.RootbeerCompiler.compile(RootbeerCompiler.java:213)
at org.trifort.rootbeer.entry.Main.run(Main.java:208)
at org.trifort.rootbeer.entry.Main.main(Main.java:244)
caching package names for: C:\Dir_Rootbeer_Samples\dist\lib\Rootbeer-1.2.3.jar
caching package names for: C:\Program Files\Java\jre1.8.0_20\lib\rt.jar
cpool == null
java.lang.NullPointerException
at soot.rbclassload.RootbeerClassLoader.loadHierarchySootClasses(RootbeerClassLoader.java:963)
at soot.rbclassload.RootbeerClassLoader.loadNecessaryClasses(RootbeerClassLoader.java:294)
at org.trifort.rootbeer.entry.RootbeerCompiler.setupSoot(RootbeerCompiler.java:198)
at org.trifort.rootbeer.entry.RootbeerCompiler.compile(RootbeerCompiler.java:219)
at org.trifort.rootbeer.entry.RootbeerCompiler.compile(RootbeerCompiler.java:213)
at org.trifort.rootbeer.entry.Main.run(Main.java:208)
at org.trifort.rootbeer.entry.Main.main(Main.java:244)
caching package names for: Rootbeer_Samples.jar
cpool == null
java.lang.NullPointerException
at soot.rbclassload.RootbeerClassLoader.loadHierarchySootClasses(RootbeerClassLoader.java:963)
at soot.rbclassload.RootbeerClassLoader.loadNecessaryClasses(RootbeerClassLoader.java:294)
at org.trifort.rootbeer.entry.RootbeerCompiler.setupSoot(RootbeerCompiler.java:198)
at org.trifort.rootbeer.entry.RootbeerCompiler.compile(RootbeerCompiler.java:219)
at org.trifort.rootbeer.entry.RootbeerCompiler.compile(RootbeerCompiler.java:213)
at org.trifort.rootbeer.entry.Main.run(Main.java:208)
at org.trifort.rootbeer.entry.Main.main(Main.java:244)
remapping class: java.util.concurrent.atomic.AtomicLong
java.lang.NullPointerException
at soot.rbclassload.RootbeerClassLoader.remapClasses(RootbeerClassLoader.java:998)
at soot.rbclassload.RootbeerClassLoader.loadNecessaryClasses(RootbeerClassLoader.java:295)
at org.trifort.rootbeer.entry.RootbeerCompiler.setupSoot(RootbeerCompiler.java:198)
at org.trifort.rootbeer.entry.RootbeerCompiler.compile(RootbeerCompiler.java:219)
at org.trifort.rootbeer.entry.RootbeerCompiler.compile(RootbeerCompiler.java:213)
at org.trifort.rootbeer.entry.Main.run(Main.java:208)
at org.trifort.rootbeer.entry.Main.main(Main.java:244)
C:\Dir_Rootbeer_Samples\dist>