Skip to content

perf: reduce memory usage - #128

Merged
daubners merged 5 commits into
tldr-group:mainfrom
loiccoyle:memory_optimisation
Jul 30, 2026
Merged

daubners merged 5 commits into
tldr-group:mainfrom
loiccoyle:memory_optimisation

Conversation

@loiccoyle

@loiccoyle loiccoyle commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reduces GPU memory use across TauFactor solvers while preserving benchmarked tortuosity values and convergence iteration counts.

  • Stores segmentation labels as uint8; uses boolean checkerboards/masks.
  • Releases initialization temporaries earlier and avoids unnecessary full-volume field-profile repeat() allocations.
  • Reuses a solve-local increment buffer and accumulates neighbour sums in-place.
  • Replaces full-volume rolling neighbour sums with direct slice-based sums, including periodic Y/Z wrapping.
  • Extends benchmark output with separate initialization and solve RAM metrics: VRAM_I_max, VRAM_I_cur, VRAM_S_max, and VRAM_S_cur.

NVIDIA RTX A6000 benchmark

Compared fcc structure runs up to 1024³ for current main versus this code, using VRAM(max) and solver wall time :

Solver Peak VRAM change Solve-time change
Solver −32.2% +4.7%
PeriodicSolver −32.1% +4.6%
ElectrodeSolver −21.5% +4.7%
PeriodicElectrodeSolver −21.4% +4.6%

Before these changes, initialization was particularly limiting for periodic solvers: periodic electrode initialization peaked at 424 MB versus 338 MB for the non-periodic version. Direct periodic neighbour sums remove that rolling-allocation bottleneck; both now peak at 287 MB during initialization. Overall peak memory is now determined by the solve phase rather than construction.

Solver Init peak reduction Init current reduction
Solver −19.9% −28.3%
PeriodicSolver −24.0% −28.5%
ElectrodeSolver −14.9% −28.3%
PeriodicElectrodeSolver −32.2% −28.5%

Validation

  • Benchmark tau values and iteration counts are unchanged in the compared runs.
  • Focused solver and benchmark tests pass; lint and diff checks pass.

@daubners
daubners force-pushed the memory_optimisation branch from 590b6f0 to 149e41f Compare July 29, 2026 16:19
@daubners
daubners merged commit b2d2b54 into tldr-group:main Jul 30, 2026
3 checks passed
@loiccoyle

Copy link
Copy Markdown
Contributor Author

🎉

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.

2 participants