本文介绍了使用NVAPI从NVidia GPU获取温度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近几天我一直在尝试使用C ++来获取GPU的温度
I have been trying for the last few days to get the temperature of my GPU using C++
使用NVAPI我有以下代码
using the NVAPI i have the following code
#include "stdafx.h"
#include "nvapi.h"
int _tmain(int argc, _TCHAR* argv[])
{
NvAPI_Status ret = NVAPI_OK;
int i=0;
NvDisplayHandle hDisplay_a[NVAPI_MAX_PHYSICAL_GPUS*2] = {0};
ret = NvAPI_Initialize();
if (!ret == NVAPI_OK){
NvAPI_ShortString string;
NvAPI_GetErrorMessage(ret, string);
printf("NVAPI NvAPI_Initialize: %s\n", string);
}
NvAPI_ShortString ver;
NvAPI_GetInterfaceVersionString(ver);
printf("NVAPI Version: %s\n", ver);
NvU32 cnt;
NvPhysicalGpuHandle phys;
ret = NvAPI_EnumPhysicalGPUs(&phys, &cnt);
if (!ret == NVAPI_OK){
NvAPI_ShortString string;
NvAPI_GetErrorMessage(ret, string);
printf("NVAPI NvAPI_EnumPhysicalGPUs: %s\n", string);
}
NvAPI_ShortString name;
NV_GPU_THERMAL_SETTINGS thermal;
ret = NvAPI_GPU_GetFullName(phys, name);
if (!ret == NVAPI_OK){
NvAPI_ShortString string;
NvAPI_GetErrorMessage(ret, string);
printf("NVAPI NvAPI_GPU_GetFullName: %s\n", string);
}
printf("Name: %s\n", name);
thermal.version =NV_GPU_THERMAL_SETTINGS_VER;
ret = NvAPI_GPU_GetThermalSettings(phys,0, &thermal);
if (!ret == NVAPI_OK){
NvAPI_ShortString string;
NvAPI_GetErrorMessage(ret, string);
printf("NVAPI NvAPI_GPU_GetThermalSettings: %s\n", string);
}
printf("Temp: %l C\n", thermal.sensor[0].currentTemp);
return 0;
}
我得到的输出是
NVAPI Version: NVidia Complete Version 1.10
Name: GeForce GTX 680
Temp: C
NVAPI正在初始化,它可以找到我的GPU,它是GTX680,但不会返回温度
So NVAPI is initializing, and it can find my GPU which is a GTX680, but it wont return a temperature
推荐答案
我认为问题在于您需要通过以下方式设置热量设置:
I think that the problem is that you are required to set thermal settings in the following way:
NV_GPU_THERMAL_SETTINGS ThermalInfo;
ThermalInfo.version = NV_GPU_THERMAL_SETTINGS_VER_2;
ThermalInfo.sensor[0].controller = NVAPI_THERMAL_CONTROLLER_GPU_INTERNAL;
ThermalInfo.sensor[0].target = NVAPI_THERMAL_TARGET_GPU;
此外,您还应该写:
NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS];
因为您可能破坏内存. (请注意,请参阅NVAPI随附的文档中的NvAPI_EnumPhysicalGPU.)
because you could corrupt memory. (Note look at NvAPI_EnumPhysicalGPUs in the documentation supplied with NVAPI).
这篇关于使用NVAPI从NVidia GPU获取温度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!