-
Notifications
You must be signed in to change notification settings - Fork 329
MNMG Approximation Algorithm for the Weighted Matching Problem #4315
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
701ae2b
MNMG Approximation Algorithm for the Weighted Matching Problem
5f355bf
Update comments and rename variable
179d875
Add docstrings
55be8d8
Fix bugs, add tests
7ae0647
Merge branch 'branch-24.06' into approx_matching
naimnv 49fd768
Rename files
468e05e
Merge branch 'branch-24.06' into approx_matching
naimnv 8dd7111
Merge branch 'branch-24.06' into approx_matching
naimnv 5c04b9c
Debug edge masking bug
1dc8e2d
Revert "Debug edge masking bug"
e167aaa
Test with edge masked input graphs
f01dbd9
Update implementation to handle edge masked graphs and ddd tests for …
0614691
Merge branch 'branch-24.06' of github.com:rapidsai/cugraph into appro…
c2a0e15
Update implementation to handle edge masked graphs and ddd tests for …
93f6968
Update implementation to handle edge masked graphs and ddd tests for …
66bf11e
Update implementation to handle edge masked graphs and add tests for …
425e794
Remove redundant graph_view_t object
564d577
Use bool as flag_t
7ba1fec
Remove unused variable from capture list
40f8894
Merge branch 'branch-24.06' into approx_matching
naimnv a54273e
Merge branch 'branch-24.06' into approx_matching
naimnv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "approx_weighted_matching_impl.cuh" | ||
|
||
namespace cugraph { | ||
|
||
template std::tuple<rmm::device_uvector<int32_t>, float> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int32_t, int32_t, false, true> const& graph_view, | ||
edge_property_view_t<int32_t, float const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int32_t>, double> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int32_t, int32_t, false, true> const& graph_view, | ||
edge_property_view_t<int32_t, double const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int32_t>, float> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int32_t, int64_t, false, true> const& graph_view, | ||
edge_property_view_t<int64_t, float const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int64_t>, float> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int64_t, int64_t, false, true> const& graph_view, | ||
edge_property_view_t<int64_t, float const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int32_t>, double> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int32_t, int64_t, false, true> const& graph_view, | ||
edge_property_view_t<int64_t, double const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int64_t>, double> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int64_t, int64_t, false, true> const& graph_view, | ||
edge_property_view_t<int64_t, double const*> edge_weight_view); | ||
|
||
} // namespace cugraph |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "approx_weighted_matching_impl.cuh" | ||
|
||
namespace cugraph { | ||
|
||
template std::tuple<rmm::device_uvector<int32_t>, float> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int32_t, int32_t, false, false> const& graph_view, | ||
edge_property_view_t<int32_t, float const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int32_t>, double> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int32_t, int32_t, false, false> const& graph_view, | ||
edge_property_view_t<int32_t, double const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int32_t>, float> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int32_t, int64_t, false, false> const& graph_view, | ||
edge_property_view_t<int64_t, float const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int64_t>, float> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int64_t, int64_t, false, false> const& graph_view, | ||
edge_property_view_t<int64_t, float const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int32_t>, double> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int32_t, int64_t, false, false> const& graph_view, | ||
edge_property_view_t<int64_t, double const*> edge_weight_view); | ||
|
||
template std::tuple<rmm::device_uvector<int64_t>, double> approximate_weighted_matching( | ||
raft::handle_t const& handle, | ||
graph_view_t<int64_t, int64_t, false, false> const& graph_view, | ||
edge_property_view_t<int64_t, double const*> edge_weight_view); | ||
|
||
} // namespace cugraph |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governin_from_mtxg permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "utilities/base_fixture.hpp" | ||
#include "utilities/conversion_utilities.hpp" | ||
#include "utilities/property_generator_utilities.hpp" | ||
#include "utilities/test_graphs.hpp" | ||
|
||
#include <cugraph/algorithms.hpp> | ||
#include <cugraph/edge_partition_view.hpp> | ||
#include <cugraph/edge_property.hpp> | ||
#include <cugraph/edge_src_dst_property.hpp> | ||
#include <cugraph/graph_functions.hpp> | ||
#include <cugraph/graph_view.hpp> | ||
#include <cugraph/utilities/dataframe_buffer.hpp> | ||
#include <cugraph/utilities/high_res_timer.hpp> | ||
#include <cugraph/utilities/host_scalar_comm.hpp> | ||
|
||
#include <raft/random/rng_state.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <chrono> | ||
#include <iostream> | ||
#include <random> | ||
|
||
struct WeightedMatching_UseCase { | ||
bool edge_masking{false}; | ||
bool check_correctness{true}; | ||
}; | ||
|
||
template <typename input_usecase_t> | ||
class Tests_MGWeightedMatching | ||
: public ::testing::TestWithParam<std::tuple<WeightedMatching_UseCase, input_usecase_t>> { | ||
public: | ||
Tests_MGWeightedMatching() {} | ||
|
||
static void SetUpTestCase() { handle_ = cugraph::test::initialize_mg_handle(); } | ||
static void TearDownTestCase() { handle_.reset(); } | ||
|
||
virtual void SetUp() {} | ||
virtual void TearDown() {} | ||
|
||
template <typename vertex_t, typename edge_t, typename weight_t, typename result_t> | ||
void run_current_test(std::tuple<WeightedMatching_UseCase, input_usecase_t> const& param) | ||
{ | ||
auto [weighted_matching_usecase, input_usecase] = param; | ||
|
||
HighResTimer hr_timer{}; | ||
|
||
if (cugraph::test::g_perf) { | ||
RAFT_CUDA_TRY(cudaDeviceSynchronize()); | ||
handle_->get_comms().barrier(); | ||
hr_timer.start("MG Construct graph"); | ||
} | ||
|
||
constexpr bool multi_gpu = true; | ||
|
||
bool test_weighted = true; | ||
bool renumber = true; | ||
bool drop_self_loops = false; | ||
bool drop_multi_edges = false; | ||
|
||
auto [mg_graph, mg_edge_weights, mg_renumber_map] = | ||
cugraph::test::construct_graph<vertex_t, edge_t, weight_t, false, multi_gpu>( | ||
*handle_, input_usecase, test_weighted, renumber, drop_self_loops, drop_multi_edges); | ||
|
||
std::tie(mg_graph, mg_edge_weights, mg_renumber_map) = cugraph::symmetrize_graph( | ||
*handle_, | ||
std::move(mg_graph), | ||
std::move(mg_edge_weights), | ||
mg_renumber_map ? std::optional<rmm::device_uvector<vertex_t>>(std::move(*mg_renumber_map)) | ||
: std::nullopt, | ||
false); | ||
|
||
if (cugraph::test::g_perf) { | ||
RAFT_CUDA_TRY(cudaDeviceSynchronize()); | ||
handle_->get_comms().barrier(); | ||
hr_timer.stop(); | ||
hr_timer.display_and_clear(std::cout); | ||
} | ||
|
||
auto mg_graph_view = mg_graph.view(); | ||
auto mg_edge_weight_view = | ||
mg_edge_weights ? std::make_optional((*mg_edge_weights).view()) : std::nullopt; | ||
|
||
std::optional<cugraph::edge_property_t<decltype(mg_graph_view), bool>> edge_mask{std::nullopt}; | ||
if (weighted_matching_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()); | ||
} | ||
|
||
rmm::device_uvector<vertex_t> mg_partners(0, handle_->get_stream()); | ||
weight_t mg_matching_weights; | ||
|
||
std::forward_as_tuple(mg_partners, mg_matching_weights) = | ||
cugraph::approximate_weighted_matching<vertex_t, edge_t, weight_t, multi_gpu>( | ||
*handle_, mg_graph_view, (*mg_edge_weights).view()); | ||
|
||
if (weighted_matching_usecase.check_correctness) { | ||
auto h_mg_partners = cugraph::test::to_host(*handle_, mg_partners); | ||
|
||
auto constexpr invalid_partner = cugraph::invalid_vertex_id<vertex_t>::value; | ||
|
||
rmm::device_uvector<vertex_t> mg_aggregate_partners(0, handle_->get_stream()); | ||
std::tie(std::ignore, mg_aggregate_partners) = | ||
cugraph::test::mg_vertex_property_values_to_sg_vertex_property_values( | ||
*handle_, | ||
std::optional<raft::device_span<vertex_t const>>{std::nullopt}, | ||
mg_graph_view.local_vertex_partition_range(), | ||
std::optional<raft::device_span<vertex_t const>>{std::nullopt}, | ||
std::optional<raft::device_span<vertex_t const>>{std::nullopt}, | ||
raft::device_span<vertex_t const>(mg_partners.data(), mg_partners.size())); | ||
|
||
cugraph::graph_t<vertex_t, edge_t, false, false> sg_graph(*handle_); | ||
std::optional< | ||
cugraph::edge_property_t<cugraph::graph_view_t<vertex_t, edge_t, false, false>, weight_t>> | ||
sg_edge_weights{std::nullopt}; | ||
std::tie(sg_graph, sg_edge_weights, std::ignore) = cugraph::test::mg_graph_to_sg_graph( | ||
*handle_, | ||
mg_graph_view, | ||
mg_edge_weight_view, | ||
std::optional<raft::device_span<vertex_t const>>(std::nullopt), | ||
false); | ||
|
||
if (handle_->get_comms().get_rank() == 0) { | ||
auto sg_graph_view = sg_graph.view(); | ||
|
||
rmm::device_uvector<vertex_t> sg_partners(0, handle_->get_stream()); | ||
weight_t sg_matching_weights; | ||
|
||
std::forward_as_tuple(sg_partners, sg_matching_weights) = | ||
cugraph::approximate_weighted_matching<vertex_t, edge_t, weight_t, false>( | ||
*handle_, sg_graph_view, (*sg_edge_weights).view()); | ||
auto h_sg_partners = cugraph::test::to_host(*handle_, sg_partners); | ||
auto h_mg_aggregate_partners = cugraph::test::to_host(*handle_, mg_aggregate_partners); | ||
|
||
ASSERT_FLOAT_EQ(mg_matching_weights, sg_matching_weights) | ||
<< "SG and MG matching weights are different"; | ||
ASSERT_TRUE( | ||
std::equal(h_sg_partners.begin(), h_sg_partners.end(), h_mg_aggregate_partners.begin())); | ||
} | ||
} | ||
} | ||
|
||
private: | ||
static std::unique_ptr<raft::handle_t> handle_; | ||
}; | ||
|
||
template <typename input_usecase_t> | ||
std::unique_ptr<raft::handle_t> Tests_MGWeightedMatching<input_usecase_t>::handle_ = nullptr; | ||
|
||
using Tests_MGWeightedMatching_File = Tests_MGWeightedMatching<cugraph::test::File_Usecase>; | ||
using Tests_MGWeightedMatching_Rmat = Tests_MGWeightedMatching<cugraph::test::Rmat_Usecase>; | ||
|
||
TEST_P(Tests_MGWeightedMatching_File, CheckInt32Int32FloatFloat) | ||
{ | ||
run_current_test<int32_t, int32_t, float, int>( | ||
override_File_Usecase_with_cmd_line_arguments(GetParam())); | ||
} | ||
|
||
TEST_P(Tests_MGWeightedMatching_File, CheckInt32Int64FloatFloat) | ||
{ | ||
run_current_test<int32_t, int64_t, float, int>( | ||
override_File_Usecase_with_cmd_line_arguments(GetParam())); | ||
} | ||
|
||
TEST_P(Tests_MGWeightedMatching_File, CheckInt64Int64FloatFloat) | ||
{ | ||
run_current_test<int64_t, int64_t, float, int>( | ||
override_File_Usecase_with_cmd_line_arguments(GetParam())); | ||
} | ||
|
||
TEST_P(Tests_MGWeightedMatching_Rmat, CheckInt32Int32FloatFloat) | ||
{ | ||
run_current_test<int32_t, int32_t, float, int>( | ||
override_Rmat_Usecase_with_cmd_line_arguments(GetParam())); | ||
} | ||
|
||
TEST_P(Tests_MGWeightedMatching_Rmat, CheckInt32Int64FloatFloat) | ||
{ | ||
run_current_test<int32_t, int64_t, float, int>( | ||
override_Rmat_Usecase_with_cmd_line_arguments(GetParam())); | ||
} | ||
|
||
TEST_P(Tests_MGWeightedMatching_Rmat, CheckInt64Int64FloatFloat) | ||
{ | ||
run_current_test<int64_t, int64_t, float, int>( | ||
override_Rmat_Usecase_with_cmd_line_arguments(GetParam())); | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P( | ||
file_test, | ||
Tests_MGWeightedMatching_File, | ||
::testing::Combine(::testing::Values(WeightedMatching_UseCase{false}, | ||
WeightedMatching_UseCase{true}), | ||
::testing::Values(cugraph::test::File_Usecase("test/datasets/karate.mtx")))); | ||
|
||
INSTANTIATE_TEST_SUITE_P(rmat_small_test, | ||
Tests_MGWeightedMatching_Rmat, | ||
::testing::Combine(::testing::Values(WeightedMatching_UseCase{false}, | ||
WeightedMatching_UseCase{true}), | ||
::testing::Values(cugraph::test::Rmat_Usecase( | ||
3, 2, 0.57, 0.19, 0.19, 0, true, false)))); | ||
|
||
INSTANTIATE_TEST_SUITE_P( | ||
rmat_benchmark_test, /* note that scale & edge factor can be overridden in benchmarking (with | ||
--gtest_filter to select only the rmat_benchmark_test with a specific | ||
vertex & edge type combination) by command line arguments and do not | ||
include more than one Rmat_Usecase that differ only in scale or edge | ||
factor (to avoid running same benchmarks more than once) */ | ||
Tests_MGWeightedMatching_Rmat, | ||
::testing::Combine( | ||
::testing::Values(WeightedMatching_UseCase{false, false}, | ||
WeightedMatching_UseCase{true, false}), | ||
::testing::Values(cugraph::test::Rmat_Usecase(20, 32, 0.57, 0.19, 0.19, 0, true, false)))); | ||
|
||
CUGRAPH_MG_TEST_PROGRAM_MAIN() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.