﻿# RCCL AllGather: sendcount counts typed elements, while the receive buffer spans ranks

Allocate and interpret RCCL AllGather buffers using per-rank typed counts and communicator rank order instead of passing tensor byte lengths as element counts.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-rccl-allgather-count-elements-rank-layout/
Language: en

## Identify the unit of the collective count

The [RCCL library specification](https://rocm.docs.amd.com/projects/rccl/en/latest/api-reference/library-specification.html) defines collective counts in elements of the declared datatype. A framework may expose its tensor size in bytes, but passing that number directly as a typed element count requests different communication. Derive the count from the logical payload and keep datatype width separate when allocating bytes. Check the same interpretation on every rank instead of relying on identical pointer types.

## Allocate the complete gathered result

AllGather collects the per-rank contribution into a receive representation containing rank-ordered blocks. Its destination therefore differs from a same-size reduction output. Write down the contribution size and communicator membership before allocating the final region. A local test with distinguishable rank payloads can show the intended concatenation without requiring a large model. Ensure a downstream tensor view describes the gathered result rather than only the original local shard.

## Keep rank identity separate from device numbering

The [RCCL API reference](https://rocm.docs.amd.com/projects/rccl/en/latest/api-reference/api-library.html) provides communicator rank and device information as separate concepts. Device ordinal in a process is not automatically the rank position of its contribution. Preserve the communicator mapping when reshaping a gathered buffer back into model shards. Otherwise, data can be numerically valid yet attached to the wrong logical shard, especially when initialization order or process-to-device assignment changes.

## Respect the documented in-place arrangement

An in-place collective is not arbitrary input/output overlap. Follow the operation's required placement of the local contribution within the receive buffer and retain that region until the collective is complete. A large shared allocation can still have the wrong local offset. Validate both ordinary and intended in-place operation against the same rank-identifiable example, and check that no independent producer overwrites another rank's destination during communication.

## Test correctness before interpreting bandwidth

The [current RCCL test project](https://github.com/ROCm/rocm-systems/tree/develop/projects/rccl-tests) provides correctness and performance tooling for collective operations. Match the tested count units and datatype to the application's actual payload. The existing [HIP portability guide](/journal/learn-hip-launch-portability/) and [stream-dependency guide](/journal/learn-stream-ordering-dependencies/) support related context. A useful result states per-rank elements, total receive storage, rank mapping and completion boundaries before making communication-throughput claims.
