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

[FEA] Rng: expose host-rng-state in host-only API #609

Merged
merged 18 commits into from
Apr 25, 2022

Conversation

MatthiasKohl
Copy link
Contributor

Changes:

  • Move RngState and GeneratorType to own header so they can be used in public APIs without a CUDA-compatible compiler (useful for python bindings etc.).
  • Move the type of generator into the state object
  • Add the advance method to the state object as well, allowing libraries to use RngState for host-only code
  • Remove the rng.hpp header: if we want to expose the Rng object itself as a host-only object, the implementation/definition would have to be separated from the declaration, and this means it would be hard to keep a header-only library for these objects. Otherwise, there is simply no way that this rng.hpp actually fulfills its contract of a host-only header, so we remove it.

This is not the only way of creating a host-only API, but it's most likely the one which needs the least amount of changes in dependent libraries, and these libraries can basically "opt-in" to the host-only API.

@cjnolet Do you agree with this approach? I'd like to get this PR into 22.06 fairly soon, so we can finally go back to sane APIs and compile commands in cugraph-ops and cugraph.

@MatthiasKohl MatthiasKohl requested a review from a team as a code owner April 2, 2022 12:17
@github-actions github-actions bot added the cpp label Apr 2, 2022
@MatthiasKohl MatthiasKohl added 3 - Ready for Review feature request New feature or request breaking Breaking change and removed cpp labels Apr 2, 2022
@github-actions github-actions bot added the cpp label Apr 5, 2022
@MatthiasKohl MatthiasKohl added 2 - In Progress Currenty a work in progress and removed 3 - Ready for Review labels Apr 7, 2022
@MatthiasKohl MatthiasKohl added 3 - Ready for Review and removed 2 - In Progress Currenty a work in progress labels Apr 19, 2022
@MatthiasKohl
Copy link
Contributor Author

This PR fixes #406

Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

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

Overall I really like the separation of the rng state and the flattened functions because they are more consistent w/ the rest of raft's public APIs. I suggest we still use rng.cuh for the flattened API functions if we can.

cpp/include/raft/random/detail/rng_state.hpp Outdated Show resolved Hide resolved
cpp/include/raft/random/rng_launch.cuh Outdated Show resolved Hide resolved
cpp/include/raft/random/rng_state.hpp Outdated Show resolved Hide resolved
@MatthiasKohl
Copy link
Contributor Author

@cjnolet I believe I addressed your comments. I haven't fully tested all the possible deprecation messages, which are much more tricky since we want to keep the rng.cuh file.
But things compile at least and since there is no change to the actual code, I'm confident it works OK :)

DI void custom_next(
GenType& gen, OutType* val, SamplingParams<OutType, LenType> params, LenType idx, LenType stride)
template <typename DataT, typename WeightsT, typename IdxT = int>
void sampleWithoutReplacement(RngState& rng_state,
Copy link
Member

Choose a reason for hiding this comment

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

One very small nitpick I have here is that the handle should always be the first argument for primitives that accept one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the handle here since it wasn't being used in the implementation at all (the stream is already given as another parameter).
This also keeps the API in line with other RNG APIs

Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

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

I found a few more trivial things in my second pass that I missed in the first pass but overall I think it looks great. Have you tried building cuml/cugraph with these changes yet just to make sure they build successfully? I don't know that we need to open full PRs to test this anymore unless there are direct changes to the public API, but it would be a good idea to check whether things like "warnings as errors" flags cause builds to fail.

@MatthiasKohl
Copy link
Contributor Author

@cjnolet I haven't tried the cuml/cugraph builds yet but I can do that once I've addressed your latest comments

@MatthiasKohl
Copy link
Contributor Author

MatthiasKohl commented Apr 25, 2022

@cjnolet I've addressed the issues you mentioned, and I've been able to build cuml. I'm currently building cugraph as well, and the files requiring RNG seem to compile fine at least.
EDIT: cugraph builds fine as well AFAICT

Copy link
Member

@cjnolet cjnolet left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @MatthiasKohl!

@cjnolet
Copy link
Member

cjnolet commented Apr 25, 2022

@gpucibot merge

@rapids-bot rapids-bot bot merged commit d68b894 into rapidsai:branch-22.06 Apr 25, 2022
@MatthiasKohl MatthiasKohl deleted the fea-rng-hpp-api branch April 26, 2022 07:36
@MatthiasKohl MatthiasKohl mentioned this pull request Apr 26, 2022
rapids-bot bot pushed a commit that referenced this pull request Apr 27, 2022
After merging PR #609 , I realized that there were still a few bugs (all minor):
1. The deprecated `Rng` class had the `type` attribute removed. I added it back. This was used in cugraph-ops but not in other projects (cugraph, cuml).
2. The template function to call another function with the device state was actually unusable since you wouldn't be able to instantiate a function to call it with. So I removed that.
3. The macro used to call functions with a device state wasn't using fully namespace-qualified names, which made it unusable outside of RAFT.
4. Removed the deprecation warning of the new `rng_device.cuh` since it has to be included anyway through `rng.cuh`, so those deprecations didn't make sense.

Authors:
  - Matt Joux (https://github.com/MatthiasKohl)

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

URL: #630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review breaking Breaking change cpp feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants