Skip to content

Sort with many chares per GPU - #26

Open
AdvaitTahilyani wants to merge 8 commits into
scale/10-alloc-reusefrom
scale/11-sort-many-chares
Open

AdvaitTahilyani wants to merge 8 commits into
scale/10-alloc-reusefrom
scale/11-sort-many-chares

Conversation

@AdvaitTahilyani

Copy link
Copy Markdown

Stacked on #25.

  • Above 64 chares, sort buckets go to one chare per PE, so the exchange is O(chares × PEs) instead of O(chares²).

~1,900 chares: 8 s → 0.4 s on CPU; the 2e9-element A100 sort no longer times out.

Tested (full stack): CPU +p1/+p2 15/15 originals, 25/25 ports, 30/30 ops; A100 1 GPU 15/15, 25/25, 30/30 and 4 GPUs (one process per GPU) 15/15, 25/25.

🤖 Generated with Claude Code

AdvaitTahilyani and others added 2 commits November 3, 2026 23:41
With ~1,900 chares the sample sort still sent P buckets from every chare
(P^2 piece and count messages): 2e9 elements at CNUM_ODF=2048 on one GPU ran
past 300 s, and the same chare count on CPU took 8 s per sort. Above 64
participants the buckets now go to the first chare of each PE (at most 256);
splitters sit at those chares' tile starts, so the sorted runs mostly land on
the same PE, and chares without a bucket only wait for their result tile.
The CPU case drops to 0.4 s; on one A100 the run completes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@adityapb adityapb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: request changes.

This is a static review. Line numbers are at this PR's head.

The protocol change is consistent, so there's no hang:

  • Owners wait for P counts.
  • The root waits for owner.size() S_NB messages.
  • Non-owners skip the sort.

The problem is where the bucket boundaries go.

  1. [major] Above 64 chares, almost all the data goes to one chare.
    • Where: executor_sort.cpp:886-904, together with chare_home_pe (array_region.hpp:459), which places 1-D chares round-robin.
    • Cause:
      • The owners are the first chare on each PE, i.e. participants 0..E−1 (E = number of PEs).
      • Splitter j sits at pstart[owner[j]]/n ≈ j/P.
      • So buckets 0..E−2 get about one tile each, and the last owner gets n·(1−(E−1)/P).
    • Examples:
      • With 4 GPUs and 128 chares, chare 3 sorts 97.7% of the array. For an argsort of 2e9 float32 elements that's about 70 GB on one GPU.
      • The PR's own CPU +p2 run (~1,900 chares) puts 99.95% of the elements on chare 1.
    • The output is still correct.
    • Fix: put splitter j at fraction j/B (or at each owner PE's cumulative share), or pick owners evenly spaced among the participants.
    • Still at #44.
  2. Nit: the owner array is read through reinterpret_cast<const int64_t*> at an offset that isn't 8-byte aligned for 1-, 2- or 4-byte keys when nspl is odd (:923). #28 switched the neighbouring reads to memcpy but not this one.

Splitters sat at the owners' tile starts; owners are the first chare of each
PE (participants 0..E-1 under round-robin placement), so the last bucket got
nearly the whole array. Bucket j now ends at the cumulative share of the
elements on owner PEs 0..j (evenly when kMaxBuckets leaves PEs without a
bucket). The owner list is read with memcpy (unaligned after 1-4 byte keys).
CNUM_SORT_DEBUG=1 prints the largest bucket per sort.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AdvaitTahilyani

AdvaitTahilyani commented Nov 10, 2026 •

Copy link
Copy Markdown
Author
  1. Splitters above 64 chares: fixed in 5cbb51f. Bucket j now ends at the cumulative share of the elements on owner PEs 0..j (an even split when kMaxBuckets leaves some PEs without a bucket). CNUM_SORT_DEBUG=1 prints the largest bucket per sort.
  2. Nit, unaligned owner read: fixed in 5cbb51f (memcpy).

Validated on the nc build of this head:

  • CPU regress at +p1 and +p2: orig 15/15, ports 25/25, ops 29/29 (test_sort_scale passes).
  • Bucket balance at +p2 with 1,908 chares and n=5e8 (sort int64, sort float32, argsort float32): largest bucket 50.02-50.06% (even split is 50%) (the review measured 99.95% before the fix). 100 chares: 50.00-50.21%. Output is sorted and the permutation is complete.
  • The 4-GPU check (sort balance with 128 chares on 4 GPUs plus test_sort_scale) is pending as Slurm job 23722396.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AdvaitTahilyani

Copy link
Copy Markdown
Author

GPU check on 4 A100s: with 128 chares on 4 buckets, the largest bucket is 25.14–25.23% (even split: 25.00%). sortbal (6 checks) and test_sort_scale pass.

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.

2 participants