From 408a2d731a91dd90602dd7e9ae12d4b0f7fa4fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 17 Jul 2024 14:52:35 +0800 Subject: [PATCH] GPU: support printing frequency in MHz --- src/detection/gpu/gpu.h | 4 ++-- src/detection/gpu/gpu_amd.c | 2 +- src/detection/gpu/gpu_driver_specific.h | 2 +- src/detection/gpu/gpu_intel.c | 2 +- src/detection/gpu/gpu_linux.c | 4 ++-- src/detection/gpu/gpu_nvidia.c | 6 +----- src/detection/opencl/opencl.c | 2 +- src/modules/gpu/gpu.c | 7 +++++-- 8 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 0ba9ea74e..e3e50dacd 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -5,7 +5,7 @@ #define FF_GPU_TEMP_UNSET (0/0.0) #define FF_GPU_CORE_COUNT_UNSET -1 #define FF_GPU_VMEM_SIZE_UNSET ((uint64_t)-1) -#define FF_GPU_FREQUENCY_UNSET (0/0.0) +#define FF_GPU_FREQUENCY_UNSET 0 extern const char* FF_GPU_VENDOR_NAME_APPLE; extern const char* FF_GPU_VENDOR_NAME_AMD; @@ -32,7 +32,7 @@ typedef struct FFGPUResult FFstrbuf platformApi; double temperature; int32_t coreCount; - double frequency; // Maximum time clock frequency in GHz + uint32_t frequency; // Maximum time clock frequency in MHz FFGPUMemory dedicated; FFGPUMemory shared; uint64_t deviceId; // Used internally, may be uninitialized diff --git a/src/detection/gpu/gpu_amd.c b/src/detection/gpu/gpu_amd.c index 8df677f65..d50451ef4 100644 --- a/src/detection/gpu/gpu_amd.c +++ b/src/detection/gpu/gpu_amd.c @@ -60,7 +60,7 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu } if (result.frequency) - *result.frequency = device->coreClock / 1000.; // Maximum frequency + *result.frequency = (uint32_t) device->coreClock; // Maximum frequency if (result.type) *result.type = device->isAPU ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE; diff --git a/src/detection/gpu/gpu_driver_specific.h b/src/detection/gpu/gpu_driver_specific.h index 8405e0de0..8c935ff8c 100644 --- a/src/detection/gpu/gpu_driver_specific.h +++ b/src/detection/gpu/gpu_driver_specific.h @@ -41,7 +41,7 @@ typedef struct FFGpuDriverResult FFGPUMemory* memory; uint32_t* coreCount; FFGPUType* type; - double* frequency; + uint32_t* frequency; } FFGpuDriverResult; const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName); diff --git a/src/detection/gpu/gpu_intel.c b/src/detection/gpu/gpu_intel.c index 7da51cc07..3d4638cd3 100644 --- a/src/detection/gpu/gpu_intel.c +++ b/src/detection/gpu/gpu_intel.c @@ -191,7 +191,7 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe maxValue = props.max; } } - *result.frequency = maxValue / 1000; + *result.frequency = (uint32_t) (maxValue + 0.5); } } diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index e27a3e3ce..7b0fb5462 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -152,7 +152,7 @@ static void pciDetectIntelSpecific(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* ffStrbufAppendS(pciDir, "/gt_max_freq_mhz"); } if (ffReadFileBuffer(pciDir->chars, buffer)) - gpu->frequency = ffStrbufToDouble(buffer) / 1000.0; + gpu->frequency = (uint32_t) ffStrbufToUInt(buffer, 0); } static bool loadPciIds(FFstrbuf* pciids) @@ -346,7 +346,7 @@ FF_MAYBE_UNUSED static const char* detectAsahi(FFlist* gpus, FFstrbuf* buffer, F }) >= 0) { gpu->coreCount = (int) paramsGlobal.num_cores_total_active; - gpu->frequency = paramsGlobal.max_frequency_khz / 1e6; + gpu->frequency = paramsGlobal.max_frequency_khz / 1000; gpu->deviceId = paramsGlobal.chip_id; } } diff --git a/src/detection/gpu/gpu_nvidia.c b/src/detection/gpu/gpu_nvidia.c index 84a793800..683e681ef 100644 --- a/src/detection/gpu/gpu_nvidia.c +++ b/src/detection/gpu/gpu_nvidia.c @@ -122,11 +122,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR nvmlData.ffnvmlDeviceGetNumGpuCores(device, result.coreCount); if (result.frequency) - { - uint32_t clockMHz; - if (nvmlData.ffnvmlDeviceGetMaxClockInfo(device, NVML_CLOCK_GRAPHICS, &clockMHz) == NVML_SUCCESS) - *result.frequency = clockMHz / 1000.; - } + nvmlData.ffnvmlDeviceGetMaxClockInfo(device, NVML_CLOCK_GRAPHICS, result.frequency); return NULL; diff --git a/src/detection/opencl/opencl.c b/src/detection/opencl/opencl.c index 0626dd4d3..462f3aff2 100644 --- a/src/detection/opencl/opencl.c +++ b/src/detection/opencl/opencl.c @@ -116,7 +116,7 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result) { cl_uint value; if (data->ffclGetDeviceInfo(deviceID, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(value), &value, NULL) == CL_SUCCESS) - gpu->frequency = value / 1000.; + gpu->frequency = value; } { diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index d7cecf516..22cef578c 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -39,8 +39,11 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET) ffStrbufAppendF(&output, " (%d)", gpu->coreCount); - if(gpu->frequency == gpu->frequency && gpu->frequency > 0 /* Inactive? */) - ffStrbufAppendF(&output, " @ %.2f GHz", gpu->frequency); + if(gpu->frequency > 0) + { + ffStrbufAppendS(&output, " @ "); + ffParseFrequency(gpu->frequency, &output); + } if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET {