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

Update triangle count to internally use edge masking and update Triangle counting & K-hop neighbor tests to include edge masked graph view inputs #4261

Merged
merged 22 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
70c6a9b
update host graph creation utility functions to take renumber_map
seunghwak Mar 13, 2024
4cc26b0
delete unused function
seunghwak Mar 14, 2024
7bec99e
rename files
seunghwak Mar 14, 2024
7792789
split test_utilities.hpp
seunghwak Mar 15, 2024
4d22945
Merge branch 'branch-24.04' of https://github.com/rapidsai/cugraph in…
seunghwak Mar 15, 2024
d6915ef
refactor property generator to re-use in non-prim tests
seunghwak Mar 15, 2024
33e950e
update core number tests with edge masking
seunghwak Mar 15, 2024
ba4a7aa
Merge branch 'branch-24.04' of https://github.com/rapidsai/cugraph in…
seunghwak Mar 15, 2024
9930ee2
remove random_vector calls
seunghwak Mar 15, 2024
25f95ec
delete unused files
seunghwak Mar 15, 2024
2a87478
Merge branch 'branch-24.04' of https://github.com/rapidsai/cugraph in…
seunghwak Mar 15, 2024
ffa8483
update triangle counting to exploit edge masking and work on only two…
seunghwak Mar 18, 2024
100ad11
bug fixes
seunghwak Mar 19, 2024
1d9ac71
use masking instead of creating a new graph when vertices.has_value()…
seunghwak Mar 19, 2024
212c727
allow edge-masked graph_view in k_hop_nbrs
seunghwak Mar 20, 2024
c776734
add tests with edge masked graphs
seunghwak Mar 20, 2024
6d4b412
add edge masking tests
seunghwak Mar 20, 2024
a8866ac
Merge branch 'branch-24.06' of https://github.com/rapidsai/cugraph in…
seunghwak Mar 20, 2024
bdb2577
resolve merge conflicts
seunghwak Mar 20, 2024
64097be
Merge branch 'branch-24.06' of https://github.com/rapidsai/cugraph in…
seunghwak Mar 20, 2024
7ebab44
Merge branch 'branch-24.06' of https://github.com/rapidsai/cugraph in…
seunghwak Mar 25, 2024
2411bd4
Merge branch 'branch-24.06' of https://github.com/rapidsai/cugraph in…
seunghwak Apr 2, 2024
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
327 changes: 204 additions & 123 deletions cpp/src/community/triangle_count_impl.cuh

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions cpp/src/traversal/k_hop_nbrs_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ std::tuple<rmm::device_uvector<size_t>, rmm::device_uvector<vertex_t>> k_hop_nbr
size_t k,
bool do_expensive_check)
{
CUGRAPH_EXPECTS(!graph_view.has_edge_mask(), "unimplemented.");

return detail::k_hop_nbrs(handle, graph_view, start_vertices, k, do_expensive_check);
}

Expand Down
26 changes: 22 additions & 4 deletions cpp/tests/community/mg_triangle_count_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "utilities/conversion_utilities.hpp"
#include "utilities/device_comm_wrapper.hpp"
#include "utilities/mg_utilities.hpp"
#include "utilities/property_generator_utilities.hpp"
#include "utilities/test_graphs.hpp"
#include "utilities/thrust_wrapper.hpp"

Expand All @@ -40,6 +41,8 @@

struct TriangleCount_Usecase {
double vertex_subset_ratio{0.0};

bool edge_masking{false};
bool check_correctness{true};
};

Expand Down Expand Up @@ -88,6 +91,13 @@ class Tests_MGTriangleCount

auto mg_graph_view = mg_graph.view();

std::optional<cugraph::edge_property_t<decltype(mg_graph_view), bool>> edge_mask{std::nullopt};
if (triangle_count_usecase.edge_masking) {
edge_mask = cugraph::test::generate<decltype(mg_graph_view), bool>::edge_property(
*handle_, mg_graph_view, 2);
mg_graph_view.attach_edge_mask((*edge_mask).view());
}

// 2. generate a vertex subset to compute triangle counts

std::optional<std::vector<vertex_t>> h_mg_vertices{std::nullopt};
Expand Down Expand Up @@ -253,14 +263,19 @@ INSTANTIATE_TEST_SUITE_P(
Tests_MGTriangleCount_File,
::testing::Combine(
// enable correctness checks
::testing::Values(TriangleCount_Usecase{0.1}, TriangleCount_Usecase{1.0}),
::testing::Values(TriangleCount_Usecase{0.1, false},
TriangleCount_Usecase{0.1, true},
TriangleCount_Usecase{1.0, false},
TriangleCount_Usecase{1.0, true}),
::testing::Values(cugraph::test::File_Usecase("test/datasets/karate.mtx"),
cugraph::test::File_Usecase("test/datasets/dolphins.mtx"))));

INSTANTIATE_TEST_SUITE_P(rmat_small_tests,
Tests_MGTriangleCount_Rmat,
::testing::Combine(::testing::Values(TriangleCount_Usecase{0.1},
TriangleCount_Usecase{1.0}),
::testing::Combine(::testing::Values(TriangleCount_Usecase{0.1, false},
TriangleCount_Usecase{0.1, true},
TriangleCount_Usecase{1.0, false},
TriangleCount_Usecase{1.0, true}),
::testing::Values(cugraph::test::Rmat_Usecase(
10, 16, 0.57, 0.19, 0.19, 0, true, false))));

Expand All @@ -272,7 +287,10 @@ INSTANTIATE_TEST_SUITE_P(
factor (to avoid running same benchmarks more than once) */
Tests_MGTriangleCount_Rmat,
::testing::Combine(
::testing::Values(TriangleCount_Usecase{0.1, false}, TriangleCount_Usecase{1.0, false}),
::testing::Values(TriangleCount_Usecase{0.1, false, false},
TriangleCount_Usecase{0.1, true, false},
TriangleCount_Usecase{1.0, false, false},
TriangleCount_Usecase{1.0, true, false}),
::testing::Values(cugraph::test::Rmat_Usecase(20, 32, 0.57, 0.19, 0.19, 0, true, false))));

CUGRAPH_MG_TEST_PROGRAM_MAIN()
59 changes: 40 additions & 19 deletions cpp/tests/community/triangle_count_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "utilities/base_fixture.hpp"
#include "utilities/conversion_utilities.hpp"
#include "utilities/property_generator_utilities.hpp"
#include "utilities/test_graphs.hpp"
#include "utilities/thrust_wrapper.hpp"

Expand Down Expand Up @@ -91,6 +92,8 @@ void triangle_count_reference(edge_t const* offsets,

struct TriangleCount_Usecase {
double vertex_subset_ratio{0.0};

bool edge_masking{false};
bool check_correctness{true};
};

Expand Down Expand Up @@ -138,6 +141,13 @@ class Tests_TriangleCount

auto graph_view = graph.view();

std::optional<cugraph::edge_property_t<decltype(graph_view), bool>> edge_mask{std::nullopt};
if (triangle_count_usecase.edge_masking) {
edge_mask =
cugraph::test::generate<decltype(graph_view), bool>::edge_property(handle, graph_view, 2);
graph_view.attach_edge_mask((*edge_mask).view());
}

std::optional<std::vector<vertex_t>> h_vertices{std::nullopt};
if (triangle_count_usecase.vertex_subset_ratio < 1.0) {
std::default_random_engine generator{};
Expand Down Expand Up @@ -188,24 +198,23 @@ class Tests_TriangleCount
}

if (triangle_count_usecase.check_correctness) {
cugraph::graph_t<vertex_t, edge_t, false, false> unrenumbered_graph(handle);
if (renumber) {
std::tie(unrenumbered_graph, std::ignore, std::ignore) =
cugraph::test::construct_graph<vertex_t, edge_t, weight_t, false, false>(
handle, input_usecase, false, false, false, true);
}
auto unrenumbered_graph_view = renumber ? unrenumbered_graph.view() : graph_view;

auto h_offsets = cugraph::test::to_host(
handle, unrenumbered_graph_view.local_edge_partition_view().offsets());
auto h_indices = cugraph::test::to_host(
handle, unrenumbered_graph_view.local_edge_partition_view().indices());

std::vector<edge_t> h_reference_triangle_counts(unrenumbered_graph_view.number_of_vertices());
std::vector<edge_t> h_offsets{};
std::vector<vertex_t> h_indices{};
std::tie(h_offsets, h_indices, std::ignore) =
cugraph::test::graph_to_host_csr<vertex_t, edge_t, weight_t, false, false>(
handle,
graph_view,
std::nullopt,
d_renumber_map_labels
? std::make_optional<raft::device_span<vertex_t const>>((*d_renumber_map_labels).data(),
(*d_renumber_map_labels).size())
: std::nullopt);

std::vector<edge_t> h_reference_triangle_counts(graph_view.number_of_vertices());

triangle_count_reference(h_offsets.data(),
h_indices.data(),
unrenumbered_graph_view.number_of_vertices(),
graph_view.number_of_vertices(),
h_reference_triangle_counts.data());

std::vector<vertex_t> h_cugraph_vertices{};
Expand Down Expand Up @@ -269,7 +278,10 @@ INSTANTIATE_TEST_SUITE_P(
Tests_TriangleCount_File,
::testing::Combine(
// enable correctness checks
::testing::Values(TriangleCount_Usecase{0.1}, TriangleCount_Usecase{1.0}),
::testing::Values(TriangleCount_Usecase{0.1, false},
TriangleCount_Usecase{0.1, true},
TriangleCount_Usecase{1.0, false},
TriangleCount_Usecase{1.0, true}),
::testing::Values(cugraph::test::File_Usecase("test/datasets/karate.mtx"),
cugraph::test::File_Usecase("test/datasets/dolphins.mtx"))));

Expand All @@ -278,7 +290,10 @@ INSTANTIATE_TEST_SUITE_P(
Tests_TriangleCount_Rmat,
::testing::Combine(
// enable correctness checks
::testing::Values(TriangleCount_Usecase{0.1}, TriangleCount_Usecase{1.0}),
::testing::Values(TriangleCount_Usecase{0.1, false},
TriangleCount_Usecase{0.1, true},
TriangleCount_Usecase{1.0, false},
TriangleCount_Usecase{1.0, true}),
naimnv marked this conversation as resolved.
Show resolved Hide resolved
::testing::Values(cugraph::test::Rmat_Usecase(10, 16, 0.57, 0.19, 0.19, 0, true, false))));

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -290,7 +305,10 @@ INSTANTIATE_TEST_SUITE_P(
Tests_TriangleCount_File,
::testing::Combine(
// disable correctness checks
::testing::Values(TriangleCount_Usecase{0.1, false}, TriangleCount_Usecase{1.0, false}),
::testing::Values(TriangleCount_Usecase{0.1, false, false},
TriangleCount_Usecase{0.1, true, false},
TriangleCount_Usecase{1.0, false, false},
TriangleCount_Usecase{1.0, true, false}),
::testing::Values(cugraph::test::File_Usecase("test/datasets/karate.mtx"))));

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -302,7 +320,10 @@ INSTANTIATE_TEST_SUITE_P(
Tests_TriangleCount_Rmat,
::testing::Combine(
// disable correctness checks for large graphs
::testing::Values(TriangleCount_Usecase{0.1, false}, TriangleCount_Usecase{1.0, false}),
::testing::Values(TriangleCount_Usecase{0.1, false, false},
TriangleCount_Usecase{0.1, true, false},
TriangleCount_Usecase{1.0, false, false},
TriangleCount_Usecase{1.0, true, false}),
naimnv marked this conversation as resolved.
Show resolved Hide resolved
::testing::Values(cugraph::test::Rmat_Usecase(10, 16, 0.57, 0.19, 0.19, 0, true, false))));

CUGRAPH_TEST_PROGRAM_MAIN()
69 changes: 45 additions & 24 deletions cpp/tests/traversal/k_hop_nbrs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "utilities/base_fixture.hpp"
#include "utilities/conversion_utilities.hpp"
#include "utilities/property_generator_utilities.hpp"
#include "utilities/test_graphs.hpp"
#include "utilities/thrust_wrapper.hpp"

Expand Down Expand Up @@ -99,6 +100,8 @@ std::tuple<std::vector<size_t>, std::vector<vertex_t>> k_hop_nbrs_reference(
struct KHopNbrs_Usecase {
size_t num_start_vertices{0};
size_t k{0};

bool edge_masking{false};
bool check_correctness{true};
};

Expand Down Expand Up @@ -144,6 +147,13 @@ class Tests_KHopNbrs

auto graph_view = graph.view();

std::optional<cugraph::edge_property_t<decltype(graph_view), bool>> edge_mask{std::nullopt};
if (k_hop_nbrs_usecase.edge_masking) {
edge_mask =
cugraph::test::generate<decltype(graph_view), bool>::edge_property(handle, graph_view, 2);
graph_view.attach_edge_mask((*edge_mask).view());
}

std::vector<vertex_t> h_start_vertices(k_hop_nbrs_usecase.num_start_vertices);
for (size_t i = 0; i < h_start_vertices.size(); ++i) {
h_start_vertices[i] =
Expand Down Expand Up @@ -173,18 +183,17 @@ class Tests_KHopNbrs
}

if (k_hop_nbrs_usecase.check_correctness) {
cugraph::graph_t<vertex_t, edge_t, false, false> unrenumbered_graph(handle);
if (renumber) {
std::tie(unrenumbered_graph, std::ignore, std::ignore) =
cugraph::test::construct_graph<vertex_t, edge_t, weight_t, false, false>(
handle, input_usecase, false, false);
}
auto unrenumbered_graph_view = renumber ? unrenumbered_graph.view() : graph_view;

auto h_offsets = cugraph::test::to_host(
handle, unrenumbered_graph_view.local_edge_partition_view().offsets());
auto h_indices = cugraph::test::to_host(
handle, unrenumbered_graph_view.local_edge_partition_view().indices());
std::vector<edge_t> h_offsets{};
std::vector<vertex_t> h_indices{};
std::tie(h_offsets, h_indices, std::ignore) =
cugraph::test::graph_to_host_csr<vertex_t, edge_t, weight_t, false, false>(
handle,
graph_view,
std::nullopt,
d_renumber_map_labels
? std::make_optional<raft::device_span<vertex_t const>>((*d_renumber_map_labels).data(),
(*d_renumber_map_labels).size())
: std::nullopt);

auto unrenumbered_start_vertices = std::vector<vertex_t>(h_start_vertices.size());
if (renumber) {
Expand Down Expand Up @@ -266,24 +275,34 @@ INSTANTIATE_TEST_SUITE_P(
Tests_KHopNbrs_File,
::testing::Values(
// enable correctness checks
std::make_tuple(KHopNbrs_Usecase{1024, 5},
std::make_tuple(KHopNbrs_Usecase{1024, 5, false},
cugraph::test::File_Usecase("test/datasets/karate.mtx")),
std::make_tuple(KHopNbrs_Usecase{1024, 4},
std::make_tuple(KHopNbrs_Usecase{1024, 5, true},
cugraph::test::File_Usecase("test/datasets/karate.mtx")),
std::make_tuple(KHopNbrs_Usecase{1024, 4, false},
cugraph::test::File_Usecase("test/datasets/polbooks.mtx")),
std::make_tuple(KHopNbrs_Usecase{1024, 4, true},
cugraph::test::File_Usecase("test/datasets/polbooks.mtx")),
std::make_tuple(KHopNbrs_Usecase{1024, 3},
std::make_tuple(KHopNbrs_Usecase{1024, 3, false},
cugraph::test::File_Usecase("test/datasets/netscience.mtx")),
std::make_tuple(KHopNbrs_Usecase{1024, 3, true},
cugraph::test::File_Usecase("test/datasets/netscience.mtx")),
std::make_tuple(KHopNbrs_Usecase{1024, 2},
std::make_tuple(KHopNbrs_Usecase{1024, 2, false},
cugraph::test::File_Usecase("test/datasets/wiki2003.mtx")),
std::make_tuple(KHopNbrs_Usecase{1024, 1},
std::make_tuple(KHopNbrs_Usecase{1024, 2, true},
cugraph::test::File_Usecase("test/datasets/wiki2003.mtx")),
std::make_tuple(KHopNbrs_Usecase{1024, 1, false},
cugraph::test::File_Usecase("test/datasets/wiki-Talk.mtx")),
std::make_tuple(KHopNbrs_Usecase{1024, 1, true},
cugraph::test::File_Usecase("test/datasets/wiki-Talk.mtx"))));

INSTANTIATE_TEST_SUITE_P(
rmat_small_test,
Tests_KHopNbrs_Rmat,
::testing::Values(
::testing::Combine(
// enable correctness checks
std::make_tuple(KHopNbrs_Usecase{1024, 2},
cugraph::test::Rmat_Usecase(10, 16, 0.57, 0.19, 0.19, 0, false, false))));
testing::Values(KHopNbrs_Usecase{1024, 2, false}, KHopNbrs_Usecase{1024, 2, true}),
testing::Values(cugraph::test::Rmat_Usecase(10, 16, 0.57, 0.19, 0.19, 0, false, false))));

INSTANTIATE_TEST_SUITE_P(
rmat_benchmark_test, /* note that scale & edge factor can be overridden in benchmarking (with
Expand All @@ -292,9 +311,11 @@ INSTANTIATE_TEST_SUITE_P(
include more than one Rmat_Usecase that differ only in scale or edge
factor (to avoid running same benchmarks more than once) */
Tests_KHopNbrs_Rmat,
::testing::Values(
// disable correctness checks for large graphs
std::make_pair(KHopNbrs_Usecase{4, 2, false},
cugraph::test::Rmat_Usecase(20, 32, 0.57, 0.19, 0.19, 0, false, false))));
::testing::Combine(
testing::Values(
// disable correctness checks for large graphs
KHopNbrs_Usecase{4, 2, false, false},
KHopNbrs_Usecase{4, 2, true, false}),
testing::Values(cugraph::test::Rmat_Usecase(20, 32, 0.57, 0.19, 0.19, 0, false, false))));

CUGRAPH_TEST_PROGRAM_MAIN()
40 changes: 28 additions & 12 deletions cpp/tests/traversal/mg_k_hop_nbrs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "utilities/conversion_utilities.hpp"
#include "utilities/device_comm_wrapper.hpp"
#include "utilities/mg_utilities.hpp"
#include "utilities/property_generator_utilities.hpp"
#include "utilities/test_graphs.hpp"
#include "utilities/thrust_wrapper.hpp"

Expand All @@ -41,6 +42,8 @@
struct KHopNbrs_Usecase {
size_t num_start_vertices{0};
size_t k{0};

bool edge_masking{false};
bool check_correctness{true};
};

Expand Down Expand Up @@ -92,6 +95,13 @@ class Tests_MGKHopNbrs

auto mg_graph_view = mg_graph.view();

std::optional<cugraph::edge_property_t<decltype(mg_graph_view), bool>> edge_mask{std::nullopt};
if (k_hop_nbrs_usecase.edge_masking) {
edge_mask = cugraph::test::generate<decltype(mg_graph_view), bool>::edge_property(
*handle_, mg_graph_view, 2);
mg_graph_view.attach_edge_mask((*edge_mask).view());
}

std::vector<vertex_t> h_mg_start_vertices(
std::min(static_cast<size_t>(
(k_hop_nbrs_usecase.num_start_vertices / comm_size) +
Expand Down Expand Up @@ -261,19 +271,23 @@ INSTANTIATE_TEST_SUITE_P(
Tests_MGKHopNbrs_File,
::testing::Combine(
// enable correctness checks
::testing::Values(KHopNbrs_Usecase{1024, 2}, KHopNbrs_Usecase{1024, 1}),
::testing::Values(KHopNbrs_Usecase{1024, 2, false},
KHopNbrs_Usecase{1024, 2, true},
KHopNbrs_Usecase{1024, 1, false},
KHopNbrs_Usecase{1024, 1, true}),
::testing::Values(cugraph::test::File_Usecase("test/datasets/karate.mtx"),
cugraph::test::File_Usecase("test/datasets/web-Google.mtx"),
cugraph::test::File_Usecase("test/datasets/ljournal-2008.mtx"),
cugraph::test::File_Usecase("test/datasets/webbase-1M.mtx"))));

INSTANTIATE_TEST_SUITE_P(
rmat_small_test,
Tests_MGKHopNbrs_Rmat,
::testing::Values(
// enable correctness checks
std::make_tuple(KHopNbrs_Usecase{1024, 2},
cugraph::test::Rmat_Usecase(10, 16, 0.57, 0.19, 0.19, 0, false, false))));
INSTANTIATE_TEST_SUITE_P(rmat_small_test,
Tests_MGKHopNbrs_Rmat,
::testing::Combine(::testing::Values(
// enable correctness checks
KHopNbrs_Usecase{1024, 2, false},
KHopNbrs_Usecase{1024, 2, true}),
::testing::Values(cugraph::test::Rmat_Usecase(
10, 16, 0.57, 0.19, 0.19, 0, false, false))));

INSTANTIATE_TEST_SUITE_P(
rmat_benchmark_test, /* note that scale & edge factor can be overridden in benchmarking (with
Expand All @@ -282,9 +296,11 @@ INSTANTIATE_TEST_SUITE_P(
include more than one Rmat_Usecase that differ only in scale or edge
factor (to avoid running same benchmarks more than once) */
Tests_MGKHopNbrs_Rmat,
::testing::Values(
// disable correctness checks for large graphs
std::make_tuple(KHopNbrs_Usecase{4, 2, false},
cugraph::test::Rmat_Usecase(20, 32, 0.57, 0.19, 0.19, 0, false, false))));
::testing::Combine(
::testing::Values(
// disable correctness checks for large graphs
KHopNbrs_Usecase{4, 2, false, false},
KHopNbrs_Usecase{4, 2, true, false}),
::testing::Values(cugraph::test::Rmat_Usecase(20, 32, 0.57, 0.19, 0.19, 0, false, false))));

CUGRAPH_MG_TEST_PROGRAM_MAIN()
Loading