I'm learning to use Rootbeer, but I got stuck when I ran its sample apps, and no one could answer my question : Rootbeer runtime error, how to fix?
So I downloaded the source code of Rootbeer, and took a look at the code, here is where the problem is [ CUDAContext.java:119 ]:
public void setKernel(Kernel kernelTemplate) {
this.kernelTemplate = kernelTemplate;
[ 119 ] this.compiledKernel = (CompiledKernel) kernelTemplate;
}
And the definitions of Kernel and CompiledKernel are :
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();
}
Is the cast done properly in line 119 ? If it is, why did I get the error saying :
java.lang.ClassCastException: ArrayMult cannot be cast to org.trifort.rootbeer.runtime.CompiledKernel
at org.trifort.rootbeer.runtime.CUDAContext.setKernel(CUDAContext.java:119)
If it's not done correctly, what's the right way to cast it ?
Edit : Here is the sample code
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; }
}