Repository navigation
perf(structure): sort edges on one packed 64-bit key - #3
Merged
Merged
Conversation
`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>
This was referenced Nov 16, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sort_and_compress_edgelistsorted(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 with1,740,318,538edges and88,180,447vertices spent0.834 sin 76DeviceMergeSortMergeKernellaunches.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.minor_range_firstandminor_range_lastparameters, unused until now, give the minor width.mem_frugal_partitiontakes anintpivot, 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
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 sto4.880 s, and the ten highest scores are identical.Tests
Algeon's
test_graph_construction_keeps_stable_csr_order_with_and_without_frugal_sortbuilds 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_typepaths, and an 8-byte frugal sort with a major range above2^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