Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

investigate switching KDTree usage from SciPy to CuPy #732

Open
grlee77 opened this issue Apr 27, 2024 · 2 comments
Open

investigate switching KDTree usage from SciPy to CuPy #732

grlee77 opened this issue Apr 27, 2024 · 2 comments
Labels
improvement Improves an existing functionality

Comments

@grlee77
Copy link
Contributor

grlee77 commented Apr 27, 2024

CuPy's main branch now has a KDTree implementation (cupyx.scipy.spatial.KDTree). It is not released for CuPy 13.x, but we should investigate whether it provides benefit over falling back to the host side implementation from SciPy.

Functions currently replying on SciPy for use of KDTree are:

  • cucim.skimage.feature.corner_peaks
  • cucim.skimage.feature.peak_local_max (via private utility function cucim.skimage._shared.ensure_spacing)

Other functions that use it in scikit-image, but for which CuPy has an alternative CUDA kernel is the _prune_blobs helper function used by

  • cucim.skimage.feature.blob_dog
  • cucim.skimage.feature.blob_doh
  • cucim.skimage.feature.blob_log

we can check if that kernel or the CuPy KDTree implementation is preferable.

If CuPy KDTree performance is good we can add implementation for the following scikit-image functions that primarily rely on it

  • skimage.metrics.hausdorff_distance
  • skimage.metrics.hausdorff_pair
  • skimage.transform.hough_circle_peaks
@grlee77 grlee77 added the improvement Improves an existing functionality label Apr 27, 2024
@grlee77 grlee77 added this to cucim Apr 27, 2024
rapids-bot bot pushed a commit that referenced this issue Apr 30, 2024
Functionality is equivalent since SciPy 1.6 (see note [here](https://docs.scipy.org/doc/scipy-1.13.0/reference/generated/scipy.spatial.cKDTree.html)).

I pinned SciPy to >= 1.6 (released Dec 31, 2020)

This MR also adds some missing test cases for the `_ensure_spacing` helper function used by `cucim.skimage.feature.peak_local_max`. The new tests revealed a bug in that function in the case of non-scalar `spacing` which is now fixed.

Also, CuPy recently added KDTree so we can hopefully improve performance by moving to that in the future. I opened issue #732 as a reminder to investigate that.

Authors:
  - Gregory Lee (https://github.com/grlee77)

Approvers:
  - Ray Douglass (https://github.com/raydouglass)
  - https://github.com/jakirkham

URL: #733
@cb11711211
Copy link

Hi, I am current investigate to replace scipy cKDTree with cupy KDTree, and could I provide which version of cupy provide the function?

@monzelr
Copy link
Contributor

monzelr commented Jul 25, 2024

in my first implementation for the blob algorithms I have used scipy's cKDTree - because it was a CPU solution it was a bottleneck.
I will give cupy's KDtree a try to see the performance

@cb11711211
it is not in the official release, but you find it already in the repository
you have to build cupy by yourself to test it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality
Projects
Status: No status
Development

No branches or pull requests

3 participants