Fix Windows memory budget detection
This commit is contained in:
@@ -13,6 +13,7 @@ from meshnet_node.downloader import download_shard, write_shard_archive
|
||||
from meshnet_node.hardware import detect_hardware, benchmark_throughput
|
||||
from meshnet_node.startup import (
|
||||
_infer_relay_url_from_tracker,
|
||||
_memory_budget,
|
||||
_probationary_status_line,
|
||||
run_startup,
|
||||
)
|
||||
@@ -34,13 +35,80 @@ def test_detect_hardware_returns_valid_profile():
|
||||
assert isinstance(hw.get("ram_mb"), int)
|
||||
assert hw["ram_mb"] > 0
|
||||
if hw["device"] == "cpu":
|
||||
assert hw["gpu_name"] is None
|
||||
assert hw["vram_mb"] == 0
|
||||
assert hw["gpu_name"] is None or isinstance(hw["gpu_name"], str)
|
||||
assert hw["vram_mb"] >= 0
|
||||
else:
|
||||
assert isinstance(hw["gpu_name"], str) and hw["gpu_name"]
|
||||
assert hw["vram_mb"] > 0
|
||||
|
||||
|
||||
def test_windows_ram_fallback_is_used_when_sysconf_is_unavailable(monkeypatch):
|
||||
"""Windows hosts do not have os.sysconf; RAM must not collapse to 0 MB."""
|
||||
import meshnet_node.hardware as hardware_mod
|
||||
|
||||
monkeypatch.setattr(
|
||||
hardware_mod.os,
|
||||
"sysconf",
|
||||
lambda _name: (_ for _ in ()).throw(AttributeError()),
|
||||
raising=False,
|
||||
)
|
||||
monkeypatch.setattr(hardware_mod, "_detect_windows_ram_mb", lambda: 64 * 1024)
|
||||
|
||||
assert hardware_mod._detect_ram_mb() == 64 * 1024
|
||||
|
||||
|
||||
def test_windows_gpu_memory_fallback_preserves_cpu_execution(monkeypatch):
|
||||
"""A Windows-visible GPU is reported, but CUDA execution is not claimed without CUDA."""
|
||||
import meshnet_node.hardware as hardware_mod
|
||||
|
||||
calls = []
|
||||
|
||||
class FakeResult:
|
||||
def __init__(self, stdout):
|
||||
self.returncode = 0
|
||||
self.stdout = stdout
|
||||
|
||||
def fake_run(command, *args, **kwargs):
|
||||
calls.append(command)
|
||||
joined = " ".join(command)
|
||||
if "nvidia-smi" in joined:
|
||||
raise FileNotFoundError
|
||||
if "Win32_ComputerSystem" in joined:
|
||||
return FakeResult(str(80 * 1024 * 1024 * 1024))
|
||||
if "Win32_VideoController" in joined:
|
||||
return FakeResult('{"Name":"NVIDIA GeForce RTX Laptop GPU","AdapterRAM":8589934592}')
|
||||
raise AssertionError(command)
|
||||
|
||||
monkeypatch.setattr(
|
||||
hardware_mod.os,
|
||||
"sysconf",
|
||||
lambda _name: (_ for _ in ()).throw(AttributeError()),
|
||||
raising=False,
|
||||
)
|
||||
monkeypatch.setattr(hardware_mod.subprocess, "run", fake_run)
|
||||
monkeypatch.setattr(hardware_mod, "_detect_windows_ram_mb", lambda: 80 * 1024)
|
||||
monkeypatch.setitem(sys.modules, "torch", types.SimpleNamespace(cuda=types.SimpleNamespace(is_available=lambda: False)))
|
||||
|
||||
hw = hardware_mod.detect_hardware()
|
||||
|
||||
assert hw["device"] == "cpu"
|
||||
assert hw["gpu_name"] == "NVIDIA GeForce RTX Laptop GPU"
|
||||
assert hw["vram_mb"] == 8192
|
||||
assert hw["shared_vram_mb"] == 40 * 1024
|
||||
assert hw["ram_mb"] == 80 * 1024
|
||||
|
||||
|
||||
def test_memory_budget_uses_ram_for_cpu_and_shared_memory_for_cuda():
|
||||
assert _memory_budget("cpu", vram_mb=8192, ram_mb=80 * 1024, shared_vram_mb=40 * 1024) == (
|
||||
80 * 1024,
|
||||
"RAM",
|
||||
)
|
||||
assert _memory_budget("cuda", vram_mb=8192, ram_mb=80 * 1024, shared_vram_mb=40 * 1024) == (
|
||||
48 * 1024,
|
||||
"VRAM + shared RAM",
|
||||
)
|
||||
|
||||
|
||||
def test_benchmark_throughput_cpu_returns_positive():
|
||||
"""CPU benchmark returns a positive float greater than the 1.0 error fallback."""
|
||||
result = benchmark_throughput("cpu")
|
||||
|
||||
Reference in New Issue
Block a user