Skip to content

Commit

Permalink
C API fixes, Python/PLC API work
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarghi-nv committed Sep 11, 2023
1 parent 2947b33 commit 0a2b2b7
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 109 deletions.
17 changes: 4 additions & 13 deletions cpp/include/cugraph_c/sampling_algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,12 @@ cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_hop(
const cugraph_sample_result_t* result);

/**
* @brief Get the hop offsets from the sampling algorithm result
* @brief Get the label-hop offsets from the sampling algorithm result
*
* @param [in] result The result from a sampling algorithm
* @return type erased array pointing to the hop offsets
* @return type erased array pointing to the label-hop offsets
*/
cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_hop_offsets(
cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_label_hop_offsets(
const cugraph_sample_result_t* result);

/**
Expand All @@ -511,7 +511,7 @@ cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_index(
const cugraph_sample_result_t* result);

/**
* @deprecated This call should be replaced with cugraph_sample_get_get_label_offsets
* @deprecated This call should be replaced with cugraph_sample_get_get_label_hop_offsets
* @brief Get the result offsets from the sampling algorithm result
*
* @param [in] result The result from a sampling algorithm
Expand All @@ -520,15 +520,6 @@ cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_index(
cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_offsets(
const cugraph_sample_result_t* result);

/**
* @brief Get the result label offsets from the sampling algorithm result
*
* @param [in] result The result from a sampling algorithm
* @return type erased array pointing to the result label offsets
*/
cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_label_offsets(
const cugraph_sample_result_t* result);

/**
* @brief Get the renumber map
*
Expand Down
121 changes: 63 additions & 58 deletions cpp/src/c_api/uniform_neighbor_sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ struct cugraph_sample_result_t {
cugraph_type_erased_device_array_t* edge_type_{nullptr};
cugraph_type_erased_device_array_t* wgt_{nullptr};
cugraph_type_erased_device_array_t* hop_{nullptr};
cugraph_type_erased_device_array_t* hop_offsets_{nullptr};
cugraph_type_erased_device_array_t* label_hop_offsets_{nullptr};
cugraph_type_erased_device_array_t* label_{nullptr};
cugraph_type_erased_device_array_t* label_offsets_{nullptr};
cugraph_type_erased_device_array_t* renumber_map_{nullptr};
cugraph_type_erased_device_array_t* renumber_map_offsets_{nullptr};
};
Expand Down Expand Up @@ -237,29 +236,28 @@ struct uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_funct
rmm::device_uvector<vertex_t> minors(0, handle_.get_stream());
std::optional<rmm::device_uvector<size_t>> major_offsets{std::nullopt};

std::optional<rmm::device_uvector<size_t>> hop_offsets{std::nullopt};
std::optional<rmm::device_uvector<size_t>> label_hop_offsets{std::nullopt};

std::optional<rmm::device_uvector<vertex_t>> renumber_map{std::nullopt};
std::optional<rmm::device_uvector<size_t>> renumber_map_offsets{std::nullopt};

if (options_.renumber_results_) {
bool src_is_major = (options_.compression_type_ == cugraph::compression_type_t::CSR) ||
(options_.compression_type_ == cugraph::compression_type_t::DCSR);
if (options_.compression_type_ != cugraph::compression_type_t::COO) {
bool doubly_compress =
(options_.compression_type_ == cugraph::compression_type_t::DCSR) ||
(options_.compression_type_ == cugraph::compression_type_t::DCSC);

std::tie(majors,
*major_offsets,
if (options_.compression_type_ == cugraph::compression_type_t::COO) {
// COO

rmm::device_uvector<vertex_t> output_majors(0, handle_.get_stream());
rmm::device_uvector<vertex_t> output_renumber_map(0, handle_.get_stream());
std::tie(output_majors,
minors,
wgt,
edge_id,
edge_type,
hop_offsets,
*renumber_map,
label_hop_offsets,
output_renumber_map,
renumber_map_offsets) =
cugraph::renumber_and_compress_sampled_edgelist(
cugraph::renumber_and_sort_sampled_edgelist(
handle_,
std::move(src),
std::move(dst),
Expand All @@ -273,20 +271,29 @@ struct uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_funct
edge_label->size()))
: std::nullopt,
src_is_major,
options_.compress_per_hop_,
doubly_compress,
do_expensive_check_);

majors.emplace(std::move(output_majors));
renumber_map.emplace(std::move(output_renumber_map));
} else {
// COO
std::tie(*majors,
// (D)CSC, (D)CSR

bool doubly_compress =
(options_.compression_type_ == cugraph::compression_type_t::DCSR) ||
(options_.compression_type_ == cugraph::compression_type_t::DCSC);

rmm::device_uvector<size_t> output_major_offsets(0, handle_.get_stream());
rmm::device_uvector<vertex_t> output_renumber_map(0, handle_.get_stream());
std::tie(majors,
output_major_offsets,
minors,
wgt,
edge_id,
edge_type,
hop_offsets,
*renumber_map,
label_hop_offsets,
renumber_map,
renumber_map_offsets) =
cugraph::renumber_and_sort_sampled_edgelist(
cugraph::renumber_and_compress_sampled_edgelist(
handle_,
std::move(src),
std::move(dst),
Expand All @@ -300,31 +307,24 @@ struct uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_funct
edge_label->size()))
: std::nullopt,
src_is_major,
options_.compress_per_hop_,
doubly_compress,
do_expensive_check_);

renumber_map.emplace(std::move(output_renumber_map));
major_offsets.emplace(std::move(output_major_offsets));
}

// These are now represented by label_hop_offsets
hop.reset();
offsets.reset();
} else {
*majors = std::move(src);
minors = std::move(dst);
majors.emplace(std::move(src));
minors = std::move(dst);

label_hop_offsets = std::move(offsets);
}

/*
cugraph_type_erased_device_array_t* major_offsets_{nullptr};
cugraph_type_erased_device_array_t* majors_{nullptr};
cugraph_type_erased_device_array_t* minors_{nullptr};
cugraph_type_erased_device_array_t* edge_id_{nullptr};
cugraph_type_erased_device_array_t* edge_type_{nullptr};
cugraph_type_erased_device_array_t* wgt_{nullptr};
cugraph_type_erased_device_array_t* hop_{nullptr};
cugraph_type_erased_device_array_t* hop_offsets_{nullptr};
cugraph_type_erased_device_array_t* label_{nullptr};
cugraph_type_erased_device_array_t* label_offsets_{nullptr};
cugraph_type_erased_device_array_t* renumber_map_{nullptr};
cugraph_type_erased_device_array_t* renumber_map_offsets_{nullptr};
*/

result_ = new cugraph::c_api::cugraph_sample_result_t{
(major_offsets)
? new cugraph::c_api::cugraph_type_erased_device_array_t(*major_offsets, SIZE_T)
Expand All @@ -341,14 +341,12 @@ struct uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_funct
: nullptr,
(wgt) ? new cugraph::c_api::cugraph_type_erased_device_array_t(*wgt, graph_->weight_type_)
: nullptr,
(hop) ? new cugraph::c_api::cugraph_type_erased_device_array_t(*hop, INT32) : nullptr,
(hop_offsets) ? new cugraph::c_api::cugraph_type_erased_device_array_t(*hop_offsets, SIZE_T)
(hop) ? new cugraph::c_api::cugraph_type_erased_device_array_t(*hop, INT32) : nullptr, // FIXME get rid of this once Seunghwa updates the API
(label_hop_offsets) ? new cugraph::c_api::cugraph_type_erased_device_array_t(*label_hop_offsets, SIZE_T)
: nullptr,
(edge_label)
? new cugraph::c_api::cugraph_type_erased_device_array_t(edge_label.value(), INT32)
: nullptr,
(offsets) ? new cugraph::c_api::cugraph_type_erased_device_array_t(offsets.value(), SIZE_T)
: nullptr,
(renumber_map) ? new cugraph::c_api::cugraph_type_erased_device_array_t(
renumber_map.value(), graph_->vertex_type_)
: nullptr,
Expand Down Expand Up @@ -402,7 +400,25 @@ extern "C" void cugraph_sampling_set_return_hops(cugraph_sampling_options_t* opt

extern "C" void cugraph_sampling_set_compression_type(cugraph_sampling_options_t* options, cugraph_compression_type_t value) {
auto internal_pointer = reinterpret_cast<cugraph::c_api::cugraph_sampling_options_t*>(options);
internal_pointer->compression_type_ = value;
switch(value) {
case COO:
internal_pointer->compression_type_ = cugraph::compression_type_t::COO;
break;
case CSR:
internal_pointer->compression_type_ = cugraph::compression_type_t::CSR;
break;
case CSC:
internal_pointer->compression_type_ = cugraph::compression_type_t::CSC;
break;
case DCSR:
internal_pointer->compression_type_ = cugraph::compression_type_t::DCSR;
break;
case DCSC:
internal_pointer->compression_type_ = cugraph::compression_type_t::DCSC;
break;
default:
CUGRAPH_FAIL("Invalid compression type");
}
}

extern "C" void cugraph_sampling_set_prior_sources_behavior(cugraph_sampling_options_t* options,
Expand Down Expand Up @@ -529,13 +545,13 @@ extern "C" cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_ho
: NULL;
}

extern "C" cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_hop_offsets(
extern "C" cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_label_hop_offsets(
const cugraph_sample_result_t* result)
{
auto internal_pointer = reinterpret_cast<cugraph::c_api::cugraph_sample_result_t const*>(result);
return internal_pointer->hop_offsets_ != nullptr
return internal_pointer->label_hop_offsets_ != nullptr
? reinterpret_cast<cugraph_type_erased_device_array_view_t*>(
internal_pointer->hop_offsets_->view())
internal_pointer->label_hop_offsets_->view())
: NULL;
}

Expand All @@ -551,17 +567,7 @@ extern "C" cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_of
const cugraph_sample_result_t* result)
{
// Deprecated.
return cugraph_sample_result_get_label_offsets(result);
}

extern "C" cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_label_offsets(
const cugraph_sample_result_t* result)
{
auto internal_pointer = reinterpret_cast<cugraph::c_api::cugraph_sample_result_t const*>(result);
return internal_pointer->label_offsets_ != nullptr
? reinterpret_cast<cugraph_type_erased_device_array_view_t*>(
internal_pointer->label_offsets_->view())
: NULL;
return cugraph_sample_result_get_label_hop_offsets(result);
}

extern "C" cugraph_type_erased_device_array_view_t* cugraph_sample_result_get_renumber_map(
Expand Down Expand Up @@ -828,9 +834,8 @@ extern "C" void cugraph_sample_result_free(cugraph_sample_result_t* result)
delete internal_pointer->edge_type_;
delete internal_pointer->wgt_;
delete internal_pointer->hop_;
delete internal_pointer->hop_offsets_;
delete internal_pointer->label_hop_offsets_;
delete internal_pointer->label_;
delete internal_pointer->label_offsets_;
delete internal_pointer->renumber_map_;
delete internal_pointer->renumber_map_offsets_;
delete internal_pointer;
Expand Down
Loading

0 comments on commit 0a2b2b7

Please sign in to comment.