Skip to content

Add memory guard to flow_direction_mfd numpy/cupy backends#1424

Merged
brendancol merged 1 commit intomainfrom
issue-1423
May 4, 2026
Merged

Add memory guard to flow_direction_mfd numpy/cupy backends#1424
brendancol merged 1 commit intomainfrom
issue-1423

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1423.

Summary

  • flow_direction_mfd allocates an (8, H, W) float64 buffer (64 B/px) on numpy and cupy with no memory guard. A 50000x50000 DEM asks for ~100 GB before erroring out.
  • Port _check_memory / _check_gpu_memory helpers from flow_accumulation_mfd (64 B/px, 50% threshold) and call them from _run_numpy and _run_cupy.
  • Dask paths process per-chunk through map_overlap and inherit the per-chunk guard via _cpu.

Test plan

  • pytest xrspatial/hydro/tests/test_flow_direction_mfd.py — 50 passed (4 new memory-guard tests + 46 existing).
  • Confirmed message includes raster dimensions and dask suggestion.
  • CI run on full suite.

The (8, H, W) float64 fractions buffer is an 8x amplifier on top of
the input raster.  Without a guard, a 50000x50000 DEM asks for ~100 GB
silently before any error.

Port the _check_memory / _check_gpu_memory helpers from
flow_accumulation_mfd (64 bytes/pixel budget, 50% threshold) and call
them from _run_numpy and _run_cupy.  Dask paths process per-chunk
through map_overlap and inherit the per-chunk guard.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 3, 2026
brendancol added a commit that referenced this pull request May 3, 2026
Records the 11 PRs filed this round:
- hydro: HIGH flow_direction_mfd memory guard (PR #1424); MEDIUM
  bundles for _validate_raster on secondary args (#1426), scalar
  param validation (#1428), and cellsize validation (#1430).
- reproject: MEDIUM bundles for _validate_raster (#1432), grid/bounds/
  precision validation (#1434), and NaN/Inf rejection (#1436).
- flood: mannings_n DataArray validation (#1438).
- pathfinding: waypoint cap + _validate_raster (#1440).
- polygonize: _validate_raster (#1442).
- terrain: scratch memory guard + scalar validation (#1444).
@brendancol brendancol merged commit e5a0d4f into main May 4, 2026
11 checks passed
@brendancol brendancol deleted the issue-1423 branch May 4, 2026 19:49
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_direction_mfd(): numpy and cupy backends have no memory guard

1 participant