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

[REVIEW] Execution policy class #816

Merged
merged 4 commits into from
Aug 13, 2021

Conversation

viclafargue
Copy link
Contributor

Changes currently planned for the RAFT code include updating the RAFT handle for it to store a singleton of a thrust execution policy. An execution policy class would prove useful to write a clearer code. This PR is a proof of concept for it.

cc @divyegala

@github-actions github-actions bot added the cpp Pertains to C++ code label Jul 6, 2021
@jrhemstad
Copy link
Contributor

to store a singleton of a thrust execution policy

I'm curious why you wish to do this. Are you concerned about the overhead of constructing an execution policy on the fly with the existing rmm::exec_policy function?

@viclafargue
Copy link
Contributor Author

to store a singleton of a thrust execution policy

I'm curious why you wish to do this. Are you concerned about the overhead of constructing an execution policy on the fly with the existing rmm::exec_policy function?

We are planning on adding a raft::handle_t::get_thrust_policy() method to the RAFT handle and use it everywhere a thrust execution policy is required. This would be to provide an abstraction over the rmm::exec_policy and would prevent any depreciation. Indeed, if the RMM code is modified, we would only have to update this method in the RAFT handle. But this idea is still in discussion. The idea of having a singleton is for both efficiency and also to be coherent in the way resources are created and provided to developers in the RAFT handler. Indeed, cuBlas, cuSparse and cuSolver handles are stored as singleton as well.

@jrhemstad
Copy link
Contributor

jrhemstad commented Jul 6, 2021

raft::handle_t::get_thrust_policy() could just return a call to rmm::exec_policy() as it is today, right?

I don't think you have to worry about the overhead of constructing the execution policy as it will all get inlined/optimized away anyways.

That said, I'm not opposed to an exec_policy class, but I don't want to have to change all of the existing calls to rmm::exec_policy to rmm::create_exec_policy.

@divyegala
Copy link
Member

divyegala commented Jul 6, 2021

@jrhemstad if the overhead isn't very high of creating, then I agree that raft::handle_t::get_thrust_policy() could just call rmm::exec_policy(). But it would be nice to hide that behind an rmm::exec_policy class that will handle deprecations to both the RMM and thrust APIs. Furthermore, I agree that a factory method here isn't the right approach.

In that case, rmm::exec_policy could be a class that has an implicit conversion operator to thrust's policy class, and is coupled with a stream view instance. Would that work?

Edit: It would look something like this:

class exec_policy {

    explicit exec_policy(cuda_stream_view stream_) : 
        stream(stream_) { }

    operator thrust_exec_policy_t() {
         return ...;
    }

    cuda_stream_view stream;
};

@viclafargue
Copy link
Contributor Author

I renamed the rmm::exec_policy function back to its original name, and implemented the suggested class.

@viclafargue viclafargue changed the title [WIP] Execution policy class [REVIEW] Execution policy class Jul 6, 2021
@harrism
Copy link
Member

harrism commented Jul 7, 2021

Why is deprecation such a concern? rmm::exec_policy has only had one deprecation in the life of the library, and I think the current API should be quite stable.

@harrism harrism added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Jul 7, 2021
@harrism
Copy link
Member

harrism commented Jul 7, 2021

To pass the style checks please merge the latest from upstream into your PR branch.

@viclafargue
Copy link
Contributor Author

viclafargue commented Jul 7, 2021

Why is deprecation such a concern? rmm::exec_policy has only had one deprecation in the life of the library, and I think the current API should be quite stable.

It might indeed never come useful if the API is left unchanged. However, I guess it's probably better to be prepared for such eventuality. The change might come from a change in the Thrust library.

Copy link
Member

@divyegala divyegala left a comment

Choose a reason for hiding this comment

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

I believe with this, we can have a non-breaking API update without changing the way this was originally working. cc @jrhemstad @harrism who will be able to help us best here

include/rmm/exec_policy.hpp Outdated Show resolved Hide resolved
include/rmm/exec_policy.hpp Outdated Show resolved Hide resolved
@harrism
Copy link
Member

harrism commented Jul 8, 2021

It would be nice to follow Divye's suggestion to make this a replacement for the existing function that works identically. Also, I believe _t names are meant to be reserved for use by standard library types.

@viclafargue
Copy link
Contributor Author

I removed the function and renamed the class as exec_policy. After some discussion with Divye, it appeared that the conversion function couldn't work because of templates in thrust. Instead the class is now designed to inherit from the thrust execution policy.

Copy link
Member

@divyegala divyegala left a comment

Choose a reason for hiding this comment

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

This looks good for RAFT and doesn't break the existing code. LGTM!

@caryr35 caryr35 added this to PR-WIP in v21.08 Release via automation Jul 12, 2021
@caryr35 caryr35 moved this from PR-WIP to PR-Needs review in v21.08 Release Jul 12, 2021
@caryr35 caryr35 removed this from PR-Needs review in v21.08 Release Jul 15, 2021
@caryr35 caryr35 added this to PR-WIP in v21.10 Release via automation Jul 15, 2021
@viclafargue viclafargue marked this pull request as ready for review July 16, 2021 15:23
@viclafargue viclafargue requested a review from a team as a code owner July 16, 2021 15:23
@viclafargue viclafargue requested a review from rongou July 16, 2021 15:23
@viclafargue viclafargue changed the base branch from branch-21.08 to branch-21.10 July 19, 2021 16:31
@viclafargue
Copy link
Contributor Author

rerun tests

@viclafargue
Copy link
Contributor Author

The PR should be ready to be merged.

Copy link
Member

@harrism harrism left a comment

Choose a reason for hiding this comment

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

Thanks!

v21.10 Release automation moved this from PR-WIP to PR-Reviewer approved Aug 10, 2021
@galipremsagar
Copy link
Contributor

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 570de8f into rapidsai:branch-21.10 Aug 13, 2021
v21.10 Release automation moved this from PR-Reviewer approved to Done Aug 13, 2021
rapids-bot bot pushed a commit to rapidsai/cugraph that referenced this pull request Aug 27, 2021
This PR apply modifications to the cuGraph codebase to account for changes in RAFT and RMM :
- rapidsai/raft#283
- rapidsai/raft#285
- rapidsai/raft#286
- rapidsai/rmm#816

This PR requires some changes in the cuHornet dependency : rapidsai/cuhornet#52

Authors:
  - Victor Lafargue (https://github.com/viclafargue)

Approvers:
  - Brad Rees (https://github.com/BradReesWork)
  - AJ Schmidt (https://github.com/ajschmidt8)
  - Seunghwa Kang (https://github.com/seunghwak)
  - Chuck Hastings (https://github.com/ChuckHastings)

URL: #1707
rapids-bot bot pushed a commit to rapidsai/cuml that referenced this pull request Aug 30, 2021
This PR apply modifications to the cuML codebase to account for changes in RAFT and RMM :
- rapidsai/raft#283
- rapidsai/raft#285
- rapidsai/raft#286
- rapidsai/rmm#816

Authors:
  - Victor Lafargue (https://github.com/viclafargue)
  - Dante Gama Dessavre (https://github.com/dantegd)

Approvers:
  - William Hicks (https://github.com/wphicks)
  - Micka (https://github.com/lowener)
  - Dante Gama Dessavre (https://github.com/dantegd)
  - Divye Gala (https://github.com/divyegala)

URL: #4077
vimarsh6739 pushed a commit to vimarsh6739/cuml that referenced this pull request Oct 9, 2023
This PR apply modifications to the cuML codebase to account for changes in RAFT and RMM :
- rapidsai/raft#283
- rapidsai/raft#285
- rapidsai/raft#286
- rapidsai/rmm#816

Authors:
  - Victor Lafargue (https://github.com/viclafargue)
  - Dante Gama Dessavre (https://github.com/dantegd)

Approvers:
  - William Hicks (https://github.com/wphicks)
  - Micka (https://github.com/lowener)
  - Dante Gama Dessavre (https://github.com/dantegd)
  - Divye Gala (https://github.com/divyegala)

URL: rapidsai#4077
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp Pertains to C++ code improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants