jow*_*iri 5 c++ nvidia intel opencl
我是OpenCL的新手。在运行Windows 7的具有Intel(R)HD Graphics 4000的Core i5计算机上工作,我安装了支持OpenCL的最新Intel驱动程序。GpuCapsViewer确认我具有OpenCL支持设置。我使用英特尔OpenCL SDK开发了一个简单的HelloWorld程序。我已经成功编译了程序,但是运行时,由于分段错误而调用clGetPlatformIDs()时,它崩溃了。这是我的代码:
#include <iostream>
#include <CL/opencl.h>
int main() {
std::cout << "Test OCL without driver" << std::endl;
cl_int err;
cl_uint num_platforms;
err = clGetPlatformIDs(0, NULL, &num_platforms);
if (err == CL_SUCCESS) {
std::cout << "Success. Platforms available: " << num_platforms
<< std::endl;
} else {
std::cout << "Error. Platforms available: " << num_platforms
<< std::endl;
}
std::cout << "Test OCL without driver" << std::endl;
std::cout << "Press button to exit." << std::endl;
std::cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
GpuCapsViewer如何成功确认OpenCL支持并可以使用它运行其演示,但我却无法运行我的代码?两者必须使用相同的功能,对吗?
已经为此工作了几天。甚至尝试重新安装驱动程序。有任何想法吗?
GpuCapsViewer说:
驱动程序:R295.93(r295_00-233)/ 10.18.10.3496(3-11-2014)
OPENGL:OpenGL 4.2(GeForce GT 630M / PCIe / SSE2具有290 ext。)
OPENCL:OpenCL 1.1,GeForce GT 630M计算单位:2 @ 950MHz
CUDA:GeForce GT 630M CC:2.1,多处理器:2 @ 950MHz
PHYSX:GPU PhysX(NVIDIA GeForce GT 630M)
MULTI-GPU:不支持多GPU(2个物理GPU)
更新:
编译行:
g++ -I"C:\Program Files (x86)\Intel\OpenCL SDK\4.4\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Test3.d" -MT"Test3.d" -o "Test3.o" "../Test3.cpp"
Finished building: ../Test3.cpp
Run Code Online (Sandbox Code Playgroud)
链接器行:
g++ -L"C:\Program Files (x86)\Intel\OpenCL SDK\4.4\lib\x64" -o "TestOpenCL" ./HelloWorld.o ./HelloWorld2.o ./Test3.o -lOpenCL
Finished building target: TestOpenCL
Run Code Online (Sandbox Code Playgroud)
操作系统:Windows 7 Ultimate Version 6.1(内部版本7601:Service Pack 1)
更新2,崩溃信息:
Problem Event Name: APPCRASH
Application Name: TestOpenCL.exe
Application Version: 0.0.0.0
Application Timestamp: 53bc6ac5
Fault Module Name: TestOpenCL.exe
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 53bc6ac5
Exception Code: c0000005
Exception Offset: 0000000000002cc0
OS Version: 6.1.7601.2.1.0.256.1
Locale ID: 1033
Additional Information 1: 56e3
Additional Information 2: 56e3743a8a234df3bdeba0b507471c44
Additional Information 3: 8fe0
Additional Information 4: 8fe0ef5706153941955de850e5612393
Run Code Online (Sandbox Code Playgroud)
更新3:
使用DependencyWalker(http://dependencywalker.com/)来替代dumpbin。它生成以下警告:
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
Run Code Online (Sandbox Code Playgroud)
警告似乎是指以下所有DLL,这些DLL都标有“错误打开文件。系统找不到指定的文件(2)”错误消息。
API-MS-WIN-CORE-COM-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-0.DLL
DCOMP.DLL
IESHIMS.DLL
Run Code Online (Sandbox Code Playgroud)
更新4,GDB BACKTRACE:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000402cc0 in clGetPlatformIDs ()
(gdb) backtrace full
#0 0x0000000000402cc0 in clGetPlatformIDs ()
No symbol table info available.
#1 0x0000000000402af3 in main () at ../Test3.cpp:11
err = 0
num_platforms = 0
platform = 0x0
(gdb) backtrace
#0 0x0000000000402cc0 in clGetPlatformIDs ()
#1 0x0000000000402af3 in main () at ../Test3.cpp:11
Run Code Online (Sandbox Code Playgroud)
更新5,GDB无效:
(gdb) disass
Dump of assembler code for function clGetPlatformIDs:
=> 0x0000000000402cc0 <+0>: jmpq *0x4b74e8(%rip) # 0x8ba1ae
0x0000000000402cc6 <+6>: nop
0x0000000000402cc7 <+7>: nop
End of assembler dump.
Run Code Online (Sandbox Code Playgroud)
更新6,GDB信息已共享:
(gdb) INFO SHARED
From To Syms Read Shared Object Library
0x0000000077191000 0x00000000773384e0 Yes (*) C:\Windows\system32\ntdll.dll
0x0000000077071000 0x000000007718eab4 Yes (*) C:\Windows\system32\kernel32.dll
0x000007fefc081000 0x000007fefc0eb13c Yes (*) C:\Windows\system32\KernelBase.dll
0x000007fedf8d1000 0x000007fedf8e96aa Yes (*) C:\Windows\system32\OpenCL.dll
0x000007fefe101000 0x000007fefe1da628 Yes (*) C:\Windows\system32\advapi32.dll
0x000007fefe061000 0x000007fefe0fe4bc Yes (*) C:\Windows\system32\msvcrt.dll
0x000007fefdcc1000 0x000007fefdcde39a Yes (*) C:\Windows\SYSTEM32\sechost.dll
0x000007fefc6a1000 0x000007fefc7cc914 Yes (*) C:\Windows\system32\rpcrt4.dll
(*): Shared library is missing debugging information.
Run Code Online (Sandbox Code Playgroud)
二进制文件,x64,包括文件夹:
https://drive.google.com/file/d/0BxKA63T2GnKMRW02QWZnam5lSGM/edit?usp=sharing
Run Code Online (Sandbox Code Playgroud)
更新7,GPUcaps情况:
GPUcaps可检测2个GPU:
您可以在此处查看屏幕截图:
https://drive.google.com/file/d/0BxKA63T2GnKMa00tU1gydGNJeXc/edit?usp=sharing
Run Code Online (Sandbox Code Playgroud)
更新8:
根据@antiduh的回答,我一直在尝试直接针对Windows \ System32文件夹中存在的OpenCL.dll进行链接。我正在使用mingw64。我得到这个:
Invoking: Cross G++ Linker
g++ -L"C:\Windows\System32" -o "TestOpenCL" ./HelloWorld.o ./HelloWorld2.o ./Test3.o -lOpenCL
d:/ws/apps_inst/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Windows\System32/OpenCL.dll when searching for -lOpenCL
d:/ws/apps_inst/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Windows\System32/OpenCL.dll when searching for -lOpenCL
d:/ws/apps_inst/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lOpenCL
d:/ws/apps_inst/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Windows\System32/msvcrt.dll when searching for -lmsvcrt
d:/ws/apps_inst/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Windows\System32/advapi32.dll when searching for -ladvapi32
d:/ws/apps_inst/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Windows\System32/shell32.dll when searching for -lshell32
d:/ws/apps_inst/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Windows\System32/user32.dll when searching for -luser32
d:/ws/apps_inst/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Windows\System32/kernel32.dll when searching for -lkernel32
d:/ws/apps_inst/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.1/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\Windows\System32/msvcrt.dll when searching for -lmsvcrt
Run Code Online (Sandbox Code Playgroud)
更新9:现在,我可以使用以下代码行手动编译,链接和运行示例代码。
g++ -I. s.cpp -L. -lOpenCL
Run Code Online (Sandbox Code Playgroud)
我简化了一切,并且一切正常。这显然与Eclipse使用的compile和link命令有很大不同。知道eclipse使用哪个参数会引起问题吗?而且,为什么eclipse首先在两个单独的步骤中编译为目标文件,然后尝试链接它们?
程序使用外部库的方式共有三种:
您通常无法在没有 .lib 的情况下链接 dll。编译器希望将这些函数调用引用解析为真实地址,但我们不想放入真实地址,因为我们希望将 DLL 加载到任意内存地址(DLL 是“可重定位的”)。
根据我的理解,用作导入库的 .lib 包含主程序直接链接的存根 - 因此程序中的所有调用都通过存根。然后存根引用“导入地址表”。当操作系统将 DLL 加载到进程的内存中时,它通过填写 IAT 来实现。然后存根只是通过进行引用正确的间接跳转来调用 DLL IAT 中的插槽。
因此,如果 DLLMathLib具有Factorial我的 exe 正在导入的导出函数,那么导入 .lib 文件具有一个实际函数 Factorial,我的 exe 静态编译该函数。该 .lib 中的因子类似于以下伪代码:
int Factorial( int value ) {
// Read MathLib's IAT which should always be at address 0x8ba100.
// Factorial's real address gets stored in slot 2, so add 8 to the address
// to read from.
__asm jmp *0x8ba108; // nb this is an indirect jump.
}
Run Code Online (Sandbox Code Playgroud)
然后我们希望当操作系统加载那个 DLL 时,IAT 被正确填写,否则我们会跳入虚无。
所以我认为发生的事情是您正在针对一个 .lib 进行编译,但是“加载时”链接到了错误的 opencl.dll。IAT 从未被创建,或者创建在错误的位置,所以你跳入了虚无;这就是为什么这一行创建了一个段错误:
0x0000000000402cc0 <+0>: jmpq *0x4b74e8(%rip) # 0x8ba1ae
所以让我们弄清楚为什么我们链接错误。您的计算机上可能有 3 组 opencl.dll/opencl.lib 文件:
您实际拥有这些文件中的哪些?我的估计是这样的:
c:\windows\system32.您肯定是在针对 Intel opencl.lib 进行链接,但似乎是在c:\windows\system32. 一种解决方案是让程序在运行程序时加载 Intel opencl.dll,方法是将它们的 dll 放在程序目录中。
但是,您声明您可以使用以下编译行使事情正常工作:
g++ -I. s.cpp -L. -lOpenCL
有在Windows上的东西整齐约GCC -链接,以便对一个图书馆,你没有需要有.LIB。Gcc 通过检查 dll 为您计算出来;当有人给他们一个 dll 但没有 lib 时,其他人已经想出了如何做同样的事情。在大多数其他编译器中,尤其是 Visual Studio,您需要有一个 .lib 和一个 .dll 来链接某些东西。这就是 Win SDK 安装数百个 .lib(例如,kernel32.lib)的原因。事实证明,如果编译器愿意,它实际上可以推断出它,但库作为一种古老的机制存在。
无论如何,您在 gcc 链接行上方运行了它,它使用搜索路径找到了一个合适的 opencl.dll,为它发明了自己的 .lib,并针对它进行了编译;你启动了你的程序,它使用相同的搜索路径来获取 opencl.dll,它与你编译的相同,所以你的程序运行。哇。
我还有一些建议:
关于 libs 和 dll 的一些更相关的问题:
| 归档时间: |
|
| 查看次数: |
3165 次 |
| 最近记录: |