From 799628c083c950d8e6207bd843f657c300036728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 28 Oct 2023 17:23:49 +0800 Subject: [PATCH] GPU: guard nvml related code behind `--allow-slow-operations` --- src/detection/gpu/gpu_linux.c | 21 +++++++++++---------- src/detection/gpu/gpu_windows.c | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 1401ebd88..36e1fc475 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -242,24 +242,25 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; gpu->temperature = FF_GPU_TEMP_UNSET; - #ifdef __linux__ - if(options->temp) - pciDetectTemp(gpu, device); - #endif - - if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || instance.config.general.allowSlowOperations)) { char pciDeviceId[32]; snprintf(pciDeviceId, sizeof(pciDeviceId) - 1, "%04x:%02x:%02x.%d", device->domain, device->bus, device->dev, device->func); ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) { .pciBusId = pciDeviceId }, (FFGpuNvidiaResult) { - .temp = gpu->temperature != gpu->temperature ? &gpu->temperature : NULL, - .memory = &gpu->dedicated, - .coreCount = (uint32_t*) &gpu->coreCount, + .temp = options->temp ? &gpu->temperature : NULL, + .memory = instance.config.general.allowSlowOperations ? &gpu->dedicated : NULL, + .coreCount = instance.config.general.allowSlowOperations ? (uint32_t*) &gpu->coreCount : NULL, }); - gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; + if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) + gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; } + + #ifdef __linux__ + if(options->temp && gpu->temperature != gpu->temperature) + pciDetectTemp(gpu, device); + #endif } jmp_buf pciInitJmpBuf; diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index ce2d535c1..c9a585bee 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -97,8 +97,8 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* .pciSubSystemId = subSystemId, }, (FFGpuNvidiaResult) { .temp = options->temp ? &gpu->temperature : NULL, - .memory = &gpu->dedicated, - .coreCount = (uint32_t*) &gpu->coreCount, + .memory = instance.config.general.allowSlowOperations ? &gpu->dedicated : NULL, + .coreCount = instance.config.general.allowSlowOperations ? (uint32_t*) &gpu->coreCount : NULL, }); } }