clij / clij2-fft

20 stars 6 forks source link

Add dask rl and related utility functions #23

Closed bnorthan closed 8 months ago

bnorthan commented 8 months ago

Add new dask scheme with using design and utility functions from Dimitris Nicoloutsopoulos.

Notes: This is a handy scheme to deconvolve a 3D image with large image plane sizes but somewhat smaller number of planes (ie sizes like 'a few thousand' in x by 'a few thousand' in y by 'a few hundred' in z, for example 2304, 2304, 300). The scheme likely won't work if there are thousands of planes. The implementation also only uses 1 GPU, for cases with thousands of planes and/or multiple GPUs please open an issue on clij2-fft or start a discussion on image.sc to brainstorm potential approaches.

The dask richardson lucy implementation is as follows.

  1. Detect amount of GPU memory, or (optionally) caller specifies how much GPU memory to be used. Note it is much more difficult to detect realtime GPU memory use with opencl compared to cuda, thus we are detecting memory on the card, not memory in use, and give the caller the option of limiting memory to deal with situations where some GPU memory is used by other processes.
  2. Calculate RL memory footprint given image size, psf size, depth (overlap) size, and adding a factor of safety for potential extra memory use by the clfft library and/or memory use by concurrent GPU processes.
  3. Compute a power of 2 chunk factor (2,4,8 etc). This will be used to subdivide in the x and y dimensions, so total blocks will be a power of 4 (4, 16, 64, etc.)
  4. Compute chunk sizes based on chunk factor then deconvolve using dask.