Guard hand_dinf() against unbounded memory allocations (#1344)#1346
Merged
brendancol merged 1 commit intomainfrom Apr 29, 2026
Merged
Guard hand_dinf() against unbounded memory allocations (#1344)#1346brendancol merged 1 commit intomainfrom
brendancol merged 1 commit intomainfrom
Conversation
Mirrors the fix from #1326 (hand_d8) and #1340 (hand_mfd). The numpy and cupy backends call _hand_dinf_cpu which allocates seven full-grid working arrays totaling 38 bytes/pixel; a 50000x50000 raster would ask for ~95 GB before any sanity check ran. Adds _check_memory and _check_gpu_memory helpers, wired into the numpy and cupy dispatch in hand_dinf(). Dask backends are unchanged since per-tile allocations are bounded by the user's chunk size. Five new tests cover oversize rejection on numpy and cupy, valid pass-through, dask bypass, and error message content.
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.
Closes #1344.
Same shape as #1326 (
hand_d8) and #1340 (hand_mfd). The numpy and cupy backends ofhand_dinfboth run_hand_dinf_cpu, which allocates seven full-grid working arrays totalling 38 bytes/pixel. A 50000x50000 raster would ask for ~95 GB before any sanity check ran.Allocations
_hand_dinf_cpuallocates:The cupy path copies its three inputs to host via
.get()then runs the same CPU kernel, so it also pays 38 B/px on the host plus the input copies. A conservative 32 B/px applies on the device side for symmetry with #1326 and #1340.Fix
Adds
_check_memoryand_check_gpu_memoryhelpers and wires them into the numpy and cupy branches ofhand_dinf(). Dask paths are untouched since per-tile allocations are bounded by chunk size.Tests
Five new tests cover:
MemoryErrorMemoryError(CUDA-only)Full hydro suite runs 635 passed, 1 failed (
test_stream_link_dask_temp_cleanup, a known flake unrelated to this change).