Guard flow_path_dinf() against unbounded memory allocations (#1363)#1367
Merged
brendancol merged 1 commit intomainfrom Apr 29, 2026
Merged
Guard flow_path_dinf() against unbounded memory allocations (#1363)#1367brendancol merged 1 commit intomainfrom
brendancol merged 1 commit intomainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1363.
Summary
_check_memoryand_check_gpu_memoryhelpers toflow_path_dinf.py(24 B/px CPU, 32 B/px GPU, 50% threshold) modelled on the flow_length_d8/dinf/mfd guards.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)