Two days inside MSCCL++ on an A100: 5x allgather, 2.4x allreduce, and a deadlock that needs fewer than 128 SMs
MSCCL++ is Microsoft's GPU communication library. One way to use it is as a drop-in NCCL replacement: preload libmscclpp_nccl.so and every ncclAllReduce or ncclAllGather goes to MSCCL++ algorithms, with real NCCL as the fallback. Most of its tuning targets H100 and Blackwell. I ran it on two A100-SXM4-80GB GPUs connected by NVLink, compared it with NCCL 2.29 using NVIDIA's nccl-tests, and followed every number that looked wrong. That produced seven pull requests, all in review at the time of writing.
Results
| change | before | after | PR |
|---|---|---|---|
| allgather, 1 MB total, no CUDA graph | 143 µs (NCCL: 20 µs) | 27 µs | #990 |
| allreduce, 2 MB, CUDA graph | 50 µs (NCCL: 45 µs) | 19 µs | #993 |
| allreduce, 16 MB, CUDA graph | 127 µs (NCCL: 124 µs) | 84 µs | #993 |
| allreduce ≥ 64 MB, uint8 min | hangs | completes | #992 |
| 100k allreduce calls | +420 MB GPU, +870 MB host per rank | flat | #986 |
bf16, 2 ranks, medians of 3 interleaved rounds of 500–1000 iterations, 0 wrong values. Every run was checked for other processes on the GPUs and repeated if any appeared (the machine is shared).
1. A fixed 135 µs in every small allgather
By default, the shim runs without "symmetric memory". The user's buffers can then change from call to call, so the default allgather algorithm (fullmesh2, zero-copy) registers both buffers and exchanges their IPC handles with every peer over the bootstrap network on every call. That puts a floor of about 135 µs under every allgather up to 32 MB, whatever the size: 8 KB and 8 MB took about the same time.
The library already had a second allgather, fullmesh, which stages data through a buffer that is registered once. Selecting it for non-graph calls up to 16 MB gave 5.0–5.5x from 8 KB to 1 MB and 2.4x at 8 MB. Two details mattered more than the switch itself:
- CUDA graphs reverse the trade-off. My first version also used
fullmeshunder graph capture, and small graph-mode allgathers became 2.5x slower. Under capture, the handle exchange happens once, and the zero-copy kernel is faster on every replay. The final version keepsfullmesh2under capture. - Every selection condition must be the same on all ranks. I first required 16-byte-aligned buffers. Copilot's review pointed out that alignment is per rank: with rank 0 aligned and rank 1 offset by two bytes, the ranks pick different algorithms and wait for each other forever. I reproduced that hang, then made the kernel alignment-agnostic (each rank picks 16/8/4/2/1-byte accesses for its own buffers, which does not change what goes over the wire). The same review found that the staging writes could be misread as ready flags by packet-based allreduce sharing the buffer. That reproduced too, as a wrong allreduce at iteration 5, and the fix was a dedicated staging buffer.
2. Fast allreduce algorithms that A100 never used
On GPUs without NVLS (A100, and most PCIe GPUs), the selector handed every allreduce above 1 MB to NCCL. Forcing each candidate algorithm with a small experiment switch showed that the algorithms Blackwell already uses are faster here too:
| size | NCCL, graph | rsag_zero_copy, graph | NCCL, no graph | rsag / rsag_pipeline, no graph |
|---|---|---|---|---|
| 2 MB | 45 µs | 19 µs | 59 µs | 41 µs |
| 8 MB | 79 µs | 47 µs | 87 µs | 69 µs |
| 32 MB | 224 µs | 158 µs | 220 µs | 201 µs |
| 256 MB | 1492 µs | 1204 µs | 1429 µs | 1436 µs (left to NCCL) |
#993 selects them on non-NVLS GPUs, with only rank-uniform conditions: size divisible into whole 16-byte vectors per rank, a supported rank count, and at most 16 ranks for the pipeline variant, whose stage must fit the 128 MB scratch buffer. Copilot raised all three of those during review, and each was a real out-of-bounds or invalid-configuration case.
3. A deadlock that needs fewer than 128 SMs
Testing #993 across data types, uint8 min at 64 MB hung. Sum at the same size was fine, and so was min at 48 MB. The zero-copy kernel synchronizes all of its blocks with a grid-wide barrier, so every block must be resident at once. From 64 MB up it launches 128 blocks of 1024 threads. cuobjdump --dump-resource-usage explained the rest:
- uint8 sum uses 32 registers per thread, so two 1024-thread blocks fit per SM: 216 resident blocks on an A100.
- uint8 min uses 36 registers, so one block fits per SM: 108 resident blocks. The other 20 never start, and the barrier never completes.
H100 (132 SMs) and B200 (148 SMs) hold 128 blocks even at one per SM, which is why this had not been seen. The fix in #992 caps the grid with cudaOccupancyMaxActiveBlocksPerMultiprocessor. Copilot added one more requirement: the cap must be the same on every rank, because block i pairs with block i on each peer. The ranks now agree on the smallest SM count during initialization.
4. Leaks and silently wrong results
- Context leak (#986). Without symmetric memory, three algorithms created a fresh context on every call, and the shim cached each one forever. The fix releases them after their work completes, in batches of 256. A Microsoft maintainer reviewed it and asked for an API change, which I made.
- Out-of-bounds write in
mscclpp::copy(#989). A copy shorter than the distance to the next aligned address underflowed an unsigned count, so a 2-rank allgather of two fp16 values per rank crashed. - uint32 min was wrong (#991). The kernels reduce uint32 as int32. That is fine for sum but wrong for min: about half of the elements in each nccl-tests run were wrong, with no error reported.
- Unsupported types and ops (#991). int8, int64 and float64 aborted the process even with NCCL available, and
max/prodreturnedinvalid argument. They now go to the fallback, and a CI step covers all 19 combinations.
What I would do again
- Benchmark with and without CUDA graphs. In this library they change which algorithm wins.
- On a shared machine, verify the measurement environment, not just the code. Two of my sweeps were ruined by jobs that appeared mid-run; a wrapper that retries any run during which another process touched the GPUs fixed that.
- Treat any per-rank input to a collective decision (buffer addresses, SM counts) as a potential hang.
- A grid-wide barrier needs an occupancy check. A launch configuration that fits on the GPU you tuned on can deadlock on the next one.
- Automated review is worth reading closely: it found two hangs and three out-of-bounds cases in my own patches.
Caveats
Everything above was measured with 2 ranks on one pair of NVLink-connected A100s. Thresholds may move with 4 or 8 ranks, and PCIe-only GPUs are untested. Allreduce on buffers that are not 16-byte aligned is still an open question for the native paths (main already fails at ≤ 1 MB), and I asked the maintainers how they would like it handled. All seven PRs were still under review when this was written.
I used Claude (Anthropic) to help investigate, write the patches and draft this post. I ran and checked the measurements myself.