Skip to content

Binary size improvement: use device functors instead of lambdas - #5641

Open
ChuckHastings wants to merge 4 commits into
rapidsai:mainfrom
ChuckHastings:binary_size_gather_functors
Open

Binary size improvement: use device functors instead of lambdas#5641
ChuckHastings wants to merge 4 commits into
rapidsai:mainfrom
ChuckHastings:binary_size_gather_functors

Conversation

@ChuckHastings

@ChuckHastings ChuckHastings commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Convert to using device functors in places in the code where the same device logic is executed in different places or different instantiations of a template so that the device kernels can be reused.

Artifact Before this PR After this PR % improvement
libcugraph_common.so 390.7 MiB 311.1 MiB -20.4%
libcugraph.so 566.4 MiB 561.8 MiB -0.8%
libcugraph_mg.so 681.9 MiB 677.9 MiB -0.7%
Total 1675.2 MiB 1586.9 MiB -5.3%

@copy-pr-bot

copy-pr-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@ChuckHastings ChuckHastings added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Sep 1, 2026
@ChuckHastings
ChuckHastings marked this pull request as ready for review September 1, 2026 17:09
@ChuckHastings
ChuckHastings requested a review from a team as a code owner September 1, 2026 17:09
// Shared device functors for sampling local neighbor indices. Named functors deduplicate
// thrust/CUB instantiations across sample_and_compute_local_nbr_indices entry points.
template <typename bias_t>
struct negate_positive_bias_op_t {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep sampling specific functors here, for more generic functors, we may use the ones from device_functors.cuh (https://github.com/rapidsai/cugraph/blob/main/cpp/include/cugraph/utilities/device_functors.cuh); if missing there, better define there.

This basically inverts a value. Sounds very generic.

Should we better define something like

template <typename T>
struct invert_t {
...
};

in device_functors.cuh?

};

template <typename bias_t>
struct nonzero_bias_op_t {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar here, we can either use the existing is_not_equal_t or create is_nonzero_t.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or as I mentioned elsewhere, this can be is_not_equal_to_const_t with compare = 0.

};

template <typename T>
struct less_than_op_t {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds generic.

We may rename this to less_than_t and place next to is_equal_t and is_not_equal_t?

};

template <typename edge_t>
struct valid_local_nbr_idx_op_t {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is is_not_equal(_to)_t.

}
};

struct segment_idx_from_prefix_offsets_op_t {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have segment_id_t in device_functors.cuh (note that this functor takes lasts, not offsets).

};

template <typename T>
struct local_idx_from_prefix_offsets_op_t {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

segment_local_idx_t?

We may update this based on the existing segment_id_t.

Comment on lines +107 to +108
vertex_t const* visited_minors{};
size_t visited_minors_size{};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better take this as a span.

Comment on lines +119 to +123
vertex_t const* minors{};
label_t const* labels{};
vertex_t const* visited_minors{};
label_t const* visited_labels{};
size_t visited_minors_size{};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better take spans?

Comment on lines +166 to +168
time_stamp_t const* edge_times{};
time_stamp_t const* per_edge_window_starts{};
time_stamp_t const* per_edge_window_ends{};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In functors, we may better take spans instead of raw pointers where-ever applicable.

}
};

struct edge_type_gather_filter_op_t {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double_indirection_t or nested_indirection_t?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants