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] Raft RNG updated API #2260

Merged
merged 6 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cpp/include/cugraph/algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <cugraph-ops/graph/sampling.hpp>

#include <raft/handle.hpp>
#include <raft/random/rng_state.hpp>
#include <raft/span.hpp>

namespace cugraph {
Expand Down Expand Up @@ -1389,7 +1390,7 @@ random_walks(raft::handle_t const& handle,
* single-gpu).
* @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and
* handles to various CUDA libraries) to run graph algorithms.
* @param rng The Rng (stateful) instance holding pseudo-random number generator state.
* @param rng_state The RngState instance holding pseudo-random number generator state.
* @param graph Graph (view )object to sub-sample.
* @param ptr_d_start Device pointer to set of starting vertex indices for the sub-sampling.
* @param num_start_vertices = number(vertices) to use for sub-sampling.
Expand All @@ -1404,7 +1405,7 @@ template <typename graph_t>
std::tuple<rmm::device_uvector<typename graph_t::edge_type>,
rmm::device_uvector<typename graph_t::vertex_type>>
sample_neighbors_adjacency_list(raft::handle_t const& handle,
ops::gnn::graph::Rng& rng,
raft::random::RngState& rng_state,
graph_t const& graph,
typename graph_t::vertex_type const* ptr_d_start,
size_t num_start_vertices,
Expand All @@ -1420,7 +1421,7 @@ sample_neighbors_adjacency_list(raft::handle_t const& handle,
* single-gpu).
* @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and
* handles to various CUDA libraries) to run graph algorithms.
* @param rng The Rng (stateful) instance holding pseudo-random number generator state.
* @param rng_state The RngState instance holding pseudo-random number generator state.
* @param graph Graph (view )object to sub-sample.
* @param ptr_d_start Device pointer to set of starting vertex indices for the sub-sampling.
* @param num_start_vertices = number(vertices) to use for sub-sampling.
Expand All @@ -1435,7 +1436,7 @@ template <typename graph_t>
std::tuple<rmm::device_uvector<typename graph_t::vertex_type>,
rmm::device_uvector<typename graph_t::vertex_type>>
sample_neighbors_edgelist(raft::handle_t const& handle,
ops::gnn::graph::Rng& rng,
raft::random::RngState& rng_state,
graph_t const& graph,
typename graph_t::vertex_type const* ptr_d_start,
size_t num_start_vertices,
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/detail/utility_wrappers.cu
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ void uniform_random_fill(rmm::cuda_stream_view const& stream_view,
value_t max_value,
uint64_t seed)
{
raft::random::Rng rng(seed);
rng.uniform<value_t, size_t>(d_value, size, min_value, max_value, stream_view.value());
raft::random::RngState rng_state(seed, raft::random::GeneratorType::GenPhilox);
raft::random::uniform<value_t, size_t>(
rng_state, d_value, size, min_value, max_value, stream_view.value());
}

template void uniform_random_fill(rmm::cuda_stream_view const& stream_view,
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/sampling/nbr_sampling_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ uniform_nbr_sample_impl(
//
device_vec_t<edge_t> d_rnd_indices(d_new_in.size() * k_level, handle.get_stream());

cugraph_ops::Rng rng(row_rank + level);
raft::random::RngState rng_state(row_rank + level);
cugraph_ops::get_sampling_index(detail::raw_ptr(d_rnd_indices),
rng,
rng_state,
detail::raw_const_ptr(d_out_degs),
static_cast<edge_t>(d_out_degs.size()),
static_cast<int32_t>(k_level),
Expand Down
18 changes: 10 additions & 8 deletions cpp/src/sampling/neighborhood.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@

#include <cugraph-ops/graph/sampling.hpp>

#include <raft/random/rng_state.hpp>

namespace cugraph {

template <typename graph_t>
std::tuple<rmm::device_uvector<typename graph_t::edge_type>,
rmm::device_uvector<typename graph_t::vertex_type>>
sample_neighbors_adjacency_list(raft::handle_t const& handle,
ops::gnn::graph::Rng& rng,
raft::random::RngState& rng_state,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You will have to make the corresponding changes to cpp/include/cugraph/algorithms.hpp file. The functions sample_neighbors* do not have a python binding yet so CI should not break because of this.
@rlratzel thoghts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. I've updated the public API in algorithms.
I don't see any uses in python or binding code, so I think this should be good enough for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

You will have to make the corresponding changes to cpp/include/cugraph/algorithms.hpp file. The functions sample_neighbors* do not have a python binding yet so CI should not break because of this. @rlratzel thoghts?

This should be okay since the python binding for neighborhood sampling will use the C API, which does not expose this function signature to the binding code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I will merge this change (once it is merged into the code base) into my refactor branch for uniform neighborhood sampling. I've been talking with Corey about wanting to make this change, so I'm ready.

graph_t const& graph,
typename graph_t::vertex_type const* ptr_d_start,
size_t num_start_vertices,
size_t sampling_size,
ops::gnn::graph::SamplingAlgoT sampling_algo)
{
const auto [ops_graph, max_degree] = detail::get_graph_and_max_degree(graph);
return ops::gnn::graph::uniform_sample_csr(rng,
return ops::gnn::graph::uniform_sample_csr(rng_state,
ops_graph,
ptr_d_start,
num_start_vertices,
Expand All @@ -48,15 +50,15 @@ template <typename graph_t>
std::tuple<rmm::device_uvector<typename graph_t::vertex_type>,
rmm::device_uvector<typename graph_t::vertex_type>>
sample_neighbors_edgelist(raft::handle_t const& handle,
ops::gnn::graph::Rng& rng,
raft::random::RngState& rng_state,
graph_t const& graph,
typename graph_t::vertex_type const* ptr_d_start,
size_t num_start_vertices,
size_t sampling_size,
ops::gnn::graph::SamplingAlgoT sampling_algo)
{
const auto [ops_graph, max_degree] = detail::get_graph_and_max_degree(graph);
return ops::gnn::graph::uniform_sample_coo(rng,
return ops::gnn::graph::uniform_sample_coo(rng_state,
ops_graph,
ptr_d_start,
num_start_vertices,
Expand All @@ -72,7 +74,7 @@ sample_neighbors_edgelist(raft::handle_t const& handle,
template std::tuple<rmm::device_uvector<int32_t>, rmm::device_uvector<int32_t>>
sample_neighbors_adjacency_list<graph_view_t<int32_t, int32_t, float, false, false>>(
raft::handle_t const& handle,
ops::gnn::graph::Rng& rng,
raft::random::RngState& rng_state,
graph_view_t<int32_t, int32_t, float, false, false> const& gview,
int32_t const* ptr_d_start,
size_t num_start_vertices,
Expand All @@ -82,7 +84,7 @@ sample_neighbors_adjacency_list<graph_view_t<int32_t, int32_t, float, false, fal
template std::tuple<rmm::device_uvector<int64_t>, rmm::device_uvector<int64_t>>
sample_neighbors_adjacency_list<graph_view_t<int64_t, int64_t, float, false, false>>(
raft::handle_t const& handle,
ops::gnn::graph::Rng& rng,
raft::random::RngState& rng_state,
graph_view_t<int64_t, int64_t, float, false, false> const& gview,
int64_t const* ptr_d_start,
size_t num_start_vertices,
Expand All @@ -94,7 +96,7 @@ sample_neighbors_adjacency_list<graph_view_t<int64_t, int64_t, float, false, fal
template std::tuple<rmm::device_uvector<int32_t>, rmm::device_uvector<int32_t>>
sample_neighbors_edgelist<graph_view_t<int32_t, int32_t, float, false, false>>(
raft::handle_t const& handle,
ops::gnn::graph::Rng& rng,
raft::random::RngState& rng_state,
graph_view_t<int32_t, int32_t, float, false, false> const& gview,
int32_t const* ptr_d_start,
size_t num_start_vertices,
Expand All @@ -104,7 +106,7 @@ sample_neighbors_edgelist<graph_view_t<int32_t, int32_t, float, false, false>>(
template std::tuple<rmm::device_uvector<int64_t>, rmm::device_uvector<int64_t>>
sample_neighbors_edgelist<graph_view_t<int64_t, int64_t, float, false, false>>(
raft::handle_t const& handle,
ops::gnn::graph::Rng& rng,
raft::random::RngState& rng_state,
graph_view_t<int64_t, int64_t, float, false, false> const& gview,
int64_t const* ptr_d_start,
size_t num_start_vertices,
Expand Down
1 change: 0 additions & 1 deletion cpp/src/sampling/rw_traversals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include <raft/device_atomics.cuh>
#include <raft/handle.hpp>
#include <raft/random/rng.cuh>

#include <rmm/device_uvector.hpp>

Expand Down
1 change: 0 additions & 1 deletion cpp/tests/sampling/random_walks_profiling.cu
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <sampling/random_walks.cuh>

#include <raft/handle.hpp>
#include <raft/random/rng.cuh>

#include <rmm/exec_policy.hpp>

Expand Down
1 change: 0 additions & 1 deletion cpp/tests/sampling/random_walks_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <sampling/random_walks.cuh>

#include <raft/handle.hpp>
#include <raft/random/rng.cuh>

#include "random_walks_utils.cuh"

Expand Down
1 change: 0 additions & 1 deletion cpp/tests/sampling/rw_low_level_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <sampling/random_walks.cuh>

#include <raft/handle.hpp>
#include <raft/random/rng.cuh>

#include "random_walks_utils.cuh"

Expand Down