OpenwaterHealth / OpenLIFU-python

focused ultrasound toolbox
GNU Affero General Public License v3.0
12 stars 2 forks source link

protocol.calc_solution does not use GPU #175

Open peterhollender opened 3 days ago

peterhollender commented 3 days ago

kwave.kspaceFirstOrder3D has CPU (C++) and GPU (CUDA)-accelerated binaries, with the CUDA version providing substantial performance improvements over the CPU version. However, in the current implementation of protocol.calc_solution, the call to run_simulation is hard coded with gpu = False, which disables the use of the CUDA version and significantly degrades performance.

In the MATLAB version of the code, I would have the simulation code try to use the CUDA code and then fall back to the C++ code if the GPU resource wasn't available (via an exception), but we may want a cleaner way to check if the GPU is available here up front. In fact, one of our product requirements is to verify that sufficient computation resources are available, so we could have it always use the GPU and through a well-formed error if the GPU isn't available, although I would prefer that we take more of a "stern warning" approach so that CPU-bound users aren't completely shut out, but clinical system operators using the custom application would be required to be using the appropriate hardware.

ltetrel commented 2 days ago

We could either check with https://github.com/NVIDIA/cuda-python or manually with

import subprocess

try:
    subprocess.check_output("nvidia-smi")
except Exception:
    print("No Nvidia GPU detected.")