获取nvidia显卡温度的方法

 

int i=0;
unsigned long cnt;
NvAPI_Status status;
NvDisplayHandle hDisplay_a[NVAPI_MAX_PHYSICAL_GPUS * 2] = {0};
NvPhysicalGpuHandle nvGPUHandle;
//-----------------------------------------------------

status = NvAPI_Initialize();//初始化,nvapi.dll只能动态加载
if (status != NVAPI_OK)
{
NvAPI_ShortString string;
NvAPI_GetErrorMessage(status, string);
TRACE("NVAPI NvAPI_Initialize: %s/n", string);
return false;
}

//-----------------------------------------------------

NV_DISPLAY_DRIVER_VERSION version = {0};
version.version = NV_DISPLAY_DRIVER_VERSION_VER;
status = NvAPI_GetDisplayDriverVersion(NVAPI_DEFAULT_HANDLE, &version);
if (status != NVAPI_OK)
{
NvAPI_ShortString string;
NvAPI_GetErrorMessage(status, string);
TRACE("NVAPI NvAPI_GetDisplayDriverVersion: %s/n", string);
return false;
}

//-----------------------------------------------------

status = NvAPI_EnumNvidiaDisplayHandle(i, &hDisplay_a[i]);//查找显示卡
if (status != NVAPI_OK)
{
NvAPI_ShortString string;
NvAPI_GetErrorMessage(status, string);
TRACE("NVAPI NvAPI_EnumNvidiaDisplayHandle: %s/n", string);
return false;
}

//-----------------------------------------------------

status = NvAPI_GetPhysicalGPUsFromDisplay(hDisplay_a[0], &nvGPUHandle, &cnt);
if (status != NVAPI_OK)
{
NvAPI_ShortString string;
NvAPI_GetErrorMessage(status, string);
TRACE("NVAPI NvAPI_GetPhysicalGPUsFromDisplay: %s/n", string);
return false;
}

//-----------------------------------------------------
NvU32 temp = 0;

NV_GPU_THERMAL_SETTINGS set = {0};
set.version = NV_GPU_THERMAL_SETTINGS_VER;
set.count = NVAPI_MAX_THERMAL_SENSORS_PER_GPU;
set.sensor[NVAPI_MAX_THERMAL_SENSORS_PER_GPU].controller = NVAPI_THERMAL_CONTROLLER_UNKNOWN;
set.sensor[NVAPI_MAX_THERMAL_SENSORS_PER_GPU].currentTemp = temp;//当前温度
set.sensor[NVAPI_MAX_THERMAL_SENSORS_PER_GPU].target = NVAPI_THERMAL_TARGET_GPU;

status = NvAPI_GPU_GetThermalSettings(nvGPUHandle, 0 ,&set);
if (status != NVAPI_OK)
{
NvAPI_ShortString string;
NvAPI_GetErrorMessage(status, string);
TRACE("NVAPI NvAPI_GPU_GetThermalSettings: %s/n", string);
return false;
}

TRACE("NVAPI Current Temp: %u C/n",set.sensor[0].currentTemp);
TRACE("NVAPI GPU Handle: %u/n",nvGPUHandle); // TODO: Add your control notification handler code here
return 2; 
}

你可能感兴趣的:(获取nvidia显卡温度的方法)