Require executable CUDA for GPU mode

This commit is contained in:
Dobromir Popov
2026-07-01 10:53:29 +02:00
parent d778b23e1e
commit c4a63d9461
3 changed files with 97 additions and 34 deletions

View File

@@ -12,6 +12,7 @@ import pytest
from meshnet_node.downloader import download_shard, write_shard_archive
from meshnet_node.hardware import detect_hardware, benchmark_throughput
from meshnet_node.startup import (
_hardware_label,
_infer_relay_url_from_tracker,
_memory_budget,
_probationary_status_line,
@@ -98,6 +99,29 @@ def test_windows_gpu_memory_fallback_preserves_cpu_execution(monkeypatch):
assert hw["ram_mb"] == 80 * 1024
def test_nvidia_smi_without_torch_cuda_keeps_cpu_execution(monkeypatch):
"""nvidia-smi proves GPU inventory, not that this Python can execute CUDA."""
import meshnet_node.hardware as hardware_mod
class FakeResult:
returncode = 0
stdout = "NVIDIA GeForce RTX 4060 Laptop GPU, 8188\n"
fake_torch = types.SimpleNamespace(cuda=types.SimpleNamespace(is_available=lambda: False))
monkeypatch.setattr(hardware_mod, "_detect_ram_mb", lambda: 80 * 1024)
monkeypatch.setattr(hardware_mod.subprocess, "run", lambda *a, **kw: FakeResult())
monkeypatch.setitem(sys.modules, "torch", fake_torch)
hw = hardware_mod.detect_hardware()
assert hw["device"] == "cpu"
assert hw["cuda_available"] is False
assert hw["gpu_name"] == "NVIDIA GeForce RTX 4060 Laptop GPU"
assert hw["vram_mb"] == 8188
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,
@@ -109,6 +133,12 @@ def test_memory_budget_uses_ram_for_cpu_and_shared_memory_for_cuda():
)
def test_hardware_label_marks_inventory_only_gpu_as_cuda_inactive():
assert _hardware_label("cpu", "NVIDIA GeForce RTX 4060 Laptop GPU") == "CPU (CUDA inactive)"
assert _hardware_label("cpu", None) == "CPU"
assert _hardware_label("cuda", "NVIDIA GeForce RTX 4060 Laptop GPU") == "CUDA"
def test_benchmark_throughput_cpu_returns_positive():
"""CPU benchmark returns a positive float greater than the 1.0 error fallback."""
result = benchmark_throughput("cpu")