Skip to content

Guard flow_path_dinf() against unbounded memory allocations (#1363)#1367

Merged
brendancol merged 1 commit intomainfrom
issue-1363
Apr 29, 2026
Merged

Guard flow_path_dinf() against unbounded memory allocations (#1363)#1367
brendancol merged 1 commit intomainfrom
issue-1363

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Fixes #1363.

Summary

  • Add _check_memory and _check_gpu_memory helpers to flow_path_dinf.py (24 B/px CPU, 32 B/px GPU, 50% threshold) modelled on the flow_length_d8/dinf/mfd guards.
  • Wire them into the public flow_path_dinf() dispatch on the eager numpy and cupy branches before the float64 casts. Dask paths skip the guard.

Why

The numpy and cupy branches allocate ~24 B/pixel of working memory with no check against host RAM. A 50000x50000 float64 grid asks for ~60 GB of working memory and triggers the OOM killer rather than raising a clean MemoryError.

Test plan

  • pytest xrspatial/hydro/tests/test_flow_path_dinf.py -- 21 passed (16 existing + 5 new guard tests)
  • Full hydro suite: 736 passed, 2 deselected (known flakes per AGENTS.md)
  • Numpy huge-raster MemoryError fires with mocked low memory
  • Cupy huge-raster MemoryError fires with mocked low GPU memory
  • Dask path bypasses the guard
  • Error message includes grid dimensions and a dask hint

The numpy and cupy branches allocate ~24 B/pixel of working memory
(input float64 cast, start-points float64 cast, output) with no check
against available host RAM. A 50000x50000 float64 grid asks for ~60 GB
of working memory and triggers the OOM killer rather than raising a
clean error. The cupy branch additionally round-trips through host
memory before reallocating on device.

Add `_check_memory` and `_check_gpu_memory` helpers (24 B/px CPU,
32 B/px GPU, 50% threshold) and call them from the public dispatch
on the eager numpy and cupy branches. Dask paths skip the guard --
per-tile allocations are bounded by the user's chunk size.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 29, 2026
@brendancol brendancol merged commit 845f818 into main Apr 29, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flow_path_dinf: no memory guard on H*W working arrays

1 participant