gpt4 book ai didi

visual-c++ - 在 DLLMain 中调用 CUDA 函数

转载 作者:行者123 更新时间:2023-12-04 05:33:05 24 4
gpt4 key购买 nike

我在 Windows 中开发了一个 C++ DLL,它有许多 CUDA 加速功能。
目前我还没有创建 DllMain 函数,因为它不是强制性的。

我知道可以在 DllMain 中调用的函数有很多限制。

我只是想知道在 DllMain 中调用 CUDA 运行时函数只是为了初始化默认上下文是否安全,以便后续的 CUDA 调用更快?

我使用 Visual Studio 2008、CUDA 5.0 和 Windows 8 进行开发。

最佳答案

Reading the DLLMain documentation ,我建议不要这样做。从文档:

Warning There are serious limits on what you can do in a DLL entry point. To provide more complex initialization, create an initialization routine for the DLL. You can require applications to call the initialization routine before calling any other routines in the DLL.



更具体地说:

Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose.



由于 CUDA 运行时 API 需要 cudart.dll,因此这适用于您的问题。

因此,我将为您的库创建一个初始化函数来执行 CUDA 初始化,并要求在应用程序启动时显式调用它。

关于visual-c++ - 在 DLLMain 中调用 CUDA 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12341611/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com