【问题标题】:C Program to get GPU temp获取GPU温度的C程序
【发布时间】:2021-03-29 20:55:11
【问题描述】:

所以在Linux中有一个命令叫做

nvidia-settings -q=[gpu:0]/GPUCoreTemp

这让我看到我的 GPU 的温度为 41°C。

Attribute 'GPUCoreTemp' (devnux:0[gpu:0]): 41.
'GPUCoreTemp' is an integer attribute.
'GPUCoreTemp' is a read-only attribute.
'GPUCoreTemp' can use the following target types: X Screen, GPU.

是否有可能以类似的整数形式直接获取 C 中的温度?否则,当我想持续检查温度时,我将不得不读取输出并对其进行修整。

【问题讨论】:

  • 您可能可以从/proc 的某个文件中读取它。还是您要求 Windows?
  • 我要Linux

标签: c gpu nvidia monitor temp


【解决方案1】:

您可以使用 Nvidia 管理库 (nvml) 访问该信息。 我用 nvcc 编译了这个:

#include <stdio.h>
#include <nvml.h>
int main(){

    nvmlReturn_t result;
    unsigned int temp;
    nvmlDevice_t device;

    result = nvmlInit();
    if(NVML_SUCCESS != result){
                    printf("failed to initialyse nvml \n");
                    return 1;
    }
    result = nvmlDeviceGetHandleByIndex(0, &device);
    result = nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &temp);
    if (NVML_SUCCESS != result) {
            printf("Failed to get temperature of device %i: %s\n", 0, nvmlErrorString(result));
    }else{
            printf("%d\n", temp);
    }

    return 0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多