Skip to content

Commit 72b62f8

Browse files
committed
Add gracefully handling of device errors when converting result to the strings
1 parent 71d3c23 commit 72b62f8

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

dpnp/tests/third_party/cupy/testing/_loops.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,11 +933,23 @@ def test_func(*args, **kw):
933933
return
934934

935935
if cupy_result != numpy_result:
936+
# Safely convert results to strings, handling device errors gracefully
937+
# This prevents crashes when device is lost during error reporting
938+
try:
939+
cupy_str = str(cupy_result)
940+
except Exception as e:
941+
cupy_str = f"<Failed to format cupy result: {type(e).__name__}: {e}>"
942+
943+
try:
944+
numpy_str = str(numpy_result)
945+
except Exception as e:
946+
numpy_str = f"<Failed to format numpy result: {type(e).__name__}: {e}>"
947+
936948
message = """Results are not equal:
937949
cupy: {}
938950
numpy: {}""".format(
939-
str(cupy_result),
940-
str(numpy_result),
951+
cupy_str,
952+
numpy_str,
941953
)
942954
raise AssertionError(message)
943955

0 commit comments

Comments
 (0)