Skip to content

gradient engine speed improvements (approx. 25% for 4 modes, 1024x 1024) with managing fft shifts - #153

Merged
ShantanuKodgirwar merged 5 commits into
mainfrom
minor-GE-speed-mem-improvements
Nov 16, 2026
Merged

ShantanuKodgirwar merged 5 commits into
mainfrom
minor-GE-speed-mem-improvements

Conversation

@ShantanuKodgirwar

Copy link
Copy Markdown
Contributor

What and why

GradientEngine iterations spent much of their GPU time on FFT shifts that copy every probe mode's full field. These changes apply the shifts to smaller arrays (the patch, the probe and the summed intensity), which gives the same results faster.

  • PtyLab/Engines/GradientEngine/propagation.py: add KernelPropagator.unshifted, the same propagation without the outer fftshift/ifftshift.
  • PtyLab/Engines/GradientEngine/models.py: forward shifts the object patch, the probe and the summed intensity instead of every mode's field. illumination squares a shared probe once instead of once per frame.
  • PtyLab/Engines/GradientEngine/engine.py: clearer compile docstring.

How it was tested

New test_forward_matches_centered_fields: the new path gives the same intensities and gradients as the centered fields for all propagators, with mixed states and OPR. The full test suite passes.

Notes

Results are unchanged, and data, background and masks stay in centered order. With 4 probe modes at 1024 x 1024 an iteration is about 25 % faster on an H200; with one mode the speed is about the same, except scaledASP, which is about 17 % faster. ASP is unchanged. The shifts reuse temporary memory, so saves memory traffic, but the peak memory use is unaffected.

@ShantanuKodgirwar
ShantanuKodgirwar merged commit f35304e into main Nov 16, 2026
6 checks passed
@ShantanuKodgirwar
ShantanuKodgirwar deleted the minor-GE-speed-mem-improvements branch November 16, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant