Skip to content

perf(structure): sort edges on one packed 64-bit key - #3

Merged
morristai merged 1 commit into
algeon-26.08from
perf/packed-edge-sort
Nov 20, 2026
Merged

morristai merged 1 commit into
algeon-26.08from
perf/packed-edge-sort

Conversation

@morristai

Copy link
Copy Markdown
Member

sort_and_compress_edgelist sorted (major, minor) through a zip iterator of two columns. A tuple key makes Thrust use its comparison merge sort: on a 96 GB GPU, constructing an unweighted graph with 1,740,318,538 edges and 88,180,447 vertices spent 0.834 s in 76 DeviceMergeSortMergeKernel launches.

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. Thrust sorts that key with a radix sort. Both sorts are stable, so parallel edges and their values keep their input order.

Changes

All in cpp/src/structure/detail/structure_utils.cuh.

  • 8-byte vertex IDs. The key overwrites the minor column in place and the major column is freed before the sort. The unweighted overload needs no quarter partitioning: the keys and the radix copy fit in the 16 bytes per edge the two input columns held. The weighted overload keeps the quarter partitions of 5fddb4f and moves each value with its key.
  • 4-byte vertex IDs. The key needs its own buffer. Outside the memory-frugal path the per-edge peak is unchanged. 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. The minor_range_first and minor_range_last parameters, unused until now, give the minor width.
  • mem_frugal_partition takes an int pivot, which cannot hold every major offset. The packed path partitions with a group functor that compares the 64-bit major offset itself.

Peak bytes per edge inside the sort

Branch Before After
8-byte, unweighted, non-frugal 32 16
8-byte, unweighted, frugal 20 16
8-byte, weighted (8-byte value), non-frugal 48 32
8-byte, weighted (8-byte value), frugal 30 24
4-byte, non-frugal 16 (+ 2 per value byte) same, plus a fixed radix scratch of at most 57 MiB
4-byte, frugal 10.125 unweighted, 20.125 with an 8-byte value unchanged (merge sort)

Derived from the allocations in the function and in CCCL 3.4.3 (thrust/system/cuda/detail/sort.h, cub/device/dispatch/dispatch_merge_sort.cuh), and checked against measured construction peaks at one million edges.

Measurement

Whole-table PageRank through Algeon on the graph above (Int64 IDs, undirected, RTX PRO 6000 Blackwell, third of three runs): the graph algorithm task drops from 5.864 s to 4.880 s, and the ten highest scores are identical.

Tests

Algeon's test_graph_construction_keeps_stable_csr_order_with_and_without_frugal_sort builds 4-byte and 8-byte, weighted and unweighted multigraphs with uniform and skewed sources, under a memory cap that rules the frugal path out and one that forces it, and compares the CSR edge order with a stable host sort. The Algeon cuGraph suites pass against the rebuilt library (166 + 51 + 213 tests).

Not exercised by any test: the multi-GPU callers, the large_*_buffer_type paths, and an 8-byte frugal sort with a major range above 2^32.

Merging

algeon-dev/algeon pins this commit (8c7eb9219) in its submodule. Merge with a fast-forward or rebase so the SHA stays, or update the pin in the Algeon PR after a squash.

🤖 Generated with Claude Code

`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>
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