proximity: match GPU max_distance precision to the CPU brute-force (#3389)#3391
Merged
brendancol merged 2 commits intoJun 19, 2026
Merged
Conversation
The CPU brute-force _distance casts to float32 before the best_dist <= max_distance check, while the CUDA kernel compared the float64 distance. A max_distance landing in a target's float32 ulp gap qualified the target on numpy/dask+numpy but rejected it on cupy/dask+cupy. Round best_dist to float32 in the kernel before the range test so all four backends agree.
brendancol
commented
Jun 19, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: proximity: match GPU max_distance precision to the CPU brute-force (#3389)
Blockers (must fix before merge)
None.
Suggestions (should fix, not blocking)
None.
Nits (optional improvements)
- The bounded-dask EUCLIDEAN-allocation float32-ulp edge is recorded in the PR body and the sweep state, but it is out of scope here. A one-line follow-up issue would make it easier to track than a buried note.
What looks good
- Root cause is correct.
_distancereturnsnp.float32(d), so the CPU compares a float32-rounded distance againstmax_distance, while_proximity_cuda_kernelcompared the float64 distance. Roundingbest_distto float32 before the<= max_distancetest makes the in-range decision identical on both. - The stored PROXIMITY value does not change in practice:
outis float32, so the previous float64best_distwas already cast on store. The fix only moves the cast ahead of the comparison. - The tests pin the real divergence. Each sets
max_distancestrictly between the float32 and float64 distance (asserted withfloat(np.float32(d64)) < md < d64) and checks numpy against cupy. They fail before the fix (cupy returns NaN) and pass after. - Both brute-force output branches of the kernel are covered: GREAT_CIRCLE proximity and EUCLIDEAN allocation.
- No dispatch change. The fix lives in the shared kernel, so cupy and dask+cupy (which reuses the kernel per chunk) both pick it up.
Checklist
- Algorithm matches the CPU reference behaviour
- All implemented backends produce consistent results at the boundary
- NaN handling correct (in-range decision now matches across backends)
- Edge case (float32 ulp boundary) covered by tests
- Dask chunk boundaries unaffected (kernel-level change, dask+cupy reuses it)
- No premature materialization or unnecessary copies
- Benchmark not needed (no performance-relevant change)
- README feature matrix unchanged (no new function, no backend change)
- Docstrings unaffected (internal kernel comment added)
Contributor
Author
|
Filed the out-of-scope bounded-dask EUCLIDEAN-allocation float32-ulp edge as #3392 for tracking (review nit). |
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 #3389
The CPU brute-force search compares a float32-rounded distance against
max_distance(_distancereturnsnp.float32(d)), while the CUDA kernel compared the float64 distance. Amax_distancesitting in a target's float32 ulp gap then qualified the target on numpy/dask+numpy but rejected it on cupy/dask+cupy for the same input.best_distto float32 in_proximity_cuda_kernelbefore thebest_dist <= max_distancerange test, so the in-range decision matches the CPU path.Backend coverage: the change is in the shared CUDA kernel, so it covers cupy and dask+cupy (which reuses the kernel per chunk). numpy and dask+numpy were already on the float32 side and are unchanged.
A separate, pre-existing edge is out of scope here: the bounded dask+numpy EUCLIDEAN allocation path can still return NaN for a target sitting exactly at a float32-ulp
max_distance, via the halo-sizing path rather than the kernel. It predates this change and is noted in the sweep state for follow-up.Test plan:
pytest xrspatial/tests/test_proximity.py(518 passed on a CUDA host, including cupy and dask+cupy)