Skip to content

[cudax] __sharded: sort -- the MGMN distributed sort as the engine behind the sharded name - #6

Open
caugonnet wants to merge 17 commits into
sharded/communicatorfrom
sharded/sort
Open

[cudax] __sharded: sort -- the MGMN distributed sort as the engine behind the sharded name#6
caugonnet wants to merge 17 commits into
sharded/communicatorfrom
sharded/sort

Conversation

@caugonnet

@caugonnet caugonnet commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Stacked on #5 (review this diff against sharded/communicator).

sharded::sort(group, data, comp) — a global, in-place sort of a sharded array — completes the two-tier picture introduced in #5:

  • Tier 1 (container): owns placement, resources and bookkeeping. It manufactures the communicator / environment / iterator / size ranges with bind_engine — engine temporaries come from each rank's environment, so scratch lands on the place whose rank uses it.
  • Tier 2 (engine): the __multi_gpu distributed sort runs over those ranges unmodified. The same MGMN construct that sorts across multi-process ranks sorts across in-process places, through the places communicator — the ladder's portability claim, exercised end to end.

Contract

The engine delivers to each rank its slice of the globally sorted sequence, redistributed back to the rank's original element count. That composes exactly with the container's fixed-size contract: shard sizes, offsets and capacities are unchanged by construction, and — unlike the size-mutating compaction algorithms — contiguous (allocate_contiguous) arrays are fully supported: after the sort, contiguous_data() reads as ONE globally sorted array through the base pointer. Sorting is not stable.

The engine slot is deliberately swappable behind the same name and contract: a future in-process, placement-aware specialization would be a performance change, not an API change.

Tests (cudax/test/sharded/algorithms/sort.cu, 2 locality domains)

  • correctness vs std::sort of the concatenated shards (byte-exact) over mixed distributions — uniform random, all-equal, pre-sorted, reverse-sorted, duplicate-heavy ints — on uneven shards (first shard ~2x the others, odd total);
  • custom comparator (descending) through the same path;
  • shard metadata invariants: per-shard sizes, offsets and capacities preserved, total preserved, validate() clean after every sort;
  • contiguous arrays: sorted in place and read back through contiguous_data() as one plain array, byte-exact vs the sorted host reference;
  • repeated runs on identical input are byte-identical (checked empirically over 3 runs; for keys-only sorting this is also guaranteed structurally — the sorted multiset is unique);
  • shape mismatch (shard count != place count) refused with std::invalid_argument before any engine work; empty arrays are a no-op.

All places + sharded tests green on GB300 (sm_103a, CUDA 13.4, 2 locality domains): 28/28 ctest, built with -Dcudax_ENABLE_NCCL=OFF.

Design review with Andrei.

🤖 Generated with Claude Code

… the sharded name

Two-tier end to end: the container tier manufactures the communicator/
environment/iterator/size ranges via bind_engine; the engine tier -- the
__multi_gpu distributed sort -- owns the cross-place choreography and runs
over in-process places unmodified, through the places communicator.

The engine redistributes each rank's slice of the globally sorted
sequence back to the rank's original element count, so shard sizes,
offsets and capacities are unchanged by construction and the
fixed-boundary contract of allocate_contiguous is preserved: sorting a
contiguous sharded array leaves contiguous_data() reading as one
globally sorted array. The engine slot is swappable behind the same
name/contract (a future in-process placement-aware specialization is a
performance change, not an API change).

Tests: correctness vs std::sort over uniform/all-equal/pre-sorted/
reverse/duplicate-heavy distributions on uneven shards across 2 locality
domains; custom comparator; shard metadata invariants (sizes, offsets,
capacities, total preserved); contiguous arrays sorted and read back
through the base pointer; repeated runs byte-identical (keys-only: the
sorted multiset is unique); shape-mismatch refusal; empty no-op.

Co-Authored-By: Claude Fable 5 <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