diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 16042e92a27..c9f87388859 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -220,7 +220,6 @@ set(CUGRAPH_SOURCES src/sampling/detail/sampling_utils_sg.cu src/sampling/uniform_neighbor_sampling_mg.cpp src/sampling/uniform_neighbor_sampling_sg.cpp - src/cores/legacy/core_number.cu src/cores/core_number_sg.cu src/cores/core_number_mg.cu src/cores/k_core_sg.cu diff --git a/cpp/include/cugraph/algorithms.hpp b/cpp/include/cugraph/algorithms.hpp index 09e22ea09f9..4bb39922fd3 100644 --- a/cpp/include/cugraph/algorithms.hpp +++ b/cpp/include/cugraph/algorithms.hpp @@ -468,48 +468,6 @@ std::unique_ptr> k_truss_subgraph( int k, rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); -/** - * @brief Compute the Core Number for the nodes of the graph G - * - * @param[in] graph cuGraph graph descriptor with a valid edgeList or adjList - * @param[out] core_number Populated by the core number of every vertex in the graph - * - * @throws cugraph::logic_error when an error occurs. - */ -/* ----------------------------------------------------------------------------*/ -template -void core_number(legacy::GraphCSRView const& graph, VT* core_number); - -/** - * @brief Compute K Core of the graph G - * - * @throws cugraph::logic_error when an error occurs. - * - * @tparam VT Type of vertex identifiers. Supported value : int (signed, - * 32-bit) - * @tparam ET Type of edge identifiers. Supported value : int (signed, - * 32-bit) - * @tparam WT Type of edge weights. Supported values : float or double. - * - * @param[in] graph cuGraph graph in coordinate format - * @param[in] k Order of the core. This value must not be negative. - * @param[in] vertex_id User specified vertex identifiers for which core number values - * are supplied - * @param[in] core_number User supplied core number values corresponding to vertex_id - * @param[in] num_vertex_ids Number of elements in vertex_id/core_number arrays - * @param[in] mr Memory resource used to allocate the returned graph - * - * @param[out] out_graph Unique pointer to K Core subgraph in COO format - */ -template -std::unique_ptr> k_core( - legacy::GraphCOOView const& graph, - int k, - VT const* vertex_id, - VT const* core_number, - VT num_vertex_ids, - rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); - /** * @brief Find all 2-hop neighbors in the graph * diff --git a/cpp/src/cores/legacy/core_number.cu b/cpp/src/cores/legacy/core_number.cu deleted file mode 100644 index a854f037585..00000000000 --- a/cpp/src/cores/legacy/core_number.cu +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2019-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 -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -//#include - -namespace cugraph { -namespace detail { - -template -void core_number(legacy::GraphCSRView const& graph, int* core_number) -{ - using HornetGraph = hornet::gpu::HornetStatic; - using HornetInit = hornet::HornetInit; - using CoreNumber = hornets_nest::CoreNumberStatic; - HornetInit init(graph.number_of_vertices, graph.number_of_edges, graph.offsets, graph.indices); - HornetGraph hnt(init, hornet::DeviceType::DEVICE); - CoreNumber cn(hnt, core_number); - cn.run(); -} - -struct FilterEdges { - int k; - int* core_number; - - FilterEdges(int _k, int* d_core_num) : k(_k), core_number(d_core_num) {} - - template - __host__ __device__ bool operator()(T t) - { - int src = thrust::get<0>(t); - int dst = thrust::get<1>(t); - return (core_number[src] >= k) && (core_number[dst] >= k); - } -}; - -template -void extract_edges(legacy::GraphCOOView const& i_graph, - legacy::GraphCOOView& o_graph, - VT* d_core, - int k) -{ - cudaStream_t stream{nullptr}; - - // If an edge satisfies k-core conditions i.e. core_num[src] and core_num[dst] - // are both greater than or equal to k, copy it to the output graph - if (i_graph.has_data()) { - auto inEdge = thrust::make_zip_iterator( - thrust::make_tuple(i_graph.src_indices, i_graph.dst_indices, i_graph.edge_data)); - auto outEdge = thrust::make_zip_iterator( - thrust::make_tuple(o_graph.src_indices, o_graph.dst_indices, o_graph.edge_data)); - auto ptr = thrust::copy_if(rmm::exec_policy(stream), - inEdge, - inEdge + i_graph.number_of_edges, - outEdge, - FilterEdges(k, d_core)); - if (thrust::distance(outEdge, ptr) != o_graph.number_of_edges) { - CUGRAPH_FAIL("Edge extraction failed"); - } - } else { - auto inEdge = - thrust::make_zip_iterator(thrust::make_tuple(i_graph.src_indices, i_graph.dst_indices)); - auto outEdge = - thrust::make_zip_iterator(thrust::make_tuple(o_graph.src_indices, o_graph.dst_indices)); - auto ptr = thrust::copy_if(rmm::exec_policy(stream), - inEdge, - inEdge + i_graph.number_of_edges, - outEdge, - FilterEdges(k, d_core)); - if (thrust::distance(outEdge, ptr) != o_graph.number_of_edges) { - CUGRAPH_FAIL("Edge extraction failed"); - } - } -} - -// Extract a subgraph from in_graph (with or without weights) -// to out_graph based on whether edges in in_graph satisfy kcore -// conditions. -// i.e. All edges (s,d,w) in in_graph are copied over to out_graph -// if core_num[s] and core_num[d] are greater than or equal to k. -template -std::unique_ptr> extract_subgraph( - legacy::GraphCOOView const& in_graph, - int const* vid, - int const* core_num, - int k, - int len, - rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()) - -{ - cudaStream_t stream{nullptr}; - - rmm::device_vector sorted_core_num(in_graph.number_of_vertices); - - thrust::scatter(rmm::exec_policy(stream), core_num, core_num + len, vid, sorted_core_num.begin()); - - VT* d_sorted_core_num = sorted_core_num.data().get(); - - // Count number of edges in the input graph that satisfy kcore conditions - // i.e. core_num[src] and core_num[dst] are both greater than or equal to k - auto edge = - thrust::make_zip_iterator(thrust::make_tuple(in_graph.src_indices, in_graph.dst_indices)); - - auto out_graph = std::make_unique>( - in_graph.number_of_vertices, - thrust::count_if(rmm::exec_policy(stream), - edge, - edge + in_graph.number_of_edges, - detail::FilterEdges(k, d_sorted_core_num)), - in_graph.has_data(), - stream, - mr); - - legacy::GraphCOOView out_graph_view = out_graph->view(); - extract_edges(in_graph, out_graph_view, d_sorted_core_num, k); - - return out_graph; -} - -} // namespace detail - -template -void core_number(legacy::GraphCSRView const& graph, VT* core_number) -{ - return detail::core_number(graph, core_number); -} - -template -std::unique_ptr> k_core( - legacy::GraphCOOView const& in_graph, - int k, - VT const* vertex_id, - VT const* core_number, - VT num_vertex_ids, - rmm::mr::device_memory_resource* mr) -{ - CUGRAPH_EXPECTS(vertex_id != nullptr, "Invalid input argument: vertex_id is NULL"); - CUGRAPH_EXPECTS(core_number != nullptr, "Invalid input argument: core_number is NULL"); - CUGRAPH_EXPECTS(k >= 0, "Invalid input argument: k must be >= 0"); - - return detail::extract_subgraph(in_graph, vertex_id, core_number, k, num_vertex_ids, mr); -} - -template void core_number( - legacy::GraphCSRView const&, int32_t* core_number); -template std::unique_ptr> k_core( - legacy::GraphCOOView const&, - int, - int32_t const*, - int32_t const*, - int32_t, - rmm::mr::device_memory_resource*); -template std::unique_ptr> -k_core(legacy::GraphCOOView const&, - int, - int32_t const*, - int32_t const*, - int32_t, - rmm::mr::device_memory_resource*); - -} // namespace cugraph