diff options
author | Krzysztof Bogacki <krzysztof.bogacki@leancode.pl> | 2022-06-18 20:35:43 +0300 |
---|---|---|
committer | Jens Peters <jp7677@gmail.com> | 2022-06-25 01:53:54 +0300 |
commit | b3c13ff773bed1074e578b3da342b66b6f515c7e (patch) | |
tree | e801e84fb4c22aaabb766cb5cb1ef304be3ee08b | |
parent | f55fb166f021e22faf44fe1cc949378051b1afde (diff) |
nvapi-gpu: Adjust implementation of NvAPI_GPU_GetThermalSettings to handle some quirks
-rw-r--r-- | src/nvapi_gpu.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/nvapi_gpu.cpp b/src/nvapi_gpu.cpp index cd747eb..a8c7f52 100644 --- a/src/nvapi_gpu.cpp +++ b/src/nvapi_gpu.cpp @@ -520,31 +520,42 @@ extern "C" { if (!adapter->HasNvmlDevice()) return HandleInvalidated(str::format(n, ": NVML available but current adapter is not NVML compatible"), alreadyLoggedHandleInvalidated); + unsigned sensors; + // NVML claims that defaultMinTemp is unsigned int, but it can return values like uint32_t(4294967256) + // which would be equal to -40 if interpreted as signed, while NvAPI simply returns NvS32(-40) for the same device + signed int defaultMinTemp; nvmlGpuThermalSettings_t thermalSettings; auto result = adapter->GetNvmlDeviceThermalSettings(sensorIndex, &thermalSettings); switch (result) { case NVML_SUCCESS: + // both NvAPI and NVML fill $(count) sensors when sensorIndex == 15, + // 1 sensor when 0 ≤ sensorIndex < $(count) and 0 sensors otherwise + sensors = sensorIndex == NVAPI_THERMAL_TARGET_ALL + ? thermalSettings.count + : sensorIndex < thermalSettings.count; switch (pThermalSettings->version) { case NV_GPU_THERMAL_SETTINGS_VER_1: { auto pThermalSettingsV1 = reinterpret_cast<NV_GPU_THERMAL_SETTINGS_V1*>(pThermalSettings); pThermalSettingsV1->count = thermalSettings.count; - for (auto i = 0U; i < thermalSettings.count; i++) { + for (auto i = 0U; i < sensors; i++) { pThermalSettingsV1->sensor[i].controller = MapThermalController(thermalSettings.sensor[i].controller); pThermalSettingsV1->sensor[i].target = MapThermalTarget(thermalSettings.sensor[i].target); pThermalSettingsV1->sensor[i].currentTemp = thermalSettings.sensor[i].currentTemp; pThermalSettingsV1->sensor[i].defaultMaxTemp = thermalSettings.sensor[i].defaultMaxTemp; - pThermalSettingsV1->sensor[i].defaultMinTemp = thermalSettings.sensor[i].defaultMinTemp; + memcpy(&defaultMinTemp, &thermalSettings.sensor[i].defaultMinTemp, sizeof(defaultMinTemp)); + pThermalSettingsV1->sensor[i].defaultMinTemp = static_cast<NvU32>(std::max(defaultMinTemp, 0)); } break; } case NV_GPU_THERMAL_SETTINGS_VER_2: pThermalSettings->count = thermalSettings.count; - for (auto i = 0U; i < thermalSettings.count; i++) { + for (auto i = 0U; i < sensors; i++) { pThermalSettings->sensor[i].controller = MapThermalController(thermalSettings.sensor[i].controller); pThermalSettings->sensor[i].target = MapThermalTarget(thermalSettings.sensor[i].target); pThermalSettings->sensor[i].currentTemp = static_cast<NvS32>(thermalSettings.sensor[i].currentTemp); pThermalSettings->sensor[i].defaultMaxTemp = static_cast<NvS32>(thermalSettings.sensor[i].defaultMaxTemp); - pThermalSettings->sensor[i].defaultMinTemp = static_cast<NvS32>(thermalSettings.sensor[i].defaultMinTemp); + memcpy(&defaultMinTemp, &thermalSettings.sensor[i].defaultMinTemp, sizeof(defaultMinTemp)); + pThermalSettings->sensor[i].defaultMinTemp = defaultMinTemp; } break; default: |