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

Use linalg & inline _get_manders_overlap_coeff #578

Merged
merged 5 commits into from
Jul 17, 2023

Conversation

jakirkham
Copy link
Member

@jakirkham jakirkham commented Jul 14, 2023

As most of the operations in _get_manders_overlap_coeff can be constructed from other linalg operations, use those directly to compute the result. Once this is done, there is less of a need to fuse it into a kernel. Instead those linalg functions can just be called as-is.

Note: This resolves a bug seen with test_moc in the CUDA 11.2 CI on the CUDA 12 PR ( #572 (comment) ) ( #572 (comment) )

@jakirkham jakirkham added bug Something isn't working non-breaking Introduces a non-breaking change labels Jul 14, 2023
@jakirkham jakirkham changed the title Use sqrt in _get_manders_overlap_coeff Use norm in _get_manders_overlap_coeff Jul 14, 2023
@jakirkham jakirkham changed the title Use norm in _get_manders_overlap_coeff Use BLAS & inline _get_manders_overlap_coeff Jul 14, 2023
@jakirkham jakirkham changed the title Use BLAS & inline _get_manders_overlap_coeff Use linalg & inline _get_manders_overlap_coeff Jul 14, 2023
@jakirkham
Copy link
Member Author

@grlee77 would be curious to hear your thoughts on this approach 🙂

@jakirkham jakirkham marked this pull request as ready for review July 14, 2023 22:32
@jakirkham jakirkham requested a review from a team as a code owner July 14, 2023 22:32
@jakirkham jakirkham requested a review from grlee77 July 14, 2023 22:36
Comment on lines +258 to +259
denom = cp.linalg.norm(image0) * cp.linalg.norm(image1)
return cp.vdot(image0, image1) / denom
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could go further here and do

1 - cupyx.scipy.spatial.distance.cosine(image0, image1)

This was added in PR ( cupy/cupy#7063 ) and would require CuPy 12.0.0+ & pylibraft from RAPIDS

Copy link
Contributor

@grlee77 grlee77 Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we have to ravel to 1D to use the cosine solution and then do a subtraction to get the equivalent result of the linalg implementation:

1 - cosine(image0.reshape(1, -1), image1.reshape(1, -1))

If the RAFT solution is faster we can provide it with fallback to the linalg one here when unavailable. In my initial testing it was slower than using linalg in this case, so let's just keep the suggested solution here for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Thanks Greg! 🙏

Copy link
Contributor

@grlee77 grlee77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @jakirkham, looks great!

@jakirkham
Copy link
Member Author

/merge

@rapids-bot rapids-bot bot merged commit a168ad9 into rapidsai:branch-23.08 Jul 17, 2023
@jakirkham jakirkham deleted the use_sqrt_moc branch July 17, 2023 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working non-breaking Introduces a non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants