From f8be6322df60338996ffbc21d6954e2db183f736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 20 Dec 2023 14:59:27 +0800 Subject: [PATCH] GPU: rename `use-nvml` to `driver-specific` Because we are supporting drivers other than NVML --- doc/json_schema.json | 4 ++-- src/data/help.json | 6 +++--- src/detection/gpu/gpu_linux.c | 16 ++++++++-------- src/detection/gpu/gpu_windows.c | 10 +++++----- src/detection/gpu/gpu_wsl.cpp | 17 ++++++++++------- src/modules/gpu/gpu.c | 14 +++++++------- src/modules/gpu/option.h | 2 +- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/doc/json_schema.json b/doc/json_schema.json index 7b5516411..9da9dc902 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1191,8 +1191,8 @@ "type": "boolean", "default": false }, - "useNvml": { - "description": "Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc)", + "driverSpecific": { + "description": "Use driver specific method to detect more detailed GPU information (memory usage, core count, etc)", "type": "boolean", "default": false }, diff --git a/src/data/help.json b/src/data/help.json index 32f6ba73e..f30c5ed5b 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1082,9 +1082,9 @@ } }, { - "long": "gpu-use-nvml", - "desc": "Use nvml (NVIDIA Management Library) to detect more detailed GPU information", - "remark": "Detects memory usage, CUDA core count, etc. Requires NVIDIA proprietary driver installed", + "long": "gpu-driver-specific", + "desc": "Use driver specific method to detect more detailed GPU information (memory usage, core count, etc)", + "remark": "Correctly NVML (NVIDIA) and IGCL (Intel, Windows only) are supported. Both require the latest proprietary driver to be installed", "arg": { "type": "bool", "optional": true, diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 094d9c4dc..630f12ead 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -241,22 +241,22 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->temperature = FF_GPU_TEMP_UNSET; gpu->frequency = FF_GPU_FREQUENCY_UNSET; - if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->useNvml)) + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->driverSpecific)) { ffDetectNvidiaGpuInfo(&(FFGpuDriverCondition) { .type = FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID, - .pciDeviceId = { - .domain = device->domain, + .pciBusId = { + .domain = (uint32_t) device->domain, .bus = device->bus, .device = device->dev, .func = device->func, }, - }, (FFGpuNvidiaResult) { + }, (FFGpuDriverResult) { .temp = options->temp ? &gpu->temperature : NULL, - .memory = options->useNvml ? &gpu->dedicated : NULL, - .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, - .type = options->useNvml ? (uint32_t*) &gpu->type : NULL, - .frequency = options->useNvml ? &gpu->frequency : NULL, + .memory = options->driverSpecific ? &gpu->dedicated : NULL, + .coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL, + .type = options->driverSpecific ? &gpu->type : NULL, + .frequency = options->driverSpecific ? &gpu->frequency : NULL, }, "libnvidia-ml.so"); if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index f56b87a1f..3d27a7ba3 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -90,7 +90,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* } if ((gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA || gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL) && - (options->temp || options->useNvml)) + (options->temp || options->driverSpecific)) { uint32_t vendorId, deviceId, subSystemId, revId; // See: https://download.nvidia.com/XFree86/Linux-x86_64/545.23.06/README/supportedchips.html @@ -108,10 +108,10 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* }, }, (FFGpuDriverResult) { .temp = options->temp ? &gpu->temperature : NULL, - .memory = options->useNvml ? &gpu->dedicated : NULL, - .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, - .type = options->useNvml ? (uint32_t*) &gpu->type : NULL, - .frequency = options->useNvml ? &gpu->frequency : NULL, + .memory = options->driverSpecific ? &gpu->dedicated : NULL, + .coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL, + .type = options->driverSpecific ? &gpu->type : NULL, + .frequency = options->driverSpecific ? &gpu->frequency : NULL, }, gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA ? "nvml.dll" : #ifdef _WIN64 "ControlLib.dll" diff --git a/src/detection/gpu/gpu_wsl.cpp b/src/detection/gpu/gpu_wsl.cpp index 8f8af9f07..117eb2cee 100644 --- a/src/detection/gpu/gpu_wsl.cpp +++ b/src/detection/gpu/gpu_wsl.cpp @@ -14,6 +14,8 @@ extern "C" { #include #include +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" + template struct on_scope_exit { on_scope_exit(Fn &&fn): _fn(std::move(fn)) {} @@ -96,9 +98,9 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF const char* vendorStr = ffGetGPUVendorString((unsigned) hardwareId.vendorID); ffStrbufSetStatic(&gpu->vendor, vendorStr); - if (vendorStr == FF_GPU_VENDOR_NAME_NVIDIA && options->useNvml) + if (vendorStr == FF_GPU_VENDOR_NAME_NVIDIA && options->driverSpecific) { - ffDetectNvidiaGpuInfo(&(FFGpuDriverCondition) { + FFGpuDriverCondition cond = { .type = FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID, .pciDeviceId = { .deviceId = hardwareId.deviceID, @@ -106,12 +108,13 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF .subSystemId = hardwareId.subSysID, .revId = hardwareId.revision, }, - }, (FFGpuNvidiaResult) { + }; + ffDetectNvidiaGpuInfo(&cond, (FFGpuDriverResult) { .temp = options->temp ? &gpu->temperature : NULL, - .memory = options->useNvml ? &gpu->dedicated : NULL, - .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, - .type = options->useNvml ? (uint32_t*) &gpu->type : NULL, - .frequency = options->useNvml ? &gpu->frequency : NULL, + .memory = options->driverSpecific ? &gpu->dedicated : NULL, + .coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL, + .type = options->driverSpecific ? &gpu->type : NULL, + .frequency = options->driverSpecific ? &gpu->frequency : NULL, }, "/usr/lib/wsl/lib/libnvidia-ml.so"); } } diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 3d02eb4d9..a159764ef 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -133,9 +133,9 @@ bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; - if (ffStrEqualsIgnCase(subKey, "use-nvml")) + if (ffStrEqualsIgnCase(subKey, "driver-specific")) { - options->useNvml = ffOptionParseBoolean(value); + options->driverSpecific = ffOptionParseBoolean(value); return true; } @@ -183,9 +183,9 @@ void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module) continue; } - if (ffStrEqualsIgnCase(key, "useNvml")) + if (ffStrEqualsIgnCase(key, "driverSpecific")) { - options->useNvml = yyjson_get_bool(val); + options->driverSpecific = yyjson_get_bool(val); continue; } @@ -222,8 +222,8 @@ void ffGenerateGPUJsonConfig(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_ ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); - if (options->useNvml != defaultOptions.useNvml) - yyjson_mut_obj_add_bool(doc, module, "useNvml", options->useNvml); + if (options->driverSpecific != defaultOptions.driverSpecific) + yyjson_mut_obj_add_bool(doc, module, "driverSpecific", options->driverSpecific); if (options->forceVulkan != defaultOptions.forceVulkan) yyjson_mut_obj_add_bool(doc, module, "forceVulkan", options->forceVulkan); @@ -354,7 +354,7 @@ void ffInitGPUOptions(FFGPUOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); - options->useNvml = false; + options->driverSpecific = false; options->forceVulkan = false; options->temp = false; options->hideType = FF_GPU_TYPE_UNKNOWN; diff --git a/src/modules/gpu/option.h b/src/modules/gpu/option.h index 6aa34a9fe..77babf437 100644 --- a/src/modules/gpu/option.h +++ b/src/modules/gpu/option.h @@ -18,6 +18,6 @@ typedef struct FFGPUOptions FFGPUType hideType; bool temp; - bool useNvml; + bool driverSpecific; bool forceVulkan; } FFGPUOptions;