5

I use some NVIDIA Management Library features to produce metrics in my application.

Every 1 second I call nvmlDeviceGetMemoryInfo() in a thread, and after a few minutes, in the output of Visual Studio, I can read hundreds of :

'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'
...

Other functions from NVML like nvmlDeviceGetCount(), nvmlDeviceGetHandleByIndex(), nvmlDeviceGetClockInfo() or nvmlDeviceGetUtilizationRates() don't produce this ponctual loading/unloading of the nvapi64.dll.

Is it possible to avoid unloading this dll, to keep it available for my next call to nvmlDeviceGetMemoryInfo() ?

EDIT :

I call this function to retreive gpu memory statistics like that :

nvmlMemory_t memInfo;
if (nvmlDeviceGetMemoryInfo(device, &memInfo) == NVML_SUCCESS) {
    this->gpuMemUsed = memInfo.used;
    this->gpuMemTotal = memInfo.total;
}

I see these output line in Debug and Release, each time I call nvmlDeviceGetMemoryInfo() there is on couple of Loaded nvapi64.dll / Unloaded nvapi64.dll

NVML comes with Cuda V10.2 .

SamT
  • 528
  • 4
  • 14
  • What does it return? Is it debug or release? What's the *NV* version? Also did you see that for one function call the other *.dll* is loaded/unloaded several times? – CristiFati Oct 21 '20 at 11:53
  • I have edited the question with required info – SamT Oct 21 '20 at 12:12
  • 3
    you can simply call `LoadLibraryW(L"nvapi64.dll");` after this dll already will be not unloaded – RbMm Oct 30 '20 at 11:03
  • I remember having similar problems with some NVidia driver years ago. Internally there was some COM object created which die cause loading the NVidia driver which after the COM object was destroyed the dll was immediately unloaded which is pretty wasteful. Increasing the dll reference count will work until you get to a machine with an ATI graphics card ... – Alois Kraus Nov 05 '20 at 19:24

1 Answers1

3

you can simply call LoadLibraryW(L"nvapi64.dll"); after this dll already will be not unloaded (RbMm)

This did the trick

SamT
  • 528
  • 4
  • 14