我正在学习使用 Rootbeer,但是当我运行它的示例应用程序时卡住了,没有人能回答我的问题:Rootbeer 运行时错误,如何解决?
于是我下载了Rootbeer的源代码,看了看代码,问题出在[CUDAContext.java:119]:
public void setKernel(Kernel kernelTemplate) {
this.kernelTemplate = kernelTemplate;
[ 119 ] this.compiledKernel = (CompiledKernel) kernelTemplate;
}
Kernel 和 CompiledKernel 的定义是:
public interface Kernel
{
public void gpuMethod();
}
public interface CompiledKernel
{
public String getCodeUnix();
public String getCodeWindows();
public int getNullPointerNumber();
public int getOutOfMemoryNumber();
public String getCubin32();
public int getCubin32Size();
public boolean getCubin32Error();
public String getCubin64();
public int getCubin64Size();
public boolean getCubin64Error();
public Serializer getSerializer(Memory memory,Memory memory1);
public boolean isUsingGarbageCollector();
}
第 119 行的演员表是否正确完成?如果是,为什么我会收到错误消息:
java.lang.ClassCastException: ArrayMult cannot be cast to org.trifort.rootbeer.runtime.CompiledKernel
at org.trifort.rootbeer.runtime.CUDAContext.setKernel(CUDAContext.java:119)
如果没有正确完成,那么正确的投射方式是什么?
编辑:这是示例代码
import java.util.List;
import java.util.ArrayList;
import org.trifort.rootbeer.runtime.Kernel;
import org.trifort.rootbeer.runtime.Rootbeer;
public class ArrayMultApp
{
public 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) Out("start array["+i+"]: "+array[i]);
multArray(array);
for (int i=0;i<array.length;++i) Out("final array["+i+"]: "+array[i]);
}
public void multArray(int[] array)
{
try
{
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);
}
catch (Exception e) { e.printStackTrace(); }
}
public static void main(String[] args) { ArrayMultApp app=new ArrayMultApp(); }
private static void out(String message) { System.out.print(message); }
private static void Out(String message) { System.out.println(message); }
}
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; }
}