Skip to content

Commit c7e295f

Browse files
committed
Catch exception on checking cuda device on Github build machine
Signed-off-by: M Q <[email protected]>
1 parent d87f868 commit c7e295f

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

monai/deploy/operators/decoder_nvimgcodec.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,12 @@ def _is_nvimgcodec_available() -> bool:
229229
if not nvimgcodec or not _passes_version_check(NVIMGCODEC_MODULE_NAME, NVIMGCODEC_MIN_VERSION_TUPLE) or not cp:
230230
_logger.debug(f"nvimgcodec (version >= {NVIMGCODEC_MIN_VERSION}) or CuPy missing.")
231231
return False
232-
if not cp.cuda.is_available():
233-
_logger.debug("CUDA device not found.")
232+
try:
233+
if not cp.cuda.is_available():
234+
_logger.debug("CUDA device not found.")
235+
return False
236+
except Exception as exc: # pragma: no cover - environment specific
237+
_logger.debug("CUDA availability check failed: %s", exc)
234238
return False
235239

236240
return True

tests/unit/test_decoder_nvimgcodec.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,23 @@
8080

8181
@pytest.mark.skipif(
8282
(not _is_nvimgcodec_available()) or (not pydicom_config.have_gdcm),
83-
reason="nvimgcodec and GDCM dependencies unavailable",
83+
reason="nvimgcodec (with CUDA) and GDCM must be available",
8484
)
85-
def test_nvimgcodec_decoder_matches_default():
86-
"""Ensure nvimgcodec decoder matches default decoding for supported transfer syntaxes."""
85+
def test_nvimgcodec_decoder_matches_default() -> None:
86+
"""Ensure nvimgcodec decoder matches default decoding for supported syntaxes."""
8787

8888
test_files = get_testdata_files("*.dcm")
8989
baseline_total = 0.0
9090
nvimgcodec_total = 0.0
9191
compared = 0
92-
_rtol = 0.01 # The relative tolerance parameter
93-
_atol = 1.00 # The absolute tolerance parameter
92+
rtol = 0.01
93+
atol = 1.0
9494

95-
default_errored_files = dict()
96-
nvimgcodec_errored_files = dict()
97-
unequal_pixel_files = dict()
98-
inspected_unequal_files = dict()
99-
confirmed_equal_pixel_files = dict()
95+
default_errored_files: dict[str, str] = {}
96+
nvimgcodec_errored_files: dict[str, str] = {}
97+
unequal_pixel_files: dict[str, str] = {}
98+
inspected_unequal_files: dict[str, dict[str, float | str]] = {}
99+
confirmed_equal_pixel_files: dict[str, str] = {}
100100

101101
for path in test_files:
102102
default_errored = False
@@ -113,6 +113,10 @@ def test_nvimgcodec_decoder_matches_default():
113113
print(f"Skipping: unsupported transfer syntax DICOM file {path}: {transfer_syntax}")
114114
continue
115115

116+
baseline_pixels = None
117+
nv_pixels = None
118+
119+
# Baseline (default pydicom) decode
116120
try:
117121
ds_default = dcmread(path, force=True)
118122
start = time.perf_counter()

0 commit comments

Comments
 (0)