ttricco / sarracen

A Python library for smoothed particle hydrodynamics (SPH) analysis and visualization.
https://sarracen.readthedocs.io
GNU General Public License v3.0
15 stars 17 forks source link

Automatic selection of computation backend #47

Closed AndrewHarris709 closed 1 year ago

AndrewHarris709 commented 1 year ago

Change the behavior of computation backend selection, to automatically use gpu when CUDA is available. Resolves #45

Now, backend selection behavior is as follows:

ttricco commented 1 year ago

Warning: here's a long winded answer to a small change.

This opens a bigger conversation for me about handling global variables with Sarracen. I think you're right that the sdf.backend is kind of clunky, that is, having a backend set per data frame. We were talking earlier today about dealing with time series and loading multiple data frames inside one analysis. That got me thinking that setting the backend once per session, rather than per data frame, would be more sensible.

I was poking around how pandas handles this. They have a _config directory, and then _config/init.py and _config/config.py, in which global variables are set and stored. This seems like it might be a good framework. Would be extensible to future global variables.

We could define a private dictionary inside config.py that would currently just have one key. 'backend'. Could set the value for this key on import using the numba check for Cuda, just like how you've done in the PR here. Maybe putting initialization in the .config/init.py is ok for now?

For the render calls, could still accept backend= 'gpu' or 'cpu'. I was wondering if we should introduce 'auto' as the default option, which for now would just reference the global variable. backend=None seems like a weird phrasing (does it mean no backend?).

Thoughts?