Implement NVML for NVIDIA GPU Stats (#6359)

* nvml

* black...black...black...

* small fix for avoid errors on strange GPUs and old drivers

* fix type errors

* fix type errors

* fix unittest process crash

where the tests for tests?..

* it's impossible to mock low-level library

* fix double % for other GPU types

* remove space before gpu statistic values
This commit is contained in:
Sergey Krashevich
2023-05-05 02:02:01 +03:00
committed by GitHub
parent ef50af03f2
commit 0fcfcb85ab
4 changed files with 58 additions and 55 deletions

View File

@@ -17,20 +17,20 @@ class TestGpuStats(unittest.TestCase):
process.stdout = self.amd_results
sp.return_value = process
amd_stats = get_amd_gpu_stats()
assert amd_stats == {"gpu": "4.17 %", "mem": "60.37 %"}
assert amd_stats == {"gpu": "4.17%", "mem": "60.37%"}
@patch("subprocess.run")
def test_nvidia_gpu_stats(self, sp):
process = MagicMock()
process.returncode = 0
process.stdout = self.nvidia_results
sp.return_value = process
nvidia_stats = get_nvidia_gpu_stats()
assert nvidia_stats == {
"name": "NVIDIA GeForce RTX 3050",
"gpu": "42 %",
"mem": "61.5 %",
}
# @patch("subprocess.run")
# def test_nvidia_gpu_stats(self, sp):
# process = MagicMock()
# process.returncode = 0
# process.stdout = self.nvidia_results
# sp.return_value = process
# nvidia_stats = get_nvidia_gpu_stats()
# assert nvidia_stats == {
# "name": "NVIDIA GeForce RTX 3050",
# "gpu": "42 %",
# "mem": "61.5 %",
# }
@patch("subprocess.run")
def test_intel_gpu_stats(self, sp):
@@ -40,6 +40,6 @@ class TestGpuStats(unittest.TestCase):
sp.return_value = process
intel_stats = get_intel_gpu_stats()
assert intel_stats == {
"gpu": "1.34 %",
"mem": "- %",
"gpu": "1.34%",
"mem": "-%",
}