Skip to content

Commit

Permalink
Triangle Counts C++ API (#2233)
Browse files Browse the repository at this point in the history
Define C++ API for triangle counting.

Authors:
  - Seunghwa Kang (https://github.com/seunghwak)

Approvers:
  - Chuck Hastings (https://github.com/ChuckHastings)
  - Joseph Nke (https://github.com/jnke2016)

URL: #2233
  • Loading branch information
seunghwak authored Apr 26, 2022
1 parent 3c4cd18 commit 4545cb8
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ add_library(cugraph
src/visitors/bfs_visitor.cpp
src/visitors/rw_visitor.cpp
src/visitors/graph_make_visitor.cpp
src/community/triangle_counts_sg.cu
src/community/triangle_counts_mg.cu
)

set_target_properties(cugraph
Expand Down
28 changes: 28 additions & 0 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/span.hpp>

namespace cugraph {

Expand Down Expand Up @@ -1534,4 +1535,31 @@ uniform_nbr_sample(raft::handle_t const& handle,
std::vector<int> const& h_fan_out,
bool with_replacement = true);

/*
* @brief Compute triangle counts.
*
* Compute triangle counts for the entire set of vertices (if @p vertices is std::nullopt) or the
* given vertices (@p vertices.has_value() is true).
*
* @tparam vertex_t Type of vertex identifiers. Needs to be an integral type.
* @tparam edge_t Type of edge identifiers. Needs to be an integral type.
* @tparam weight_t Type of edge weights. Needs to be a floating point type.
* @tparam multi_gpu Flag indicating whether template instantiation should target single-GPU (false)
* @param handle RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and
* handles to various CUDA libraries) to run graph algorithms.
* @param graph_view Graph view object.
* @param vertices Vertices to compute triangle counts. If @p vertices.has_value() is false, compute
* triangle counts for the entire set of vertices.
* @param counts Output triangle count array. The size of the array should be the local vertex
* partition range size (if @p vertices is std::nullopt) or the size of @p vertices (if @p
* vertices.has_value() is true).
* @param do_expensive_check A flag to run expensive checks for input arguments (if set to `true`).
*/
template <typename vertex_t, typename edge_t, typename weight_t, bool multi_gpu>
void triangle_counts(raft::handle_t const& handle,
graph_view_t<vertex_t, edge_t, weight_t, false, multi_gpu> const& graph_view,
std::optional<raft::device_span<vertex_t>> vertices,
raft::device_span<edge_t> counts,
bool do_expensive_check = false);

} // namespace cugraph
33 changes: 33 additions & 0 deletions cpp/src/community/triangle_counts_impl.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2022, 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.
*/
#pragma once

#include <cugraph/algorithms.hpp>

namespace cugraph {

template <typename vertex_t, typename edge_t, typename weight_t, bool multi_gpu>
void triangle_counts(raft::handle_t const& handle,
graph_view_t<vertex_t, edge_t, weight_t, false, multi_gpu> const& graph_view,
std::optional<raft::device_span<vertex_t>> vertices,
raft::device_span<edge_t> counts,
bool do_expensive_check)
{
CUGRAPH_FAIL("unimplemented.");
return;
}

} // namespace cugraph
57 changes: 57 additions & 0 deletions cpp/src/community/triangle_counts_mg.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2022, 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 <community/triangle_counts_impl.cuh>

namespace cugraph {

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int32_t, int32_t, float, false, true> const& graph_view,
std::optional<raft::device_span<int32_t>> vertices,
raft::device_span<int32_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int32_t, int32_t, double, false, true> const& graph_view,
std::optional<raft::device_span<int32_t>> vertices,
raft::device_span<int32_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int32_t, int64_t, float, false, true> const& graph_view,
std::optional<raft::device_span<int32_t>> vertices,
raft::device_span<int64_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int32_t, int64_t, double, false, true> const& graph_view,
std::optional<raft::device_span<int32_t>> vertices,
raft::device_span<int64_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int64_t, int64_t, float, false, true> const& graph_view,
std::optional<raft::device_span<int64_t>> vertices,
raft::device_span<int64_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int64_t, int64_t, double, false, true> const& graph_view,
std::optional<raft::device_span<int64_t>> vertices,
raft::device_span<int64_t> counts,
bool do_expensive_check);

} // namespace cugraph
57 changes: 57 additions & 0 deletions cpp/src/community/triangle_counts_sg.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2022, 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 <community/triangle_counts_impl.cuh>

namespace cugraph {

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int32_t, int32_t, float, false, false> const& graph_view,
std::optional<raft::device_span<int32_t>> vertices,
raft::device_span<int32_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int32_t, int32_t, double, false, false> const& graph_view,
std::optional<raft::device_span<int32_t>> vertices,
raft::device_span<int32_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int32_t, int64_t, float, false, false> const& graph_view,
std::optional<raft::device_span<int32_t>> vertices,
raft::device_span<int64_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int32_t, int64_t, double, false, false> const& graph_view,
std::optional<raft::device_span<int32_t>> vertices,
raft::device_span<int64_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int64_t, int64_t, float, false, false> const& graph_view,
std::optional<raft::device_span<int64_t>> vertices,
raft::device_span<int64_t> counts,
bool do_expensive_check);

void triangle_counts(raft::handle_t const& handle,
graph_view_t<int64_t, int64_t, double, false, false> const& graph_view,
std::optional<raft::device_span<int64_t>> vertices,
raft::device_span<int64_t> counts,
bool do_expensive_check);

} // namespace cugraph

0 comments on commit 4545cb8

Please sign in to comment.