我正在使用OpenCl库很长一段时间,而且很好。最后,当我运行测试程序时,我遇到了这样的错误
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 29020.0x38e0]
0x0186e9da in ?? ()
(gdb) backtrace
#0 0x0186e9da in ?? ()
#1 0x7718b46b in ntdll!LdrRemoveLoadAsDataTable () from C:\Windows\SysWOW64\ntdll.dll
#2 0x0186eb00 in ?? ()
#3 0x77140133 in ntdll!KiUserExceptionDispatcher () from C:\Windows\SysWOW64\ntdll.dll
#4 0x0086eb00 in ?? ()
#5 0x0186ef60 in ?? ()
我正在使用Windows 7 x64系统和x86 amd app sdk 2.9版本与MinGW。所以我要链接libOpenCL.a。每当我尝试使用以下方法获取系统中的设备数量时:
result = clGetPlatformIDs(0, NULL, &platforms);
我得到了那些段错误。也!有时我得到SIGI
L错误Segmentation fault, illegal instruction
。我怎样才能解决这个奇怪的错误?如果我在调用这些代码行的断点上的gdb中键入clGetPlatformIds
,我也无法进入step
,我立即得到一个或另一个段错误。我知道在这个网站上已有一个关于OpenCL中的段错误的话题,但是!我重新检查了,我正在链接amd app sdk库,我只是将它从目录中移除而gcc打印出来gcc.exe: error: C:/MinGW/lib/libOpenCL.a: No such file or directory
所以,我不知道错误。<\ n / p>
更新
我设法在clGetPlatformIds
warning:
STATUS_STACK_BUFFER_OVERRUN encountered
Program received signal SIGTRAP, Trace/breakpoint trap.
0x768c025e in KERNEL32!GetProfileStringW () from C:\Windows\syswow64\kernel32.dll
(gdb) backtrace
#0 0x768c025e in KERNEL32!GetProfileStringW () from C:\Windows\syswow64\kernel32.dll
#1 0x779117b4 in RPCRT4!I_RpcInitHttpImports () from C:\Windows\syswow64\rpcrt4.dll
#2 0x77895dce in RpcExceptionFilter () from C:\Windows\syswow64\rpcrt4.dll
#3 0x77e9b499 in ntdll!LdrRemoveLoadAsDataTable () from C:\Windows\SysWOW64\ntdll.dll
#4 0x0194dd08 in ?? ()
#5 0x77e9b46b in ntdll!LdrRemoveLoadAsDataTable () from C:\Windows\SysWOW64\ntdll.dll
#6 0x0194dd08 in ?? ()
#7 0x77e50133 in ntdll!KiUserExceptionDispatcher () from C:\Windows\SysWOW64\ntdll.dll
#8 0x0094dd08 in ?? ()
#9 0x0194dd58 in ?? ()
#10 0x767e3f5f in msvcrt!_except_handler4_common () from C:\Windows\syswow64\msvcrt.dll
#11 0x767e3ed7 in msvcrt!_except_handler4_common () from C:\Windows\syswow64\msvcrt.dll
#12 0x7612bbf8 in CM_Locate_DevNodeA () from C:\Windows\syswow64\cfgmgr32.dll
#13 0x77e9b499 in ntdll!LdrRemoveLoadAsDataTable () from C:\Windows\SysWOW64\ntdll.dll
#14 0x0194e524 in ?? ()
#15 0x77e9b46b in ntdll!LdrRemoveLoadAsDataTable () from C:\Windows\SysWOW64\ntdll.dll
#16 0x0194e524 in ?? ()
#17 0x77e50133 in ntdll!KiUserExceptionDispatcher () from C:\Windows\SysWOW64\ntdll.dll
#18 0x0094e524 in ?? ()
#19 0x0194e574 in ?? ()
#20 0x767e3f5f in msvcrt!_except_handler4_common () from C:\Windows\syswow64\msvcrt.dll
#21 0x767e3ed7 in msvcrt!_except_handler4_common () from C:\Windows\syswow64\msvcrt.dll
#22 0x7612bbf8 in CM_Locate_DevNodeA () from C:\Windows\syswow64\cfgmgr32.dll
#23 0x77e9b499 in ntdll!LdrRemoveLoadAsDataTable () from C:\Windows\SysWOW64\ntdll.dll
#24 0x0194ed40 in ?? ()
#25 0x77e9b46b in ntdll!LdrRemoveLoadAsDataTable () from C:\Windows\SysWOW64\ntdll.dll
#26 0x0194ed40 in ?? ()
#27 0x77e50133 in ntdll!KiUserExceptionDispatcher () from C:\Windows\SysWOW64\ntdll.dll
#28 0x0094ed40 in ?? ()
#29 0x0194ed90 in ?? ()
#30 0x00000000 in ?? ()
更新2
我尝试将OpenCL.lib
用于amd sdk附带的vc ++,它运行正常。我在视觉工作室做了一个测试应用程序,它调用clGetPlatformIDs
并且它与MinGW相反正常工作。我查看了VC版本和MinGW版本中加载的模块。不同的是,MinGW正在加载
0x6cbd1000 0x6cbe2d02 Yes (*) C:\Windows\system32\OpenCL.dll
在Visual Studio中,OpenCL从以下版本加载:
C:\Windows\SysWOW64\OpenCL.dll
MSVC应用程序是为win32架构而构建的。 VC版本也是如此,但OpenCL.lib
似乎与AMD APP SDK的MinGW版本libOpenCL.a
的功能不同。我尝试更改为2.9.1 SDK,但结果是一样的!
更新3
我使用gdb对汇编代码进行了一些研究。在调用clGetPlatformIDs
程序后,successuffly执行一些指令,然后模块更改为C:\Windows\System32\opencl.dll
:
=> 0x401a50 <main@4+57>: movl $0x0,(%esp)
(gdb)
0x00401a57 189 cl_int tN = clGetPlatformIDs(0,NULL,&numPlatforms);
1: x/i $pc
=> 0x401a57 <main@4+64>: call 0x402410 <clGetPlatformIDs@12>
(gdb) stepi
0x00402410 in clGetPlatformIDs@12 ()
1: x/i $pc
=> 0x402410 <clGetPlatformIDs@12>: jmp *0x409270
(gdb) nexti
0x6cbd3480 in clGetPlatformIDs () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd3480 <clGetPlatformIDs>: push %ebp
(gdb)
所以我假设没有链接问题吧?我的意思是,代码在OpenCL.dll
中执行一切都应该没问题。然后发生以下情况,(我使用nexti
命令):
0x6cbd3485 in clGetPlatformIDs () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd3485 <clGetPlatformIDs+5>: call 0x6cbd1030
(gdb)
0x6cbd1030 in ?? () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd1030: cmpl $0x0,0x6cbdeda0
(gdb) nexti
0x6cbd1037 in ?? () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd1037: jne 0x6cbd1043
(gdb) nexti
0x6cbd1039 in ?? () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd1039: call 0x6cbd3a50 <clWaitForEvents+128>
(gdb) nexti
0x6cbd3a50 in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd3a50 <clWaitForEvents+128>: push $0x0
(gdb)
0x6cbd3a52 in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd3a52 <clWaitForEvents+130>: push $0x0
(gdb)
0x6cbd3a54 in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd3a54 <clWaitForEvents+132>: push $0x6cbd3a70
(gdb)
0x6cbd3a59 in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd3a59 <clWaitForEvents+137>: push $0x6cbdeda8
(gdb)
0x6cbd3a5e in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd3a5e <clWaitForEvents+142>: call *0x6cbda010
(gdb)
warning:
STATUS_STACK_BUFFER_OVERRUN encountered
Program received signal SIGTRAP, Trace/breakpoint trap.
0x768c025e in KERNEL32!GetProfileStringW () from C:\Windows\syswow64\kernel32.dll
所以clGetPlatformIDs
正在调用一些Proc,它正在调用clWaitForEvents
,然后clWaitForEvents
正在调用*0x6cbda010
处的内容,这会导致崩溃。这个&#39;东西&#39;在*0x6cbda010
是一个kernel32函数(这里我正在stepi
查看调用内容):
0x6cbd3a5e in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
1: x/i $pc
=> 0x6cbd3a5e <clWaitForEvents+142>: call *0x6cbda010
(gdb) stepi
0x7689d5f7 in KERNEL32!InitOnceExecuteOnce () from C:\Windows\syswow64\kernel32.dll
1: x/i $pc
=> 0x7689d5f7 <KERNEL32!InitOnceExecuteOnce>: mov %edi,%edi
如果我继续走得更远,那么跟踪将会是这样的
(gdb) backtrace
#0 0x6cbd4725 in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
#1 0x77e7c057 in ntdll!LdrEnumerateLoadedModules () from C:\Windows\SysWOW64\ntdll.dl
#2 0x6cbdeda8 in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
#3 0x7689d60e in KERNEL32!InitOnceExecuteOnce () from C:\Windows\syswow64\kernel32.dl
#4 0x6cbd3a64 in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
#5 0x00401a5c in main@4 (some=0x0) at cl.c:189
另一种痕迹,(由于某种原因,有??
代替clWairForEvents
)
#0 0x6cbd1050 in ?? () from C:\Windows\system32\OpenCL.dll
#1 0x77e7c057 in ntdll!LdrEnumerateLoadedModules () from C:\Windows\SysWOW64\ntdll.dll
#2 0x6cbdeda8 in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
#3 0x7689d60e in KERNEL32!InitOnceExecuteOnce () from C:\Windows\syswow64\kernel32.dll
#4 0x6cbd3a64 in clWaitForEvents () from C:\Windows\system32\OpenCL.dll
#5 0x00401a5c in main@4 (some=0x0) at cl.c:189
实际崩溃之前的堆栈跟踪如下所示。那么到底为什么clWaitForEvents
会导致崩溃?我认为问题出在clWaitForEvents
函数
答案 0 :(得分:0)
编译内容时遇到了类似的问题 结果是32位/ 64位地址问题。
C:\ Windows \ system32 \ OpenCL.dll(32位)
C:\ Windows \ SysWOW64 \ OpenCL.dll(64位)
现在为解决方案。