Unable to cast a class error

て烟熏妆下的殇ゞ 提交于 2020-01-11 06:16:28

问题


I am going to use rootbeer1 for the first time. I am in windows 7 machine, 32 bit system having GForce 610 GPU. I installed CUDA 5.5 successfully and executed the examples to make sure it works fine too. Then I installed rootbeer1 according to the guidance given in the github page.

Then I loaded Rootbeer.jar into NetBeans IDE as an external jar and copied and pasted the example code of rootbeer which is listed in here. One change I made is changing the imports, where the code in github page imports

import edu.syr.pcpratts.rootbeer.runtime.Rootbeer;
import edu.syr.pcpratts.rootbeer.runtime.Kernel;

and my code imports

import org.trifort.rootbeer.runtime.Rootbeer;
import org.trifort.rootbeer.runtime.Kernel;

Apart from that I changed rootbeer.runAll(jobs); to rootbeer.run(jobs); because rootbeer.runAll(); does not exists.

That is because netbeans says package edu.syr.pcpratts.rootbeer.runtime.Rootbeer does not exists.

Below is my code

KeepMainTest.java

import java.util.ArrayList;
import java.util.List;
import org.trifort.rootbeer.runtime.Kernel;
import org.trifort.rootbeer.runtime.Rootbeer;

public class KeepMainTest {

  public static void main(String[] args){
    KeepMainTest app = new KeepMainTest();
    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("array["+i+"] = " + array[i]);
    }

    app.MultiplyArray(array, 5);

    for(int i = 0; i < array.length; ++i){
      System.out.println("array["+i+"] * 5 = " + array[i]);
    }
  }

  public void MultiplyArray(int[] array, int width){
    List<Kernel> jobs = new ArrayList<Kernel>();
    for(int i = 0; i < array.length; ++i){
      jobs.add(new Multiply(array, i, width));
    }

    Rootbeer rootbeer = new Rootbeer();
    rootbeer.runAll(jobs);
  }
}

Multiply.java

import org.trifort.rootbeer.runtime.Kernel;

public class Multiply implements Kernel {

  private int[] m_array;
  private int m_index;
  private int m_width;

  public Multiply(int[] array, int index, int width){
    m_array = array;
    m_index = index;
    m_width = width;
  }

  public void gpuMethod(){
    m_array[m_index] *= m_width;
  }
}

When I run this code, I am getting the following output, with an error

array[0] = 0
array[1] = 1
array[2] = 2
array[3] = 3
array[4] = 4
array[5] = 5
array[6] = 6
array[7] = 7
array[8] = 8
array[9] = 9
Exception in thread "main" java.lang.ClassCastException: Multiply cannot be cast to org.trifort.rootbeer.runtime.CompiledKernel
    at org.trifort.rootbeer.runtime.CUDAContext.run(CUDAContext.java:153)
    at org.trifort.rootbeer.runtime.Rootbeer.run(Rootbeer.java:105)
    at KeepMainTest.MultiplyArray(KeepMainTest.java:34)
    at KeepMainTest.main(KeepMainTest.java:20)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

What has gone wrong here?

Update

I did it in the way suggested by 2 users. Below are the commands I used my output.

C:\Users\Dev\Documents\NetBeansProjects\GPU\dist>java -Xmx512m -jar Rootbeer.jar GPU.jar GPU1.jar
C:\Users\Dev\Documents\NetBeansProjects\GPU\dist>java -jar GPU1.jar

First command worked fine, no worries. But the second one, when I am trying to run the Jar called GPU1.JAR it gave me the following error.

array[0] = 0
array[1] = 1
array[2] = 2
array[3] = 3
array[4] = 4
array[5] = 5
array[6] = 6
array[7] = 7
array[8] = 8
array[9] = 9
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7410125c, pid=3532, tid=5948
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)

# Java VM: Java HotSpot(TM) Client VM (24.51-b03 mixed mode, sharing windows-x86
 )
# Problematic frame:
# C  [rootbeer_x86.dll+0x125c]
#
# Failed to write core dump. Minidumps are not enabled by default on client vers
ions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Dev\Documents\NetBeansProjects\GPU\dist\hs_err_pid3532.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

The log file it generated is below.

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7410125c, pid=3532, tid=5948
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) Client VM (24.51-b03 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [rootbeer_x86.dll+0x125c]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

Current thread (0x0053c400):  JavaThread "main" [_thread_in_native, id=5948, stack(0x00b50000,0x00ba0000)]

siginfo: ExceptionCode=0xc0000005, writing address 0x00000000

Registers:
EAX=0x00000000, EBX=0x33459170, ECX=0x00000000, EDX=0xffffffff
ESP=0x00b9f444, EBP=0x00b9f448, ESI=0x33459170, EDI=0x0053c400
EIP=0x7410125c, EFLAGS=0x00010246

Top of Stack: (sp=0x00b9f444)
0x00b9f444:   00000000 00b9f494 01aba9dd 0053c530
0x00b9f454:   00b9f4b8 00000000 00000000 ffffffff
0x00b9f464:   00000000 00000000 0053cbd8 0053cbe8
0x00b9f474:   00b9f474 33459170 00b9f4b8 3345ac18
0x00b9f484:   00000000 33459170 00000000 00b9f4a4
0x00b9f494:   00b9f4dc 01ab3207 00000000 01ab88c9
0x00b9f4a4:   00000000 00000000 ffffffff 00000000
0x00b9f4b4:   00000000 23553738 00b9f4bc 33457722 

Instructions: (pc=0x7410125c)
0x7410123c:   6a 04 8b 4d 14 51 8b 55 10 52 e8 e5 04 00 00 6a
0x7410124c:   00 6a 04 52 50 e8 9a 04 00 00 8b 4d fc 8b 55 18
0x7410125c:   89 14 01 8b e5 5d c2 1c 00 cc cc cc cc cc cc cc
0x7410126c:   cc cc cc cc 55 8b ec 51 8b 45 1c 89 45 fc 6a 00 


Register to memory mapping:

EAX=0x00000000 is an unknown value
EBX=0x33459170 is an oop
{method} 
 - klass: {other class}
ECX=0x00000000 is an unknown value
EDX=0xffffffff is an unknown value
ESP=0x00b9f444 is pointing into the stack for thread: 0x0053c400
EBP=0x00b9f448 is pointing into the stack for thread: 0x0053c400
ESI=0x33459170 is an oop
{method} 
 - klass: {other class}
EDI=0x0053c400 is a thread


Stack: [0x00b50000,0x00ba0000],  sp=0x00b9f444,  free space=317k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [rootbeer_x86.dll+0x125c]
j  org.trifort.rootbeer.runtime.FixedMemory.doWriteInt(JIJ)V+0
j  org.trifort.rootbeer.runtime.FixedMemory.writeInt(I)V+10
j  MultiplySerializer.doWriteStaticsToHeap()V+40
j  org.trifort.rootbeer.runtime.Serializer.writeStaticsToHeap()V+1
j  org.trifort.rootbeer.runtime.CUDAContext.writeBlocks(Ljava/util/List;)V+61
j  org.trifort.rootbeer.runtime.CUDAContext.run(Ljava/util/List;Lorg/trifort/rootbeer/runtime/ThreadConfig;)V+188
j  org.trifort.rootbeer.runtime.Rootbeer.run(Ljava/util/List;)V+20
j  KeepMainTest.MultiplyArray([II)V+67
j  KeepMainTest.main([Ljava/lang/String;)V+121
v  ~StubRoutines::call_stub
V  [jvm.dll+0x13f35a]
V  [jvm.dll+0x202c6e]
V  [jvm.dll+0x13f3dd]
V  [jvm.dll+0xc9945]
V  [jvm.dll+0xd45e7]
C  [java.exe+0x2063]
C  [java.exe+0xa591]
C  [java.exe+0xa61b]
C  [kernel32.dll+0x4ed5c]
C  [ntdll.dll+0x637eb]
C  [ntdll.dll+0x637be]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.trifort.rootbeer.runtime.FixedMemory.doWriteInt(JIJ)V+0
j  org.trifort.rootbeer.runtime.FixedMemory.writeInt(I)V+10
j  MultiplySerializer.doWriteStaticsToHeap()V+40
j  org.trifort.rootbeer.runtime.Serializer.writeStaticsToHeap()V+1
j  org.trifort.rootbeer.runtime.CUDAContext.writeBlocks(Ljava/util/List;)V+61
j  org.trifort.rootbeer.runtime.CUDAContext.run(Ljava/util/List;Lorg/trifort/rootbeer/runtime/ThreadConfig;)V+188
j  org.trifort.rootbeer.runtime.Rootbeer.run(Ljava/util/List;)V+20
j  KeepMainTest.MultiplyArray([II)V+67
j  KeepMainTest.main([Ljava/lang/String;)V+121
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x03d36800 JavaThread "Thread-0" daemon [_thread_blocked, id=744, stack(0x043a0000,0x043f0000)]
  0x009f8800 JavaThread "Service Thread" daemon [_thread_blocked, id=2324, stack(0x03cd0000,0x03d20000)]
  0x009f3c00 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=2996, stack(0x03c80000,0x03cd0000)]
  0x009f2400 JavaThread "Attach Listener" daemon [_thread_blocked, id=5876, stack(0x03c30000,0x03c80000)]
  0x009ef400 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=2704, stack(0x00dd0000,0x00e20000)]
  0x00985400 JavaThread "Finalizer" daemon [_thread_blocked, id=5008, stack(0x03ac0000,0x03b10000)]
  0x00980000 JavaThread "Reference Handler" daemon [_thread_blocked, id=5104, stack(0x00d20000,0x00d70000)]
=>0x0053c400 JavaThread "main" [_thread_in_native, id=5948, stack(0x00b50000,0x00ba0000)]

Other Threads:
  0x0097e800 VMThread [stack: 0x00c80000,0x00cd0000] [id=4368]
  0x00a0a000 WatcherThread [stack: 0x03bb0000,0x03c00000] [id=1076]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
 def new generation   total 4928K, used 1472K [0x23420000, 0x23970000, 0x28970000)
  eden space 4416K,  33% used [0x23420000, 0x23590190, 0x23870000)
  from space 512K,   0% used [0x23870000, 0x23870000, 0x238f0000)
  to   space 512K,   0% used [0x238f0000, 0x238f0000, 0x23970000)
 tenured generation   total 10944K, used 0K [0x28970000, 0x29420000, 0x33420000)
   the space 10944K,   0% used [0x28970000, 0x28970000, 0x28970200, 0x29420000)
 compacting perm gen  total 12288K, used 271K [0x33420000, 0x34020000, 0x37420000)
   the space 12288K,   2% used [0x33420000, 0x33463ed0, 0x33464000, 0x34020000)
    ro space 10240K,  41% used [0x37420000, 0x37852050, 0x37852200, 0x37e20000)
    rw space 12288K,  52% used [0x37e20000, 0x38466800, 0x38466800, 0x38a20000)

Card table byte_map: [0x00aa0000,0x00b50000] byte_map_base: 0x00985f00

Polling page: 0x00260000

Code Cache  [0x01ab0000, 0x01b50000, 0x03ab0000)
 total_blobs=163 nmethods=27 adapters=74 free_code_cache=32138Kb largest_free_block=32909760

Compilation events (10 events):
Event: 0.111 Thread 0x009f3c00   23             java.lang.String::length (6 bytes)
Event: 0.111 Thread 0x009f3c00 nmethod 23 0x01b497c8 code [0x01b498c0, 0x01b49950]
Event: 0.193 Thread 0x009f3c00   24             sun.nio.cs.UTF_8$Encoder::encode (361 bytes)
Event: 0.194 Thread 0x009f3c00 nmethod 24 0x01b49c48 code [0x01b49da0, 0x01b4a228]
Event: 0.194 Thread 0x009f3c00   25             sun.net.www.ParseUtil::encodePath (336 bytes)
Event: 0.195 Thread 0x009f3c00 nmethod 25 0x01b4a988 code [0x01b4ab30, 0x01b4b1d8]
Event: 0.198 Thread 0x009f3c00   26             java.lang.Math::min (11 bytes)
Event: 0.198 Thread 0x009f3c00 nmethod 26 0x01b4bc08 code [0x01b4bd00, 0x01b4bd70]
Event: 0.201 Thread 0x009f3c00   27 %           org.trifort.rootbeer.util.ResourceReader::getResourceArray @ 89 (129 bytes)
Event: 0.202 Thread 0x009f3c00 nmethod 27% 0x01b4bdc8 code [0x01b4c040, 0x01b4c9d8]

GC Heap History (0 events):
No events

Deoptimization events (0 events):
No events

Internal exceptions (10 events):
Event: 0.195 Thread 0x0053c400 Threw 0x2352c950 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.195 Thread 0x0053c400 Threw 0x2352f158 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.196 Thread 0x0053c400 Threw 0x23538250 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.197 Thread 0x0053c400 Threw 0x2353b740 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.198 Thread 0x0053c400 Threw 0x2353fb10 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.199 Thread 0x0053c400 Threw 0x23542c50 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.200 Thread 0x0053c400 Threw 0x23545d48 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.200 Thread 0x0053c400 Threw 0x23547d80 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.202 Thread 0x0053c400 Threw 0x23553d88 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.202 Thread 0x0053c400 Threw 0x2357c0d0 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244

Events (10 events):
Event: 0.199 loading class 0x38a60f70
Event: 0.199 loading class 0x38a60f70 done
Event: 0.200 loading class 0x00a4b600
Event: 0.200 loading class 0x00a4b600 done
Event: 0.200 loading class 0x00a4bbc0
Event: 0.200 loading class 0x00a4bbc0 done
Event: 0.202 loading class 0x00a4b280
Event: 0.202 loading class 0x00a4b280 done
Event: 0.202 loading class 0x00988088
Event: 0.202 loading class 0x00988088 done


Dynamic libraries:
0x00e80000 - 0x00eaf000     C:\Windows\system32\java.exe
0x77540000 - 0x7767c000     C:\Windows\SYSTEM32\ntdll.dll
0x762d0000 - 0x763a4000     C:\Windows\system32\kernel32.dll
0x75700000 - 0x7574b000     C:\Windows\system32\KERNELBASE.dll
0x76460000 - 0x76500000     C:\Windows\system32\ADVAPI32.dll
0x75ff0000 - 0x7609c000     C:\Windows\system32\msvcrt.dll
0x75a70000 - 0x75a89000     C:\Windows\SYSTEM32\sechost.dll
0x763b0000 - 0x76452000     C:\Windows\system32\RPCRT4.dll
0x758c0000 - 0x75989000     C:\Windows\system32\USER32.dll
0x77720000 - 0x7776e000     C:\Windows\system32\GDI32.dll
0x75a60000 - 0x75a6a000     C:\Windows\system32\LPK.dll
0x75f00000 - 0x75f9d000     C:\Windows\system32\USP10.dll
0x74540000 - 0x746de000     C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_41e6975e2bd6f2b2\COMCTL32.dll
0x75c40000 - 0x75c97000     C:\Windows\system32\SHLWAPI.dll
0x75ca0000 - 0x75cbf000     C:\Windows\system32\IMM32.DLL
0x75990000 - 0x75a5c000     C:\Windows\system32\MSCTF.dll
0x65f70000 - 0x6602f000     C:\Program Files\Java\jre7\bin\msvcr100.dll
0x62630000 - 0x629b0000     C:\Program Files\Java\jre7\bin\client\jvm.dll
0x6f3e0000 - 0x6f3e7000     C:\Windows\system32\WSOCK32.dll
0x77680000 - 0x776b5000     C:\Windows\system32\WS2_32.dll
0x75ef0000 - 0x75ef6000     C:\Windows\system32\NSI.dll
0x73630000 - 0x73662000     C:\Windows\system32\WINMM.dll
0x758b0000 - 0x758b5000     C:\Windows\system32\PSAPI.DLL
0x73a20000 - 0x73a2c000     C:\Program Files\Java\jre7\bin\verify.dll
0x72d90000 - 0x72db0000     C:\Program Files\Java\jre7\bin\java.dll
0x70f30000 - 0x70f43000     C:\Program Files\Java\jre7\bin\zip.dll
0x5bce0000 - 0x5c620000     C:\Windows\System32\nvcuda.dll
0x760a0000 - 0x7623d000     C:\Windows\system32\SETUPAPI.dll
0x75750000 - 0x75777000     C:\Windows\system32\CFGMGR32.dll
0x75d00000 - 0x75d8f000     C:\Windows\system32\OLEAUT32.dll
0x75d90000 - 0x75eec000     C:\Windows\system32\ole32.dll
0x75820000 - 0x75832000     C:\Windows\system32\DEVOBJ.dll
0x76720000 - 0x7736a000     C:\Windows\system32\SHELL32.dll
0x74100000 - 0x74110000     C:\Users\Dev\.rootbeer\rootbeer_x86.dll
0x70c20000 - 0x70c31000     C:\Users\Dev\.rootbeer\rootbeer_cuda_x86.dll
0x726a0000 - 0x72956000     C:\Windows\system32\nvapi.dll
0x74b30000 - 0x74b39000     C:\Windows\system32\VERSION.dll
0x75880000 - 0x758ae000     C:\Windows\system32\WINTRUST.dll
0x755e0000 - 0x75700000     C:\Windows\system32\CRYPT32.dll
0x755c0000 - 0x755cc000     C:\Windows\system32\MSASN1.dll
0x6da20000 - 0x6db0b000     C:\Windows\system32\dbghelp.dll

VM Arguments:
java_command: GPU1.jar
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_51
PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\libnvvp;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files\Hewlett-Packard\Drive Encryption\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Java\jdk1.7.0_51\bin;C:\Users\Dev\Downloads\Apache Ant\apache-ant-1.9.3-bin\apache-ant-1.9.3\bin
USERNAME=Dev
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 37 Stepping 5, GenuineIntel



---------------  S Y S T E M  ---------------

OS: Windows 7 Build 7601 Service Pack 1

CPU:total 2 (2 cores per cpu, 1 threads per core) family 6 model 37 stepping 5, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, popcnt, tsc, tscinvbit

Memory: 4k page, physical 3464308k(1337940k free), swap 6926864k(4493144k free)

vm_info: Java HotSpot(TM) Client VM (24.51-b03) for windows-x86 JRE (1.7.0_51-b13), built on Dec 18 2013 19:09:58 by "java_re" with unknown MS VC++:1600

time: Tue Mar 25 06:18:38 2014
elapsed time: 0 seconds

What can I do now?


回答1:


Marco13 is correct here. You need to run something like

java -jar Rootbeer.jar ArraySumApp.jar ArraySumApp-GPU.jar

and then you need to run your app with

java -jar ArraySumApp-GPU.jar



来源:https://stackoverflow.com/questions/22597183/unable-to-cast-a-class-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!