Repository navigation
test(rccl): add host microtests for nccl_device/core.cc team helpers #13316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
aduforest
wants to merge
6
commits into
develop
from
users/aduforest/aicomrccl-2825-core-host-microtests
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
171f680
test(rccl): add host microtests for nccl_device/core.cc team helpers
aduforest 12d9413
test(rccl): address ARGUS findings on core.cc microtests
aduforest efc6421
test(rccl): pick a TeamRail rank where / and % differ
aduforest 854da50
test(rccl): pin ncclTeamWorld/RankToWorld staying ungated, fix fake-o…
aduforest 9d54be4
test(rccl): trim microtest docs and comments to match the other host …
aduforest b8776e6
test(rccl): follow the microtest naming and registration rules
aduforest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| /************************************************************************* | ||
| * Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| * | ||
| * See LICENSE.txt for license information | ||
| ************************************************************************/ | ||
|
|
||
| // Host-only microtests for src/nccl_device/core.cc's ncclTeam* and rank-translation helpers. | ||
| // ncclDevrInitOnce is faked so both its success and failure paths run. | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "fakes/dev_runtime_fakes.h" | ||
|
|
||
| #include CORE_CC_PATH | ||
|
|
||
| namespace { | ||
|
|
||
| class CoreMicrotest : public ::testing::Test { | ||
| protected: | ||
| std::unique_ptr<ncclComm> commStorage; | ||
| ncclComm* comm = nullptr; | ||
|
|
||
| void SetUp() override { | ||
| commStorage = std::make_unique<ncclComm>(); // value-initialised: POD members zeroed | ||
| comm = commStorage.get(); | ||
| } | ||
|
|
||
| void TearDown() override { ResetDevRuntimeFakes(); } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| TEST_F(CoreMicrotest, TeamWorld_ReturnsCommNRanksAndRankWithStrideOne) { | ||
| comm->nRanks = 4; | ||
| comm->rank = 2; | ||
| ncclTeam_t team = ncclTeamWorld(comm); | ||
| EXPECT_EQ(team.nRanks, 4); | ||
| EXPECT_EQ(team.rank, 2); | ||
| EXPECT_EQ(team.stride, 1); | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamWorldAndRankToWorld_IgnoreAFailingInitOnce) { | ||
| // The two that don't gate on ncclDevrInitOnce still return real values when it fails. | ||
| g_devrInitOnce = [](ncclComm*) { return ncclSystemError; }; | ||
| comm->nRanks = 4; | ||
| comm->rank = 2; | ||
| ncclTeam_t world = ncclTeamWorld(comm); | ||
| EXPECT_EQ(world.nRanks, 4); | ||
| EXPECT_EQ(world.rank, 2); | ||
| EXPECT_EQ(world.stride, 1); | ||
| ncclTeam_t team{/*nRanks=*/4, /*rank=*/2, /*stride=*/3}; | ||
| EXPECT_EQ(ncclTeamRankToWorld(comm, team, team.rank + 1), 5); // 2 + (3 - 2) * 3 | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamLsa_SuccessPath_ReadsLsaSizeAndSelfFromDevrState) { | ||
| comm->devrState.lsaSize = 8; | ||
| comm->devrState.lsaSelf = 3; | ||
| ncclTeam_t team = ncclTeamLsa(comm); | ||
| EXPECT_EQ(team.nRanks, 8); | ||
| EXPECT_EQ(team.rank, 3); | ||
| EXPECT_EQ(team.stride, 1); | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamLsa_InitOnceFails_ReturnsZeroedTeamWithoutReadingDevrState) { | ||
| // Poisoned, so reading them despite the failure shows up below. | ||
| comm->devrState.lsaSize = 99; | ||
| comm->devrState.lsaSelf = 99; | ||
| g_devrInitOnce = [](ncclComm*) { return ncclSystemError; }; | ||
| ncclTeam_t team = ncclTeamLsa(comm); | ||
| EXPECT_EQ(team.nRanks, 0); | ||
| EXPECT_EQ(team.rank, 0); | ||
| EXPECT_EQ(team.stride, 0); | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamCftMultimem_SuccessPath_ReadsCftMcSizeAndSelfFromDevrState) { | ||
| comm->devrState.cftMcSize = 16; | ||
| comm->devrState.cftMcSelf = 5; | ||
| ncclTeam_t team = ncclTeamCftMultimem(comm); | ||
| EXPECT_EQ(team.nRanks, 16); | ||
| EXPECT_EQ(team.rank, 5); | ||
| EXPECT_EQ(team.stride, 1); | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamCftMultimem_InitOnceFails_ReturnsZeroedTeam) { | ||
| comm->devrState.cftMcSize = 99; | ||
| comm->devrState.cftMcSelf = 99; | ||
| g_devrInitOnce = [](ncclComm*) { return ncclSystemError; }; | ||
| ncclTeam_t team = ncclTeamCftMultimem(comm); | ||
| EXPECT_EQ(team.nRanks, 0); | ||
| EXPECT_EQ(team.rank, 0); | ||
| EXPECT_EQ(team.stride, 0); | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamRail_SuccessPath_DividesCommNRanksAndRankByLsaSize) { | ||
| // 24/4 = 6 and 9/4 = 2 differ from the `%` results ncclTeamInnerFactor would give. | ||
| comm->nRanks = 24; | ||
| comm->rank = 9; | ||
| comm->devrState.lsaSize = 4; | ||
| ncclTeam_t team = ncclTeamRail(comm); | ||
| EXPECT_EQ(team.nRanks, 6); // 24 / 4 | ||
| EXPECT_EQ(team.rank, 2); // 9 / 4 | ||
| EXPECT_EQ(team.stride, 4); // == lsaSize | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamRail_InitOnceFails_ReturnsZeroedTeamWithoutDividingByLsaSize) { | ||
| // If the failure branch were missing, this would divide by zero instead. | ||
| comm->nRanks = 16; | ||
| comm->rank = 10; | ||
| comm->devrState.lsaSize = 0; | ||
| g_devrInitOnce = [](ncclComm*) { return ncclSystemError; }; | ||
| ncclTeam_t team = ncclTeamRail(comm); | ||
| EXPECT_EQ(team.nRanks, 0); | ||
| EXPECT_EQ(team.rank, 0); | ||
| EXPECT_EQ(team.stride, 0); | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamCft_FlatMode_ReturnsFlatTeamFromCftSizeAndSelf) { | ||
| comm->devrState.cftSize = 12; | ||
| comm->devrState.cftSelf = 7; | ||
| ncclTeam_t team = ncclTeamCft(comm, NCCL_CFT_TEAM_FLAT); | ||
| EXPECT_EQ(team.nRanks, 12); | ||
| EXPECT_EQ(team.rank, 7); | ||
| EXPECT_EQ(team.stride, 1); | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamCft_HierMultimemMode_OuterFactorsTheFlatTeamByCftMcSize) { | ||
| // lsaSize is a distinct non-zero value, so swapped mode arms give a wrong answer, not a crash. | ||
| comm->devrState.cftSize = 12; | ||
| comm->devrState.cftSelf = 7; | ||
| comm->devrState.cftMcSize = 3; | ||
|
aduforest marked this conversation as resolved.
Resolved
|
||
| comm->devrState.lsaSize = 2; | ||
| ncclTeam_t team = ncclTeamCft(comm, NCCL_CFT_TEAM_HIER_MULTIMEM); | ||
| EXPECT_EQ(team.nRanks, 4); // 12 / 3 | ||
| EXPECT_EQ(team.rank, 2); // 7 / 3 | ||
| EXPECT_EQ(team.stride, 3); // 1 * 3 | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamCft_HierLsaMode_OuterFactorsTheFlatTeamByLsaSize) { | ||
| // cftMcSize is distinct for the same reason. | ||
| comm->devrState.cftSize = 20; | ||
| comm->devrState.cftSelf = 9; | ||
| comm->devrState.lsaSize = 5; | ||
| comm->devrState.cftMcSize = 3; | ||
| ncclTeam_t team = ncclTeamCft(comm, NCCL_CFT_TEAM_HIER_LSA); | ||
| EXPECT_EQ(team.nRanks, 4); // 20 / 5 | ||
| EXPECT_EQ(team.rank, 1); // 9 / 5 | ||
| EXPECT_EQ(team.stride, 5); // 1 * 5 | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamCft_UnrecognisedMode_ReturnsZeroedTeam) { | ||
| comm->devrState.cftSize = 12; | ||
| comm->devrState.cftSelf = 7; | ||
| ncclTeam_t team = ncclTeamCft(comm, static_cast<ncclCftTeamMode_t>(99)); | ||
| EXPECT_EQ(team.nRanks, 0); | ||
| EXPECT_EQ(team.rank, 0); | ||
| EXPECT_EQ(team.stride, 0); | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamCft_InitOnceFails_ReturnsZeroedTeamRegardlessOfMode) { | ||
| comm->devrState.cftSize = 99; | ||
| comm->devrState.cftSelf = 99; | ||
| g_devrInitOnce = [](ncclComm*) { return ncclSystemError; }; | ||
| for (ncclCftTeamMode_t mode : {NCCL_CFT_TEAM_FLAT, NCCL_CFT_TEAM_HIER_MULTIMEM, NCCL_CFT_TEAM_HIER_LSA}) { | ||
| ncclTeam_t team = ncclTeamCft(comm, mode); | ||
| EXPECT_EQ(team.nRanks, 0); | ||
| EXPECT_EQ(team.rank, 0); | ||
| EXPECT_EQ(team.stride, 0); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamRankToWorld_MapsATeamLocalRankBackToItsWorldRankViaStride) { | ||
| // Pure arithmetic: doesn't gate on ncclDevrInitOnce. | ||
| comm->rank = 10; | ||
| ncclTeam_t team{/*nRanks=*/4, /*rank=*/2, /*stride=*/3}; | ||
| // comm->rank + (rank - team.rank) * team.stride | ||
| EXPECT_EQ(ncclTeamRankToWorld(comm, team, team.rank), 10); // self: offset 0 | ||
| EXPECT_EQ(ncclTeamRankToWorld(comm, team, team.rank + 1), 13); | ||
| EXPECT_EQ(ncclTeamRankToWorld(comm, team, team.rank - 1), 7); | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamRankToLsa_SuccessPath_MapsATeamLocalRankToAnLsaRankViaLsaSelf) { | ||
| comm->devrState.lsaSelf = 5; | ||
| ncclTeam_t team{/*nRanks=*/4, /*rank=*/2, /*stride=*/3}; | ||
| // devrState.lsaSelf + (rank - team.rank) * team.stride | ||
| EXPECT_EQ(ncclTeamRankToLsa(comm, team, team.rank), 5); | ||
| EXPECT_EQ(ncclTeamRankToLsa(comm, team, team.rank + 1), 8); | ||
|
aduforest marked this conversation as resolved.
Resolved
|
||
| EXPECT_EQ(ncclTeamRankToLsa(comm, team, team.rank - 1), 2); // 5 + (-1)*3 | ||
| } | ||
|
|
||
| TEST_F(CoreMicrotest, TeamRankToLsa_InitOnceFails_ReturnsNegativeOneWithoutReadingLsaSelf) { | ||
| comm->devrState.lsaSelf = 99; | ||
| g_devrInitOnce = [](ncclComm*) { return ncclSystemError; }; | ||
| ncclTeam_t team{/*nRanks=*/4, /*rank=*/2, /*stride=*/3}; | ||
| EXPECT_EQ(ncclTeamRankToLsa(comm, team, team.rank), -1); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # rccl-UnitTestsMicroCore — shared/ctest schema. | ||
| # Host-only micro-tests for src/nccl_device/core.cc (no GPU, no librccl). | ||
| # RCCL does not support Windows: exclude_windows matches all tests so generated suites are empty on Windows. | ||
|
|
||
| test_categories: | ||
| quick: µ_core_quick | ||
| description: "Smoke — host-only nccl_device/core.cc team-helper micro-tests, sub-second." | ||
| test_patterns: | ||
| - "Core*" | ||
| exclude_windows: | ||
| - "*" | ||
| labels: | ||
| - "rccl" | ||
| - "quick" | ||
| - "smoke" | ||
| - "precheck" | ||
| - "microtest" | ||
| standard: | ||
| <<: *micro_core_quick | ||
| labels: | ||
| - "rccl" | ||
| - "standard" | ||
| - "regression" | ||
| - "microtest" | ||
| comprehensive: | ||
| <<: *micro_core_quick | ||
| labels: | ||
| - "rccl" | ||
| - "comprehensive" | ||
| - "comprehensive_regression" | ||
| - "microtest" | ||
| full: | ||
| <<: *micro_core_quick | ||
| labels: | ||
| - "rccl" | ||
| - "full" | ||
| - "full_regression" | ||
| - "microtest" | ||
|
|
||
| execution_settings: | ||
| timeout_multiplier: 1 | ||
| category_timeouts: | ||
| quick: 600 | ||
| standard: 600 | ||
| comprehensive: 600 | ||
| full: 600 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.