如何在main()之外调用CUDA函数?
我对 CUDA 编程非常陌生,而且设置起来并不困难。我正在使用驱动程序 API,我修改了编译工作流程,并且我所有的学习内核和主机程序都运行良好。我直接从 cuda 源示例中学习,因为 SDK 主要依赖它们。一切都很完美。
但我试图将我的程序从经典控制台示例扩展到 GUI,并且我很难调用经典 main() 函数之外的任何 cuda 函数。我在 Win32 下,任何 main() 外部的调用都会导致“访问冲突”,在 main() 内部调用内核或设备查询函数可以正常工作,gui 程序也可以正常工作。所有 API 调用(包括 cuInit())都会发生这种情况,因此,使上下文成为当前上下文、推送和弹出上下文是不可能的。如果您查看 SDK 示例,您会发现所有这些示例都在 main() 中进行编码。
有人对这个问题有线索吗?你也遇到这种情况吗?如何修复它?
非常感谢您提前提出的意见。
信息:
- CUDA SDK 版本:4.0
- 设备:GeForce GTS 450 (GF106),设备功能 2.1
- Win32 平台(Win7 x64 和 WOW64)。
- CUDA Driver API
- Host 程序用D 编程语言编写。
I'm very new to CUDA programming and have NOT had a hard time setting it all up. I'm using the driver API, i've modified the compilation workflow and all of my learning kernels and host programs work great. I'm learning directly from the cuda source samples as the SDK rely mostly on them. Everything is just perfect.
But i'm trying to extend my programs from the classic console example to a GUI and i am having a hard time calling any cuda function outside the classic main() function. I'm under Win32 and any call outside main() results in an "access violation", calling kernels or device query functions inside main() works ok, the gui program works ok too. This happends with all the API calls including cuInit(), so, making contexts current, pushing and popping contexts are not posible. If you take a look at the SDK examples, all of them are coded within main().
Does anyone have a clue about this issue? Does this happends to you as well? How to fix it?
Thank you very much for your comments in advance.
INFO:
- CUDA SDK version: 4.0
- Device: GeForce GTS 450 (GF106), Device Capability 2.1
- Win32 platform (Win7 x64 with WOW64).
- CUDA Driver API
- Host program made with the D programming language.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有成千上万的程序完全在 main 之外使用 CUDA,问题更有可能是您的程序是用 D 而不是 C/C++ 编写的。这并不是说它不能工作(我从未使用过 D),但您需要记住您正在调用 C API 并且 C 是非托管的。
There are thousands of programs that use CUDA entirely outside main, the problem is more likely to be that your program is written in D and not C/C++. That's not to say it can't work (I've never used D) but you will need to remember that you are calling into a C API and that C is unmanaged.