Skip to content

Commit 7cb8583

Browse files
authored
Bindings for RMAT (#1573)
Bindings for RMAT Bindings for the list of RMAT graphs includes some quick fixes to address some sphinx doc-building warnings closes #1473 Authors: - Joseph Nke (https://github.com/jnke2016) - Rick Ratzel (https://github.com/rlratzel) Approvers: - Andrei Schaffer (https://github.com/aschaffer) - Chuck Hastings (https://github.com/ChuckHastings) - Rick Ratzel (https://github.com/rlratzel) URL: #1573
1 parent 924f678 commit 7cb8583

File tree

11 files changed

+1005
-85
lines changed

11 files changed

+1005
-85
lines changed

cpp/include/utilities/cython.hpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616
#pragma once
17-
1817
#include <experimental/graph.hpp>
18+
#include <experimental/graph_generator.hpp>
1919
#include <graph.hpp>
2020
#include <raft/handle.hpp>
2121
#include <rmm/device_uvector.hpp>
@@ -207,6 +207,12 @@ struct random_walk_ret_t {
207207
std::unique_ptr<rmm::device_buffer> d_sizes_;
208208
};
209209

210+
struct graph_generator_t {
211+
std::unique_ptr<rmm::device_buffer> d_source;
212+
std::unique_ptr<rmm::device_buffer> d_destination;
213+
};
214+
215+
// enum class generator_distribution_t { POWER_LAW = 0, UNIFORM };
210216
// aggregate for random_walks() COO return type
211217
// to be exposed to cython:
212218
//
@@ -488,6 +494,31 @@ std::unique_ptr<cy_multi_edgelists_t> call_egonet(raft::handle_t const& handle,
488494
vertex_t* source_vertex,
489495
vertex_t n_subgraphs,
490496
vertex_t radius);
497+
498+
// Wrapper for calling graph generator
499+
template <typename vertex_t>
500+
std::unique_ptr<graph_generator_t> call_generate_rmat_edgelist(raft::handle_t const& handle,
501+
size_t scale,
502+
size_t num_edges,
503+
double a,
504+
double b,
505+
double c,
506+
uint64_t seed,
507+
bool clip_and_flip,
508+
bool scramble_vertex_ids);
509+
template <typename vertex_t>
510+
std::vector<std::pair<std::unique_ptr<rmm::device_buffer>, std::unique_ptr<rmm::device_buffer>>>
511+
call_generate_rmat_edgelists(raft::handle_t const& handle,
512+
size_t n_edgelists,
513+
size_t min_scale,
514+
size_t max_scale,
515+
size_t edge_factor,
516+
cugraph::experimental::generator_distribution_t size_distribution,
517+
cugraph::experimental::generator_distribution_t edge_distribution,
518+
uint64_t seed,
519+
bool clip_and_flip,
520+
bool scramble_vertex_ids);
521+
491522
// wrapper for random_walks.
492523
//
493524
template <typename vertex_t, typename edge_t>

cpp/src/utilities/cython.cu

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
16+
#include <experimental/graph_generator.hpp>
17+
//#include <experimental/generate_rmat_edgelist.cu>
1718
#include <algorithms.hpp>
1819
#include <experimental/detail/graph_utils.cuh>
1920
#include <experimental/graph_functions.hpp>
@@ -789,6 +790,70 @@ std::unique_ptr<cy_multi_edgelists_t> call_egonet(raft::handle_t const& handle,
789790
CUGRAPH_FAIL("vertexType/edgeType combination unsupported");
790791
}
791792
}
793+
// Wrapper for graph generate_rmat_edgelist()
794+
// to expose the API to cython
795+
// enum class generator_distribution_t { POWER_LAW = 0, UNIFORM };
796+
template <typename vertex_t>
797+
std::unique_ptr<graph_generator_t> call_generate_rmat_edgelist(raft::handle_t const& handle,
798+
size_t scale,
799+
size_t num_edges,
800+
double a,
801+
double b,
802+
double c,
803+
uint64_t seed,
804+
bool clip_and_flip,
805+
bool scramble_vertex_ids)
806+
{
807+
auto src_dst_tuple = cugraph::experimental::generate_rmat_edgelist<vertex_t>(
808+
handle, scale, num_edges, a, b, c, seed, clip_and_flip, scramble_vertex_ids);
809+
810+
graph_generator_t gg_vals{
811+
std::make_unique<rmm::device_buffer>(std::get<0>(src_dst_tuple).release()),
812+
std::make_unique<rmm::device_buffer>(std::get<1>(src_dst_tuple).release())};
813+
814+
return std::make_unique<graph_generator_t>(std::move(gg_vals));
815+
}
816+
817+
template <typename vertex_t>
818+
std::vector<std::pair<std::unique_ptr<rmm::device_buffer>, std::unique_ptr<rmm::device_buffer>>>
819+
call_generate_rmat_edgelists(raft::handle_t const& handle,
820+
size_t n_edgelists,
821+
size_t min_scale,
822+
size_t max_scale,
823+
size_t edge_factor,
824+
cugraph::experimental::generator_distribution_t size_distribution,
825+
cugraph::experimental::generator_distribution_t edge_distribution,
826+
uint64_t seed,
827+
bool clip_and_flip,
828+
bool scramble_vertex_ids)
829+
{
830+
auto src_dst_vec_tuple =
831+
cugraph::experimental::generate_rmat_edgelists<vertex_t>(handle,
832+
n_edgelists,
833+
min_scale,
834+
max_scale,
835+
edge_factor,
836+
size_distribution,
837+
edge_distribution,
838+
seed,
839+
clip_and_flip,
840+
scramble_vertex_ids);
841+
842+
std::vector<std::pair<std::unique_ptr<rmm::device_buffer>, std::unique_ptr<rmm::device_buffer>>>
843+
gg_vec;
844+
845+
std::transform(
846+
src_dst_vec_tuple.begin(),
847+
src_dst_vec_tuple.end(),
848+
std::back_inserter(gg_vec),
849+
[](auto& tpl_dev_uvec) {
850+
return std::make_pair(
851+
std::move(std::make_unique<rmm::device_buffer>(std::get<0>(tpl_dev_uvec).release())),
852+
std::move(std::make_unique<rmm::device_buffer>(std::get<1>(tpl_dev_uvec).release())));
853+
});
854+
855+
return gg_vec;
856+
}
792857

793858
// Wrapper for random_walks() through a graph container
794859
// to expose the API to cython.
@@ -1360,5 +1425,55 @@ template std::unique_ptr<renum_quad_t<int64_t, int64_t>> call_renumber(
13601425
bool do_expensive_check,
13611426
bool multi_gpu);
13621427

1428+
template std::unique_ptr<graph_generator_t> call_generate_rmat_edgelist<int32_t>(
1429+
raft::handle_t const& handle,
1430+
size_t scale,
1431+
size_t num_edges,
1432+
double a,
1433+
double b,
1434+
double c,
1435+
uint64_t seed,
1436+
bool clip_and_flip,
1437+
bool scramble_vertex_ids);
1438+
1439+
template std::unique_ptr<graph_generator_t> call_generate_rmat_edgelist<int64_t>(
1440+
raft::handle_t const& handle,
1441+
size_t scale,
1442+
size_t num_edges,
1443+
double a,
1444+
double b,
1445+
double c,
1446+
uint64_t seed,
1447+
bool clip_and_flip,
1448+
bool scramble_vertex_ids);
1449+
1450+
template std::vector<
1451+
std::pair<std::unique_ptr<rmm::device_buffer>, std::unique_ptr<rmm::device_buffer>>>
1452+
call_generate_rmat_edgelists<int32_t>(
1453+
raft::handle_t const& handle,
1454+
size_t n_edgelists,
1455+
size_t min_scale,
1456+
size_t max_scale,
1457+
size_t edge_factor,
1458+
cugraph::experimental::generator_distribution_t size_distribution,
1459+
cugraph::experimental::generator_distribution_t edge_distribution,
1460+
uint64_t seed,
1461+
bool clip_and_flip,
1462+
bool scramble_vertex_ids);
1463+
1464+
template std::vector<
1465+
std::pair<std::unique_ptr<rmm::device_buffer>, std::unique_ptr<rmm::device_buffer>>>
1466+
call_generate_rmat_edgelists<int64_t>(
1467+
raft::handle_t const& handle,
1468+
size_t n_edgelists,
1469+
size_t min_scale,
1470+
size_t max_scale,
1471+
size_t edge_factor,
1472+
cugraph::experimental::generator_distribution_t size_distribution,
1473+
cugraph::experimental::generator_distribution_t edge_distribution,
1474+
uint64_t seed,
1475+
bool clip_and_flip,
1476+
bool scramble_vertex_ids);
1477+
13631478
} // namespace cython
13641479
} // namespace cugraph

docs/cugraph/source/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Structure
1010
Graph
1111
-----
1212

13-
.. autoclass:: cugraph.structure.graph.Graph
13+
.. autoclass:: cugraph.structure.graph_classes.Graph
1414
:members:
1515
:undoc-members:
1616

@@ -143,7 +143,7 @@ Core Number
143143
.. automodule:: cugraph.cores.core_number
144144
:members:
145145
:undoc-members:
146-
146+
147147
K-Core
148148
------
149149

@@ -196,7 +196,7 @@ Pagerank (MG)
196196

197197
.. automodule:: cugraph.dask.link_analysis.pagerank
198198
:members: pagerank
199-
:undoc-members:
199+
:undoc-members:
200200

201201

202202
Link Prediction
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2021, NVIDIA CORPORATION.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
from .rmat import rmat, multi_rmat

python/cugraph/generators/rmat.pxd

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2021, NVIDIA CORPORATION.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
from libcpp cimport bool
14+
from cugraph.structure.graph_utilities cimport *
15+
from libcpp.vector cimport vector
16+
17+
cdef extern from "experimental/graph_generator.hpp" namespace "cugraph::experimental":
18+
ctypedef enum generator_distribution_t:
19+
POWER_LAW "cugraph::experimental::generator_distribution_t::POWER_LAW"
20+
UNIFORM "cugraph::experimental::generator_distribution_t::UNIFORM"
21+
22+
23+
cdef extern from "utilities/cython.hpp" namespace "cugraph::cython":
24+
cdef unique_ptr[graph_generator_t] call_generate_rmat_edgelist[vertex_t] (
25+
const handle_t &handle,
26+
size_t scale,
27+
size_t num_edges,
28+
double a,
29+
double b,
30+
double c,
31+
int seed,
32+
bool clip_and_flip,
33+
bool scramble_vertex_ids) except +
34+
35+
cdef vector[pair[unique_ptr[device_buffer], unique_ptr[device_buffer]]] call_generate_rmat_edgelists[vertex_t](
36+
const handle_t &handle,
37+
size_t n_edgelists,
38+
size_t min_scale,
39+
size_t max_scale,
40+
size_t edge_factor,
41+
generator_distribution_t size_distribution,
42+
generator_distribution_t edge_distribution,
43+
int seed,
44+
bool clip_and_flip,
45+
bool scramble_vertex_ids) except +

0 commit comments

Comments
 (0)