Skip to content

Batch CuPy reductions and drop redundant copies in reproject#1460

Merged
brendancol merged 1 commit intomainfrom
cupy-batched-reductions-and-copy-cleanup
May 4, 2026
Merged

Batch CuPy reductions and drop redundant copies in reproject#1460
brendancol merged 1 commit intomainfrom
cupy-batched-reductions-and-copy-cleanup

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1457

Summary

  • The cupy chunk path called .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_cupy and _reproject_dask_cupy.
  • Drop .copy() calls that immediately follow .astype(np.float64) / .astype(cp.float64). astype defaults to copy=True so 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)
  • New regression test test_cupy_reproject_with_nan_chunks exercises both the all-NaN early-return and the finite-result branch through the batched reduction path

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.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 4, 2026
@brendancol brendancol merged commit 1a5f198 into main May 4, 2026
11 checks passed
@brendancol brendancol deleted the cupy-batched-reductions-and-copy-cleanup branch May 5, 2026 03:45
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.

Reduce CuPy host round-trips and remove redundant copies in reproject

1 participant