CUDA 插件 dlopen

发布于 2024-09-24 03:07:41 字数 527 浏览 2 评论 0原文

我编写了一个 cuda 插件(动态库),并且我有一个用 C 编写的程序,它使用 dlopen() 来加载该插件。我正在使用 dlsym() 从该插件获取函数。对于我的应用程序来说,任何时候加载插件时,程序都会通过 dlopen() 调用获得新的句柄(库文件可能随后会被修改),这一点非常重要。 因此,在使用我的插件中的函数之后,我调用 dlclose()。调用 dlopen() - dlsym() - dlclose() 发生在我的程序执行期间(在循环中)。

如果我在使用 NVIDIA 驱动程序 256.35(CUDA 3.0 或 3.1)的计算机上工作,则会出现内存泄漏(我在插件 cudaMemGetInfo() 中使用调用诊断)。 如果我在使用 NVIDIA 驱动程序 195.36.15 (CUDA 3.0) 的计算机上工作,程序执行一段时间后会出现错误:“NVIDIA:无法打开设备文件 /dev/nvidia0(打开的文件太多)。”

如果我不使用 dlclose() 调用,程序运行正常,但在这种情况下,我无法在程序执行期间将插件替换为新插件。

有人遇到过这个问题吗? 谢谢。

I've written a cuda plugin (dynamic library), and I have a program written in C which uses dlopen() to load this plugin. I am using dlsym() to get the functions from this plugin. For my application it is very important that any time of loading plugin the program gets a new handle with dlopen() calling (the library file may modified subsequently).
Therefore after the using of functions from my plugin I invoke the dlclose(). The invocations dlopen() - dlsym() - dlclose() are occur during my program execution (in the loop).

If I working on the computer with NVIDIA driver 256.35 (CUDA 3.0 or 3.1) I have a memory leak (I use in my plugin cudaMemGetInfo() calling for the diagnostics).
If I working on the computer with NVIDIA driver 195.36.15 (CUDA 3.0) I have an error after some time of the program execution: “NVIDIA: could not open the device file /dev/nvidia0 (Too many open files).”

If I don't use the dlclose() invocation the program is working fine, but in this case I can't replace the plugin on a new one's during my program execution.

Anyone encountered this problem?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

所有深爱都是秘密 2024-10-01 03:07:41

没人写CUDA插件吗?

我在 CUDA SDK 上找到了类似的示例:matrixMulDynlinkJIT。我对代码做了一些小修正。特别是,在文件 cuda_drvapi_dynlink.c 中,我更正了 cuInit() 函数:

CUDADRIVER CudaDrvLib = NULL;

CUresult CUDAAPI cuInit(unsigned int Flags)

{

    //CUDADRIVER CudaDrvLib;

    CUresult result;
    int driverVer;

    if (CudaDrvLib != NULL) {
      dlclose (CudaDrvLib);
      CudaDrvLib = NULL;
    }
     .......
}

并在文件 matrixMulDynlinkJIT.cpp 中添加了在 main() 函数中循环:

int main(int argc, char** argv)

{

   printf("[ %s ]\n", sSDKsample);


    while (1) {
       // initialize CUDA

       CUfunction matrixMul = NULL;
       cutilDrvSafeCallNoSync(initCUDA(&matrixMul, argc, argv));

        .....

    }//while (1)
    cutilExit();
}

所以,我遇到了与我的程序相同的问题(执行一段时间后):“NVIDIA:无法打开设备文件 /dev/nvidia0(打开的设备文件太多)文件)”。
但是当我注释掉 cuda_drvapi_dynlink.c 文件中的 dlclose() 时 – 一切正常,

我无法理解这种行为......
有什么想法吗?

Nobody wrote plugins on CUDA?

I've found the similar example on CUDA SDK: matrixMulDynlinkJIT. I've done small correction in the code. In particular, in the file cuda_drvapi_dynlink.c I've corrected cuInit() function:

CUDADRIVER CudaDrvLib = NULL;

CUresult CUDAAPI cuInit(unsigned int Flags)

{

    //CUDADRIVER CudaDrvLib;

    CUresult result;
    int driverVer;

    if (CudaDrvLib != NULL) {
      dlclose (CudaDrvLib);
      CudaDrvLib = NULL;
    }
     .......
}

And in the file matrixMulDynlinkJIT.cpp I've added loop in the main() function:

int main(int argc, char** argv)

{

   printf("[ %s ]\n", sSDKsample);


    while (1) {
       // initialize CUDA

       CUfunction matrixMul = NULL;
       cutilDrvSafeCallNoSync(initCUDA(&matrixMul, argc, argv));

        .....

    }//while (1)
    cutilExit();
}

So, I have the same problem like in my program (after some time execution): “NVIDIA: could not open the device file /dev/nvidia0 (Too many open files).”
But when I comment out the dlclose() in the cuda_drvapi_dynlink.c file – all works fine

I can't understand this behavior...
Any ideas?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文