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

remove all algorithms from cython.cu #2955

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
345 changes: 1 addition & 344 deletions cpp/include/cugraph/utilities/cython.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
#pragma once

#include <cugraph/graph.hpp>
#include <cugraph/graph_generators.hpp>
#include <cugraph/legacy/graph.hpp>
#include <cugraph/utilities/graph_traits.hpp>
#include <cugraph/graph_view.hpp>

#include <raft/handle.hpp>

Expand All @@ -29,121 +27,6 @@ namespace cython {

enum class numberTypeEnum : int { int32Type, int64Type, floatType, doubleType };

enum class graphTypeEnum : int {
// represents unintiialized or NULL ptr
null,
// represents some legacy Cxx type. This and other LegacyCxx values are not
// used for the unique_ptr in a graph_container_t, but instead for when this
// enum is used for determining high-level code paths to take to prevent
// needing to expose each legacy enum value to cython.
LegacyCSR,
LegacyCSC,
LegacyCOO,
// represents that a GraphCxxView* unique_ptr type is present in a
// graph_container_t.
GraphCSRViewFloat,
GraphCSRViewDouble,
GraphCOOViewFloat,
GraphCOOViewDouble,
// represents values present in the graph_container_t to construct a graph_t,
// but unlike legacy classes does not mean a graph_t unique_ptr is present in
// the container.
graph_t,
};

// "container" for a graph type instance which insulates the owner from the
// specifics of the actual graph type. This is intended to be used in Cython
// code that only needs to pass a graph object to another wrapped C++ API. This
// greatly simplifies the Cython code since the Cython definition only needs to
// define the container and not the various individual graph types in Cython.
struct graph_container_t {
// FIXME: This union is in place only to support legacy calls, remove when
// migration to graph_t types is complete, or when legacy graph objects are
// constructed in the call_<<algo> wrappers instead of the
// populate_graph_container_legacy() function.
union graphPtrUnion {
~graphPtrUnion() {}

void* null;
std::unique_ptr<legacy::GraphCSRView<int32_t, int32_t, float>> GraphCSRViewFloatPtr;
std::unique_ptr<legacy::GraphCSRView<int32_t, int32_t, double>> GraphCSRViewDoublePtr;
std::unique_ptr<legacy::GraphCOOView<int32_t, int32_t, float>> GraphCOOViewFloatPtr;
std::unique_ptr<legacy::GraphCOOView<int32_t, int32_t, double>> GraphCOOViewDoublePtr;
};

graph_container_t() : graph_ptr_union{nullptr}, graph_type{graphTypeEnum::null} {}
~graph_container_t() {}

// The expected usage of a graph_container_t is for it to be created as part
// of a cython wrapper simply for passing a templated instantiation of a
// particular graph class from one call to another, and not to exist outside
// of the individual wrapper function (deleted when the instance goes out of
// scope once the wrapper function returns). Therefore, copys and assignments
// to an instance are not supported and these methods are deleted.
graph_container_t(const graph_container_t&) = delete;
graph_container_t& operator=(const graph_container_t&) = delete;

graphPtrUnion graph_ptr_union;
graphTypeEnum graph_type;

// primitive data used for constructing graph_t instances.
void* src_vertices;
void* dst_vertices;
void* weights;
bool is_weighted;
void* vertex_partition_offsets;
void* segment_offsets;
size_t num_segments;

size_t num_local_edges;
size_t num_global_vertices;
size_t num_global_edges;
numberTypeEnum vertexType;
numberTypeEnum edgeType;
numberTypeEnum weightType;
bool transposed;
bool is_multi_gpu;
bool do_expensive_check;
int row_comm_size;
int col_comm_size;
int row_comm_rank;
int col_comm_rank;
graph_properties_t graph_props;
};

/**
* @brief Owning struct. Allows returning multiple edge lists and edge offsets.
* cython only
*
* @param number_of_vertices The total number of vertices
* @param number_of_edges The total number of edges (number of elements in src_indices,
dst_indices and edge_data)
* @param number_of_subgraph The number of subgraphs, number of elements in subgraph_offsets - 1
* @param source_indices This array of size E (number of edges) contains
* the index of the
* source for each edge. Indices must be in the range [0, V-1].
* @param destination_indices This array of size E (number of edges) contains
* the index of the
* destination for each edge. Indices must be in the range [0, V-1].
* @param edge_data This array size E (number of edges) contains
* the weight for each
* edge. This array can be null in which case the graph is considered
* unweighted.
* @param subgraph_offsets This array size number_of_subgraph + 1 contains edge offsets
for each subgraph


*/
struct cy_multi_edgelists_t {
size_t number_of_vertices;
size_t number_of_edges;
size_t number_of_subgraph;
std::unique_ptr<rmm::device_buffer> src_indices;
std::unique_ptr<rmm::device_buffer> dst_indices;
std::unique_ptr<rmm::device_buffer> edge_data;
std::unique_ptr<rmm::device_buffer> subgraph_offsets;
};

// replacement for std::tuple<,,>, since std::tuple is not
// supported in cython
//
Expand Down Expand Up @@ -195,51 +78,11 @@ struct major_minor_weights_t {
std::vector<edge_t> edge_counts_{};
};

// aggregate for random_walks() return type
// to be exposed to cython:
//
struct random_walk_ret_t {
size_t coalesced_sz_v_;
size_t coalesced_sz_w_;
size_t num_paths_;
size_t max_depth_;
std::unique_ptr<rmm::device_buffer> d_coalesced_v_;
std::unique_ptr<rmm::device_buffer> d_coalesced_w_;
std::unique_ptr<rmm::device_buffer> d_sizes_;
};

struct random_walk_path_t {
std::unique_ptr<rmm::device_buffer> d_v_offsets;
std::unique_ptr<rmm::device_buffer> d_w_sizes;
std::unique_ptr<rmm::device_buffer> d_w_offsets;
};

struct graph_generator_t {
std::unique_ptr<rmm::device_buffer> d_source;
std::unique_ptr<rmm::device_buffer> d_destination;
};

// enum class generator_distribution_t { POWER_LAW = 0, UNIFORM };
// aggregate for random_walks() COO return type
// to be exposed to cython:
//
struct random_walk_coo_t {
size_t num_edges_; // total number of COO triplets (for all paths)
size_t num_offsets_; // offsets of where each COO set starts for each path;
// NOTE: this can differ than num_paths_,
// because paths with 0 edges (one vertex)
// don't participate to the COO

std::unique_ptr<rmm::device_buffer>
d_src_; // coalesced set of COO source vertices; |d_src_| = num_edges_
std::unique_ptr<rmm::device_buffer>
d_dst_; // coalesced set of COO destination vertices; |d_dst_| = num_edges_
std::unique_ptr<rmm::device_buffer>
d_weights_; // coalesced set of COO edge weights; |d_weights_| = num_edges_
std::unique_ptr<rmm::device_buffer>
d_offsets_; // offsets where each COO subset for each path starts; |d_offsets_| = num_offsets_
};

// wrapper for renumber_edgelist() return
// (unrenumbering maps, etc.)
//
Expand Down Expand Up @@ -365,175 +208,6 @@ struct renum_tuple_t {
std::vector<vertex_t> segment_offsets_;
};

// FIXME: finish description for vertex_partition_offsets
//
// Factory function for populating an empty graph container with a new graph
// object from basic types, and sets the corresponding meta-data. Args are:
//
// graph_container_t& graph_container
// Reference to the graph_container_t instance to
// populate. populate_graph_container() can only be called on an "empty"
// container (ie. a container that has not been previously populated by
// populate_graph_container())
//
// graphTypeEnum legacyType
// Specifies the type of graph when instantiating a legacy graph type
// (GraphCSRViewFloat, etc.).
// NOTE: this parameter will be removed when the transition to exclusinve use
// of the new 2D graph classes is complete.
//
// raft::handle_t const& handle
// Raft handle to be set on the new graph instance in the container
//
// void* src_vertices, dst_vertices, weights
// Pointer to an array of values representing source and destination vertices,
// and edge weights respectively. The value types of the array are specified
// using numberTypeEnum values separately (see below). offsets should be size
// num_vertices+1, indices should be size num_edges, weights should also be
// size num_edges
//
// void* vertex_partition_offsets
// Pointer to an array of vertexType values representing offsets into the
// individual partitions for a multi-GPU paritioned graph. The offsets are used for ...
//
// numberTypeEnum vertexType, edgeType, weightType
// numberTypeEnum enum value describing the data type for the vertices,
// offsets, and weights arrays respectively. These enum values are used to
// instantiate the proper templated graph type and for casting the arrays
// accordingly.
//
// int num_vertices, num_edges
// The number of vertices and edges respectively in the graph represented by
// the above arrays.
//
// bool is_weighted
// true if the resulting graph object should store edge weights
//
// bool transposed
// true if the resulting graph object should store a transposed adjacency
// matrix
//
// bool multi_gpu
// true if the resulting graph object is to be used for a multi-gpu
// application
void populate_graph_container(graph_container_t& graph_container,
raft::handle_t& handle,
void* src_vertices,
void* dst_vertices,
void* weights,
void* vertex_partition_offsets,
void* segment_offsets,
size_t num_segments,
numberTypeEnum vertexType,
numberTypeEnum edgeType,
numberTypeEnum weightType,
size_t num_local_edges,
size_t num_global_vertices,
size_t num_global_edges,
bool is_weighted,
bool is_symmetric,
bool transposed,
bool multi_gpu);

// FIXME: comment this function
// FIXME: Should local_* values be void* as well?
void populate_graph_container_legacy(graph_container_t& graph_container,
graphTypeEnum legacyType,
raft::handle_t const& handle,
void* offsets,
void* indices,
void* weights,
numberTypeEnum offsetType,
numberTypeEnum indexType,
numberTypeEnum weightType,
size_t num_global_vertices,
size_t num_global_edges,
int* local_vertices,
int* local_edges,
int* local_offsets);

// Wrapper for calling Louvain using a graph container
template <typename weight_t>
std::pair<size_t, weight_t> call_louvain(raft::handle_t const& handle,
graph_container_t const& graph_container,
void* identifiers,
void* parts,
size_t max_level,
weight_t resolution);

// Wrapper for calling Pagerank using a graph container
template <typename vertex_t, typename weight_t>
void call_pagerank(raft::handle_t const& handle,
graph_container_t const& graph_container,
vertex_t* identifiers,
weight_t* pagerank,
vertex_t personalization_subset_size,
vertex_t* personalization_subset,
weight_t* personalization_values,
double alpha,
double tolerance,
int64_t max_iter,
bool has_guess);

// Wrapper for calling Katz centrality using a graph container
template <typename vertex_t, typename weight_t>
void call_katz_centrality(raft::handle_t const& handle,
graph_container_t const& graph_container,
vertex_t* identifiers,
weight_t* katz_centrality,
double alpha,
double beta,
double tolerance,
int64_t max_iter,
bool normalized,
bool has_guess);

// Wrapper for calling BFS through a graph container
template <typename vertex_t, typename weight_t>
void call_bfs(raft::handle_t const& handle,
graph_container_t const& graph_container,
vertex_t* identifiers,
vertex_t* distances,
vertex_t* predecessors,
vertex_t depth_limit,
vertex_t* sources,
size_t n_sources,
bool direction_optimizing);

// Wrapper for calling SSSP through a graph container
template <typename vertex_t, typename weight_t>
void call_sssp(raft::handle_t const& handle,
graph_container_t const& graph_container,
vertex_t* identifiers,
weight_t* distances,
vertex_t* predecessors,
const vertex_t source_vertex);

// Wrapper for calling egonet through a graph container
template <typename vertex_t, typename weight_t>
std::unique_ptr<cy_multi_edgelists_t> call_egonet(raft::handle_t const& handle,
graph_container_t const& graph_container,
vertex_t* source_vertex,
vertex_t n_subgraphs,
vertex_t radius);

// Wrapper for calling WCC through a graph container
template <typename vertex_t, typename weight_t>
void call_wcc(raft::handle_t const& handle,
graph_container_t const& graph_container,
vertex_t* components);

// Wrapper for calling HITS through a graph container
template <typename vertex_t, typename weight_t>
void call_hits(raft::handle_t const& handle,
graph_container_t const& graph_container,
weight_t* hubs,
weight_t* authorities,
size_t max_iter,
weight_t tolerance,
const weight_t* starting_value,
bool normalized);

// Wrapper for calling graph generator
template <typename vertex_t>
std::unique_ptr<graph_generator_t> call_generate_rmat_edgelist(raft::handle_t const& handle,
Expand All @@ -558,23 +232,6 @@ call_generate_rmat_edgelists(raft::handle_t const& handle,
bool clip_and_flip,
bool scramble_vertex_ids);

// wrapper for random_walks.
//
template <typename vertex_t, typename edge_t>
std::enable_if_t<cugraph::is_vertex_edge_combo<vertex_t, edge_t>::value,
std::unique_ptr<random_walk_ret_t>>
call_random_walks(raft::handle_t const& handle,
graph_container_t const& graph_container,
vertex_t const* ptr_start_set,
edge_t num_paths,
edge_t max_depth,
bool use_padding);

template <typename index_t>
std::unique_ptr<random_walk_path_t> call_rw_paths(raft::handle_t const& handle,
index_t num_paths,
index_t const* vertex_path_sizes);

// wrapper for shuffling:
//
template <typename vertex_t, typename edge_t, typename weight_t>
Expand Down
Loading