mirror of
https://github.com/RevLayDust/RLD-UVR-Opt.git
synced 2026-11-20 13:07:58 +09:00
feat(engine): add Ampere architecture guard for TensorRT-RTX and unit tests
This commit is contained in:
1 parent
b21faacf85
commit
cb416c221b
2 files changed
+38
-1
No files matched your search
@@ -95,11 +95,31 @@ def is_trt_rtx_installed() -> bool:
|
||||
|
||||
|
||||
def is_trt_rtx_available(device_id: int = 0) -> bool:
|
||||
"""Check whether TensorRT-RTX can genuinely execute on the specified GPU device."""
|
||||
"""Check whether TensorRT-RTX can genuinely execute on the specified GPU device.
|
||||
|
||||
TensorRT-RTX requires NVIDIA Ampere architecture (Compute Capability >= 8.0, e.g.
|
||||
GeForce RTX 30-series, RTX 40-series, RTX 50-series). Earlier architectures such
|
||||
as Turing (RTX 20-series, CC 7.5) are unsupported and should use CUDAExecutionProvider.
|
||||
"""
|
||||
if not torch.cuda.is_available():
|
||||
return False
|
||||
if device_id < 0 or device_id >= torch.cuda.device_count():
|
||||
return False
|
||||
|
||||
# Check CUDA Compute Capability (Ampere or newer required: major >= 8)
|
||||
try:
|
||||
major, minor = torch.cuda.get_device_capability(device_id)
|
||||
if major < 8:
|
||||
gpu_name = torch.cuda.get_device_name(device_id)
|
||||
print(
|
||||
f"[BACKEND] Device {device_id} ({gpu_name}, Compute Capability {major}.{minor}) "
|
||||
f"does not meet TensorRT-RTX hardware requirement (Ampere / CC >= 8.0 required, e.g. RTX 30-series or newer). "
|
||||
f"Falling back to CUDAExecutionProvider."
|
||||
)
|
||||
return False
|
||||
except Exception as exc:
|
||||
print(f"[BACKEND] Warning: Failed to inspect device compute capability: {exc}")
|
||||
|
||||
return is_trt_rtx_installed()
|
||||
|
||||
|
||||
|
||||
@@ -50,6 +50,23 @@ class TensorRTRTXEngineTests(unittest.TestCase):
|
||||
self.assertNotIn(PROVIDER_TRT_RTX, providers)
|
||||
self.assertIn(PROVIDER_CUDA, providers)
|
||||
|
||||
@mock.patch("torch.cuda.is_available", return_value=True)
|
||||
@mock.patch("torch.cuda.device_count", return_value=1)
|
||||
def test_trt_rtx_architecture_guard_rejects_turing(self, mock_count, mock_cuda_avail):
|
||||
# Turing (RTX 20 series, compute capability 7.5) must be rejected
|
||||
with mock.patch("torch.cuda.get_device_capability", return_value=(7, 5)):
|
||||
with mock.patch("torch.cuda.get_device_name", return_value="NVIDIA GeForce RTX 2080 Ti"):
|
||||
with mock.patch("engine.tensorrt_rtx.environment.is_trt_rtx_installed", return_value=True):
|
||||
self.assertFalse(is_trt_rtx_available(0))
|
||||
|
||||
@mock.patch("torch.cuda.is_available", return_value=True)
|
||||
@mock.patch("torch.cuda.device_count", return_value=1)
|
||||
def test_trt_rtx_architecture_guard_accepts_ampere_and_newer(self, mock_count, mock_cuda_avail):
|
||||
# Ampere (RTX 30 series, CC 8.6) must be accepted when plugin is installed
|
||||
with mock.patch("torch.cuda.get_device_capability", return_value=(8, 6)):
|
||||
with mock.patch("engine.tensorrt_rtx.environment.is_trt_rtx_installed", return_value=True):
|
||||
self.assertTrue(is_trt_rtx_available(0))
|
||||
|
||||
def test_provider_resolution_rules(self):
|
||||
# Rule 3: GPU not selected -> returns CPUExecutionProvider
|
||||
cpu_providers = get_supported_execution_providers(has_gpu_selected=False)
|
||||
|
||||
Reference in new issue
Block a user