Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions projects/rccl/src/include/rccl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@ bool rcclDdaEnabled(const ncclComm* comm, size_t totalBytes, size_t gfx942Defaul

int getFirmwareVersion();
bool rcclIsArchSupportedForFunc(struct ncclTaskColl* info, char const* archName);

// Decide the host-side value of comm->cheapPostSendFenceOff.
// Returns 1 if the cheap post-send fence must be OFF (kernel uses the full
// __threadfence_system()), or 0 if the cheap post-send fence can be ON.
// cudaArch : numeric device arch (comm->cudaArch = 100*major +
// 10*minor, i.e. gfx942 = 940, gfx950 = 950,
// gfx1250 = 1250).
// param : RCCL_CHEAP_POST_SEND_FENCE_OFF value
// (0 = arch-tuned auto, 1 = force off, 2 = force on).
// uncachedMemSupported : whether cache-bypassing load/store builtins are
// available (HIP_UNCACHED_MEMORY); cheap fence is only
// safe when true.
int rcclComputeCheapPostSendFenceOff(int cudaArch, int64_t param, bool uncachedMemSupported);
#ifdef ENABLE_WARP_SPEED
RCCL_PARAM_DECLARE(WarpSpeedARThreshold);
RCCL_PARAM_DECLARE(WarpSpeedAutoMode);
Expand Down
31 changes: 21 additions & 10 deletions projects/rccl/src/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,23 @@ RCCL_PARAM(RocshmemEnabled, "ROCSHMEM_ENABLE", 1);
std::unordered_map<ncclComm_t, rocshmem::rocshmem_team_t> ncclCommToRshmemTeam;
#endif

// RCCL_CHEAP_POST_SEND_FENCE_OFF: 0 = arch-tuned (default), non-zero = force cheap fence off (__threadfence_system)
// RCCL_CHEAP_POST_SEND_FENCE_OFF: 0 = arch-tuned auto (default; cheap fence on for gfx942/gfx1250, off for gfx950),
// 1 = force cheap fence off (__threadfence_system), 2 = force cheap fence on (override auto, e.g. re-enable on gfx950)
RCCL_PARAM(CheapPostSendFenceOff, "CHEAP_POST_SEND_FENCE_OFF", 0);

int rcclComputeCheapPostSendFenceOff(int cudaArch, int64_t param, bool uncachedMemSupported) {
// Cheap fence is only safe when cache-bypassing load/store builtins are available.
if (!uncachedMemSupported) return 1;
// Force cheap fence on regardless of arch (override auto, e.g. re-enable on gfx950).
if (param == 2) return 0;
// Any other non-zero value forces the full __threadfence_system().
if (param != 0) return 1;
// Arch-tuned auto: cheap fence on for gfx942 (940) and gfx1250 (1250);
// off for gfx950 (950) and everything else.
if (cudaArch == 940 || cudaArch == 1250) return 0;
return 1;
}

/**
* Used on gfx1151 (StrixHalo) to set the nChannels for ncclTopoPreset before determining number of nodes.
*/
Expand Down Expand Up @@ -1799,17 +1813,14 @@ static ncclResult_t initTransportsRank(struct ncclComm* comm, struct ncclComm* p
if (IsArchMatch(comm->topo->nodes[GPU].nodes[idx].gpu.gcn, "gfx90a"))
allGather3Data[rank].nc = std::max(allGather3Data[rank].nc, 4 / ringGraph->nChannels);
if (ringGraph->nChannels > MAXCHANNELS / 2) allGather3Data[rank].nc = 1;
comm->cheapPostSendFenceOff = 1;
#ifdef HIP_UNCACHED_MEMORY
// cheap fence is only safe with cache bypassing load/store availability in kernel
// only enabled on gfx942, gfx950 and gfx1250
if (!rcclParamCheapPostSendFenceOff()) {
if (IsArchMatch(comm->topo->nodes[GPU].nodes[idx].gpu.gcn, "gfx942") ||
IsArchMatch(comm->topo->nodes[GPU].nodes[idx].gpu.gcn, "gfx950") ||
IsArchMatch(comm->topo->nodes[GPU].nodes[idx].gpu.gcn, "gfx1250"))
comm->cheapPostSendFenceOff = 0;
}
// cheap fence is only safe with cache bypassing load/store availability in kernel.
const bool uncachedMemSupported = true;
#else
const bool uncachedMemSupported = false;
#endif
comm->cheapPostSendFenceOff = rcclComputeCheapPostSendFenceOff(
comm->cudaArch, rcclParamCheapPostSendFenceOff(), uncachedMemSupported);
INFO(NCCL_INIT, "Cheap post-send fence is %s", comm->cheapPostSendFenceOff ? "OFF" : "ON");
// RCCL: Only use one slice per primitive on some single node gfx9xx systems, only currently enabled for AllReduce, ReduceScatter, and AllGather
if (IsArchMatch(comm->topo->nodes[GPU].nodes[idx].gpu.gcn, "gfx942") ||
Expand Down
1 change: 1 addition & 0 deletions projects/rccl/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ if(BUILD_TESTS)
ScatterTests.cpp
P2pChannelScalingTests.cpp
VersionGateTests.cpp
CheapPostSendFenceTests.cpp
SendRecvTests.cpp
StandaloneTests.cpp
DdaIpcTests.cpp
Expand Down
91 changes: 91 additions & 0 deletions projects/rccl/test/CheapPostSendFenceTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*************************************************************************
* Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
*
* See LICENSE.txt for license information
************************************************************************/

// Unit tests for rcclComputeCheapPostSendFenceOff(), the host-side decision
// for comm->cheapPostSendFenceOff. The return value gates whether the LL128 /
// simple post-send path issues the full __threadfence_system() (return 1, cheap
// fence OFF) or the cheap signal-only fence (return 0, cheap fence ON).
//
// Behavior under test:
// * cheap fence is only safe when cache-bypassing builtins are available
// (uncachedMemSupported); otherwise it must always be OFF.
// * RCCL_CHEAP_POST_SEND_FENCE_OFF param: 0 = arch-tuned auto, 1 = force off,
// 2 = force on (override auto).
// * auto (0) enables the cheap fence on gfx942/gfx1250 only; gfx950 and every
// other arch default to the full fence.

#include "gtest/gtest.h"
#include "rccl_common.h"

namespace RcclUnitTesting
{

// Numeric device archs (comm->cudaArch = 100*major + 10*minor).
static constexpr int kGfx942 = 940;
static constexpr int kGfx950 = 950;
static constexpr int kGfx1250 = 1250;
static constexpr int kGfx90a = 900;

// Param values.
static constexpr int64_t kAuto = 0;
static constexpr int64_t kForceOff = 1;
static constexpr int64_t kForceOn = 2;

TEST(CheapPostSendFenceTests, UncachedMemUnsupportedAlwaysOff)
{
// Without cache-bypass builtins the cheap fence is unsafe: always OFF (1),
// regardless of arch or param (including the force-on override).
for (int64_t param : {kAuto, kForceOff, kForceOn, (int64_t)3}) {
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx942, param, /*uncached=*/false), 1);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx950, param, /*uncached=*/false), 1);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx1250, param, /*uncached=*/false), 1);
}
}

TEST(CheapPostSendFenceTests, AutoModeArchTuned)
{
// Auto: cheap fence ON (0) for gfx942/gfx1250, OFF (1) for gfx950 and others.
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx942, kAuto, true), 0);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx1250, kAuto, true), 0);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx950, kAuto, true), 1);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx90a, kAuto, true), 1);
}

TEST(CheapPostSendFenceTests, ForceOffOverridesEveryArch)
{
// param == 1 forces the full fence even where auto would enable the cheap one.
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx942, kForceOff, true), 1);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx950, kForceOff, true), 1);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx1250, kForceOff, true), 1);
}

TEST(CheapPostSendFenceTests, ForceOnOverridesEveryArch)
{
// param == 2 forces the cheap fence ON regardless of arch, notably
// re-enabling it on gfx950 where auto disables it.
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx942, kForceOn, true), 0);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx950, kForceOn, true), 0);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx1250, kForceOn, true), 0);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx90a, kForceOn, true), 0);
}

TEST(CheapPostSendFenceTests, OtherNonZeroParamForcesOff)
{
// Any non-zero value other than 2 behaves like force-off (1).
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx942, /*param=*/3, true), 1);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(kGfx1250, /*param=*/-1, true), 1);
}

TEST(CheapPostSendFenceTests, UnknownArchDefaultsOff)
{
// An unrecognized arch must default to the full fence under auto/force-off,
// while force-on still returns ON (0).
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(/*cudaArch=*/0, kAuto, true), 1);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(/*cudaArch=*/0, kForceOff, true), 1);
EXPECT_EQ(rcclComputeCheapPostSendFenceOff(/*cudaArch=*/0, kForceOn, true), 0);
}

} // namespace RcclUnitTesting
Loading