mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
GPU: support Nvidia GPU temp detection
This commit is contained in:
@@ -15,6 +15,7 @@ Features:
|
||||
* Support st version detection (Terminal, Linux)
|
||||
* Support st terminal font detection (TerminalFont, Linux)
|
||||
* Add option `--migrate-config <?target-file-path>`
|
||||
* Support Nvidia GPU temp detection via nvml (GPU)
|
||||
|
||||
Bugfixes:
|
||||
* Better GPU memory and type detection (GPU, Windows)
|
||||
|
||||
@@ -412,6 +412,7 @@ if(LINUX)
|
||||
src/detection/sound/sound_linux.c
|
||||
src/detection/swap/swap_linux.c
|
||||
src/detection/temps/temps_linux.c
|
||||
src/detection/temps/temps_nvidia.c
|
||||
src/detection/terminalfont/terminalfont_linux.c
|
||||
src/detection/terminalshell/terminalshell_linux.c
|
||||
src/detection/terminalsize/terminalsize_linux.c
|
||||
@@ -518,6 +519,7 @@ elseif(BSD)
|
||||
src/detection/sound/sound_linux.c
|
||||
src/detection/swap/swap_bsd.c
|
||||
src/detection/temps/temps_bsd.c
|
||||
src/detection/temps/temps_nvidia.c
|
||||
src/detection/terminalfont/terminalfont_linux.c
|
||||
src/detection/terminalshell/terminalshell_linux.c
|
||||
src/detection/terminalsize/terminalsize_linux.c
|
||||
@@ -622,6 +624,7 @@ elseif(WIN32)
|
||||
src/detection/terminalshell/terminalshell_windows.c
|
||||
src/detection/terminalsize/terminalsize_windows.c
|
||||
src/detection/temps/temps_windows.cpp
|
||||
src/detection/temps/temps_nvidia.c
|
||||
src/detection/theme/theme_nosupport.c
|
||||
src/detection/uptime/uptime_windows.c
|
||||
src/detection/users/users_windows.c
|
||||
|
||||
Vendored
+5684
File diff suppressed because it is too large
Load Diff
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"home": "https://developer.nvidia.com/gpu-deployment-kit",
|
||||
"license": "Embed in source",
|
||||
"version": "v9",
|
||||
"author": "NVIDIA Corporation"
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "detection/gpu/gpu.h"
|
||||
#include "detection/vulkan/vulkan.h"
|
||||
#include "detection/temps/temps_nvidia.h"
|
||||
|
||||
#ifdef FF_HAVE_LIBPCI
|
||||
#include "common/library.h"
|
||||
@@ -35,7 +36,7 @@ typedef struct PCIData
|
||||
|
||||
static void pciDetectVendorName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* device)
|
||||
{
|
||||
ffStrbufAppendS(&gpu->vendor, ffGetGPUVendorString(device->vendor_id));
|
||||
ffStrbufSetStatic(&gpu->vendor, ffGetGPUVendorString(device->vendor_id));
|
||||
|
||||
if(gpu->vendor.length > 0)
|
||||
return;
|
||||
@@ -45,11 +46,11 @@ static void pciDetectVendorName(FFGPUResult* gpu, PCIData* pci, struct pci_dev*
|
||||
ffStrbufRecalculateLength(&gpu->vendor);
|
||||
|
||||
if(ffStrbufContainS(&gpu->vendor, "AMD") || ffStrbufContainS(&gpu->vendor, "ATI"))
|
||||
ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
|
||||
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
|
||||
else if(ffStrbufContainS(&gpu->vendor, "Intel"))
|
||||
ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
|
||||
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
|
||||
else if(ffStrbufContainS(&gpu->vendor, "NVIDIA"))
|
||||
ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
|
||||
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
|
||||
}
|
||||
|
||||
static void drmDetectDeviceName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* device)
|
||||
@@ -240,6 +241,9 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
if(options->temp)
|
||||
pciDetectTemp(gpu, device);
|
||||
#endif
|
||||
|
||||
if (gpu->temperature != gpu->temperature && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA)
|
||||
ffDetectNvidiaGpuTemp(&gpu->temperature, device->device_id);
|
||||
}
|
||||
|
||||
jmp_buf pciInitJmpBuf;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "gpu.h"
|
||||
#include "detection/temps/temps_nvidia.h"
|
||||
#include "util/windows/unicode.h"
|
||||
#include "util/windows/registry.h"
|
||||
|
||||
@@ -53,11 +54,11 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
ffRegReadStrbuf(hKey, L"ProviderName", &gpu->vendor, NULL);
|
||||
|
||||
if(ffStrbufContainS(&gpu->vendor, "AMD") || ffStrbufContainS(&gpu->vendor, "ATI"))
|
||||
ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
|
||||
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
|
||||
else if(ffStrbufContainS(&gpu->vendor, "Intel"))
|
||||
ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
|
||||
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
|
||||
else if(ffStrbufContainS(&gpu->vendor, "NVIDIA"))
|
||||
ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
|
||||
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
|
||||
|
||||
wmemcpy(regDirectxKey + regDirectxKeyPrefixLength, displayDevice.DeviceKey + deviceKeyPrefixLength, strlen("00000000-0000-0000-0000-000000000000}"));
|
||||
FF_HKEY_AUTO_DESTROY hDirectxKey = NULL;
|
||||
@@ -74,6 +75,13 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
gpu->dedicated.total = dedicatedVideoMemory + dedicatedSystemMemory;
|
||||
gpu->shared.total = sharedSystemMemory;
|
||||
}
|
||||
|
||||
if (options->temp && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA)
|
||||
{
|
||||
uint32_t deviceId;
|
||||
if(ffRegReadUint(hDirectxKey, L"DeviceId", &deviceId, NULL))
|
||||
ffDetectNvidiaGpuTemp(&gpu->temperature, deviceId);
|
||||
}
|
||||
}
|
||||
else if (!ffRegReadUint64(hKey, L"HardwareInformation.qwMemorySize", &gpu->dedicated.total, NULL))
|
||||
{
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "temps_nvidia.h"
|
||||
|
||||
#include "3rdparty/nvml/nvml.h"
|
||||
#include "common/library.h"
|
||||
|
||||
struct FFNvmlData {
|
||||
FF_LIBRARY_SYMBOL(nvmlDeviceGetCount_v2)
|
||||
FF_LIBRARY_SYMBOL(nvmlDeviceGetHandleByIndex_v2)
|
||||
FF_LIBRARY_SYMBOL(nvmlDeviceGetPciInfo_v3)
|
||||
FF_LIBRARY_SYMBOL(nvmlDeviceGetTemperature)
|
||||
|
||||
bool inited;
|
||||
} nvmlData;
|
||||
|
||||
const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId)
|
||||
{
|
||||
if (!nvmlData.inited)
|
||||
{
|
||||
nvmlData.inited = true;
|
||||
FF_LIBRARY_LOAD(libnvml, NULL, "dlopen nvml failed",
|
||||
#ifdef _WIN32
|
||||
"nvml"
|
||||
#else
|
||||
"libnvidia-ml"
|
||||
#endif
|
||||
FF_LIBRARY_EXTENSION, -1
|
||||
);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlInit_v2)
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlShutdown)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetCount_v2)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetHandleByIndex_v2)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetPciInfo_v3)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetTemperature)
|
||||
|
||||
if (ffnvmlInit_v2() != NVML_SUCCESS)
|
||||
{
|
||||
nvmlData.ffnvmlDeviceGetTemperature = NULL;
|
||||
return "nvmlInit_v2() failed";
|
||||
}
|
||||
atexit((void*) ffnvmlShutdown);
|
||||
libnvml = NULL; // don't close nvml
|
||||
}
|
||||
|
||||
if (nvmlData.ffnvmlDeviceGetTemperature == NULL)
|
||||
return "loading nvml library failed";
|
||||
|
||||
uint32_t count;
|
||||
if (nvmlData.ffnvmlDeviceGetCount_v2(&count) != NVML_SUCCESS)
|
||||
return "nvmlDeviceGetCount_v2() failed";
|
||||
|
||||
for (uint32_t i = 0; i < count; i++)
|
||||
{
|
||||
nvmlDevice_t device;
|
||||
if (nvmlData.ffnvmlDeviceGetHandleByIndex_v2(i, &device) != NVML_SUCCESS)
|
||||
continue;
|
||||
|
||||
nvmlPciInfo_t pciInfo;
|
||||
if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_SUCCESS)
|
||||
continue;
|
||||
|
||||
if (pciInfo.pciDeviceId >> 16 != deviceId)
|
||||
continue;
|
||||
|
||||
uint32_t value;
|
||||
if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) != NVML_SUCCESS)
|
||||
return "nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) failed";
|
||||
|
||||
*temp = value;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return "Device not found";
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId);
|
||||
Reference in New Issue
Block a user