在 VS2008 中调试从 .NET 代码调用的 CUDA 内核,仿真模式
CUDA 可以选择在仿真模式下编译代码,它们提供的 .rules 文件支持该选项。
我有 C# .NET 3.5 SP1 代码,使用 DllImport 调用本机 dll, 原生dll是通过VS2008使用nvcc编译的,其功能是与CUDA之间传输内存并调用CUDA内核。
当 CUDA 内核正确时,一切都运行良好,但是当出现错误时,我只能进入代码,直到内核的标题并查看它们接收的参数。 (我在启动项目的调试选项中启用了调试本机代码。)
我尝试使用仿真模式进行编译,但是在调用 CUDA memcopy 主机-->设备时出现 CUDA 错误“混合设备执行”。 我尝试将 alloc+dealloc+memcopy 与其等效的非 CUDA 版本切换, 但调用内核时会发生相同的错误。
我在尝试使用调试仿真模式时做错了什么?
PS我在Vista x64 SP1 + VS2008上尝试过这个,在x86和x64上都编译了相同的解决方案,两者都不能在仿真模式下工作,都可以在非仿真模式下工作。
CUDA has an option to compile code in emulation mode, which is supported in the .rules file they provide.
I have C# .NET 3.5 SP1 code that calls a native dll, using DllImport,
the native dll is compiled via VS2008 using nvcc and its function is to transfer memory from and to CUDA and to invoke CUDA kernels.
When the CUDA kernels are correct, everything runs fine, but when there is a bug, I can only step in to the code until the title of the kernels and see the parameters they receive.
(I enabled debugging native code in the startup-project's debug options.)
I have tried compiling with emulation mode, however I get the CUDA error "mixed device execution" when calling the CUDA memcopy host-->device.
I tried switching the alloc+dealloc+memcopy with their equivalent non-CUDA versions,
but then the same error occurs when invoking the kernels.
What did I do wrong in my attempt to using the debug-emulation mode?
P.S. I tried this on Vista x64 SP1 + VS2008, with the same solution complied in both x86 and x64, neither worked in emulation mode, both worked in non-emulation mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 CUDA 编程指南 p44:
在此模式下编译应用程序时(使用 -deviceemu 选项),设备代码为
为主机编译并运行,允许程序员使用主机的本机
调试支持来调试应用程序,就好像它是主机应用程序一样。这
预处理器宏DEVICE_EMULATION就是在此模式下定义的。所有代码
对于应用程序,包括使用的任何库,必须一致地编译
用于设备仿真或设备执行。为设备编译的链接代码
使用为设备执行而编译的代码进行仿真会导致以下运行时
初始化时返回的错误:cudaErrorMixedDeviceExecution。
您是否只有一个为 EMU 重新编译的 DLL,或者是否还有其他不是 CUDA utils 库的 DLL?
这正如我在启用 EMU 的 Win7 x64 编译 Debug|x86 上所期望的那样。
以下是我正在使用的编译器和链接器设置:
From the CUDA Programming Guide p44:
When compiling an application in this mode (using the -deviceemu option), the device code is
compiled for and runs on the host, allowing the programmer to use the host’s native
debugging support to debug the application as if it were a host application. The
preprocessor macro DEVICE_EMULATION is defined in this mode. All code
for an application, including any libraries used, must be compiled consistently either
for device emulation or for device execution. Linking code compiled for device
emulation with code compiled for device execution causes the following runtime
error to be returned upon initialization: cudaErrorMixedDeviceExecution.
Do you just have a single DLL which you've recompiled for EMU or are there other DLLs which aren't for example the CUDA utils library?
This works as I'd expect on Win7 x64 compiling Debug|x86 with EMU enabled.
Here are the compiler and linker settings I'm using:
该问题是由于缺少复制 SDK 模拟 DLL 的构建事件(仅复制 TOOLKIT DLL)以及一些常规库而不是模拟库而引起的。
The issue was caused by a missing build event to copy the SDK emulation DLLS (only the TOOLKIT DLLs were copied) and a few regular libs instead of emulation libs.