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

Delete old nbr sampling software #2371

Merged
2 changes: 0 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,8 @@ add_library(cugraph
src/community/legacy/egonet.cu
src/sampling/neighborhood.cu
src/sampling/random_walks.cu
src/sampling/detail/gather_utils_impl.cu
src/sampling/detail/sampling_utils_mg.cu
src/sampling/detail/sampling_utils_sg.cu
src/sampling/nbr_sampling_mg.cu
src/sampling/uniform_neighbor_sampling_mg.cpp
src/sampling/uniform_neighbor_sampling_sg.cpp
src/cores/legacy/core_number.cu
Expand Down
36 changes: 0 additions & 36 deletions cpp/include/cugraph/algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,42 +1464,6 @@ void core_number(raft::handle_t const& handle,
size_t k_last = std::numeric_limits<size_t>::max(),
bool do_expensive_check = false);

/**
* @brief Multi-GPU Uniform Neighborhood Sampling.
* @deprecated will be removed later in this release (22.06)
*
* @tparam graph_view_t Type of graph view.
* @tparam gpu_t Type of rank (GPU) indices;
* @tparam index_t Type used for indexing; typically edge_t
* @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 to generate NBR Sampling on.
* @param ptr_d_starting_vertices Device array of starting vertex IDs for the NBR Sampling.
* @param ptr_d_ranks Device array of: rank IDs (GPU IDs) for the NBR Sampling.
* @param num_starting_vertices size of starting vertex set
* @param h_fan_out vector of branching out (fan-out) degree per source vertex for each level
* parameter used for obtaining local out-degree information
* @param with_replacement boolean flag specifying if random sampling is done with replacement
* (true); or, without replacement (false); default = true;
* @return tuple of tuple of device vectors and counts:
* ((vertex_t source_vertex, vertex_t destination_vertex, int rank, edge_t index), rx_counts)
*/
template <typename graph_view_t,
typename gpu_t,
typename index_t = typename graph_view_t::edge_type>
std::tuple<std::tuple<rmm::device_uvector<typename graph_view_t::vertex_type>,
rmm::device_uvector<typename graph_view_t::vertex_type>,
rmm::device_uvector<gpu_t>,
rmm::device_uvector<index_t>>,
std::vector<size_t>>
uniform_nbr_sample(raft::handle_t const& handle,
graph_view_t const& graph_view,
typename graph_view_t::vertex_type const* ptr_d_starting_vertices,
gpu_t const* ptr_d_ranks,
size_t num_starting_vertices,
std::vector<int> const& h_fan_out,
bool with_replacement = true);

/**
* @brief Uniform Neighborhood Sampling.
*
Expand Down
33 changes: 0 additions & 33 deletions cpp/include/cugraph_c/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ typedef struct {
* @param [in] graph Pointer to graph. NOTE: Graph might be modified if the storage
* needs to be transposed
* @param [in] start Device array of start vertices for the sampling
* @param [in] start_label Device array of start labels. These labels will propagate to the
* results so that the result can be properly organized when the input needs to be sent back to
* different callers (different processes or different gpus).
* @param [in] fanout Host array defining the fan out at each step in the sampling algorithm
* @param [in] with_replacement
* Boolean value. If true selection of edges is done with
Expand All @@ -305,37 +302,7 @@ typedef struct {
* be populated if error code is not CUGRAPH_SUCCESS
* @return error code
*/
// FIXME: This older API will be phased out this release in favor of the experimental one below
cugraph_error_code_t cugraph_uniform_neighbor_sample(
const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
const cugraph_type_erased_device_array_view_t* start,
const cugraph_type_erased_device_array_view_t* start_label,
const cugraph_type_erased_host_array_view_t* fan_out,
bool_t with_replacement,
bool_t do_expensive_check,
cugraph_sample_result_t** result,
cugraph_error_t** error);

/**
* @brief Uniform Neighborhood Sampling
*
* @param [in] handle Handle for accessing resources
* @param [in] graph Pointer to graph. NOTE: Graph might be modified if the storage
* needs to be transposed
* @param [in] start Device array of start vertices for the sampling
* @param [in] fanout Host array defining the fan out at each step in the sampling algorithm
* @param [in] with_replacement
* Boolean value. If true selection of edges is done with
* replacement. If false selection is done without replacement.
* @param [in] do_expensive_check
* A flag to run expensive checks for input arguments (if set to true)
* @param [in] result Output from the uniform_neighbor_sample call
* @param [out] error Pointer to an error object storing details of any error. Will
* be populated if error code is not CUGRAPH_SUCCESS
* @return error code
*/
cugraph_error_code_t cugraph_experimental_uniform_neighbor_sample(
const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
const cugraph_type_erased_device_array_view_t* start,
Expand Down
137 changes: 2 additions & 135 deletions cpp/src/c_api/uniform_neighbor_sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ namespace cugraph {
namespace c_api {

struct cugraph_sample_result_t {
bool experimental_{true};
cugraph_type_erased_device_array_t* src_{nullptr};
cugraph_type_erased_device_array_t* dst_{nullptr};
// FIXME: Will be deleted once experimental replaces current
// NOTE: Leaving in place while we discuss some future changes, although
// not currently used.
cugraph_type_erased_device_array_t* label_{nullptr};
cugraph_type_erased_device_array_t* index_{nullptr};
// FIXME: Will be deleted once experimental replaces current
Expand All @@ -53,7 +54,6 @@ struct uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_funct
raft::handle_t const& handle_;
cugraph::c_api::cugraph_graph_t* graph_{nullptr};
cugraph::c_api::cugraph_type_erased_device_array_view_t const* start_{nullptr};
cugraph::c_api::cugraph_type_erased_device_array_view_t const* start_label_{nullptr};
cugraph::c_api::cugraph_type_erased_host_array_view_t const* fan_out_{nullptr};
bool with_replacement_{false};
bool do_expensive_check_{false};
Expand All @@ -62,125 +62,9 @@ struct uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_funct
uniform_neighbor_sampling_functor(cugraph_resource_handle_t const* handle,
cugraph_graph_t* graph,
cugraph_type_erased_device_array_view_t const* start,
cugraph_type_erased_device_array_view_t const* start_label,
cugraph_type_erased_host_array_view_t const* fan_out,
bool with_replacement,
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)),
start_(
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t const*>(start)),
start_label_(reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t const*>(
start_label)),
fan_out_(
reinterpret_cast<cugraph::c_api::cugraph_type_erased_host_array_view_t const*>(fan_out)),
with_replacement_(with_replacement),
do_expensive_check_(do_expensive_check)
{
}

template <typename vertex_t,
typename edge_t,
typename weight_t,
bool store_transposed,
bool multi_gpu>
void operator()()
{
// FIXME: Think about how to handle SG vice MG
if constexpr (!cugraph::is_candidate<vertex_t, edge_t, weight_t>::value) {
unsupported();
} else if constexpr (!multi_gpu) {
unsupported();
} else {
// uniform_nbr_sample 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;
}

auto graph =
reinterpret_cast<cugraph::graph_t<vertex_t, edge_t, weight_t, false, multi_gpu>*>(
graph_->graph_);

auto graph_view = graph->view();

auto number_map = reinterpret_cast<rmm::device_uvector<vertex_t>*>(graph_->number_map_);

rmm::device_uvector<vertex_t> start(start_->size_, handle_.get_stream());
raft::copy(start.data(), start_->as_type<vertex_t>(), start.size(), handle_.get_stream());

//
// Need to renumber sources
//
cugraph::renumber_ext_vertices<vertex_t, multi_gpu>(
handle_,
start.data(),
start.size(),
number_map->data(),
graph_view.local_vertex_partition_range_first(),
graph_view.local_vertex_partition_range_last(),
false);

// C++ API wants an std::vector
std::vector<int> fan_out(fan_out_->size_);
std::copy_n(fan_out_->as_type<int>(), fan_out_->size_, fan_out.data());

auto&& [tmp_tuple, counts] = cugraph::uniform_nbr_sample(handle_,
graph_view,
start.data(),
start_label_->as_type<int32_t>(),
start.size(),
fan_out,
with_replacement_);

auto&& [srcs, dsts, labels, indices] = tmp_tuple;

std::vector<vertex_t> vertex_partition_lasts = graph_view.vertex_partition_range_lasts();

cugraph::unrenumber_int_vertices<vertex_t, multi_gpu>(handle_,
srcs.data(),
srcs.size(),
number_map->data(),
vertex_partition_lasts,
do_expensive_check_);

cugraph::unrenumber_int_vertices<vertex_t, multi_gpu>(handle_,
dsts.data(),
dsts.size(),
number_map->data(),
vertex_partition_lasts,
do_expensive_check_);

result_ = new cugraph::c_api::cugraph_sample_result_t{
false,
new cugraph::c_api::cugraph_type_erased_device_array_t(srcs, graph_->vertex_type_),
new cugraph::c_api::cugraph_type_erased_device_array_t(dsts, graph_->vertex_type_),
new cugraph::c_api::cugraph_type_erased_device_array_t(labels, start_label_->type_),
new cugraph::c_api::cugraph_type_erased_device_array_t(indices, graph_->edge_type_),
new cugraph::c_api::cugraph_type_erased_host_array_t(counts, graph_->vertex_type_)};
}
}
};

struct experimental_uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_functor {
raft::handle_t const& handle_;
cugraph::c_api::cugraph_graph_t* graph_{nullptr};
cugraph::c_api::cugraph_type_erased_device_array_view_t const* start_{nullptr};
cugraph::c_api::cugraph_type_erased_host_array_view_t const* fan_out_{nullptr};
bool with_replacement_{false};
bool do_expensive_check_{false};
cugraph::c_api::cugraph_sample_result_t* result_{nullptr};

experimental_uniform_neighbor_sampling_functor(
cugraph_resource_handle_t const* handle,
cugraph_graph_t* graph,
cugraph_type_erased_device_array_view_t const* start,
cugraph_type_erased_host_array_view_t const* fan_out,
bool with_replacement,
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)),
Expand Down Expand Up @@ -259,7 +143,6 @@ struct experimental_uniform_neighbor_sampling_functor : public cugraph::c_api::a
do_expensive_check_);

result_ = new cugraph::c_api::cugraph_sample_result_t{
true,
new cugraph::c_api::cugraph_type_erased_device_array_t(srcs, graph_->vertex_type_),
new cugraph::c_api::cugraph_type_erased_device_array_t(dsts, graph_->vertex_type_),
nullptr,
Expand All @@ -276,29 +159,13 @@ extern "C" cugraph_error_code_t cugraph_uniform_neighbor_sample(
const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
const cugraph_type_erased_device_array_view_t* start,
const cugraph_type_erased_device_array_view_t* start_labels,
const cugraph_type_erased_host_array_view_t* fan_out,
bool_t with_replacement,
bool_t do_expensive_check,
cugraph_sample_result_t** result,
cugraph_error_t** error)
{
uniform_neighbor_sampling_functor functor{
handle, graph, start, start_labels, fan_out, with_replacement, do_expensive_check};
return cugraph::c_api::run_algorithm(graph, functor, result, error);
}

extern "C" cugraph_error_code_t cugraph_experimental_uniform_neighbor_sample(
const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
const cugraph_type_erased_device_array_view_t* start,
const cugraph_type_erased_host_array_view_t* fan_out,
bool_t with_replacement,
bool_t do_expensive_check,
cugraph_sample_result_t** result,
cugraph_error_t** error)
{
experimental_uniform_neighbor_sampling_functor functor{
handle, graph, start, fan_out, with_replacement, do_expensive_check};
return cugraph::c_api::run_algorithm(graph, functor, result, error);
}
Expand Down
Loading