diff --git a/src/detection/gpu/gpu_amd.c b/src/detection/gpu/gpu_amd.c index 8cee407bf..9738c94b5 100644 --- a/src/detection/gpu/gpu_amd.c +++ b/src/detection/gpu/gpu_amd.c @@ -65,7 +65,7 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu FF_AUTO_FREE AdapterInfo* devices = NULL; int numDevices = 0; - if (adlData.ffADL2_Adapter_AdapterInfoX3_Get(adlData.apiHandle, -1, &numDevices, &devices) == 0) + if (adlData.ffADL2_Adapter_AdapterInfoX3_Get(adlData.apiHandle, -1, &numDevices, &devices) == 0) // Return 1 on success return "ffADL2_Adapter_AdapterInfoX3_Get() failed"; const AdapterInfo* device = NULL; @@ -146,7 +146,7 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu if (adlData.ffADL2_Adapter_ASICFamilyType_Get(adlData.apiHandle, device->iAdapterIndex, &asicTypes, &valids) == ADL_OK) { asicTypes &= valids; // This design is strange - *result.type = asicTypes & ADL_ASIC_INTEGRATED ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE; + *result.type = (asicTypes & ADL_ASIC_INTEGRATED) ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE; } } diff --git a/src/detection/gpu/gpu_intel.c b/src/detection/gpu/gpu_intel.c index b2c82b8f4..c440c7207 100644 --- a/src/detection/gpu/gpu_intel.c +++ b/src/detection/gpu/gpu_intel.c @@ -215,7 +215,8 @@ const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverRe availableCount++; } } - *result.temp = sumValue / availableCount; + if (availableCount > 0) + *result.temp = sumValue / availableCount; } } diff --git a/src/detection/gpu/gpu_nvidia.c b/src/detection/gpu/gpu_nvidia.c index 07fafb6c0..f555eb959 100644 --- a/src/detection/gpu/gpu_nvidia.c +++ b/src/detection/gpu/gpu_nvidia.c @@ -33,7 +33,7 @@ struct FFNvapiData { bool inited; } nvapiData; -const char* detectMemTypeByNvapi(FFGpuDriverResult* result) +static const char* detectMemTypeByNvapi(FFGpuDriverResult* result) { if (!nvapiData.inited) { @@ -79,11 +79,14 @@ const char* detectMemTypeByNvapi(FFGpuDriverResult* result) uint32_t gpuIndex = *result->index; - if ((uint32_t) gpuCount < gpuIndex) + if (gpuIndex >= (uint32_t) gpuCount) return "GPU index out of range"; + // Not very sure. Need to check in multi-GPU system + NvPhysicalGpuHandle gpuHandle = handles[gpuIndex]; + NvApiGPUMemoryType memType; - if (nvapiData.ffnvapi_GPU_GetRamType(handles[gpuIndex], &memType) < 0) + if (nvapiData.ffnvapi_GPU_GetRamType(gpuHandle, &memType) < 0) return "NvAPI_GPU_GetRamType() failed"; switch (memType) @@ -160,7 +163,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID) { char pciBusIdStr[32]; - snprintf(pciBusIdStr, ARRAY_SIZE(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func); + snprintf(pciBusIdStr, ARRAY_SIZE(pciBusIdStr), "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func); nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(pciBusIdStr, &device); if (ret != NVML_SUCCESS) @@ -187,24 +190,28 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR break; } - if (!device) return "Device not found"; } - nvmlBrandType_t brand; - if (nvmlData.ffnvmlDeviceGetBrand(device, &brand) == NVML_SUCCESS) + if (!device) return "Device not found"; + + if (result.type) { - switch (brand) + nvmlBrandType_t brand; + if (nvmlData.ffnvmlDeviceGetBrand(device, &brand) == NVML_SUCCESS) { - case NVML_BRAND_NVIDIA_RTX: - case NVML_BRAND_QUADRO_RTX: - case NVML_BRAND_GEFORCE: - case NVML_BRAND_TITAN: - case NVML_BRAND_TESLA: - case NVML_BRAND_QUADRO: - *result.type = FF_GPU_TYPE_DISCRETE; - break; - default: - break; + switch (brand) + { + case NVML_BRAND_NVIDIA_RTX: + case NVML_BRAND_QUADRO_RTX: + case NVML_BRAND_GEFORCE: + case NVML_BRAND_TITAN: + case NVML_BRAND_TESLA: + case NVML_BRAND_QUADRO: + *result.type = FF_GPU_TYPE_DISCRETE; + break; + default: + break; + } } } diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 8c5d0fbba..851ef5e4b 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -48,13 +48,14 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->deviceId = 0; gpu->frequency = FF_GPU_FREQUENCY_UNSET; - uint32_t pciBus = 0, pciAddr = UINT32_MAX, pciDev = 0, pciFunc = 0; + uint32_t pciBus = 0, pciAddr = 0, pciDev = 0, pciFunc = 0; if (SetupDiGetDeviceRegistryPropertyW(hdev, &did, SPDRP_BUSNUMBER, NULL, (PBYTE) &pciBus, sizeof(pciBus), NULL) && SetupDiGetDeviceRegistryPropertyW(hdev, &did, SPDRP_ADDRESS, NULL, (PBYTE) &pciAddr, sizeof(pciAddr), NULL)) { pciDev = (pciAddr >> 16) & 0xFFFF; pciFunc = pciAddr & 0xFFFF; gpu->deviceId = (pciBus * 1000ull) + (pciDev * 10ull) + pciFunc; + pciAddr = 1; // Set to 1 to indicate that the device is a PCI device } wchar_t buffer[256];