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

Merging in 22.06 branch w/ sg katz branch for eigen #47

Merged
merged 4 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion conda/environments/cugraph_dev_cuda11.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
- networkx>=2.5.1
- clang=11.1.0
- clang-tools=11.1.0
- cmake>=3.20.1,<3.23
- cmake>=3.20.1,!=3.23.0
- python>=3.6,<3.9
- notebook>=0.5.0
- boost
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/cugraph_dev_cuda11.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
- networkx>=2.5.1
- clang=11.1.0
- clang-tools=11.1.0
- cmake>=3.20.1,<3.23
- cmake>=3.20.1,!=3.23.0
- python>=3.6,<3.9
- notebook>=0.5.0
- boost
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/cugraph_dev_cuda11.5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
- networkx>=2.5.1
- clang=11.1.0
- clang-tools=11.1.0
- cmake>=3.20.1,<3.23
- cmake>=3.20.1,!=3.23.0
- python>=3.6,<3.9
- notebook>=0.5.0
- boost
Expand Down
2 changes: 1 addition & 1 deletion conda/recipes/libcugraph/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_version:
- ">=3.20.1,<3.23"
- ">=3.20.1,!=3.23.0"

doxygen_version:
- ">=1.8.11"
Expand Down
3 changes: 3 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ add_library(cugraph_c
src/c_api/extract_paths.cpp
src/c_api/random_walks.cpp
src/c_api/uniform_neighbor_sampling.cpp
src/c_api/labeling_result.cpp
src/c_api/weakly_connected_components.cpp
src/c_api/strongly_connected_components.cpp
)
add_library(cugraph::cugraph_c ALIAS cugraph_c)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ void copy_v_transform_reduce_nbr(raft::handle_t const& handle,
* value to be reduced.
* @param init Initial value to be added to the reduced @p e_op return values for each vertex.
* @param vertex_value_output_first Iterator pointing to the vertex property variables for the first
* (inclusive) vertex (assigned to tihs process in multi-GPU). `vertex_value_output_last`
* (inclusive) vertex (assigned to this process in multi-GPU). `vertex_value_output_last`
* (exclusive) is deduced as @p vertex_value_output_first + @p
* graph_view.local_vertex_partition_range_size().
*/
Expand Down Expand Up @@ -975,7 +975,7 @@ void copy_v_transform_reduce_in_nbr(
* value to be reduced.
* @param init Initial value to be added to the reduced @p e_op return values for each vertex.
* @param vertex_value_output_first Iterator pointing to the vertex property variables for the
* first (inclusive) vertex (assigned to tihs process in multi-GPU). `vertex_value_output_last`
* first (inclusive) vertex (assigned to this process in multi-GPU). `vertex_value_output_last`
* (exclusive) is deduced as @p vertex_value_output_first + @p
* graph_view.local_vertex_partition_range_size().
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ struct reduce_with_init_t {
* @param reduce_op Binary operator takes two input arguments and reduce the two variables to one.
* @param init Initial value to be added to the reduced @p reduce_op return values for each vertex.
* @param vertex_value_output_first Iterator pointing to the vertex property variables for the
* first (inclusive) vertex (assigned to tihs process in multi-GPU). `vertex_value_output_last`
* first (inclusive) vertex (assigned to this process in multi-GPU). `vertex_value_output_last`
* (exclusive) is deduced as @p vertex_value_output_first + @p
* graph_view.local_vertex_partition_range_size().
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,12 +976,12 @@ typename GraphViewType::edge_type compute_num_out_nbrs_from_frontier(
* (inclusive) vertex (assigned to this process in multi-GPU). `vertex_value_input_last` (exclusive)
* is deduced as @p vertex_value_input_first + @p graph_view.local_vertex_partition_range_size().
* @param vertex_value_output_first Iterator pointing to the vertex property variables for the first
* (inclusive) vertex (assigned to tihs process in multi-GPU). `vertex_value_output_last`
* (inclusive) vertex (assigned to this process in multi-GPU). `vertex_value_output_last`
* (exclusive) is deduced as @p vertex_value_output_first + @p
* graph_view.local_vertex_partition_range_size().
* @param v_op Ternary operator takes (tagged-)vertex ID, *(@p vertex_value_input_first + i) (where
* i is [0, @p graph_view.local_vertex_partition_range_size())) and reduced value of the @p e_op
* outputs for this vertex and returns the target bucket index (for frontier update) and new verrtex
* outputs for this vertex and returns the target bucket index (for frontier update) and new vertex
* property values (to update *(@p vertex_value_output_first + i)). The target bucket index should
* either be VertexFrontierType::kInvalidBucketIdx or an index in @p next_frontier_bucket_indices.
*/
Expand Down
2 changes: 2 additions & 0 deletions cpp/include/cugraph_c/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,5 @@ void cugraph_sample_result_free(cugraph_sample_result_t* result);
#ifdef __cplusplus
}
#endif

#include <cugraph_c/labeling_algorithms.h>
101 changes: 101 additions & 0 deletions cpp/include/cugraph_c/labeling_algorithms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* 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_c/error.h>
#include <cugraph_c/graph.h>
#include <cugraph_c/resource_handle.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Opaque labeling result type
*/
typedef struct {
int32_t align_;
} cugraph_labeling_result_t;

/**
* @brief Get the vertex ids from the labeling result
*
* @param [in] result The result from a labeling algorithm
* @return type erased array of vertex ids
*/
cugraph_type_erased_device_array_view_t* cugraph_labeling_result_get_vertices(
cugraph_labeling_result_t* result);

/**
* @brief Get the label values from the labeling result
*
* @param [in] result The result from a labeling algorithm
* @return type erased array of label values
*/
cugraph_type_erased_device_array_view_t* cugraph_labeling_result_get_labels(
cugraph_labeling_result_t* result);

/**
* @brief Free labeling result
*
* @param [in] result The result from a labeling algorithm
*/
void cugraph_labeling_result_free(cugraph_labeling_result_t* result);

/**
* @brief Labels each vertex in the input graph with its (weakly-connected-)component ID
*
* The input graph must be symmetric. Component IDs can be arbitrary integers (they can be
* non-consecutive and are not ordered by component size or any other criterion).
*
* @param [in] handle Handle for accessing resources
* @param [in] graph Pointer to graph
* @param [in] do_expensive_check A flag to run expensive checks for input arguments (if set to
* `true`).
* @param [out] result Opaque pointer to labeling results
* @param [out] error Pointer to an error object storing details of any error. Will
* be populated if error code is not CUGRAPH_SUCCESS
*/
cugraph_error_code_t cugraph_weakly_connected_components(const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
bool_t do_expensive_check,
cugraph_labeling_result_t** result,
cugraph_error_t** error);

/**
* @brief Labels each vertex in the input graph with its (strongly-connected-)component ID
*
* The input graph may be asymmetric. Component IDs can be arbitrary integers (they can be
* non-consecutive and are not ordered by component size or any other criterion).
*
* @param [in] handle Handle for accessing resources
* @param [in] graph Pointer to graph
* @param [in] do_expensive_check A flag to run expensive checks for input arguments (if set to
* `true`).
* @param [out] result Opaque pointer to labeling results
* @param [out] error Pointer to an error object storing details of any error. Will
* be populated if error code is not CUGRAPH_SUCCESS
*/
cugraph_error_code_t cugraph_strongly_connected_components(const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
bool_t do_expensive_check,
cugraph_labeling_result_t** result,
cugraph_error_t** error);

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion cpp/src/c_api/katz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct katz_functor : public cugraph::c_api::abstract_functor {
cugraph::detail::sequence_fill(handle_.get_stream(),
betas_vertex_ids.data(),
betas_vertex_ids.size(),
graph_view.local_vertex_partition_range_size());
graph_view.local_vertex_partition_range_first());

betas.resize(graph_view.local_vertex_partition_range_size(), handle_.get_stream());

Expand Down
43 changes: 43 additions & 0 deletions cpp/src/c_api/labeling_result.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 <cugraph_c/labeling_algorithms.h>

#include <c_api/labeling_result.hpp>

extern "C" cugraph_type_erased_device_array_view_t* cugraph_labeling_result_get_vertices(
cugraph_labeling_result_t* result)
{
auto internal_pointer = reinterpret_cast<cugraph::c_api::cugraph_labeling_result_t*>(result);
return reinterpret_cast<cugraph_type_erased_device_array_view_t*>(
internal_pointer->vertex_ids_->view());
}

extern "C" cugraph_type_erased_device_array_view_t* cugraph_labeling_result_get_labels(
cugraph_labeling_result_t* result)
{
auto internal_pointer = reinterpret_cast<cugraph::c_api::cugraph_labeling_result_t*>(result);
return reinterpret_cast<cugraph_type_erased_device_array_view_t*>(
internal_pointer->labels_->view());
}

extern "C" void cugraph_labeling_result_free(cugraph_labeling_result_t* result)
{
auto internal_pointer = reinterpret_cast<cugraph::c_api::cugraph_labeling_result_t*>(result);
delete internal_pointer->vertex_ids_;
delete internal_pointer->labels_;
delete internal_pointer;
}
30 changes: 30 additions & 0 deletions cpp/src/c_api/labeling_result.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 <c_api/array.hpp>

namespace cugraph {
namespace c_api {

struct cugraph_labeling_result_t {
cugraph_type_erased_device_array_t* vertex_ids_;
cugraph_type_erased_device_array_t* labels_;
};

} // namespace c_api
} // namespace cugraph
86 changes: 86 additions & 0 deletions cpp/src/c_api/strongly_connected_components.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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 <cugraph_c/labeling_algorithms.h>

#include <c_api/abstract_functor.hpp>
#include <c_api/graph.hpp>
#include <c_api/labeling_result.hpp>
#include <c_api/resource_handle.hpp>
#include <c_api/utils.hpp>

#include <cugraph/algorithms.hpp>
#include <cugraph/detail/shuffle_wrappers.hpp>
#include <cugraph/detail/utility_wrappers.hpp>
#include <cugraph/graph_functions.hpp>

#include <optional>

namespace {

struct scc_functor : public cugraph::c_api::abstract_functor {
raft::handle_t const& handle_;
cugraph::c_api::cugraph_graph_t* graph_{};
bool do_expensive_check_{};
cugraph::c_api::cugraph_labeling_result_t* result_{};

scc_functor(::cugraph_resource_handle_t const* handle,
::cugraph_graph_t* graph,
bool do_expensive_check)
: abstract_functor(),
handle_(*reinterpret_cast<cugraph::c_api::cugraph_resource_handle_t const*>(handle)->handle_),
graph_(reinterpret_cast<cugraph::c_api::cugraph_graph_t*>(graph)),
do_expensive_check_(do_expensive_check)
{
}

template <typename vertex_t,
typename edge_t,
typename weight_t,
bool store_transposed,
bool multi_gpu>
void operator()()
{
if constexpr (!cugraph::is_candidate<vertex_t, edge_t, weight_t>::value) {
unsupported();
} else {
// SCC expects store_transposed == false
if constexpr (store_transposed) {
error_code_ = cugraph::c_api::
transpose_storage<vertex_t, edge_t, weight_t, store_transposed, multi_gpu>(
handle_, graph_, error_.get());
if (error_code_ != CUGRAPH_SUCCESS) return;
}

error_code_ = CUGRAPH_NOT_IMPLEMENTED;
error_->error_message_ = "SCC Not currently implemented";
}
}
};

} // namespace

extern "C" cugraph_error_code_t cugraph_strongly_connected_components(
const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
bool_t do_expensive_check,
cugraph_labeling_result_t** result,
cugraph_error_t** error)
{
scc_functor functor(handle, graph, do_expensive_check);

return cugraph::c_api::run_algorithm(graph, functor, result, error);
}
Loading