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

Replace graph_view.hpp::number_of_edges with compute_number_of_edges #4026

Merged
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
345aee7
update transform_e to work with edge masking
seunghwak Nov 15, 2023
0887af9
remove unnecessary checks
seunghwak Nov 16, 2023
69463f4
update fill_edge_property to work with graphs with edge masks
seunghwak Nov 16, 2023
bf733aa
udpate count_if_e & transform_reduce_e to work with edge masking
seunghwak Nov 16, 2023
8d070d8
add missing includes
seunghwak Nov 16, 2023
2d74bfe
Merge branch 'branch-23.12' of https://github.com/rapidsai/cugraph in…
seunghwak Nov 16, 2023
0e6d7c1
update transform_e test with edge mask
seunghwak Nov 16, 2023
6807b0d
add edge_property utility function for prims testing
seunghwak Nov 17, 2023
138b1f4
update count_if_e & transform_reduce_e tests to include edge masking
seunghwak Nov 17, 2023
06c15a2
clang-format
seunghwak Nov 17, 2023
57a5593
Merge branch 'branch-23.12' into fea_transform_e_mask
naimnv Nov 18, 2023
5fcf9e6
Merge branch 'branch-23.12' of https://github.com/rapidsai/cugraph in…
seunghwak Nov 20, 2023
ff2c849
Merge branch 'fea_transform_e_mask' of github.com:seunghwak/cugraph i…
seunghwak Nov 20, 2023
b1f7bc3
Merge branch 'branch-23.12' of https://github.com/rapidsai/cugraph in…
seunghwak Nov 20, 2023
0c10b84
throw an exception when number_of_edges() is called with edge mask
seunghwak Nov 20, 2023
57ea6f6
Merge branch 'upstream_pr4001' into fea_number_of_edges_with_mask
seunghwak Nov 21, 2023
e60d7ff
remove handle and replace raw pointers with raft::device_span in grap…
seunghwak Nov 22, 2023
3a24f30
remove a redundant internal variable in graph_t
seunghwak Nov 22, 2023
2d04112
deprecate number_of_edges() in graph_view.hpp and replace this with c…
seunghwak Nov 29, 2023
26c02ae
Merge branch 'branch-24.02' of https://github.com/rapidsai/cugraph in…
seunghwak Nov 29, 2023
1e3de80
Merge branch 'branch-24.02' of https://github.com/rapidsai/cugraph in…
seunghwak Nov 29, 2023
3e1ce0f
bug fix in tests
seunghwak Nov 29, 2023
f6d39e4
Merge branch 'upstream_pr4001' into fea_number_of_edges_with_mask
seunghwak Nov 29, 2023
93c1d86
resolve merge conflicts
seunghwak Nov 30, 2023
260e86a
bug fix
seunghwak Dec 1, 2023
29a3a5b
Merge branch 'branch-24.02' of https://github.com/rapidsai/cugraph in…
seunghwak Dec 6, 2023
3308c8f
move edge_mask_view_ back to graph_view_t (as graph_base_t is used fo…
seunghwak Dec 6, 2023
f361b81
Merge branch 'branch-24.02' of https://github.com/rapidsai/cugraph in…
seunghwak Dec 9, 2023
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
47 changes: 22 additions & 25 deletions cpp/include/cugraph/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,25 @@ class graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<mu
graph_meta_t<vertex_t, edge_t, multi_gpu> meta,
bool do_expensive_check = false);

edge_t number_of_edges() const { return this->number_of_edges_; }

graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu> view() const
{
std::vector<edge_t const*> offsets(edge_partition_offsets_.size(), nullptr);
std::vector<vertex_t const*> indices(edge_partition_indices_.size(), nullptr);
auto dcs_nzd_vertices = edge_partition_dcs_nzd_vertices_
? std::make_optional<std::vector<vertex_t const*>>(
(*edge_partition_dcs_nzd_vertices_).size(), nullptr)
: std::nullopt;
auto dcs_nzd_vertex_counts = edge_partition_dcs_nzd_vertex_counts_
? std::make_optional<std::vector<vertex_t>>(
(*edge_partition_dcs_nzd_vertex_counts_).size(), vertex_t{0})
: std::nullopt;
std::vector<raft::device_span<edge_t const>> offsets(edge_partition_offsets_.size());
std::vector<raft::device_span<vertex_t const>> indices(edge_partition_indices_.size());
auto dcs_nzd_vertices = edge_partition_dcs_nzd_vertices_
? std::make_optional<std::vector<raft::device_span<vertex_t const>>>(
(*edge_partition_dcs_nzd_vertices_).size())
: std::nullopt;
for (size_t i = 0; i < offsets.size(); ++i) {
offsets[i] = edge_partition_offsets_[i].data();
indices[i] = edge_partition_indices_[i].data();
offsets[i] = raft::device_span<edge_t const>(edge_partition_offsets_[i].data(),
edge_partition_offsets_[i].size());
indices[i] = raft::device_span<vertex_t const>(edge_partition_indices_[i].data(),
edge_partition_indices_[i].size());
if (dcs_nzd_vertices) {
(*dcs_nzd_vertices)[i] = (*edge_partition_dcs_nzd_vertices_)[i].data();
(*dcs_nzd_vertex_counts)[i] = (*edge_partition_dcs_nzd_vertex_counts_)[i];
(*dcs_nzd_vertices)[i] =
raft::device_span<vertex_t const>((*edge_partition_dcs_nzd_vertices_)[i].data(),
(*edge_partition_dcs_nzd_vertices_)[i].size());
}
}

Expand Down Expand Up @@ -196,15 +197,13 @@ class graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<mu
}

return graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu>(
*(this->handle_ptr()),
offsets,
indices,
dcs_nzd_vertices,
dcs_nzd_vertex_counts,
graph_view_meta_t<vertex_t, edge_t, store_transposed, multi_gpu>{
this->number_of_vertices(),
this->number_of_edges(),
this->graph_properties(),
this->properties_,
partition_,
edge_partition_segment_offsets_,
local_sorted_unique_edge_srcs,
Expand All @@ -224,7 +223,6 @@ class graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<mu
// nzd: nonzero (local) degree
std::optional<std::vector<rmm::device_uvector<vertex_t>>> edge_partition_dcs_nzd_vertices_{
std::nullopt};
std::optional<std::vector<vertex_t>> edge_partition_dcs_nzd_vertex_counts_{std::nullopt};
partition_t<vertex_t> partition_{};

// segment offsets within the vertex partition based on vertex degree
Expand Down Expand Up @@ -283,16 +281,15 @@ class graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<!m
graph_meta_t<vertex_t, edge_t, multi_gpu> meta,
bool do_expensive_check = false);

edge_t number_of_edges() const { return this->number_of_edges_; }

graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu> view() const
{
return graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu>(
*(this->handle_ptr()),
offsets_.data(),
indices_.data(),
graph_view_meta_t<vertex_t, edge_t, store_transposed, multi_gpu>{this->number_of_vertices(),
this->number_of_edges(),
this->graph_properties(),
segment_offsets_});
raft::device_span<edge_t const>(offsets_.data(), offsets_.size()),
raft::device_span<vertex_t const>(indices_.data(), indices_.size()),
graph_view_meta_t<vertex_t, edge_t, store_transposed, multi_gpu>{
this->number_of_vertices(), this->number_of_edges(), this->properties_, segment_offsets_});
}

private:
Expand Down
88 changes: 39 additions & 49 deletions cpp/include/cugraph/graph_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,12 @@ class graph_base_t {
public:
graph_base_t() = default;

graph_base_t(raft::handle_t const& handle,
vertex_t number_of_vertices,
edge_t number_of_edges,
graph_properties_t properties)
: handle_ptr_(&handle),
number_of_vertices_(number_of_vertices),
graph_base_t(vertex_t number_of_vertices, edge_t number_of_edges, graph_properties_t properties)
: number_of_vertices_(number_of_vertices),
number_of_edges_(number_of_edges),
properties_(properties){};

vertex_t number_of_vertices() const { return number_of_vertices_; }
edge_t number_of_edges() const
{
CUGRAPH_EXPECTS(!(this->has_edge_mask()), "unimplemented.");
return number_of_edges_;
}

template <typename vertex_type = vertex_t>
std::enable_if_t<std::is_signed<vertex_type>::value, bool> is_valid_vertex(vertex_type v) const
Expand Down Expand Up @@ -304,16 +295,11 @@ class graph_base_t {
}

protected:
raft::handle_t const* handle_ptr() const { return handle_ptr_; };
graph_properties_t graph_properties() const { return properties_; }
edge_t number_of_edges_{0};
graph_properties_t properties_{};

private:
raft::handle_t const* handle_ptr_{nullptr};

vertex_t number_of_vertices_{0};
edge_t number_of_edges_{0};

graph_properties_t properties_{};

std::optional<edge_property_view_t<edge_t, uint32_t const*, bool>> edge_mask_view_{std::nullopt};
};
Expand Down Expand Up @@ -405,11 +391,10 @@ class graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if
static constexpr bool is_storage_transposed = store_transposed;
static constexpr bool is_multi_gpu = multi_gpu;

graph_view_t(raft::handle_t const& handle,
std::vector<edge_t const*> const& edge_partition_offsets,
std::vector<vertex_t const*> const& edge_partition_indices,
std::optional<std::vector<vertex_t const*>> const& edge_partition_dcs_nzd_vertices,
std::optional<std::vector<vertex_t>> const& edge_partition_dcs_nzd_vertex_counts,
graph_view_t(std::vector<raft::device_span<edge_t const>> const& edge_partition_offsets,
std::vector<raft::device_span<vertex_t const>> const& edge_partition_indices,
std::optional<std::vector<raft::device_span<vertex_t const>>> const&
edge_partition_dcs_nzd_vertices,
graph_view_meta_t<vertex_t, edge_t, store_transposed, multi_gpu> meta);

std::vector<vertex_t> vertex_partition_range_offsets() const
Expand Down Expand Up @@ -624,25 +609,16 @@ class graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if
this->local_edge_partition_src_value_start_offset(partition_idx);
}
std::optional<vertex_t> major_hypersparse_first{std::nullopt};
vertex_t offset_size = (major_range_last - major_range_first) + 1;
if (this->use_dcs()) {
major_hypersparse_first =
major_range_first + (*(this->local_edge_partition_segment_offsets(
partition_idx)))[detail::num_sparse_segments_per_vertex_partition];
offset_size = ((*major_hypersparse_first) - major_range_first) +
(*edge_partition_dcs_nzd_vertex_counts_)[partition_idx] + 1;
}
return edge_partition_view_t<vertex_t, edge_t, true>(
raft::device_span<edge_t const>(edge_partition_offsets_[partition_idx],
edge_partition_offsets_[partition_idx] + offset_size),
raft::device_span<vertex_t const>(
edge_partition_indices_[partition_idx],
edge_partition_indices_[partition_idx] + edge_partition_number_of_edges_[partition_idx]),
edge_partition_offsets_[partition_idx],
edge_partition_indices_[partition_idx],
edge_partition_dcs_nzd_vertices_
? std::make_optional<raft::device_span<vertex_t const>>(
(*edge_partition_dcs_nzd_vertices_)[partition_idx],
(*edge_partition_dcs_nzd_vertices_)[partition_idx] +
(*edge_partition_dcs_nzd_vertex_counts_)[partition_idx])
? std::make_optional((*edge_partition_dcs_nzd_vertices_)[partition_idx])
: std::nullopt,
major_hypersparse_first,
major_range_first,
Expand All @@ -652,6 +628,16 @@ class graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if
major_value_range_start_offset);
}

// FIXME: deprecated, replaced with copmute_number_of_edges (which works with or without edge
// masking)
edge_t number_of_edges() const
{
CUGRAPH_EXPECTS(!(this->has_edge_mask()), "unimplemented.");
return this->number_of_edges_;
}

edge_t compute_number_of_edges(raft::handle_t const& handle) const;

rmm::device_uvector<edge_t> compute_in_degrees(raft::handle_t const& handle) const;
rmm::device_uvector<edge_t> compute_out_degrees(raft::handle_t const& handle) const;

Expand Down Expand Up @@ -752,14 +738,11 @@ class graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if
}

private:
std::vector<edge_t const*> edge_partition_offsets_{};
std::vector<vertex_t const*> edge_partition_indices_{};
std::vector<raft::device_span<edge_t const>> edge_partition_offsets_{};
std::vector<raft::device_span<vertex_t const>> edge_partition_indices_{};

// relevant only if we use the CSR + DCSR (or CSC + DCSC) hybrid format
std::optional<std::vector<vertex_t const*>> edge_partition_dcs_nzd_vertices_{};
std::optional<std::vector<vertex_t>> edge_partition_dcs_nzd_vertex_counts_{};

std::vector<edge_t> edge_partition_number_of_edges_{};
std::optional<std::vector<raft::device_span<vertex_t const>>> edge_partition_dcs_nzd_vertices_{};

partition_t<vertex_t> partition_{};

Expand Down Expand Up @@ -808,9 +791,8 @@ class graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if
static constexpr bool is_storage_transposed = store_transposed;
static constexpr bool is_multi_gpu = multi_gpu;

graph_view_t(raft::handle_t const& handle,
edge_t const* offsets,
vertex_t const* indices,
graph_view_t(raft::device_span<edge_t const> offsets,
raft::device_span<vertex_t const> indices,
graph_view_meta_t<vertex_t, edge_t, store_transposed, multi_gpu> meta);

std::vector<vertex_t> vertex_partition_range_offsets() const
Expand Down Expand Up @@ -924,11 +906,19 @@ class graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if
{
assert(partition_idx == 0); // there is only one edge partition in single-GPU
return edge_partition_view_t<vertex_t, edge_t, false>(
raft::device_span<edge_t const>(offsets_, offsets_ + (this->number_of_vertices() + 1)),
raft::device_span<vertex_t const>(indices_, indices_ + this->number_of_edges()),
this->number_of_vertices());
offsets_, indices_, this->number_of_vertices());
}

// FIXME: deprecated, replaced with copmute_number_of_edges (which works with or without edge
// masking)
edge_t number_of_edges() const
{
CUGRAPH_EXPECTS(!(this->has_edge_mask()), "unimplemented.");
return this->number_of_edges_;
}

edge_t compute_number_of_edges(raft::handle_t const& handle) const;

rmm::device_uvector<edge_t> compute_in_degrees(raft::handle_t const& handle) const;
rmm::device_uvector<edge_t> compute_out_degrees(raft::handle_t const& handle) const;

Expand Down Expand Up @@ -1017,8 +1007,8 @@ class graph_view_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if
}

private:
edge_t const* offsets_{nullptr};
vertex_t const* indices_{nullptr};
raft::device_span<edge_t const> offsets_{};
raft::device_span<vertex_t const> indices_{};

// segment offsets based on vertex degree, relevant only if vertex IDs are renumbered
std::optional<std::vector<vertex_t>> segment_offsets_{std::nullopt};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,11 @@ void per_v_transform_reduce_e(raft::handle_t const& handle,
value_size = sizeof(T);
}

auto avg_vertex_degree = graph_view.number_of_vertices() > 0
? (static_cast<double>(graph_view.number_of_edges()) /
static_cast<double>(graph_view.number_of_vertices()))
: double{0.0};
auto avg_vertex_degree =
graph_view.number_of_vertices() > 0
? (static_cast<double>(graph_view.compute_number_of_edges(handle)) /
static_cast<double>(graph_view.number_of_vertices()))
: double{0.0};

num_streams =
std::min(static_cast<size_t>(avg_vertex_degree * (static_cast<double>(sizeof(vertex_t)) /
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/prims/update_edge_src_dst_property.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ void update_edge_minor_property(raft::handle_t const& handle,
bcast_size *= sizeof(typename EdgeMinorPropertyOutputWrapper::value_type);
}
auto num_concurrent_bcasts =
(static_cast<size_t>(graph_view.number_of_edges() / comm_size) * sizeof(vertex_t)) /
(static_cast<size_t>(graph_view.compute_number_of_edges(handle) / comm_size) *
sizeof(vertex_t)) /
std::max(bcast_size, size_t{1});
num_concurrent_bcasts = std::max(num_concurrent_bcasts, size_t{1});
num_concurrent_bcasts = std::min(num_concurrent_bcasts, static_cast<size_t>(major_comm_size));
Expand Down
24 changes: 6 additions & 18 deletions cpp/src/structure/graph_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ update_local_sorted_unique_edge_majors_minors(
graph_meta_t<vertex_t, edge_t, multi_gpu> const& meta,
std::vector<rmm::device_uvector<edge_t>> const& edge_partition_offsets,
std::vector<rmm::device_uvector<vertex_t>> const& edge_partition_indices,
std::optional<std::vector<rmm::device_uvector<vertex_t>>> const& edge_partition_dcs_nzd_vertices,
std::optional<std::vector<vertex_t>> const& edge_partition_dcs_nzd_vertex_counts)
std::optional<std::vector<rmm::device_uvector<vertex_t>>> const& edge_partition_dcs_nzd_vertices)
{
auto& comm = handle.get_comms();
auto& major_comm = handle.get_subcomm(cugraph::partition_manager::major_comm_name());
Expand Down Expand Up @@ -341,8 +340,7 @@ update_local_sorted_unique_edge_majors_minors(
if (use_dcs) {
thrust::copy(handle.get_thrust_policy(),
(*edge_partition_dcs_nzd_vertices)[i].begin(),
(*edge_partition_dcs_nzd_vertices)[i].begin() +
(*edge_partition_dcs_nzd_vertex_counts)[i],
(*edge_partition_dcs_nzd_vertices)[i].end(),
unique_edge_majors.begin() + cur_size);
}

Expand Down Expand Up @@ -390,7 +388,7 @@ graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<multi_gp
graph_meta_t<vertex_t, edge_t, multi_gpu> meta,
bool do_expensive_check)
: detail::graph_base_t<vertex_t, edge_t>(
handle, meta.number_of_vertices, meta.number_of_edges, meta.properties),
meta.number_of_vertices, meta.number_of_edges, meta.properties),
partition_(meta.partition)
{
CUGRAPH_EXPECTS(
Expand All @@ -408,14 +406,6 @@ graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<multi_gp
edge_partition_offsets_ = std::move(edge_partition_offsets);
edge_partition_indices_ = std::move(edge_partition_indices);
edge_partition_dcs_nzd_vertices_ = std::move(edge_partition_dcs_nzd_vertices);
if (edge_partition_dcs_nzd_vertices_) {
edge_partition_dcs_nzd_vertex_counts_ =
std::vector<vertex_t>((*edge_partition_dcs_nzd_vertices_).size());
for (size_t i = 0; i < (*edge_partition_dcs_nzd_vertex_counts_).size(); ++i) {
(*edge_partition_dcs_nzd_vertex_counts_)[i] =
static_cast<vertex_t>((*edge_partition_dcs_nzd_vertices_)[i].size());
}
}

// update local sorted unique edge sources/destinations (only if key, value pair will be used)

Expand All @@ -432,8 +422,7 @@ graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<multi_gp
meta,
edge_partition_offsets_,
edge_partition_indices_,
edge_partition_dcs_nzd_vertices_,
edge_partition_dcs_nzd_vertex_counts_);
edge_partition_dcs_nzd_vertices_);
} else {
std::tie(local_sorted_unique_edge_srcs_,
local_sorted_unique_edge_src_chunk_start_offsets_,
Expand All @@ -447,8 +436,7 @@ graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<multi_gp
meta,
edge_partition_offsets_,
edge_partition_indices_,
edge_partition_dcs_nzd_vertices_,
edge_partition_dcs_nzd_vertex_counts_);
edge_partition_dcs_nzd_vertices_);
}
}

Expand All @@ -460,7 +448,7 @@ graph_t<vertex_t, edge_t, store_transposed, multi_gpu, std::enable_if_t<!multi_g
graph_meta_t<vertex_t, edge_t, multi_gpu> meta,
bool do_expensive_check)
: detail::graph_base_t<vertex_t, edge_t>(
handle, meta.number_of_vertices, static_cast<edge_t>(indices.size()), meta.properties),
meta.number_of_vertices, static_cast<edge_t>(indices.size()), meta.properties),
offsets_(std::move(offsets)),
indices_(std::move(indices)),
segment_offsets_(meta.segment_offsets)
Expand Down
Loading
Loading