Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
17 changes: 17 additions & 0 deletions projects/rccl/test/host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ function(rccl_define_micro_source_lists)
../common/ProcessIsolatedTestRunner.cpp
PARENT_SCOPE)

set(TEST_MICRO_GIN_HOST_SOURCE_FILES
gin-host-test.cc
fakes/nccl_fakes.cc
fakes/os_fakes.cc
../common/main_altrsmi.cpp
PARENT_SCOPE)

# rccl-UnitTestsMicroEnqueue(+-devlinker) -- src/enqueue.cc.
set(TEST_MICRO_ENQUEUE_SOURCE_FILES
enqueue-test.cc
Expand Down Expand Up @@ -810,6 +817,16 @@ foreach(_variant "" "-uncached" "-faultinj")
endif()
endforeach()

# ---------------------------------------------------------------------------
# rccl-UnitTestsMicroGinHost
# ---------------------------------------------------------------------------
rccl_add_micro_binary(rccl-UnitTestsMicroGinHost
SOURCES ${TEST_MICRO_GIN_HOST_SOURCE_FILES}
EXTRA_DEFS
${_MICRO_MODE_DEFS}
GIN_HOST_CC_PATH="${RCCL_HOST_HIPIFY_DIR}/src/gin/gin_host.cc"
CATEGORIES_YAML "${CMAKE_CURRENT_SOURCE_DIR}/../test_categories_micro_ginhost.yaml")

# ---------------------------------------------------------------------------
# rccl-UnitTestsMicroEnqueue (+ shipping -devlinker arm standalone)
# ---------------------------------------------------------------------------
Expand Down
226 changes: 36 additions & 190 deletions projects/rccl/test/host/MICROTEST_README.md

Large diffs are not rendered by default.

169 changes: 169 additions & 0 deletions projects/rccl/test/host/gin-host-test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*************************************************************************
* Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
*
* See LICENSE.txt for license information
************************************************************************/

#include <gtest/gtest.h>
Comment thread
mch marked this conversation as resolved.
Resolved
#include <memory>

#include <sched.h>
#include <thread>

#include "fakes/nccl_fakes.h"
#include "fakes/os_fakes.h"

#include "nccl.h"
#include "comm.h"
#include "gin/gin_host.h"

#include "fakes/param_redirect.h"

#include GIN_HOST_CC_PATH

extern "C" ncclTeam_t ncclTeamRail(ncclComm_t) {
ncclTeam_t team{};
team.nRanks = 1;
team.rank = 0;
team.stride = 1;
return team;
}
void ncclSetThreadName(std::thread&, const char*, ...) {}

namespace {

class GinHostProxyAffinityMicrotest : public ::testing::Test {
protected:
ncclGinState ginState_;

void SetUp() override {
ResetOsFakes();
CPU_ZERO(&ginState_.cpuAffinity);
ginState_.proxyThreadStopSignal.store(true); // exit at the top of the loop
ginState_.writePending.store(false);
}

void TearDown() override { ResetOsFakes(); }

// Run ncclGinProgress on a fresh thread (so the affinity apply, if the fake
// were real, would land on a throwaway thread rather than the test runner)
// and wait for it to return.
void RunProgressOnce() {
std::thread t([this] { ncclGinProgress(&ginState_, /*threadIdx=*/0); });
t.join();
}
};

TEST_F(GinHostProxyAffinityMicrotest, NonEmptyAffinity_PinsProxyThreadToThatCpuSet) {
CPU_SET(3, &ginState_.cpuAffinity);
g_ncclOsCpuCountValue = 1;

RunProgressOnce();

ASSERT_EQ(1u, g_ncclOsSetAffinityMasks.size());
EXPECT_TRUE(CPU_ISSET(3, &g_ncclOsSetAffinityMasks[0]));
EXPECT_EQ(1, CPU_COUNT(&g_ncclOsSetAffinityMasks[0]));
}

TEST_F(GinHostProxyAffinityMicrotest, EmptyAffinity_LeavesProxyThreadAffinityUnchanged) {
g_ncclOsCpuCountValue = 0;

RunProgressOnce();

EXPECT_EQ(1, g_ncclOsCpuCountCalls);
EXPECT_TRUE(g_ncclOsSetAffinityMasks.empty());
}

struct FakeGinBackend {
ncclNetDeviceHandle_t devHandle{};
void* ginCtx = reinterpret_cast<void*>(0x1);
int createContextCalls = 0;
};
FakeGinBackend* g_fakeGinBackend = nullptr;

ncclResult_t FakeCreateContext(void* /*collComm*/, ncclGinConfig_t* /*config*/, void** ginCtx,
ncclNetDeviceHandle_t** devHandle) {
g_fakeGinBackend->createContextCalls++;
g_fakeGinBackend->devHandle.handle = reinterpret_cast<void*>(0x2);
g_fakeGinBackend->devHandle.needsProxyProgress = 1;
*ginCtx = g_fakeGinBackend->ginCtx;
*devHandle = &g_fakeGinBackend->devHandle;
return ncclSuccess;
}

ncclResult_t FakeDestroyContext(void* /*ginCtx*/) { return ncclSuccess; }

// The producer: ginDevCommSetupWithBackend copies comm->cpuAffinity into
// ginState->cpuAffinity (gin_host.cc:393) on the branch that first spawns the
// progress threads, so the consumer above has a populated set to read on a real
// comm. Drive that setup path with a scripted backend and assert the copy.
class GinHostProxyAffinitySetupMicrotest : public ::testing::Test {
protected:
std::unique_ptr<ncclComm> comm_ = std::make_unique<ncclComm>();
std::unique_ptr<ncclSharedResources> sr_ = std::make_unique<ncclSharedResources>();
FakeGinBackend fakeBackend_;
ncclGin_t vtable_{};
ncclDevComm devComm_{};

void SetUp() override {
ResetOsFakes();
g_fakeGinBackend = &fakeBackend_;

comm_->sharedRes = sr_.get();
struct ncclGinState& ginState = sr_->ginState;
ginState.ginConnectionType = NCCL_GIN_CONNECTION_FULL; // connectedStride == 1
ginState.proxyNthreads = 1;
ginState.proxyThreadsCreated = false; // so needsStart is true
ginState.proxyThreadStopSignal.store(true); // spawned threads exit immediately
ginState.writePending.store(false);

vtable_.name = "fake-gin";
vtable_.createContext = &FakeCreateContext;
vtable_.destroyContext = &FakeDestroyContext;

struct ncclGinBackendState& backend = ginState.backends[0];
backend.ginType = NCCL_GIN_TYPE_PROXY;
backend.ncclGin = &vtable_;
backend.ginCommCount = 1;
backend.ginComms[0] = reinterpret_cast<void*>(0x10);
}

void TearDown() override {
struct ncclGinState& ginState = sr_->ginState;
for (int t = 0; t < ginState.proxyNthreads; t++) {
if (ginState.thread[t].joinable()) ginState.thread[t].join();
}

if (ginState.devComms != nullptr) {
EXPECT_EQ(ncclSuccess, ncclGinDevCommFree(comm_.get(), &devComm_));
}
g_fakeGinBackend = nullptr;
ResetOsFakes();
}
};

TEST_F(GinHostProxyAffinitySetupMicrotest, StashesCommAffinityBeforeSpawningProxyThreads) {
CPU_ZERO(&comm_->cpuAffinity);
CPU_SET(5, &comm_->cpuAffinity); // a distinctive mask to spot the copy
g_ncclOsCpuCountValue = 1; // so the spawned worker takes the pin branch

struct ncclGinState& ginState = sr_->ginState;
ncclDevCommRequirements reqs{};
reqs.ginContextCount = 1;
reqs.ginConnectionType = NCCL_GIN_CONNECTION_NONE; // requestedStride stays 1
reqs.ginTrafficClass = NCCL_CONFIG_UNDEF_INT;

ncclResult_t ret =
ginDevCommSetupWithBackend(comm_.get(), &reqs, &devComm_, /*deviceCodeVersion=*/0, &ginState.backends[0]);

ASSERT_EQ(ncclSuccess, ret);
EXPECT_EQ(1, fakeBackend_.createContextCalls); // the setup path really ran
EXPECT_TRUE(ginState.proxyThreadsCreated); // it took the spawn branch
EXPECT_TRUE(CPU_EQUAL(&comm_->cpuAffinity, &ginState.cpuAffinity)); // comm mask stashed verbatim
Comment thread
mch marked this conversation as resolved.
Resolved

ginState.thread[0].join();
ASSERT_EQ(1u, g_ncclOsSetAffinityMasks.size());
EXPECT_TRUE(CPU_EQUAL(&comm_->cpuAffinity, &g_ncclOsSetAffinityMasks[0]));
}

} // namespace
1 change: 1 addition & 0 deletions projects/rccl/test/host/run_host_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ do_host_tests() {
"rccl-UnitTestsMicroEnqueue-devlinker:$SCRIPT_DIR/host_tests_micro_enqueue_devlinker.xml"
"rccl-UnitTestsMicroSymKernels:$SCRIPT_DIR/host_tests_micro_symkernels.xml"
"rccl-UnitTestsMicroTaskPrep:$SCRIPT_DIR/host_tests_micro_taskprep.xml"
"rccl-UnitTestsMicroGinHost:$SCRIPT_DIR/host_tests_micro_ginhost.xml"
)
# Binaries that only exist for some CMake option settings (rccl-UnitTestsMicroSymKernels needs
# GENERATE_SYM_KERNELS, off via install.sh --disable-sym-kernels); missing is a skip, not an error.
Expand Down
42 changes: 42 additions & 0 deletions projects/rccl/test/test_categories_micro_ginhost.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
test_categories:
quick: &micro_ginhost_quick
description: "Smoke — host-only src/gin/gin_host.cc micro-tests (GIN proxy affinity paths), sub-second."
test_patterns:
- "GinHost*"
exclude_windows:
- "*"
labels:
- "rccl"
- "quick"
- "smoke"
- "precheck"
- "microtest"
standard:
<<: *micro_ginhost_quick
labels:
- "rccl"
- "standard"
- "regression"
- "microtest"
comprehensive:
<<: *micro_ginhost_quick
labels:
- "rccl"
- "comprehensive"
- "comprehensive_regression"
- "microtest"
full:
<<: *micro_ginhost_quick
labels:
- "rccl"
- "full"
- "full_regression"
- "microtest"

execution_settings:
timeout_multiplier: 1
category_timeouts:
quick: 600
standard: 600
comprehensive: 600
full: 600
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@
"tests": [
{"name": "SymKernelsMicrotests", "description": "Host-only sym_kernels.cc/sym_kernels_host.cc microtests (no GPU, no HIP/RCCL runtime); contributes sym_kernels coverage", "test_filter": "*"}
]
},
"unit_tests_micro_ginhost": {
"is_gtest": true,
"binary": "host/rccl-UnitTestsMicroGinHost",
"num_ranks": 1,
"num_nodes": 1,
"num_gpus": 1,
"timeout": 60,
"tests": [
{"name": "GinHostMicrotests", "description": "Host-only gin/gin_host.cc microtests (no GPU, no HIP/RCCL runtime); contributes gin_host.cc coverage", "test_filter": "*"}
]
}
},
"test_suites": [
Expand Down Expand Up @@ -271,6 +282,12 @@
"description": "rccl-UnitTestsMicroSymKernels (host-only sym_kernels.cc microtests, no GPU/HIP/RCCL runtime)",
"config": "unit_tests_micro_symkernels",
"enabled": true
},
{
"name": "RCCL Microtests - gin_host.cc",
"description": "rccl-UnitTestsMicroGinHost (host-only gin/gin_host.cc microtests, no GPU/HIP/RCCL runtime)",
"config": "unit_tests_micro_ginhost",
"enabled": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3286,7 +3286,8 @@ def generate_coverage_report(self):
"rccl-UnitTestsMicroInit-uncached",
"rccl-UnitTestsMicroInit-faultinj",
"rccl-UnitTestsMicroEnqueue",
"rccl-UnitTestsMicroSymKernels"]:
"rccl-UnitTestsMicroSymKernels",
"rccl-UnitTestsMicroGinHost"]:
binary_path = os.path.join(host_test_dir, binary)
if os.path.isfile(binary_path):
object_files.extend(["--object", binary_path])
Expand Down