Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/rccl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Full documentation for RCCL is available at [https://rccl.readthedocs.io](https:
* `RCCL_FABRIC_TELEMETRY_ENABLE` (default `0`): samples every amd-smi fabric telemetry category for the GPUs this process opens communicators on and logs the counters that moved, plus a closing report over the whole sampled span when a device's last communicator is destroyed. Diagnostic only, and off by default. Also needs `RCCL_USE_AMD_SMI_LIB=1` and `render`-group access to the IFoE config character device; without either, RCCL logs why telemetry was skipped and initialization continues.
* `RCCL_FABRIC_TELEMETRY_INTERVAL_MS` (default `1000`): sampling period for `RCCL_FABRIC_TELEMETRY_ENABLE`, clamped to a 100 ms floor and a one-hour ceiling. A non-positive value disables telemetry entirely.
* Hierarchical symmetric `ncclAllGather` for multi-node using GIN and LSA (`AllGather_RailRing_LsaST`): a GIN ring over the rails team moves data between nodes and LSA stores broadcast it to the other GPUs in each node.
* Hierarchical symmetric `ncclAllGather` for partition mode in gfx1250 scale-up domain using LSA (`AllGater_HierLsaST`): each rank stores its data once to its counterpart partition on every other GPU, which forwards it to the other partitions there, so data crosses to each GPU once instead of once per partition.
* nccl4py: per-call collective configuration (`NCCLCollConfig`, `VendorOption`) including the launch completion event, communicator properties (`NCCLCommProperties`), and the `GIN_ONLY` window flag. On ROCm, the HIP `Event` shim provides only an event handle; `record()`, `sync()` and `query` are not implemented.
* `RCCL_TUNER_EMBEDDED_CONFIG` (default `1`): the built-in CSV tuner configurations in `tuner/*.csv` are now compiled into `librccl.so` and used as the stock tuning defaults, so a cluster no longer has to stage the CSV on every node or on NFS. Set `0` to ignore the embedded configurations. `NCCL_TUNER_CONFIG_FILE` and the on-disk tuner directories still take precedence, and `NCCL_TUNER_PLUGIN=none` still disables the tuner entirely.
* `RCCL_TUNING_PARTITION_MODE` (`auto`, `SPX` or `DPX`; default `auto`): selects the gfx1250 tuning table for the GPU's compute-partition mode. `auto` uses the DPX table when the GPU reports DPX, and the SPX table otherwise. A communicator uses the DPX table only when every rank selects it. The DPX table is currently a copy of the SPX table, so tuning is unchanged.
Expand Down
15 changes: 8 additions & 7 deletions projects/rccl/src/config/algorithm_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// Each row's mask bit IS its cost-model tuning id, so the mask lines up 1:1 with
// src/tuning/cost_model.cc modelMap[] (collMask mirrors modelMap[].enabled[func]):
// general -> bit (algo*NCCL_NUM_PROTOCOLS + proto), the [0,21) space
// symmetric -> bit (NCCL_TUNING_SYM_KERNEL_ID_OFFSET + symKernelId), the [21,40) space
// symmetric -> bit (NCCL_TUNING_SYM_KERNEL_ID_OFFSET + symKernelId), the [21,41) space
// Commented rows are algo/proto combinations that do not exist today; they mark where a
// future kernel would slot into the tuning-id space.
// IMPORTANT: this table need must be consistent with the modelMap in src/tuning/cost_model.cc
Expand Down Expand Up @@ -65,13 +65,14 @@ static constexpr struct ncclAlgRegEntry algRegistry[] = {
{"SYMK_STMC", ALGBIT(31), F_AG, -1, -1, ncclSymkKernelId_AllGather_STMC},
{"SYMK_RailRing_LsaST", ALGBIT(32), F_AG, -1, -1, ncclSymkKernelId_AllGather_RailRing_LsaST},
{"SYMK_RailRing_LsaSTMC", ALGBIT(33), F_AG, -1, -1, ncclSymkKernelId_AllGather_RailRing_LsaSTMC},
{"SYMK_HierLsaST", ALGBIT(34), F_AG, -1, -1, ncclSymkKernelId_AllGather_HierLsaST},
Comment thread
nawrinsu marked this conversation as resolved.
Resolved
// Symmetric ReduceScatter kernels
{"SYMK_LL", ALGBIT(34), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_LL},
{"SYMK_TmaLD", ALGBIT(35), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_TmaLD},
{"SYMK_LD", ALGBIT(36), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_LD},
{"SYMK_LDMC", ALGBIT(37), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_LDMC},
{"SYMK_RailA2A_LsaLD", ALGBIT(38), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_RailA2A_LsaLD},
{"SYMK_RailA2A_LsaLDMC", ALGBIT(39), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_RailA2A_LsaLDMC},
{"SYMK_LL", ALGBIT(35), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_LL},
{"SYMK_TmaLD", ALGBIT(36), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_TmaLD},
{"SYMK_LD", ALGBIT(37), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_LD},
{"SYMK_LDMC", ALGBIT(38), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_LDMC},
{"SYMK_RailA2A_LsaLD", ALGBIT(39), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_RailA2A_LsaLD},
{"SYMK_RailA2A_LsaLDMC", ALGBIT(40), F_RS, -1, -1, ncclSymkKernelId_ReduceScatter_RailA2A_LsaLDMC},
};
// clang-format on
static constexpr int algRegistryCount = (int)(sizeof(algRegistry) / sizeof(algRegistry[0]));
Expand Down
168 changes: 149 additions & 19 deletions projects/rccl/src/device/symmetric/all_gather.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
template <int BytePerPack, int UnrollPacks, int UnrollPeers, bool EnableTma, bool TileAligned = false>
static __device__ void bcastDeep(ncclSymkArgsHandler const& handler, int tn, int t, bool waitNeeded,
ncclLsaBarrierSession<ncclCoopCta>& bar, ncclSymPtr<char> input,
ncclSymPtr<char> output, bool inPlace, int nIters) {
ncclSymPtr<char> output, bool inPlace, int nIters, ncclTeam team, int slot0) {
using Pack = BytePack<BytePerPack>;
int wn = tn / WARP_SIZE;
int w = t / WARP_SIZE;
int lane = t % WARP_SIZE;
int const& rank = handler.comm.rank;
int const& nRanks = handler.comm.nRanks;
int const& rank = team.rank;
int const& nRanks = team.nRanks;

Pack* inpPacks = (Pack*)input.localPtr() + intptr_t(w) * UnrollPacks * WARP_SIZE +
(
Expand Down Expand Up @@ -95,13 +95,13 @@ static __device__ void bcastDeep(ncclSymkArgsHandler const& handler, int tn, int
if (partial && dr + ur == nRanks) break;
#if NCCL_SYMK_ASYNC_TILE
if NCCL_IF_CONSTEXPR (EnableTma) {
ncclSymkTileStore<TileAligned>(outLsa(r), tmaSmem->buff[0], tileSize, lane);
ncclSymkTileStore<TileAligned>(outLsa(slot0 + r), tmaSmem->buff[0], tileSize, lane);
} else
#endif
{
NVCC_PRAGMA_UNROLL(UnrollPacks)
for (int u = 0; u < UnrollPacks; u++) {
outLsa(r)[u * WARP_SIZE] = tmp[u];
outLsa(slot0 + r)[u * WARP_SIZE] = tmp[u];
}
}
if (++r == nRanks) r = 0;
Expand Down Expand Up @@ -135,9 +135,10 @@ static __device__ void bcastDeep(ncclSymkArgsHandler const& handler, int tn, int

template <int UnrollPeers, typename T>
static __device__ void bcastEnds(ncclSymkArgsHandler const& handler, int tn, int t, ncclSymPtr<T> input,
ncclSymPtr<T> output, bool inPlace, size_t nElts, uint32_t nPreElts, size_t nSufElts) {
int const& rank = handler.comm.rank;
int const& nRanks = handler.comm.nRanks;
ncclSymPtr<T> output, bool inPlace, size_t nElts, uint32_t nPreElts, size_t nSufElts,
ncclTeam team, int slot0) {
int const& rank = team.rank;
int const& nRanks = team.nRanks;
BytePack<sizeof(T)>* inpPacks = (BytePack<sizeof(T)>*)input.localPtr();
ncclLsaPointerGetter<BytePack<sizeof(T)>> outLsa((ncclSymPtr<BytePack<sizeof(T)>>)output);
NVCC_PRAGMA_UNROLL_DISABLED
Expand All @@ -151,24 +152,32 @@ static __device__ void bcastEnds(ncclSymkArgsHandler const& handler, int tn, int
for (; dr + UnrollPeers <= nRanks; dr += UnrollPeers) {
NVCC_PRAGMA_UNROLL(UnrollPeers)
for (int u = 0; u < UnrollPeers; u++) {
outLsa(r)[elt] = tmp;
outLsa(slot0 + r)[elt] = tmp;
if (++r == nRanks) r = 0;
}
}
NVCC_PRAGMA_UNROLL(UnrollPeers)
for (int u = 0; u < UnrollPeers; u++) {
if (dr + u == nRanks) break;
outLsa(r)[elt] = tmp;
outLsa(slot0 + r)[elt] = tmp;
if (++r == nRanks) r = 0;
}
}
}

template <typename T, bool EnableTma>
// Copy `input` into `output` on every rank of `team`, which must be a unit-stride sub-team of the
// LSA team, or only on LSA slot `dstSlot` when one is given.
template <typename T, bool EnableTma, bool Deep = false>
static __device__ void bcast(ncclSymkArgsHandler const& handler, int tn, int t, int nBlocks, bool waitNeeded,
ncclLsaBarrierSession<ncclCoopCta>& bar, ncclSymPtr<T> input, ncclSymPtr<T> output,
size_t nElts) {
bool inPlace = (input == output);
size_t nElts, ncclTeam team, int dstSlot = -1) {
// A single destination is always written, even when input and output name the same offset.
bool inPlace = dstSlot < 0 && input == output;
int slot0 = ncclTeamRankToLsa(handler.comm, team, 0);
if (dstSlot >= 0) {
team = ncclTeam{/*nRanks=*/1, /*rank=*/0, /*stride=*/1};
slot0 = dstSlot;
}
size_t nBytes = nElts * sizeof(T);

#if defined(__gfx950__)
Expand Down Expand Up @@ -204,7 +213,7 @@ static __device__ void bcast(ncclSymkArgsHandler const& handler, int tn, int t,
// multiple of 256, so the tiles are ncclSymkTileLine-aligned and the peel can go.
bcastDeep<BytePerPack, UnrollPacks, UnrollPeers, EnableTma, /*TileAligned=*/true>(
handler, tn, t, waitNeeded, bar, (ncclSymPtr<char>)input + cursor,
(ncclSymPtr<char>)output + cursor, inPlace, chunks * ncclSymkMinWarpsPerBlock);
(ncclSymPtr<char>)output + cursor, inPlace, chunks * ncclSymkMinWarpsPerBlock, team, slot0);
cursor = cursorAfter;
waitNeeded = false;
}
Expand All @@ -218,7 +227,7 @@ static __device__ void bcast(ncclSymkArgsHandler const& handler, int tn, int t,
// of falling to the 4-byte and per-byte paths. One pack per peer lets UnrollPeers batch them all.
constexpr int UnrollPacks = 1, UnrollPeers = 8;
#else
constexpr int UnrollPacks = ncclSymkUnrollPacks, UnrollPeers = 2;
constexpr int UnrollPacks = Deep ? 4 * ncclSymkUnrollPacks : ncclSymkUnrollPacks, UnrollPeers = 2;
#endif
constexpr int BytePerPack = ncclSymkBytePerPack;
constexpr int BytePerChunk = ncclSymkGetBytesPerChunk(ncclSymkMinWarpsPerBlock, UnrollPacks);
Expand All @@ -231,7 +240,7 @@ static __device__ void bcast(ncclSymkArgsHandler const& handler, int tn, int t,
bcastDeep<BytePerPack, UnrollPacks, UnrollPeers, EnableTma>(handler, tn, t, waitNeeded, bar,
(ncclSymPtr<char>)input + cursor,
(ncclSymPtr<char>)output + cursor, inPlace,
chunks * ncclSymkMinWarpsPerBlock);
chunks * ncclSymkMinWarpsPerBlock, team, slot0);
cursor = cursorAfter;
waitNeeded = false;
}
Expand All @@ -254,7 +263,7 @@ static __device__ void bcast(ncclSymkArgsHandler const& handler, int tn, int t,
uintptr_t cursorAfter = cursor + uintptr_t(chunks) * BytePerChunk;
bcastDeep<(sizeof(T) <= BytePerPack ? BytePerPack : 0), UnrollPacks, UnrollPeers, false>(
handler, tn, t, waitNeeded, bar, (ncclSymPtr<char>)input + cursor, (ncclSymPtr<char>)output + cursor, inPlace,
chunks * ncclSymkMinWarpsPerBlock);
chunks * ncclSymkMinWarpsPerBlock, team, slot0);
cursor = cursorAfter;
waitNeeded = false;
}
Expand All @@ -264,7 +273,7 @@ static __device__ void bcast(ncclSymkArgsHandler const& handler, int tn, int t,

constexpr int UnrollPeers = 8;
size_t nSufElts = (nBytes - cursor) / sizeof(T);
bcastEnds<UnrollPeers>(handler, tn, t, input, output, inPlace, nElts, nPreBytes / sizeof(T), nSufElts);
bcastEnds<UnrollPeers>(handler, tn, t, input, output, inPlace, nElts, nPreBytes / sizeof(T), nSufElts, team, slot0);
}

template <bool EnableProfiler, bool EnableTma>
Expand All @@ -289,7 +298,8 @@ __device__ __forceinline__ void ncclSymkRun_AllGather_ST_impl(ncclSymkDevWorkArg
int bt =
flattenIx(threadIdx.x % WARP_SIZE, WARP_SIZE, block, nBlocks, threadIdx.x / WARP_SIZE, blockDim.x / WARP_SIZE);
int btn = nBlocks * blockDim.x;
bcast<char, EnableTma>(handler, btn, bt, nBlocks, waitNeeded, bar, input, output + rank * nAllElts, nElts);
bcast<char, EnableTma>(handler, btn, bt, nBlocks, waitNeeded, bar, input, output + rank * nAllElts, nElts,
ncclTeamLsa(handler.comm));
waitNeeded = false;
});

Expand All @@ -307,6 +317,126 @@ __device__ __forceinline__ void ncclSymkRun_AllGather_TmaST(ncclSymkDevWorkArgs
ncclSymkRun_AllGather_ST_impl<EnableProfiler, /*EnableTma=*/true>(args);
}

// Largest chunk a block pushes.
static constexpr size_t ncclSymkAgHierMaxChunkBytes = 256 << 10;

static __device__ void agHierPush(ncclSymkArgsHandler const& handler, ncclLsaBarrierSession<ncclCoopCta>& bar,
int block, int nBlocks, ncclTeam scaleIn, ncclTeam scaleUp,
ncclDevResourceHandle flagsBuf, uint64_t& seq, size_t nElts, size_t nAllElts,
ncclSymPtr<char> input, ncclSymPtr<char> output) {
int const& rank = handler.comm.rank;
int lane = threadIdx.x % WARP_SIZE;
int warp = threadIdx.x / WARP_SIZE;
int nBlockWarps = blockDim.x / WARP_SIZE;
int nGroups = scaleUp.nRanks;
int nG0Blocks = ncclSymkAgHierG0Blocks(nBlocks, nGroups);
int nGroupBlocks = ncclSymkAgHierGroupBlocks(nBlocks, nGroups);
// Units below nRows hold a block of every group, the rest a block of each pushing group.
int nRows = nGroups * nG0Blocks;
int nUnits = nG0Blocks + (nGroups - 1) * nGroupBlocks;
ncclSymPtr<char> mySlot = output + rank * nAllElts;

// Half of each block pushes and half forwards, threads numbered over the half.
int nHalfWarps = nBlockWarps / 2;
bool pusher = warp < nHalfWarps;
bool forwarder = !pusher && warp < 2 * nHalfWarps;
int t = (pusher ? warp : warp - nHalfWarps) * WARP_SIZE + lane;
int tn = nHalfWarps * WARP_SIZE;
ncclCoopWarpSpan half{/*warp0=*/pusher ? 0 : nHalfWarps, /*nWarps=*/nHalfWarps, /*id=*/pusher ? 0 : 1};

// Every block of a group pushes the same number of chunks of up to ncclSymkAgHierMaxChunkBytes, each a
// multiple of ncclSymkBytePerChunk per warp, so bcast()'s 16-byte tier copies it all, split evenly.
size_t chunkAlign = size_t(nHalfWarps) * ncclSymkBytePerChunk;
size_t nBlockChunksMax = max(size_t(1), divUp(divUp(nElts, size_t(nGroupBlocks)), ncclSymkAgHierMaxChunkBytes));
size_t chunkBytes = roundUp(divUp(nElts, nBlockChunksMax * nGroupBlocks), chunkAlign);
size_t nChunks = chunkBytes == 0 ? 0 : divUp(nElts, chunkBytes);
size_t flagRow = size_t(blockIdx.x) * nGroups;

for (int unit = block; unit < nUnits; unit += nBlocks) {
int group = unit < nRows ? unit % nGroups : 1 + (unit - nRows) % (nGroups - 1);
int groupBlock = unit < nRows ? unit / nGroups : nG0Blocks + (unit - nRows) / (nGroups - 1);
if (group == 0) {
int bt = flattenIx(lane, WARP_SIZE, groupBlock, nG0Blocks, warp, nBlockWarps);
bcast<char, /*EnableTma=*/false, /*Deep=*/true>(handler, nG0Blocks * blockDim.x, bt, /*nBlocks=*/1,
/*waitNeeded=*/false, bar, input, mySlot, nElts, scaleIn);
continue;
}

int to = scaleUp.rank + group;
if (to >= nGroups) to -= nGroups;
int from = scaleUp.rank - group;
if (from < 0) from += nGroups;
int toSlot = ncclTeamRankToLsa(handler.comm, scaleUp, to);
ncclSymPtr<char> fromSlot = output + ncclTeamRankToWorld(handler.comm, scaleUp, from) * nAllElts;

// The block's chunk i is chunk i * nGroupBlocks + groupBlock of the slot.
int nBlockChunks = groupBlock < nChunks ? int(divUp(nChunks - groupBlock, size_t(nGroupBlocks))) : 0;
if (pusher) {
uint64_t* flags = (uint64_t*)ncclGetResourceBufferLsaPointer(handler.comm, flagsBuf, toSlot);
cuda::atomic_ref<uint64_t> flag(flags[flagRow + group]);
for (int i = 0; i < nBlockChunks; i++) {
size_t lo = (size_t(i) * nGroupBlocks + groupBlock) * chunkBytes;
bcast<char, false, /*Deep=*/true>(handler, tn, t, 1, false, bar, input + lo, mySlot + lo,
min(chunkBytes, nElts - lo), scaleIn, toSlot);
// half.sync() orders every pusher warp's stores before this system-scope fence
half.sync();
if (t == 0) {
cuda::atomic_thread_fence(cuda::memory_order_release, cuda::thread_scope_system);
Comment thread
nawrinsu marked this conversation as resolved.
Resolved
flag.store(seq + i + 1, cuda::memory_order_relaxed);
}
}
} else if (forwarder) {
uint64_t* flags = (uint64_t*)ncclGetResourceBufferLocalPointer(handler.comm, flagsBuf);
cuda::atomic_ref<uint64_t> flag(flags[flagRow + group]);
for (int i = 0; i < nBlockChunks; i++) {
if (t == 0) {
uint32_t steps = 0;
while (flag.load(cuda::memory_order_relaxed) < seq + i + 1) {
if (nccl::utility::testAbort(handler.comm.abortFlag, steps)) break;
}
cuda::atomic_thread_fence(cuda::memory_order_acquire, cuda::thread_scope_system);
}
half.sync();
size_t lo = (size_t(i) * nGroupBlocks + groupBlock) * chunkBytes;
bcast<char, false, /*Deep=*/true>(handler, tn, t, 1, false, bar, fromSlot + lo, fromSlot + lo,
min(chunkBytes, nElts - lo), scaleIn);
}
}
seq += nBlockChunks;
}
}

// Two-level load/store AllGather for an LSA team over packages of hierScaleInSize consecutive ranks.
// Each rank pushes its slot to its counterpart on every other package, which forwards it to its
// package peers, so each remote slot reaches a package once.
template <bool EnableProfiler>
__device__ __forceinline__ void ncclSymkRun_AllGather_HierLsaST(ncclSymkDevWorkArgs const* args) {
Comment thread
nawrinsu marked this conversation as resolved.
Resolved
ncclSymkArgsHandler handler{args};
ncclLsaBarrierSession<ncclCoopCta> bar{ncclCoopCta(), handler.comm, ncclTeamTagLsa(), blockIdx.x};

ncclTeam lsa = ncclTeamLsa(handler.comm);
ncclTeam scaleIn = ncclTeamInnerFactor(lsa, args->kcomm.hierScaleInSize);
ncclTeam scaleUp = ncclTeamOuterFactor(lsa, args->kcomm.hierScaleInSize);
// Group 0 raises no flag, so its slot in our row keeps the block's chunk count across launches.
uint64_t* seqSlot = (uint64_t*)ncclGetResourceBufferLocalPointer(handler.comm, args->kcomm.hierPushFlags) +
size_t(blockIdx.x) * scaleUp.nRanks;
uint64_t seq = *seqSlot;

ncclCoopNamedBarrierInit();
bar.sync(ncclCoopCta(), cuda::memory_order_acquire);
if NCCL_IF_CONSTEXPR (EnableProfiler) ncclSymkProfilerPhase(args, NCCL_KERNEL_PHASE_AFTER_OPEN);

handler.forEachWork<char>([&] __device__(int block, int nBlocks, size_t nElts, size_t nAllElts,
ncclSymPtr<char> input, ncclSymPtr<char> output) {
agHierPush(handler, bar, block, nBlocks, scaleIn, scaleUp, args->kcomm.hierPushFlags, seq, nElts, nAllElts, input,
output);
});
if (threadIdx.x == 0) *seqSlot = seq;

if NCCL_IF_CONSTEXPR (EnableProfiler) ncclSymkProfilerPhase(args, NCCL_KERNEL_PHASE_BEFORE_CLOSE);
bar.sync(ncclCoopCta(), cuda::memory_order_release);
}

template <bool EnableProfiler, bool EnableTma>
__device__ __forceinline__ void ncclSymkRun_AllGather_STMC_impl(ncclSymkDevWorkArgs const* args) {
ncclSymkArgsHandler handler{args};
Expand Down
2 changes: 1 addition & 1 deletion projects/rccl/src/device/symmetric/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __hash__(me):
have_tdm = "gfx1250" in gpu_targets

def enumerate_kernels():
ag_algos = ["LL","ST","RailRing_LsaST"] + (["TmaST"] if have_tdm else [])
ag_algos = ["LL","ST","RailRing_LsaST"] + (["TmaST"] if have_tdm else []) + ["HierLsaST"]
# AllGather_TmaSTMC and the other *MC algos need multimem, which ROCm has no
# equivalent for, so they stay out regardless of the target.
ar_algos = ["AGxLL_R","RSxLD_AGxST"] + (["RSxTmaLD_AGxTmaST"] if have_tdm else [])
Expand Down
Loading
Loading