Guard watershed_mfd() against unbounded memory allocations (#1339)#1342
Merged
Conversation
Adds host (97 B/pixel) and GPU (72 B/pixel) memory guards on the numpy and cupy dispatch branches of watershed_mfd. The MFD float64 fractions buffer (8 channels x 8 bytes = 64 B/pixel) is the dominant cost vs. the 8 B/pixel D8 flow direction array. Dask paths are unchanged -- per-tile allocations are bounded by the user's chunk size.
This was referenced Apr 29, 2026
brendancol
added a commit
that referenced
this pull request
Apr 29, 2026
…1348) Mirrors the pattern from watershed_d8 (#1330) and watershed_mfd (#1342). CPU peak is 33 B/pixel (single-channel float64 angle, same as D8). GPU peak is 24 B/pixel (caller's flow_dir + pour_points + result). Guards run on numpy/cupy dispatch paths; dask paths skip them since per-tile allocations are bounded by 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.
Summary
_check_memoryand_check_gpu_memoryguards (50% threshold) to the numpy and cupy dispatch branches ofwatershed_mfdCloses #1339.
Test plan
pytest xrspatial/hydro/tests/test_watershed_mfd.py(17 passed: 12 existing + 5 new)pytest xrspatial/hydro/tests/(635 passed; one unrelatedtest_basin_d8::test_basin_dask_temp_cleanupflake from parallel agents sharing/tmp/xrs_bdry_*, passes in isolation)