NVIDIA显卡在硬件上有温度传感器,可以感知显卡的运行环境。温度数据的获取,一般是通过调用NVIDIA的SDK的相关函数即可。SDK的下载的网址(https://developer.nvidia.com/nvapi),里面有一些sample code可以参考。获取温度的函数是NvAPI_GPU_GetThermalSettings。参考代码如下:
int main(){NvAPI_Status ret = NVAPI_OK;ret = NvAPI_Initialize();if(ret != NVAPI_OK){printf("NvAPI_Initialize() failed = 0x%x", ret);return 1; // Initialization failed}NvPhysicalGpuHandle hPhysicalGpu[NVAPI_MAX_PHYSICAL_GPUS];for (NvU32 PhysicalGpuIndex = 0; PhysicalGpuIndex < NVAPI_MAX_PHYSICAL_GPUS; PhysicalGpuIndex++){