简体   繁体   English

如何在编译的程序中获取函数和全局变量的 CUDA 驱动模块句柄?

[英]How can I get the CUDA driver module handle for functions and globals in the compiled program?

The CUDA Runtime API has the functions cudaGetSymbolAddress() and cudaGetSymbolSize() for working with device-side globals from host-side code, using their names (source-code identifiers) as handles. CUDA 运行时 API 具有函数cudaGetSymbolAddress()cudaGetSymbolSize()用于处理来自主机端代码的设备端全局变量,使用它们的名称(源代码标识符)作为句柄。

In the Driver API, we have cuModuleGetGlobal() , which lets us do the same thing... except that it takes a CUmodule which the global symbol is situated in. If you're working with code that you dynamically compiled and loaded/added into a module then you're all set.在驱动程序 API 中,我们有cuModuleGetGlobal() ,它可以让我们做同样的事情......除了它需要一个全局符号所在的 CUmodule。如果您正在使用动态编译和加载/添加的代码进入一个模块,然后你就准备好了。 But what if those globals are part of your program, compiled statically using NVCC rather than loaded dynamically?但是,如果这些全局变量是您程序的一部分,使用 NVCC 静态编译而不是动态加载呢?

I would assume that there's some sort of "primary module" or "default module" for each compiled program, with its baked-in globals and functions.我会假设每个编译的程序都有某种“主模块”或“默认模块”,其中包含内置的全局变量和函数。 Can I get a handle for it?我能得到它的句柄吗?

I would assume that there's some sort of "primary module" or "default module" for each compiled program, with its baked-in globals and functions.我会假设每个编译的程序都有某种“主模块”或“默认模块”,其中包含内置的全局变量和函数。

There is, and if you pull apart the runtime API emitted host boilerplate code which makes it work and some runtime traces, you will see it relies on a lot of statically defined symbols and a couple of undocumented runtime API functions which internally maintain the module the runtime API uses.有,如果你拆开运行时 API 发出的主机样板代码,使其工作和一些运行时跟踪,你会看到它依赖于许多静态定义的符号和几个未记录的运行时 API 函数,它们在内部维护模块运行时 API 使用。

Can I get a handle for it?我能得到它的句柄吗?

Using the driver API, no.使用驱动API,没有。 If you need to interact with the runtime API, then use the runtime API.如果需要与运行时 API 交互,则使用运行时 API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM