Batch CuPy reductions and drop redundant copies in reproject#1460
Merged
brendancol merged 1 commit intomainfrom May 4, 2026
Merged
Batch CuPy reductions and drop redundant copies in reproject#1460brendancol merged 1 commit intomainfrom
brendancol merged 1 commit intomainfrom
Conversation
Closes #1457 The cupy chunk path called .get() four times in a row to bring nanmin/nanmax of the row and column pixel coordinates back to the host. Each .get() is a synchronous device-to-host transfer. Stack the four reductions into a single 4-element CuPy array and pull that across in one transfer. The same change applies to the in-memory dask+cupy path. Also drop a few .copy() calls that immediately follow .astype(). astype defaults to copy=True so the result is already a fresh array; the extra copy is redundant. Adds a cupy regression test that exercises both the all-NaN early-return (target chunk fully outside the source) and the finite-result branch through the batched reduction path.
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 #1457
Summary
.get()four times in sequence on the row/col pixel min/max reductions. Each one is a synchronous device-to-host transfer. Stack the four reductions into a single CuPy array and pull them across in one transfer. Applied in both_reproject_chunk_cupyand_reproject_dask_cupy..copy()calls that immediately follow.astype(np.float64)/.astype(cp.float64).astypedefaults tocopy=Trueso it already returns a fresh array; the extra copy is redundant.Test plan
pytest xrspatial/tests/test_reproject.py -x(181 passed locally; cupy tests skip without a GPU)test_cupy_reproject_with_nan_chunksexercises both the all-NaN early-return and the finite-result branch through the batched reduction path