【发布时间】:2021-02-04 07:45:59
【问题描述】:
我使用一些 NVIDIA 管理库功能在我的应用程序中生成指标。
每 1 秒我在一个线程中调用 nvmlDeviceGetMemoryInfo(),几分钟后,在 Visual Studio 的输出中,我可以读取数百个:
'MyApp.exe' (Win32): Loaded 'C:\Windows\System32\nvapi64.dll'.
'MyApp.exe' (Win32): Unloaded 'C:\Windows\System32\nvapi64.dll'
...
'MyApp.exe' (Win32): Loaded 'C:\Windows\System32\nvapi64.dll'.
'MyApp.exe' (Win32): Unloaded 'C:\Windows\System32\nvapi64.dll'
'MyApp.exe' (Win32): Loaded 'C:\Windows\System32\nvapi64.dll'.
'MyApp.exe' (Win32): Unloaded 'C:\Windows\System32\nvapi64.dll'
...
来自 NVML 的其他函数,如 nvmlDeviceGetCount()、nvmlDeviceGetHandleByIndex()、nvmlDeviceGetClockInfo() 或 nvmlDeviceGetUtilizationRates() 不会产生 nvapi64.dll 的这种即时加载/卸载。
是否可以避免卸载此 dll,以使其在下次调用 nvmlDeviceGetMemoryInfo() 时可用?
编辑:
我调用这个函数来检索 gpu 内存统计数据:
nvmlMemory_t memInfo;
if (nvmlDeviceGetMemoryInfo(device, &memInfo) == NVML_SUCCESS) {
this->gpuMemUsed = memInfo.used;
this->gpuMemTotal = memInfo.total;
}
我在 Debug 和 Release 中看到这些输出行,每次我调用 nvmlDeviceGetMemoryInfo() 时都会有几个 Loaded nvapi64.dll / Unloaded nvapi64.dll
NVML 随 Cuda V10.2 提供。
【问题讨论】:
-
返回什么?是调试还是发布? NV 版本是多少?您是否还看到,对于一个函数调用,另一个 .dll 被加载/卸载了多次?
-
我已经用所需信息编辑了问题
-
你可以在这个dll已经不会被卸载之后调用
LoadLibraryW(L"nvapi64.dll"); -
我记得几年前的一些 NVidia 驱动程序也有类似的问题。在内部创建了一些 COM 对象,导致加载 NVidia 驱动程序,在 COM 对象被销毁后,dll 立即被卸载,这非常浪费。增加 dll 引用计数将起作用,直到您使用 ATI 显卡...