Unable to get the serial number

I was trying to get the board serial number but the functions always return a array filled with 0.

NV_PHYSICAL_GPUS_V1 nvPhysicalGPUs = { 0 };
nvPhysicalGPUs.version = NV_PHYSICAL_GPUS_VER1;
status = NvAPI_SYS_GetPhysicalGPUs(&nvPhysicalGPUs);
if (status != NVAPI_OK)
{
    NvAPI_GetErrorMessage(status, szError);
    printf("\nNvAPI_SYS_GetPhysicalGPUs() failed. The Error code is: %s", szError);
    return -1;
}

for (NvU32 i = 0; i < nvPhysicalGPUs.gpuHandleCount; i++)
{
    printf("\nPhysical_GPUHandle[%d]:0x%p | AdapterType = %d", i, nvPhysicalGPUs.gpuHandleData[i].hPhysicalGpu,
        nvPhysicalGPUs.gpuHandleData[i].adapterType);

    _NV_BOARD_INFO info = { 0 };
    info.version = NV_BOARD_INFO_VER1;
    NvPhysicalGpuHandle gpu = nvPhysicalGPUs.gpuHandleData[i].hPhysicalGpu;
    auto res = NvAPI_GPU_GetBoardInfo(gpu, &info);
    if (res != NVAPI_OK) {
        cout <<  "Fail: " << res << endl;
    }

    cout << endl;

    string serialNumber;
    for (i = 0; i < 16; i++) {
        serialNumber += std::to_string(info.BoardNum[i]);
    }
    cout << serialNumber << endl;
}

Dear @samuel.alvesg

Thank you for contacting the NVIDIA Developer Forum.
I compiled an executable with the code snippet shared by you. Here’re my observations:

  1. On my setup, the API NvAPI_GPU_GetBoardInfo reports the BoardNum array with non-zero values as well.
  2. One issue with the code above is the inner for loop is using the same loop variable defined for the outer loop. So it won’t execute the outer loop more than once even if there are more than one GPUs.

I will seek more information about your setup.

Thank you.
NVAPI Forum Moderator