Skip to content

perf(structure): renumbering degrees from sort run lengths; symmetric minor degrees from offsets - #4

Merged
morristai merged 3 commits into
algeon-26.08from
perf/renumber-run-length-degrees
Nov 20, 2026
Merged

morristai merged 3 commits into
algeon-26.08from
perf/renumber-run-length-degrees

Conversation

@morristai

Copy link
Copy Markdown
Member

Two changes to single-GPU graph construction and degree computation, stacked on #3. Upstream main (62199a7e8) has the same code in both places.

Measured with Nsight Systems on an undirected graph of 1,740,318,538 edges and 88,180,447 vertices with Int64 ids, on an RTX PRO 6000 Blackwell (96 GB).

Renumbering degrees from the major sort's run lengths (renumber_edgelist_impl.cuh)

compute_renumber_map sorted a copy of the edge majors to find the unique vertices, discarded the multiplicities with unique, and then recovered each vertex's degree with a thrust::for_each over every edge: a lower_bound over the sorted vertex list and an atomic increment. That kernel takes 0.582 s, the largest single kernel in renumbering.

  • find_uniques_and_counts returns the sorted unique majors with their run lengths. The memory-frugal split counts each half, adds the second half's count of a shared vertex into the first half's (each vertex occurs once per half, so no atomics), and unions the two key lists.
  • The degrees are placed with one binary search per vertex over the unique majors. A vertex that is no edge's major has degree 0.
  • A caller-supplied vertex list takes the same path. A major missing from that list is dropped; the old code had a debug assert and wrote out of bounds in a release build.
  • find_uniques_mem_frugal_threshold holds the 3% rule that was written out twice.
  • The multi-GPU branch sums degrees across ranks and is unchanged, so compute_sorted_local_major_degrees_without_atomics stays for it.

Peak temporary memory rises by the count array of the unique vertices (U * sizeof(edge_t)), which now lives until the degrees are placed. With a caller-supplied vertex list the majors are now sorted, under the same memory-frugal rule; that path did not sort them before.

Minor degrees of a symmetric graph from the major offsets (graph_view_impl.cuh)

compute_out_degrees on a transposed graph and compute_in_degrees on a non-transposed one ran compute_minor_degrees, a pass over every edge. In a symmetric graph each vertex's in-degree equals its out-degree, which adjacent major offsets give. Unweighted PageRank on an undirected graph calls compute_out_degrees once; that pass takes 0.131 s.

The shortcut applies when is_symmetric() holds and no edge mask is attached (a mask is not guaranteed to keep the graph symmetric). It is applied to the single-GPU and multi-GPU specializations; the multi-GPU one is compiled and not exercised by a test here.

Tests

In the Algeon repository (components/cugraph/algeon-cugraph/src/graph/tests.rs), through the C API:

  • test_renumbering_orders_vertices_by_major_degree_with_and_without_frugal_uniques: out-degrees against a host count and non-increasing internal order, for 4-byte and 8-byte ids, a cap that reaches the memory-frugal split and one that does not, vertices that appear only as destinations, skewed multigraphs, and a supplied vertex list with isolated vertices.
  • test_transposed_out_degrees_and_pagerank_match_host_for_symmetric_and_directed_graphs: degrees and unweighted PageRank against a host power iteration on a symmetric and a directed graph.

Mutations that fail them: the frugal merge dropping the second half's counts, each vertex taking its neighbor's count, the shortcut applied to a directed graph.

Not timed after the change.

morristai and others added 3 commits November 16, 2026 08:32
`sort_and_compress_edgelist` sorted `(major, minor)` through a zip iterator
of two columns. A tuple key makes Thrust use its comparison merge sort.
After renumbering both endpoints are offsets into their vertex ranges, so
`(major - major_range_first) << minor_bits | (minor - minor_range_first)`
is one unsigned 64-bit key whenever the two widths sum to at most 64 bits,
and Thrust sorts it with a radix sort. Both sorts are stable, so parallel
edges and their values keep their input order.

With 8-byte vertex IDs the key overwrites the minor column in place and the
major column is freed before the sort. The unweighted overload then needs no
quarter partitioning: the keys and the radix copy fit in the two input
columns' 16 bytes per edge, where the memory-frugal path held 20. The
weighted overload keeps the quarter partitions of 5fddb4f and moves each
value with its key (30 to 24 bytes per edge with 8-byte weights).

With 4-byte IDs the key needs its own buffer. Outside the memory-frugal
path the per-edge peak is unchanged and the radix sort adds a fixed scratch
of at most 57 MiB. Inside it a packed quarter would hold more than the merge
sort does, so that path keeps the merge sort. Ranges that do not fit 64 bits
keep the existing code.

On a 96 GB GPU, constructing an unweighted graph with 1,740,318,538 edges
and 88,180,447 vertices from Int64 IDs: the graph algorithm task of a
whole-table PageRank drops from 5.864 s to 4.880 s with identical scores.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…engths

compute_renumber_map sorted a copy of the edge majors to find the unique
vertices, dropped the multiplicities, and then recovered each vertex's degree
with a binary search over the sorted vertex list and an atomic increment for
every edge. On a graph of 1.74 billion edges and 88 million vertices that
single for_each takes 0.58 s.

The single-GPU path now keeps the run lengths of the sorted majors
(find_uniques_and_counts). The memory-frugal split counts each half, adds the
second half's count of a shared vertex into the first half's, and unions the
two key lists. The degrees are then placed with one search per vertex. A
caller-supplied vertex list takes the same path. The multi-GPU branch, which
sums degrees across ranks, is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…or offsets

compute_out_degrees on a transposed graph, and compute_in_degrees on a
non-transposed one, ran a pass over every edge (compute_minor_degrees).
In a symmetric graph each vertex's in-degree equals its out-degree, which
adjacent major offsets give directly. Unweighted PageRank on an undirected
graph calls compute_out_degrees once; on 1.74 billion edges that pass takes
0.13 s.

The shortcut applies when the graph is symmetric and has no edge mask. An
attached mask is not guaranteed to keep the graph symmetric.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Base automatically changed from perf/packed-edge-sort to algeon-26.08 November 20, 2026 20:44
@morristai
morristai merged commit 837cf82 into algeon-26.08 Nov 20, 2026
1 check passed
morristai added a commit to algeon-dev/algeon that referenced this pull request Nov 20, 2026
…t-degrees from offsets (cuGraph fork) (#91)

Moves the cuGraph fork to algeon-dev/cugraph#4 (7d56328a2), stacked on the
packed edge sort.

Single-GPU renumbering sorted the edge majors to find the vertex set and then
recovered every vertex's degree with a binary search and an atomic increment
per edge: 0.58 s for the MerRec graph of 1.74 billion edges. The degrees now
come from the run lengths of that sort.

Unweighted PageRank on an undirected graph called compute_out_degrees, a pass
over every edge of the transposed graph (0.13 s). A symmetric graph without an
edge mask reads those degrees from the major offsets.

Two tests cover the new paths through the C API: internal vertex order and
degrees with and without the memory-frugal split, and degrees and PageRank on
symmetric and directed graphs against a host computation.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant