TIGRE icon indicating copy to clipboard operation
TIGRE copied to clipboard

[Python] CUDA errors should raise catchable exceptions instead of terminating the entire process

Open victrvondoom opened this issue 2 weeks ago • 2 comments

Expected Behavior

When a CUDA operation fails during TIGRE execution through the Python interface, the error should be propagated as a catchable Python exception (such as RuntimeError) rather than terminating the entire Python process.

This would allow users to:

  • Catch CUDA-related failures using try/except.
  • Handle errors gracefully in notebooks, scripts and larger Python applications.
  • Log diagnostic information and release resources safely.
  • Continue executing unrelated operations when recovery is possible.

Ideally, error propagation should also preserve the original CUDA error message to make debugging easier.

Actual Behavior

CUDA errors reaching the shared error-handling implementation can terminate the entire process through exit(1).

This prevents Python applications from handling the failure through their normal exception-handling mechanisms.

The relevant implementation appears to be in Common/CUDA/TIGRE_common.cpp, particularly the Python error-handling path.

It would be useful to investigate whether this termination mechanism can be separated from the MATLAB error-handling path without affecting MATLAB compilation or existing behaviour.

Code to reproduce the problem (If applicable)

The following illustrates the expected Python-side error-handling behaviour. The operation should be replaced with a TIGRE CUDA operation that reliably triggers the relevant CUDA failure on the test environment.

try:
    # Execute a TIGRE operation that triggers a CUDA error.
    result = run_tigre_cuda_operation()

except RuntimeError as exc:
    print(f"TIGRE CUDA operation failed: {exc}")

print("Python process is still running.")

Expected: The CUDA failure is propagated as a Python exception, allowing the except block to handle it.

Actual: If the failure reaches the process-termination path, the Python interpreter exits before the exception can be handled.

A minimal reproducible example with a specific CUDA failure condition would help establish the exact execution path.

Specifications

  • MATLAB/Python version: MATLAB R2026b / Python 3.15.2 (reference versions; compatibility should be verified before inclusion in the supported matrix).
  • OS: Windows 11, version 26H2 (OS Build 26300.9818).
  • CUDA version: NVIDIA CUDA Toolkit 13.5.0 (reference version; actual compatibility with TIGRE and the installed GPU driver needs verification).

victrvondoom avatar Nov 16 '26 14:11 victrvondoom

Agree! Tigre is old, this decision came from when exception catches in python came with computational drawbacks. This seems to be not true anymore so this change makes sense. Will implement in the current round of updating I am doing.

AnderBiguri avatar Nov 16 '26 14:11 AnderBiguri

@AnderBiguri Thank you so much! I would really love to contribute to TIGRE. Could you please, please assign me any one of the open issues that I can work on? I'd genuinely love to take something up, learn more about the codebase, and contribute a fix. I'm really looking forward to making my first contribution here. Please do give me an opportunity. It would mean a lot. Thank you! 🙏

victrvondoom avatar Nov 16 '26 15:11 victrvondoom