Skip to content

Commit

Permalink
fix test failures, remove c++ compression enum
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarghi-nv committed Sep 23, 2023
1 parent 9dfa3fa commit 10c8c1f
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 377 deletions.
15 changes: 0 additions & 15 deletions cpp/include/cugraph/algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1894,21 +1894,6 @@ k_core(raft::handle_t const& handle,
*/
enum class prior_sources_behavior_t { DEFAULT = 0, CARRY_OVER, EXCLUDE };

/**
* @brief Selects the type of compression to use for the output samples.
*
* @param COO Outputs in COO format. Default.
* @param CSR Compresses in CSR format. This means the row (src) column
* is compressed into a row pointer.
* @param CSC Compresses in CSC format. This means the col (dst) column
* is compressed into a column pointer.
* @param DCSR Compresses in DCSR format. This outputs an additional index
* that avoids empty entries in the row pointer.
* @param DCSC Compresses in DCSC format. This outputs an additional index
* that avoid empty entries in the row pointer.
*/
enum class compression_type_t { COO = 0, CSR, CSC, DCSR, DCSC };

/**
* @brief Uniform Neighborhood Sampling.
*
Expand Down
72 changes: 10 additions & 62 deletions cpp/include/cugraph_c/sampling_algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,18 @@ typedef enum cugraph_prior_sources_behavior_t {
} cugraph_prior_sources_behavior_t;

/**
* @brief Enumeration for compression type
* @brief Selects the type of compression to use for the output samples.
*/
typedef enum cugraph_compression_type_t {
COO = 0,
CSR,
CSC,
DCSR,
DCSC
COO = 0, /** Outputs in COO format. Default. */
CSR, /** Compresses in CSR format. This means the row (src) column
is compressed into a row pointer. */
CSC, /** Compresses in CSC format. This means the col (dst) column
is compressed into a column pointer. */
DCSR, /** Compresses in DCSR format. This outputs an additional index
that avoids empty entries in the row pointer. */
DCSC /** Compresses in DCSC format. This outputs an additional index
that avoid empty entries in the row pointer. */
} cugraph_compression_type_t;

/**
Expand Down Expand Up @@ -293,62 +297,6 @@ void cugraph_sampling_set_dedupe_sources(cugraph_sampling_options_t* options, bo
*/
void cugraph_sampling_options_free(cugraph_sampling_options_t* options);

/**
* @brief Uniform Neighborhood Sampling
* @deprecated This call should be replaced with cugraph_uniform_neighbor_sample
*
* Returns a sample of the neighborhood around specified start vertices. Optionally, each
* start vertex can be associated with a label, allowing the caller to specify multiple batches
* of sampling requests in the same function call - which should improve GPU utilization.
*
* If label is NULL then all start vertices will be considered part of the same batch and the
* return value will not have a label column.
*
* @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_vertices Device array of start vertices for the sampling
* @param [in] start_vertex_labels Device array of start vertex labels for the sampling. The
* labels associated with each start vertex will be included in the output associated with results
* that were derived from that start vertex. We only support label of type INT32. If label is
* NULL, the return data will not be labeled.
* @param [in] label_list Device array of the labels included in @p start_vertex_labels. If
* @p label_to_comm_rank is not specified this parameter is ignored. If specified, label_list
* must be sorted in ascending order.
* @param [in] label_to_comm_rank Device array identifying which comm rank the output for a
* particular label should be shuffled in the output. If not specifed the data is not organized in
* output. If specified then the all data from @p label_list[i] will be shuffled to rank @p
* label_to_comm_rank[i]. If not specified then the output data will not be shuffled between ranks.
* @param [in] fanout Host array defining the fan out at each step in the sampling algorithm.
* We only support fanout values of type INT32
* @param [in/out] rng_state State of the random number generator, updated with each call
* @param [in] with_replacement
* Boolean value. If true selection of edges is done with
* replacement. If false selection is done without replacement.
* @param [in] return_hops Boolean value. If true include the hop number in the result,
* If false the hop number will not be included in result.
* @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_uniform_neighbor_sample_with_edge_properties(
const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
const cugraph_type_erased_device_array_view_t* start_vertices,
const cugraph_type_erased_device_array_view_t* start_vertex_labels,
const cugraph_type_erased_device_array_view_t* label_list,
const cugraph_type_erased_device_array_view_t* label_to_comm_rank,
const cugraph_type_erased_host_array_view_t* fan_out,
cugraph_rng_state_t* rng_state,
bool_t with_replacement,
bool_t return_hops,
bool_t do_expensive_check,
cugraph_sample_result_t** result,
cugraph_error_t** error);

/**
* @brief Uniform Neighborhood Sampling
*
Expand Down
90 changes: 14 additions & 76 deletions cpp/src/c_api/uniform_neighbor_sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct cugraph_sampling_options_t {
prior_sources_behavior_t prior_sources_behavior_{prior_sources_behavior_t::DEFAULT};
bool_t dedupe_sources_{FALSE};
bool_t renumber_results_{FALSE};
compression_type_t compression_type_{compression_type_t::COO};
cugraph_compression_type_t compression_type_{cugraph_compression_type_t::COO};
bool_t compress_per_hop_{FALSE};
};

Expand Down Expand Up @@ -243,12 +243,12 @@ struct uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_funct
std::optional<rmm::device_uvector<vertex_t>> renumber_map{std::nullopt};
std::optional<rmm::device_uvector<size_t>> renumber_map_offsets{std::nullopt};

bool src_is_major = (options_.compression_type_ == cugraph::compression_type_t::CSR) ||
(options_.compression_type_ == cugraph::compression_type_t::DCSR) ||
(options_.compression_type_ == cugraph::compression_type_t::COO);
bool src_is_major = (options_.compression_type_ == cugraph_compression_type_t::CSR) ||
(options_.compression_type_ == cugraph_compression_type_t::DCSR) ||
(options_.compression_type_ == cugraph_compression_type_t::COO);

if (options_.renumber_results_) {
if (options_.compression_type_ == cugraph::compression_type_t::COO) {
if (options_.compression_type_ == cugraph_compression_type_t::COO) {
// COO

rmm::device_uvector<vertex_t> output_majors(0, handle_.get_stream());
Expand Down Expand Up @@ -282,9 +282,8 @@ struct uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_funct
} else {
// (D)CSC, (D)CSR

bool doubly_compress =
(options_.compression_type_ == cugraph::compression_type_t::DCSR) ||
(options_.compression_type_ == cugraph::compression_type_t::DCSC);
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());
Expand Down Expand Up @@ -323,7 +322,7 @@ struct uniform_neighbor_sampling_functor : public cugraph::c_api::abstract_funct
hop.reset();
offsets.reset();
} else {
if (options_.compression_type_ != cugraph::compression_type_t::COO) {
if (options_.compression_type_ != cugraph_compression_type_t::COO) {
CUGRAPH_FAIL("Can only use COO format if not renumbering");
}

Expand Down Expand Up @@ -433,11 +432,11 @@ extern "C" void cugraph_sampling_set_compression_type(cugraph_sampling_options_t
{
auto internal_pointer = reinterpret_cast<cugraph::c_api::cugraph_sampling_options_t*>(options);
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;
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");
}
}
Expand Down Expand Up @@ -705,6 +704,7 @@ extern "C" cugraph_error_code_t cugraph_test_uniform_neighborhood_sample_result_

// create new cugraph_sample_result_t
*result = reinterpret_cast<cugraph_sample_result_t*>(new cugraph::c_api::cugraph_sample_result_t{
nullptr,
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_t*>(
new_device_srcs.release()),
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_t*>(
Expand Down Expand Up @@ -862,68 +862,6 @@ extern "C" void cugraph_sample_result_free(cugraph_sample_result_t* result)
delete internal_pointer;
}

extern "C" cugraph_error_code_t cugraph_uniform_neighbor_sample_with_edge_properties(
const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
const cugraph_type_erased_device_array_view_t* start_vertices,
const cugraph_type_erased_device_array_view_t* start_vertex_labels,
const cugraph_type_erased_device_array_view_t* label_list,
const cugraph_type_erased_device_array_view_t* label_to_comm_rank,
const cugraph_type_erased_host_array_view_t* fan_out,
cugraph_rng_state_t* rng_state,
bool_t with_replacement,
bool_t return_hops,
bool_t do_expensive_check,
cugraph_sample_result_t** result,
cugraph_error_t** error)
{
CAPI_EXPECTS((start_vertex_labels == nullptr) ||
(reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t const*>(
start_vertex_labels)
->type_ == INT32),
CUGRAPH_INVALID_INPUT,
"start_vertex_labels should be of type int",
*error);

CAPI_EXPECTS((label_to_comm_rank == nullptr) || (start_vertex_labels != nullptr),
CUGRAPH_INVALID_INPUT,
"cannot specify label_to_comm_rank unless start_vertex_labels is also specified",
*error);

CAPI_EXPECTS((label_to_comm_rank == nullptr) || (label_list != nullptr),
CUGRAPH_INVALID_INPUT,
"cannot specify label_to_comm_rank unless label_list is also specified",
*error);

CAPI_EXPECTS(reinterpret_cast<cugraph::c_api::cugraph_graph_t*>(graph)->vertex_type_ ==
reinterpret_cast<cugraph::c_api::cugraph_type_erased_device_array_view_t const*>(
start_vertices)
->type_,
CUGRAPH_INVALID_INPUT,
"vertex type of graph and start_vertices must match",
*error);

CAPI_EXPECTS(
reinterpret_cast<cugraph::c_api::cugraph_type_erased_host_array_view_t const*>(fan_out)
->type_ == INT32,
CUGRAPH_INVALID_INPUT,
"fan_out should be of type int",
*error);

uniform_neighbor_sampling_functor functor{
handle,
graph,
start_vertices,
start_vertex_labels,
label_list,
label_to_comm_rank,
fan_out,
rng_state,
cugraph::c_api::cugraph_sampling_options_t{with_replacement, return_hops},
do_expensive_check};
return cugraph::c_api::run_algorithm(graph, functor, result, error);
}

cugraph_error_code_t cugraph_uniform_neighbor_sample(
const cugraph_resource_handle_t* handle,
cugraph_graph_t* graph,
Expand Down
26 changes: 24 additions & 2 deletions cpp/tests/c_api/create_graph_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ int test_create_sg_graph_csr()
vertex_t h_start[] = {0, 1, 2, 3, 4, 5};
weight_t h_wgt[] = {0.1f, 2.1f, 1.1f, 5.1f, 3.1f, 4.1f, 7.2f, 3.2f};

bool_t with_replacement = FALSE;
bool_t return_hops = TRUE;
cugraph_prior_sources_behavior_t prior_sources_behavior = DEFAULT;
bool_t dedupe_sources = FALSE;
bool_t renumber_results = FALSE;
cugraph_compression_type_t compression = COO;
bool_t compress_per_hop = FALSE;

cugraph_resource_handle_t* handle = NULL;
cugraph_graph_t* graph = NULL;
cugraph_graph_properties_t properties;
Expand Down Expand Up @@ -238,8 +246,21 @@ int test_create_sg_graph_csr()
ret_code = cugraph_rng_state_create(handle, 0, &rng_state, &ret_error);
TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "rng_state create failed.");

ret_code = cugraph_uniform_neighbor_sample_with_edge_properties(
handle, graph, d_start_view, NULL, NULL, NULL, h_fan_out_view, rng_state, FALSE, FALSE, FALSE, &result, &ret_error);
cugraph_sampling_options_t *sampling_options;

ret_code = cugraph_sampling_options_create(&sampling_options, &ret_error);
TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "sampling_options create failed.");

cugraph_sampling_set_with_replacement(sampling_options, with_replacement);
cugraph_sampling_set_return_hops(sampling_options, return_hops);
cugraph_sampling_set_prior_sources_behavior(sampling_options, prior_sources_behavior);
cugraph_sampling_set_dedupe_sources(sampling_options, dedupe_sources);
cugraph_sampling_set_renumber_results(sampling_options, renumber_results);
cugraph_sampling_set_compression_type(sampling_options, compression);
cugraph_sampling_set_compress_per_hop(sampling_options, compress_per_hop);

ret_code = cugraph_uniform_neighbor_sample(
handle, graph, d_start_view, NULL, NULL, NULL, h_fan_out_view, rng_state, sampling_options, FALSE, &result, &ret_error);

TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, cugraph_error_message(ret_error));
TEST_ALWAYS_ASSERT(ret_code == CUGRAPH_SUCCESS, "uniform_neighbor_sample failed.");
Expand Down Expand Up @@ -289,6 +310,7 @@ int test_create_sg_graph_csr()

cugraph_free_resource_handle(handle);
cugraph_error_free(ret_error);
cugraph_sampling_options_free(sampling_options);

return test_ret_value;
}
Expand Down
47 changes: 34 additions & 13 deletions cpp/tests/c_api/mg_uniform_neighbor_sample_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,14 @@ int test_uniform_neighbor_from_alex(const cugraph_resource_handle_t* handle)
cugraph_graph_t* graph = NULL;
cugraph_sample_result_t* result = NULL;

bool_t with_replacement = FALSE;
bool_t return_hops = TRUE;
cugraph_prior_sources_behavior_t prior_sources_behavior = DEFAULT;
bool_t dedupe_sources = FALSE;
bool_t renumber_results = FALSE;
cugraph_compression_type_t compression = COO;
bool_t compress_per_hop = FALSE;

cugraph_type_erased_device_array_t* d_start = NULL;
cugraph_type_erased_device_array_t* d_label = NULL;
cugraph_type_erased_device_array_view_t* d_start_view = NULL;
Expand Down Expand Up @@ -512,19 +520,31 @@ int test_uniform_neighbor_from_alex(const cugraph_resource_handle_t* handle)

h_fan_out_view = cugraph_type_erased_host_array_view_create(fan_out, fan_out_size, INT32);

ret_code = cugraph_uniform_neighbor_sample_with_edge_properties(handle,
graph,
d_start_view,
d_label_view,
NULL,
NULL,
h_fan_out_view,
rng_state,
with_replacement,
TRUE,
FALSE,
&result,
&ret_error);
cugraph_sampling_options_t *sampling_options;

ret_code = cugraph_sampling_options_create(&sampling_options, &ret_error);
TEST_ASSERT(test_ret_value, ret_code == CUGRAPH_SUCCESS, "sampling_options create failed.");

cugraph_sampling_set_with_replacement(sampling_options, with_replacement);
cugraph_sampling_set_return_hops(sampling_options, return_hops);
cugraph_sampling_set_prior_sources_behavior(sampling_options, prior_sources_behavior);
cugraph_sampling_set_dedupe_sources(sampling_options, dedupe_sources);
cugraph_sampling_set_renumber_results(sampling_options, renumber_results);
cugraph_sampling_set_compression_type(sampling_options, compression);
cugraph_sampling_set_compress_per_hop(sampling_options, compress_per_hop);

ret_code = cugraph_uniform_neighbor_sample(handle,
graph,
d_start_view,
d_label_view,
NULL,
NULL,
h_fan_out_view,
rng_state,
sampling_options,
FALSE,
&result,
&ret_error);

#ifdef NO_CUGRAPH_OPS
TEST_ASSERT(
Expand Down Expand Up @@ -611,6 +631,7 @@ int test_uniform_neighbor_from_alex(const cugraph_resource_handle_t* handle)
cugraph_type_erased_host_array_view_free(h_fan_out_view);
cugraph_mg_graph_free(graph);
cugraph_error_free(ret_error);
cugraph_sampling_options_free(sampling_options);

return test_ret_value;
}
Expand Down
Loading

0 comments on commit 10c8c1f

Please sign in to comment.