Skip to content

GPU acceleration

Which functions run on a CUDA GPU, and how each one picks its device. Two backends are used:

  • PyTorch on CUDA (NVIDIA GPUs) for everything that builds or applies an operator, solves or fits. The device is either an explicit device= argument or the device of an input tensor (the PSF or the operator), so one choice at the start carries through.
  • CuPy, through pysrx.gpu, for some metrics: used automatically when a CUDA GPU and CuPy (the gpu extra) are present, NumPy and SciPy otherwise. Results are always returned as NumPy.

Everything also runs on the CPU, more slowly. The GPU tutorial shows the device choice, memory limits and timings.

PyTorch: optics, operators, solvers and fields

Function Device from Notes
optics.confocal.widefield_psf, pinhole_disk, confocal_psf device= PSFs are built on the device that will use them
optics.lightfield.psf_model, psf_stack device= (default "cuda") per-view PSFs and parallax shifts
optics.lightfield.fourier_shift the input tensor sub-pixel shifts in Fourier space
optics.sim.estimate_pattern device= (default "cuda") fits the lattice from the raw phases
optics.sim.otf2d device= (default "cpu")
forward.sim.SimOperator device= (default "cuda") the lattice SIM operator and its adjoint
forward.lightfield.Projector the PSF OTF cache sized from the free GPU memory
solvers.opsolve.rl_op, tikhonov_op, fit_field_op the operator any operator: lattice SIM, light field
solvers.rl.richardson_lucy, solvers.map.map_recon the PSF light-field solvers; z_chunk limits memory
field.hashgrid.fit_field, render_grid, render_points the PSF or the field InrConfig.plane_chunk, z_chunk and log2_table set the memory
field.hashgrid.load_field device= (default "cuda") a saved field, ready to render
simulate.forward_views, camera the PSF or the input in-silico data with camera noise
camera.calibrate, pixel_stats device= (default CUDA if available) per-pixel sCMOS maps; frame_chunk limits memory

Every solver result reports seconds and peak_vram_gb.

CuPy: metrics (automatic)

Function Notes
metrics.decorrelation_resolution FFTs and Gaussian filters
metrics.axial_fwhm peak search on the volume
metrics.rfrc.rolling_frc_map, self_rolling_frc_map batched window FFTs, whole window rows at a time
gpu.map_coordinates interpolation, used by registration
register.fit_distortion, search_z, displacement_field, resample_to_ref resampling and NCC through pysrx.gpu

The other metrics (frc, self_frc, tenengrad, the fidelity metrics) run with NumPy on single planes, where the transfer to a GPU costs more than it saves. gpu.clear() frees the CuPy device cache.