Cap dask graph size in read_geotiff_dask and batch adler32 transfers#1211
Merged
brendancol merged 1 commit intomasterfrom Apr 16, 2026
Merged
Cap dask graph size in read_geotiff_dask and batch adler32 transfers#1211brendancol merged 1 commit intomasterfrom
brendancol merged 1 commit intomasterfrom
Conversation
read_geotiff_dask built one delayed task per chunk with no upper bound. For very large files at small chunk sizes the Python graph itself OOMs the driver before any pixel read runs (30TB at chunks=256 would produce ~125M chunks, ~500M tasks, ~500GB graph on the host). Cap total chunks at 1,000,000 and auto-scale the requested chunks size upward, emitting a UserWarning so callers know their request was adjusted. _nvcomp_batch_compress on the deflate path copied every uncompressed tile GPU->CPU one at a time with .get().tobytes() purely to compute the zlib adler32 trailer. Each per-tile .get() is a sync point on the default stream. Batch all tiles into a single contiguous device buffer, transfer once, then compute adler32 from a host memoryview slice per tile.
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
read_geotiff_dask: cap total dask chunks at 1,000,000. When the requestedchunks=would exceed the cap, auto-scale chunk size upward and emit aUserWarning. Prevents driver OOM during graph construction for very large files at small chunk sizes._nvcomp_batch_compress(deflate path): batch all tile uncompressed buffers into a single contiguous device buffer, transfer host-side once, and computezlib.adler32from memoryview slices. Removesn_tilesper-tile.get()sync points andtobytes()copies.Motivation
Static analysis on 30TB-scale dask workloads flagged
read_geotiff_daskas WILL-OOM for an unrealistic-but-legal combination: atchunks=256a 2.87M × 2.87M image would build ~125M spatial chunks and ~500M dask tasks. Each delayed task retains ~1KB of Python graph metadata, so the driver allocates tens to hundreds of GB for the graph alone — before any file read executes. The cap keeps the graph bounded without changing behavior for normal chunk sizes.The adler32 finding is on the GPU write path: when nvCOMP returns raw deflate we have to wrap it in a zlib container, which needs an adler32 trailer computed from the uncompressed bytes. The previous code pulled each tile off the device individually, each
.get()being a stream sync, each.tobytes()an extra copy. Batching gives us one DMA instead of N.Benchmark
Graph-construction measurement for a synthetic GeoTIFF (4096 × 4096 float32):
Linear in task count confirms the O(N) graph scaling. The cap triggers only when the computed chunk count exceeds 1,000,000; at normal usage the behavior and task count are unchanged.
Test plan
pytest xrspatial/geotiff/tests/ -k "dask or read_geotiff"— 12 existing tests passread_geotiff_daskwith default chunks produces no warning; verify small-chunks case emits the expectedUserWarningwith the auto-scaled tupleOut of scope
zlib.adler32call per tile on host data).chunkssize for very large files is left for a follow-up.