0

I want to detect video memory using Nvidia API called NvAPI. The problem is that dedicatedVideoMemory always displays 0, but it should display 4096 MB.

Code:

NvAPI_Status result;
result = NvAPI_Initialize();

if (result != NVAPI_OK) {
    NvAPI_ShortString string;
    NvAPI_GetErrorMessage(result, string);
    printf("NVAPI NvAPI_Initialize: %s\n", string);
}

NvU32 cnt;
NvPhysicalGpuHandle phys;
result = NvAPI_EnumPhysicalGPUs(&phys, &cnt);

if (result != NVAPI_OK) {
    NvAPI_ShortString string;
    NvAPI_GetErrorMessage(result, string);
    printf("NVAPI NvAPI_EnumPhysicalGPUs: %s\n", string);
}

NV_DISPLAY_DRIVER_MEMORY_INFO nvidiaDisplayDriverMemory;
NvAPI_GPU_GetMemoryInfo(phys, &nvidiaDisplayDriverMemory);

qDebug() << nvidiaDisplayDriverMemory.dedicatedVideoMemory;
NvAPI_Unload();

Screenshot (NVIDIA Control Panel):

Screenshot (NVIDIA Control Panel):

Questions:

  1. How to fix it?
  2. How to get proper graphics memory detection on AMD/Intel?

Thanks in advance for the help.

Update:

 NvAPI_ShortString ver;
 NvAPI_GetInterfaceVersionString(ver);
 printf("NVAPI Version: %s\n", ver);

 NvAPI_ShortString name;
 NvAPI_GPU_GetFullName(phys, name);

 if (result != NVAPI_OK) {
     NvAPI_ShortString string;
     NvAPI_GetErrorMessage(result, string);
     printf("NVAPI NvAPI_GPU_GetFullName: %s\n", string); // emit signal - error
 }

    printf("Name: %s\n", name);

Now when I add to check version and graphics card name it displays nvidiaDisplayDriverMemory.dedicatedVideoMemory as 4096, but only in Qt debug mode, when I get to release mode, it displays 0. Any ideas? Thanks.

Cobra91151
  • 610
  • 4
  • 14
  • According to the [documentation](http://docs.nvidia.com/gameworks/content/gameworkslibrary/coresdk/nvapi/group__gpu.html#gaf838839f5aca4bd6cdb60fc743ae8ef4) the first parameter is assumed to be of type `NvPhysicalGpuHandle[NVAPI_MAX_PHYSICAL_GPUS]`. Hence if the value of `cnt` is greater than 1 after the call then you've probably got undefined behaviour. – G.M. May 08 '17 at 13:28
  • "Each structure contains a version field which the caller must initialize" from NvAPI Concepts – stark May 08 '17 at 13:37
  • @stark I have checked version: qDebug() << nvidiaDisplayDriverMemory.version; **Output:** 1402088528 – Cobra91151 May 08 '17 at 14:19
  • @G.M. And have checked: `NvU32 cnt; NvPhysicalGpuHandle phys; result = NvAPI_EnumPhysicalGPUs(&phys, &cnt); qDebug() << cnt; qDebug() << result;` **Output:** 1 0 – Cobra91151 May 08 '17 at 14:23

0 Answers0