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

Add support for nosync thrust exec policy #2293

Closed
wants to merge 2 commits into from

Conversation

abc99lr
Copy link
Contributor

@abc99lr abc99lr commented May 6, 2024

Currently, all the thrust calls used in RAFT are sync calls. There is another RMM execution policy that support async (or nosync) thrust calls. Supporting async calls is important. For example, we need the kmeans predict to be async in order to achieve kernel/copy overlapping in IVF-Flat index build (#2106).

This PR

  1. Add support for nosync thrust policy in raft::resource
  2. Change the thrust calls in kmeans predict to nosync versions. This would enable us achieve memcpy and kernel overlapping in IVF-Flat index building. Based on discussions, we should use raft::linalg::map instead. Will open another PR for this change.

@abc99lr abc99lr requested a review from a team as a code owner May 6, 2024 21:43
Copy link

copy-pr-bot bot commented May 6, 2024

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions bot added the cpp label May 6, 2024
Copy link
Contributor

@tfeher tfeher left a comment

Choose a reason for hiding this comment

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

Thanks Rui for fixing this, it is indeed important to switch to async policy to improve vector search build time. Overall it looks good!

@achirkin could you also have a look at the changes in resource handling?

@tfeher tfeher added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change Vector Search labels May 7, 2024
@tfeher tfeher requested a review from achirkin May 7, 2024 21:04
Copy link
Contributor

@achirkin achirkin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I welcome introduction of the thrust_nosync_policy, it could be useful to us in theory. However, both places you changed in kmean_balanced.cuh could better be done with raft's own linalg::map.

cpp/include/raft/cluster/detail/kmeans_balanced.cuh Outdated Show resolved Hide resolved
cpp/include/raft/cluster/detail/kmeans_balanced.cuh Outdated Show resolved Hide resolved
@cjnolet
Copy link
Member

cjnolet commented May 8, 2024

However, both places you changed in kmean_balanced.cuh could better be done with raft's own linalg::map

@abc99lr, I just want to give an additional +1 to @achirkin's comment here. In general, we prefer to reuse raft functions where at all possible across the codebase, even when the raft function itself might be a trivial wrapper around thrust, cub, or one of the math libs. The reason for this is that it centralizes these calls so that we can properly instrument, improve, or even fix bugs as they arise in a single place, rather than having to scrape through the codebase and fix them in many places.

The other reason for this is API consistency- over time, raft has improved to become quite a pleasant API experience by being able to compose larger algorithms out of a series of raft functions, which improves code readability.

@abc99lr
Copy link
Contributor Author

abc99lr commented May 8, 2024

Thanks for the comments. I'll change the thrust calls in kmeans_balanced::predict to raft::linalg::map in a separate PR. For this one, I'll only add the nosync policy and remove the changes in kmeans_balanced::predict. Sound good?

@abc99lr abc99lr changed the title [REVIEW] Add support for nosync thrust exec policy. Use nosync thrust calls for kmeans_balanced predict Add support for nosync thrust exec policy May 8, 2024
@abc99lr abc99lr requested a review from achirkin May 8, 2024 23:19
@cjnolet
Copy link
Member

cjnolet commented May 8, 2024

For this one, I'll only add the nosync policy and remove the changes in kmeans_balanced::predict. Sound good?

If we aren't going to be using this nosync policy, I'd like to avoid merging changes just for the sake of merging changes.

@abc99lr
Copy link
Contributor Author

abc99lr commented May 8, 2024

Closing.

@abc99lr abc99lr closed this May 8, 2024
@cjnolet
Copy link
Member

cjnolet commented May 8, 2024

Most functions in RAFT are assumed to be async, so I suspect we could probably scrape through all of the places we use the thrust_policy and replace them with nosync_policy. @abc99lr I'm not against merging this just for that reason alone, but would you mind creating an issue for the above so that we don't lose sight of it? Just want to avoid this getting stale and remaining unused for the non-foreseeable future.

@abc99lr
Copy link
Contributor Author

abc99lr commented May 8, 2024

If we aren't going to be using this nosync policy, I'd like to avoid merging changes just for the sake of merging changes.

Understand. But I do think RAFT should provide this functionality to developers and tell people to use nosync policy when could. Otherwise, there would be many unnecessary syncs introduced.

@abc99lr
Copy link
Contributor Author

abc99lr commented May 8, 2024

Talked with @cjnolet, we think it's worth to try using nosync_policy by default. Going to create another PR for that

rapids-bot bot pushed a commit that referenced this pull request May 13, 2024
Testing. Do not merge. 

Based on the discussions from #2293, it's a good idea to test if we could use nosync thrust calls by default. This PR changes the current `rmm::exec_policy` to its async version `rmm::exec_policy_nosync`.

Authors:
  - Rui Lan (https://github.com/abc99lr)

Approvers:
  - Corey J. Nolet (https://github.com/cjnolet)

URL: #2302
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp improvement Improvement / enhancement to an existing function non-breaking Non-breaking change Vector Search
Projects
Development

Successfully merging this pull request may close these issues.

4 participants